Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished week 9 alexander tsankov #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
111 changes: 111 additions & 0 deletions 12tone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python

"""
12tone.py -- print 12-tone matrix

Copyright (c) 2004 L. Peter Deutsch. All rights reserved.
See below for copying permission.

This program prints the matrix of transposed prime and inverted rows
derived from a 12-tone row. Its usage is:
"""
USAGE = 'Usage: python 12tone.py note1 ... note12 > matrix.txt'
"""
Each note is a letter A..G (upper or lower case) optionally followed by a
# or + for sharp or a &, b, or - for flat. There must be exactly 12
notes with no repetitions of the same pitch.

The matrix always uses sharps to indicate displaced tones. As usual, the
original row is the top row, and its inversion is the left column.

Example of usage (with a row by Dalla Piccola):

python 12tone.py A# B D# F# G# D Db G C A E > matrix.txt

---------------- Copying permission ----------------

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

If you redistribute modified sources, we would appreciate that you include
in them history information documenting your changes.
"""

import sys
from cStringIO import StringIO

PITCH2NOTE = ('C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B')
NOTE2PITCH = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
ACCDELTA = {'#': 1, '+': 1, '&': -1, 'b': -1, '-': -1}

def formatRow(items, sepr = '|'):
buf = StringIO()
buf.write(sepr)
for item in items:
buf.write(item.rjust(3) + ' ' + sepr)
return buf.getvalue()

def pitch(row, rownum, colnum):
return (row[colnum] + row[0] - row[rownum] + 12) % 12

def interval(lower, upper):
diff = upper - lower
if diff < 0: diff += 12
return diff

def printMatrix(row):
print
rule = ' +' + 12 * '----+'
top = ' ' + formatRow(map(lambda p: str(interval(row[0], p)), row), ' ')
print top
print rule
for i in range(12):
notes = map(lambda j: PITCH2NOTE[pitch(row, i, j)].ljust(2), range(12))
label = ' %2d ' % interval(row[0], pitch(row, i, 0))
print label + formatRow(notes) + label
print rule
print top

def main():
args = sys.argv[1:]
if len(args) != 12:
print USAGE
return
row = []
for note in args:
try:
if len(note) == 1:
pitch = NOTE2PITCH[note.upper()]
elif len(note) == 2:
pitch = NOTE2PITCH[note[0].upper()] + ACCDELTA[note[1]]
else:
pitch = {}[note] # causes KeyError
except KeyError:
print 'Invalid note:', note
return
if not 0 <= pitch < 12:
print 'Invalid note:', note
return
row.append(pitch)
copy = row[:]
copy.sort()
if copy != range(12):
print 'Duplicate note(s) not allowed'
return
printMatrix(row)

if __name__ == '__main__':
main()
92 changes: 46 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
# Name

write-your-name
Alexander Tsankov

# How many points have you earned?

0/100
100/100

(Make your own calculation and replace the number 0 with the points you think you've earned.)

# How many hours have you spent on this?

fill-in-your-answer
5

# When did you first start working on this week's learning challenges?

fill-in-your-answer
Saturday (10/25/14)

# What is the most difficult part about this week's challenge?

fill-in-your-answer
Getting started with the mongodb queries. Th is some weird syntax and really different from general SQL.

# Show and tell (8 points)

## Link (2 points)

[title-of-the-article](http://link-to-an-article-about-machine-learning-use-for-big-data)
[Rise of the thinkbots](http://www.pcworld.com/article/2839092/big-data-digest-rise-of-the-thinkbots.html)

## Discuss how you may apply the machine learning technique mentioned in this article to another interesting problem (6 points).

fill-in-your-answer
We can use information about how users interact with a webpage to customize dashboards on the fly. I think the idea of making custom UIs tailored to individuals would be very useful across multiple domains.

# D3 IV

## Checkpoints (3 points x 4 = 12 points)

# 1. (3 points)

![image](image.png?raw=true)
![image](checkpoint-1.png)

[checkpoint](checkpoint.html)
[checkpoint](checkpoint-1.html)

# 2. (3 points)

![image](image.png?raw=true)
![image](checkpoint-2.png)

[checkpoint](checkpoint.html)
[checkpoint](checkpoint-2.html)

# 3. (3 points)

![image](image.png?raw=true)
![image](checkpoint-3.png)

[checkpoint](checkpoint.html)
[checkpoint](checkpoint-3.html)

# 4. (3 points)

![image](image.png?raw=true)
![image](checkpoint-4.png)

[checkpoint](checkpoint.html)
[checkpoint](checkpoint-4.html)

## Challenges (4 points x 3 = 12 points)

# 1. (4 points)

![image](image.png?raw=true)
![image](d3-challenge-1.png)

# 2. (4 points)

![image](image.png?raw=true)
![image](d3-challenge-2.png)

# 3. (4 points)

![image](image.png?raw=true)
![image](d3-challenge-3.png)

[challenge3](challenge3.html)

Expand All @@ -82,89 +82,89 @@ fill-in-your-answer

### 1 (6 points)

[mongodb js code collecting github events about our course](mongodb-github.js)
[mongodb js code collecting github events about our course](mon-checkpoint-1.js)

### 2 (6 points)

![terminal output of mongodb query](screenshot.png?raw=true)
![terminal output of mongodb query](mon-checkpoint-2.png)

## Challenge 1 (4 points x 10 = 40 points)

### 1 (4 points)

> db.course_events.[complete this query]
> db.course_events.findOne({'actor.login':'antsankov'})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-1.png)

### 2 (4 points)

> db.course_events.[complete this query]
> db.course_events.findOne({'actor.login':'doubleshow'},{'actor' :1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-2.png)

### 3 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'actor.login': {$in :['doubleshow','chrisbopp']}},{'actor.login' :1},{'created_at':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-3.png)

### 4 (4 points)

> db.course_events.[complete this query]
> db.course_events.findOne({'type':'PushEvent'})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-4.png)

### 5 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'type': 'PushEvent'},{'payload.commits.author.name': 1} )

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-5.png)

### 6 (4 points)

> db.course_events.[complete this query]
> db.course_events.findOne({'type' : 'IssuesEvent'}, {'payload':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-6.png)

### 7 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'type' : 'IssuesEvent'}, {'payload.issue.user.login':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-7.png)

### 8 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'type' : { $in:['IssuesEvent']},'payload.issue.state' : 'closed'}, {'payload.issue.title':1 , 'payload.issue.state':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-8.png)

### 9 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'type' : { $in:['IssuesEvent']},'payload.issue.state' : 'open'}, {'payload.issue.user.login':1 , 'payload.issue.state':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-9.png)

### 10 (4 points)

> db.course_events.[complete this query]
> db.course_events.find({'type' : { $in:['IssuesEvent']},'payload.issue.comments' : {$gt : 0} }, {'payload.issue.user.login':1 , 'payload.issue.comments':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-10.png)


## Challenge 2 (8 points x 2 = 16 points)

### 1 (8 points)

{question-in-plain-English}
What is the most commented issue in the data set? The query below answers this question by sorting the issues by their number of comments with most commented on the top

> db.course_events.[complete this query]
> db.course_events.find({'type' : { $in:['IssuesEvent']},'payload.issue.comments' : {$gt : 0} }, {'payload.issue.user.login':1 , 'payload.issue.comments':1}).sort({'payload.issue.comments' : -1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-11.png)

### 2 (8 points)

{question-in-plain-English}
Which members of the class have gravatars tied ot their github account? This query lists users who have interacted with the repos who have gravitar ids.

> db.course_events.[complete this query]
> db.course_events.find({'actor.gravatar_id':{$exists: true}}, {'actor.login':1})

![screenshot](screenshot.png?raw=true)
![screenshot](m-challenge-12.png)
Loading