def insert_data_type(data_type): session = Session() info = DataTypeInfo(title=data_type['title'], attrs=json_wrapper.dumps(data_type['attrs'])) session.add(info) session.commit() result = info.id session.close() return result
def insert_data(data): session = Session() info = DataInfo(data_type_id=data['data_type_id'], attrs=json_wrapper.dumps(data['attrs']), time=data['time']) session.add(info) session.commit() result = info.id session.close() return result
def insert_task(task_info): session = Session() info = TaskInfo(input_data_type_id=task_info['input_data_type_id'], time_range=task_info['time_range'], functions=json_wrapper.dumps(task_info['functions']), result_data_type_id=task_info['result_data_type_id'], title=task_info['title']) session.add(info) session.commit() result = info.id session.close() return result
def dump_to_file(self, path): file = open(path, 'w') structure = { 'learn_rate': self.__learn_rate, 'default_weight': self.__default_weight, 'input_nodes': self.__input_nodes, 'output_nodes': self.__output_nodes, 'relations': self.__relations, 'weights': self.__weights, 'thetas': self.__thetas } file.write(json_wrapper.dumps(structure)) file.close()
import requests import json_wrapper course_id = { 'html': 'LgWwihnoEeWDtQoum3sFeQ', 'front': 'ycQnChn3EeWDtQoum3sFeQ', 'server': 'ngZrURn5EeWwrBKfKrqlSQ', 'angularJS': '52blABnqEeW9dA4X94-nLQ', 'mobile': '-gcU5xn4EeWwrBKfKrqlSQ', 'web': 'DzdXURoCEeWg_RJGAuFGjw' } for course in course_id: id = course_id[course] url = 'https://www.coursera.org/api/feedback.v1/?q=course&courseId=' + id + '&feedbackSystem=STAR&ratingValues=1%2C2%2C3%2C4%2C5&categories=generic&start=0&limit=1000000' r = json_wrapper.dumps(requests.get(url).json()) with open('./coursera_comment_info_' + course + '_all.json', 'w') as fo: fo.write(r) f_completed = json_wrapper.dumps(requests.get(url + '&courseCompleted=true').json()) with open('./coursera_comment_info_' + course + '_completed.json', 'w') as fo: fo.write(f_completed) # # r = requests.get("https://www.coursera.org/api/feedback.v1/?q=course&courseId=LgWwihnoEeWDtQoum3sFeQ&feedbackSystem=STAR&ratingValues=1%2C2%2C3%2C4%2C5&categories=generic&start=0&limit=1000000&courseCompleted=true").json() # fo = open("./coursera_comment_info_html_completed.json", "w") # fo.write(str(r)) # # r = requests.get("https://www.coursera.org/api/feedback.v1/?q=course&courseId=LgWwihnoEeWDtQoum3sFeQ&feedbackSystem=STAR&ratingValues=1%2C2%2C3%2C4%2C5&categories=generic&start=0&limit=1000000").json() # fo = open("./coursera_comment_info_html_all.json", "w") # fo.write(str(r)) # # r = requests.get("https://www.coursera.org/api/feedback.v1/?q=course&courseId=ycQnChn3EeWDtQoum3sFeQ&feedbackSystem=STAR&ratingValues=1%2C2%2C3%2C4%2C5&categories=generic&start=0&limit=100000&courseCompleted=true").json()
attempts = sum(map(lambda x: get_attempts(x[0]), result8)) result_user.append(attempts) for x in result_user: if x < 0: print uid break features.append(result_user) return features conn = MySQLdb.connect(host="localhost", user="******", passwd="Mdb4Learn", db="eLearning") all_users = [] all_features = [] all_grades = [] for term in terms: users, grades = get_users(conn, term) features = get_features(conn, term, users) all_users.extend(users) all_grades.extend(grades) all_features.extend(features) with open('data.json', 'w') as f: f.write( json_wrapper.dumps({ 'features': all_features, 'grades': all_grades }))
import MySQLdb import json_wrapper sql = "select student_id, created, modified" \ " from 102_2x_4T2015_courseware_studentmodule" \ " where module_type='problem' and grade is not NULL" sql2 = "select count(*)" \ " from clickstream.HKUSTx_COMP102_1x_4T2015_clickstream" \ " where user_id = %s and event_type = 'play_video' and event_time >= %s and event_time <= %s;" conn = MySQLdb.connect(host="localhost", user="******", passwd="Mdb4Learn", db="eLearning") c = conn.cursor() c.execute(sql) homeworks = c.fetchall() result = {} for row in homeworks: student_id = row[0] if str(student_id) not in result: result[str(student_id)] = 0 c.execute(sql2, (student_id, row[1], row[2])) if c.fetchall()[0][0] > 0: result[str(student_id)] += 1 with open('homework_video.json', 'w') as f: f.write(json_wrapper.dumps(result) + '\n')