forked from joerunde/edx-adapt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix review comments and recommendations
- Loading branch information
1 parent
5118fea
commit 368301c
Showing
12 changed files
with
271 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,85 @@ | ||
import requests, json, sys | ||
import json | ||
import re | ||
|
||
from config import EDX, EDXADAPT | ||
from edx_adapt.api import adapt_api | ||
|
||
DO_BASELINE_SETUP = False | ||
COURSE_ID = 'course-v1:CMU+STAT101+2014_T1' | ||
# EDXADAPT_HOST = sys.argv[1] | ||
# EDX_HOST = sys.argv[2] | ||
|
||
from edx_adapt.api import adapt_api | ||
|
||
skill2index = {} # Skill names to their indices | ||
problem2skill = {} # Dictionary of problems (seq_problemid) to their skill indices | ||
test2skill = {} # Dictionary of pretest problems to their skill indices | ||
num_pretest_per_skill = [] # Number of pretest questions per skill | ||
skill2seq = [] # list of sets, where the list index is the skill index, and the value is the set of sequentials with problems corresponding to that skill | ||
SKILL2INDEX = {} # Skill names to their indices | ||
PROBLEM2SKILL = {} # Dictionary of problems (seq_problemid) to their skill indices | ||
TEST2SKILL = {} # Dictionary of pretest problems to their skill indices | ||
NUM_PRETEST_PER_SKILL = [] # Number of pretest questions per skill | ||
SKILL2SEQ = [] # list of sets, where the list index is the skill index, and the value is the set of sequentials with | ||
# problems corresponding to that skill | ||
# The above are filled using skills.csv file, so any changes to the skill structure must be specified in the skills.csv | ||
|
||
|
||
def prepare_course(course_id): | ||
""" | ||
Add course into edx-adapt. | ||
Skills are taken from skill_test.csv and course's problems from problist.tsv | ||
""" | ||
app = adapt_api.app.test_client() | ||
headers = {'Content-type': 'application/json'} | ||
payload = json.dumps({'course_id': course_id}) | ||
# r = requests.post('http://{HOST}:{PORT}/api/v1/course'.format(**EDXADAPT), data=payload, headers=headers) | ||
r = app.post('/api/v1/course', data=payload, headers=headers) | ||
app.post('/api/v1/course', data=payload, headers=headers) | ||
with open("data/BKT/skills_test.csv", "r") as fin: | ||
max_skill_index = 0 | ||
pretest2skill = {} | ||
for line in fin: | ||
tokens = line.strip().split(",") | ||
if tokens[2] not in skill2index: | ||
skill2index[tokens[2]] = max_skill_index | ||
if tokens[2] not in SKILL2INDEX: | ||
SKILL2INDEX[tokens[2]] = max_skill_index | ||
max_skill_index += 1 | ||
skill2seq.append(set()) | ||
num_pretest_per_skill.append(0) | ||
skill_index = skill2index[tokens[2]] | ||
SKILL2SEQ.append(set()) | ||
NUM_PRETEST_PER_SKILL.append(0) | ||
skill_index = SKILL2INDEX[tokens[2]] | ||
|
||
if tokens[0].endswith("assessment"): | ||
if tokens[0].startswith("Pre"): | ||
pretest2skill[int(tokens[1])] = skill_index | ||
num_pretest_per_skill[skill_index] += 1 | ||
if re.match('^Pre.*assessment$', tokens[0]): | ||
pretest2skill[int(tokens[1])] = skill_index | ||
NUM_PRETEST_PER_SKILL[skill_index] += 1 | ||
else: | ||
problem2skill[tokens[0]+"_"+tokens[1]] = skill_index | ||
skill2seq[skill_index].add(tokens[0]) | ||
PROBLEM2SKILL[tokens[0]+"_"+tokens[1]] = skill_index | ||
SKILL2SEQ[skill_index].add(tokens[0]) | ||
|
||
test2skill = [0] * len(pretest2skill) | ||
for key in pretest2skill: | ||
test2skill[key] = pretest2skill[key] | ||
TEST2SKILL[key] = pretest2skill[key] | ||
|
||
# print pretest2skill | ||
# print skill2seq | ||
# print skill2index | ||
|
||
for k, v in skill2index.iteritems(): | ||
payload = json.dumps({'skill_name':k}) | ||
r = app.post('/api/v1/course/{}/skill'.format(course_id), data=payload, headers=headers) | ||
# r = requests.post('http://{HOST}:{PORT}/api/v1/course/{COURSE_ID}/skill'.format(**EDXADAPT), data=payload, headers=headers) | ||
# print r.data | ||
# print str(r) + str(r.json()) | ||
for k in SKILL2INDEX: | ||
payload = json.dumps({'skill_name': k}) | ||
app.post('/api/v1/course/{}/skill'.format(course_id), data=payload, headers=headers) | ||
|
||
payload = json.dumps({'skill_name': "None"}) | ||
r = app.post('/api/v1/course/{}/skill'.format(course_id), data=payload, headers=headers) | ||
# r = requests.post('http://{HOST}:{PORT}/api/v1/course/{COURSE_ID}/skill'.format(**EDXADAPT), data=payload, headers=headers) | ||
# print r.data | ||
# print str(r) + str(r.json()) | ||
|
||
""" | ||
f = open('../course-content/old_new_map.json', 'r') | ||
old_new = json.loads(f.readline()) | ||
with open("../data/BKT/skills_test.csv", "r") as fin: | ||
for line in fin: | ||
tokens = line.strip().split(",") | ||
prob = tokens[0] + "_" + tokens[1] | ||
skill = tokens[2] | ||
print prob | ||
if prob in old_new: | ||
prob = old_new[prob] | ||
if prob == "axis": | ||
payload = {'problem_name':'axis_0', 'tutor_url':'http://cmustats.tk/courses/CMU/STAT101/2014_T1/courseware/statistics/axis_0', | ||
'skills':['y_axis']} | ||
else: | ||
payload = {'problem_name':prob, 'tutor_url':'http://cmustats.tk/courses/CMU/STAT101/2014_T1/courseware/statistics/'+prob, | ||
'skills':[skill]} | ||
print "\t\told_new" | ||
else: | ||
if tokens[0] == "axis": | ||
payload = {'problem_name':'axis_0', 'tutor_url':'http://cmustats.tk/courses/CMU/STAT101/2014_T1/courseware/statistics/axis_0', | ||
'skills':['y_axis']} | ||
else: | ||
payload = {'problem_name':tokens[0], 'tutor_url':'http://cmustats.tk/courses/CMU/STAT101/2014_T1/courseware/statistics/'+tokens[0], | ||
'skills':[skill]} | ||
print "\t\tregular" | ||
print "\t\t" + str(tokens) | ||
if "Pre_as" in prob: | ||
payload['pretest'] = True | ||
if "Post_as" in prob: | ||
payload['posttest'] = True | ||
if payload['problem_name'] == "T3_2" and 'histogram' in payload['skills']: | ||
continue | ||
r = requests.post('http://'+EDXADAPT_HOST+':8080/api/v1/course/CMUSTAT101', data=json.dumps(payload), headers=headers) | ||
print str(r) + str(r.json()) | ||
""" | ||
|
||
app.post('/api/v1/course/{}/skill'.format(course_id), data=payload, headers=headers) | ||
table = [line.strip().split('\t') for line in open("data/BKT/problist.tsv").readlines()] | ||
|
||
for row in table: | ||
pname = row[0] | ||
skill = row[1] | ||
url = 'http://{HOST}/courses/{COURSE_ID}/courseware/statistics/{pname}'.format(pname=pname, **EDX) | ||
pre = False | ||
post = False | ||
|
||
if "Pre_a" in pname: | ||
pre = True | ||
if "Post_a" in pname: | ||
post = True | ||
|
||
payload = json.dumps({'problem_name': pname, 'tutor_url': url, 'skills': [skill], 'pretest': pre, | ||
'posttest': post}) | ||
r = app.post('/api/v1/course/{}'.format(course_id), data=payload, headers=headers) | ||
# r = requests.post('http://{HOST}:{PORT}/api/v1/course/{COURSE_ID}'.format(**EDXADAPT), data=json.dumps(payload), headers=headers) | ||
# print r.data | ||
# print str(r) + str(r.json()) | ||
|
||
pre = "Pre_a" in pname | ||
post = "Post_a" in pname | ||
payload = json.dumps({ | ||
'problem_name': pname, 'tutor_url': url, 'skills': [skill], 'pretest': pre, 'posttest': post | ||
}) | ||
app.post('/api/v1/course/{}'.format(course_id), data=payload, headers=headers) | ||
|
||
payload = json.dumps({'experiment_name': 'test_experiment2', 'start_time':1462736963, 'end_time':1999999999}) | ||
r = app.post('/api/v1/course/{}/experiment'.format(course_id), data=payload, headers=headers) | ||
# r = requests.post('http://{HOST}:{PORT}/api/v1/course/{COURSE_ID}/experiment'.format(**EDXADAPT), data=payload, headers=headers) | ||
# print r.data | ||
# print str(r) + str(r.json()) | ||
payload = json.dumps({'experiment_name': 'test_experiment2', 'start_time': 1462736963, 'end_time': 1999999999}) | ||
app.post('/api/v1/course/{}/experiment'.format(course_id), data=payload, headers=headers) | ||
|
||
if DO_BASELINE_SETUP: | ||
params = {'pi': 0.1, 'pt': 0.1, 'pg': 0.1, 'ps': 0.1, 'threshold': 1.0 } | ||
params = {'pi': 0.1, 'pt': 0.1, 'pg': 0.1, 'ps': 0.1, 'threshold': 1.0} | ||
tutor_params = {} | ||
for skill in ['d to h', 'y axis', 'h to d', 'center', 'shape', 'x axis', 'histogram', 'spread']: | ||
tutor_params[skill] = params | ||
#ping back the server with the new parameters | ||
# response = requests.post('http://{HOST}:{PORT}/api/v1/misc/SetBOParams'.format(**EDXADAPT), | ||
# data=json.dumps({'course_id':EDXADAPT['COURSE_ID'], 'parameters': tutor_params}), headers=headers) | ||
response = app.post('/api/v1/misc/SetBOParams'.format(**EDXADAPT), | ||
data=json.dumps({'course_id': course_id, 'parameters': tutor_params}), | ||
headers=headers) | ||
app.post( | ||
'/api/v1/misc/SetBOParams'.format(**EDXADAPT), | ||
data=json.dumps({'course_id': course_id, 'parameters': tutor_params}), | ||
headers=headers | ||
) | ||
|
||
if __name__ == '__main__': | ||
prepare_course() | ||
prepare_course(COURSE_ID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.