Skip to content

Instantly share code, notes, and snippets.

@John-Lin
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save John-Lin/7730bcd2f8e2ce852b6f to your computer and use it in GitHub Desktop.

Select an option

Save John-Lin/7730bcd2f8e2ce852b6f to your computer and use it in GitHub Desktop.
Moocs
import csv
def get_mail_list(fileobj):
mail_list = []
for row in csv.reader(fileobj):
if row[1] != '':
mail_list.append(row[1])
fileobj.close()
return mail_list
def get_course_id(fileobj):
course_list = []
for row in csv.reader(fileobj):
if row[2] != '' and row[2] == 41:
course_list.append(row[2])
fileobj.close()
return course_list
def get_id_by_mail(target, mail_list):
for i in mail_list:
if mail_list[i] == target:
return i+1
if __name__ == "__main__":
# writer = csv.writer(f6)
f1 = open('learning_log.csv')
f2 = open('all12.4.csv')
f3 = open('usr_account.csv')
f = open("uuid_email_video_exercise.csv", "w")
w = csv.writer(f)
# video_count=[]
# exercise_count=[]
# video_count = {'uuid': times}
video_count = {}
exercise_count = {}
uuid_email_vc_ec = {}
# Get video counts and exercise counts by using uuid
# usage: video_times = video_count.get(uuid)
# exercise_times = exercise_count.get(uuid)
for row in csv.reader(f1):
if row[2] == '41' and row[3] == '0':
if video_count.get(row[1]) is None:
video_count[row[1]] = 0
video_count[row[1]] = video_count[row[1]] + 1
if row[2] == '41' and row[3] == '1':
if exercise_count.get(row[1]) is None:
exercise_count[row[1]] = 0
exercise_count[row[1]] = exercise_count[row[1]] + 1
f1.close()
# print video_count.get('16079')
# print exercise_count.get('16127')
print len(video_count.keys())
print len(exercise_count.keys())
# print video_count.keys()
# for row in csv.reader(f3):
# if row[0] in video_count.keys() or row[0] in exercise_count.keys():
# uuid_email_vc_ec[row[0]] = [row[1], video_count.get(row[0]),
# exercise_count.get(row[0])]
# f3.close()
# print uuid_email_vc_ec.get('16127')
# print len(uuid_email_vc_ec.keys())
# Get uuid by using email
# usage: uuid = uuid_email.get('[email protected]')
uuid_email = {}
for row in csv.reader(f3):
uuid_email[row[1]] = row[0]
f3.close()
data = []
all_1204_mail_list = get_mail_list(f2)
for email in all_1204_mail_list:
uuid = uuid_email.get(email)
data.append([uuid, email, video_count.get(uuid),
exercise_count.get(uuid)])
# for uuid in uuid_email_vc_ec.iterkeys():
# if uuid_email_vc_ec[uuid][0] in all_1204_mail_list:
# data.append([uuid, uuid_email_vc_ec[uuid][0],
# uuid_email_vc_ec[uuid][1], uuid_email_vc_ec[uuid][2]])
# print all_1204_mail_list
w.writerows(data)
f.close()
# print data[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment