Merge pull request #82 from andywot/new-grader
Changed grader to use the new grading system
This commit is contained in:
@@ -19,7 +19,9 @@ class Grader(SubmissionBase):
|
|||||||
'Computing Cost (for multiple variables)',
|
'Computing Cost (for multiple variables)',
|
||||||
'Gradient Descent (for multiple variables)',
|
'Gradient Descent (for multiple variables)',
|
||||||
'Normal Equations']
|
'Normal Equations']
|
||||||
super().__init__('linear-regression', part_names)
|
part_names_key = ['DCRbJ', 'BGa4S', 'b65eO', 'BbS8u', 'FBlE2', 'RZAZC', '7m5Eu']
|
||||||
|
assignment_key = 'UkTlA-FyRRKV5ooohuwU6A'
|
||||||
|
super().__init__('linear-regression', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 8):
|
for part_id in range(1, 8):
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ class Grader(SubmissionBase):
|
|||||||
'Predict',
|
'Predict',
|
||||||
'Regularized Logistic Regression Cost',
|
'Regularized Logistic Regression Cost',
|
||||||
'Regularized Logistic Regression Gradient']
|
'Regularized Logistic Regression Gradient']
|
||||||
super().__init__('logistic-regression', part_names)
|
part_names_key = ['sFxIn', 'yvXBE', 'HerlY', '9fxV6', 'OddeL', 'aUo3H']
|
||||||
|
assignment_key = 'JvOPouj-S-ys8KjYcPYqrg'
|
||||||
|
super().__init__('logistic-regression', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 7):
|
for part_id in range(1, 7):
|
||||||
|
|||||||
@@ -79,8 +79,9 @@ class Grader(SubmissionBase):
|
|||||||
'One-vs-All Classifier Training',
|
'One-vs-All Classifier Training',
|
||||||
'One-vs-All Classifier Prediction',
|
'One-vs-All Classifier Prediction',
|
||||||
'Neural Network Prediction Function']
|
'Neural Network Prediction Function']
|
||||||
|
part_names_key = ['jzAIf', 'LjDnh', '3yxcY', 'yNspP']
|
||||||
super().__init__('multi-class-classification-and-neural-networks', part_names)
|
assignment_key = '2KZRbGlpQnyzVI8Ki4uXjw'
|
||||||
|
super().__init__('multi-class-classification-and-neural-networks', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 5):
|
for part_id in range(1, 5):
|
||||||
|
|||||||
@@ -193,7 +193,9 @@ class Grader(SubmissionBase):
|
|||||||
'Sigmoid Gradient',
|
'Sigmoid Gradient',
|
||||||
'Neural Network Gradient (Backpropagation)',
|
'Neural Network Gradient (Backpropagation)',
|
||||||
'Regularized Gradient']
|
'Regularized Gradient']
|
||||||
super().__init__('neural-network-learning', part_names)
|
part_names_key = ['aAiP2', '8ajiz', 'rXsEO', 'TvZch', 'pfIYT']
|
||||||
|
assignment_key = 'xolSVXukR72JH37bfzo0pg'
|
||||||
|
super().__init__('neural-network-learning', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 6):
|
for part_id in range(1, 6):
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ class Grader(SubmissionBase):
|
|||||||
'Learning Curve',
|
'Learning Curve',
|
||||||
'Polynomial Feature Mapping',
|
'Polynomial Feature Mapping',
|
||||||
'Validation Curve']
|
'Validation Curve']
|
||||||
super().__init__('regularized-linear-regression-and-bias-variance', part_names)
|
part_names_key = ['a6bvf', 'x4FhA', 'n3zWY', 'lLaa4', 'gyJbG']
|
||||||
|
assignment_key = '-wEfetVmQgG3j-mtasztYg'
|
||||||
|
super().__init__('regularized-linear-regression-and-bias-variance', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 6):
|
for part_id in range(1, 6):
|
||||||
|
|||||||
@@ -695,7 +695,9 @@ class Grader(SubmissionBase):
|
|||||||
'Parameters (C, sigma) for Dataset 3',
|
'Parameters (C, sigma) for Dataset 3',
|
||||||
'Email Processing',
|
'Email Processing',
|
||||||
'Email Feature Extraction']
|
'Email Feature Extraction']
|
||||||
super().__init__('support-vector-machines', part_names)
|
part_names_key = ['drOLk', 'JYt9Q', 'UHwLk', 'RIiFh']
|
||||||
|
assignment_key = 'xHfBJWXxTdKXrUG7dHTQ3g'
|
||||||
|
super().__init__('support-vector-machines', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 5):
|
for part_id in range(1, 5):
|
||||||
|
|||||||
@@ -211,7 +211,9 @@ class Grader(SubmissionBase):
|
|||||||
'PCA',
|
'PCA',
|
||||||
'Project Data (PCA)',
|
'Project Data (PCA)',
|
||||||
'Recover Data (PCA)']
|
'Recover Data (PCA)']
|
||||||
super().__init__('k-means-clustering-and-pca', part_names)
|
part_names_key = ['7yN0U', 'G1WGM', 'ixOMV', 'AFoJK', 'vf9EL']
|
||||||
|
assignment_key = 'rGGTuM9gQoaikOnlhLII1A'
|
||||||
|
super().__init__('k-means-clustering-and-pca', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 6):
|
for part_id in range(1, 6):
|
||||||
|
|||||||
@@ -235,7 +235,9 @@ class Grader(SubmissionBase):
|
|||||||
'Collaborative Filtering Gradient',
|
'Collaborative Filtering Gradient',
|
||||||
'Regularized Cost',
|
'Regularized Cost',
|
||||||
'Regularized Gradient']
|
'Regularized Gradient']
|
||||||
super().__init__('anomaly-detection-and-recommender-systems', part_names)
|
part_names_key = ['WGzrg', '80Tcg', 'KDzSh', 'wZud3', 'BP3th', 'YF0u1']
|
||||||
|
assignment_key = 'JvOPouj-S-ys8KjYcPYqrg'
|
||||||
|
super().__init__('anomaly-detection-and-recommender-systems', assignment_key, part_names, part_names_key)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in range(1, 7):
|
for part_id in range(1, 7):
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
from urllib.parse import urlencode
|
|
||||||
from urllib.request import urlopen
|
|
||||||
import pickle
|
|
||||||
import json
|
import json
|
||||||
from collections import OrderedDict
|
|
||||||
import numpy as np
|
|
||||||
import os
|
import os
|
||||||
|
import pickle
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class SubmissionBase:
|
class SubmissionBase:
|
||||||
|
submit_url = 'https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1?includes=evaluation'
|
||||||
submit_url = 'https://www-origin.coursera.org/api/' \
|
|
||||||
'onDemandProgrammingImmediateFormSubmissions.v1'
|
|
||||||
save_file = 'token.pkl'
|
save_file = 'token.pkl'
|
||||||
|
|
||||||
def __init__(self, assignment_slug, part_names):
|
def __init__(self, assignment_slug, assignment_key, part_names, part_names_key):
|
||||||
self.assignment_slug = assignment_slug
|
self.assignment_slug = assignment_slug
|
||||||
|
self.assignment_key = assignment_key
|
||||||
self.part_names = part_names
|
self.part_names = part_names
|
||||||
|
self.part_names_key = part_names_key
|
||||||
self.login = None
|
self.login = None
|
||||||
self.token = None
|
self.token = None
|
||||||
self.functions = OrderedDict()
|
self.functions = OrderedDict()
|
||||||
@@ -28,24 +28,25 @@ class SubmissionBase:
|
|||||||
# Evaluate the different parts of exercise
|
# Evaluate the different parts of exercise
|
||||||
parts = OrderedDict()
|
parts = OrderedDict()
|
||||||
for part_id, result in self:
|
for part_id, result in self:
|
||||||
parts[str(part_id)] = {'output': sprintf('%0.5f ', result)}
|
parts[self.part_names_key[part_id - 1]] = {'output': sprintf('%0.5f ', result)}
|
||||||
result, response = self.request(parts)
|
response = self.request(parts)
|
||||||
response = json.loads(response.decode("utf-8"))
|
response = json.loads(response.decode("utf-8"))
|
||||||
|
|
||||||
# if an error was returned, print it and stop
|
# if an error was returned, print it and stop
|
||||||
if 'errorMessage' in response:
|
if 'errorCode' in response:
|
||||||
print(response['errorMessage'])
|
print(response['message'], response['details']['learnerMessage'])
|
||||||
return
|
return
|
||||||
|
|
||||||
# Print the grading table
|
# Print the grading table
|
||||||
print('%43s | %9s | %-s' % ('Part Name', 'Score', 'Feedback'))
|
print('%43s | %9s | %-s' % ('Part Name', 'Score', 'Feedback'))
|
||||||
print('%43s | %9s | %-s' % ('---------', '-----', '--------'))
|
print('%43s | %9s | %-s' % ('---------', '-----', '--------'))
|
||||||
for part in parts:
|
for index, part in enumerate(parts):
|
||||||
part_feedback = response['partFeedbacks'][part]
|
part_feedback = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]['parts'][str(part)][
|
||||||
part_evaluation = response['partEvaluations'][part]
|
'feedback']
|
||||||
|
part_evaluation = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]['parts'][str(part)]
|
||||||
score = '%d / %3d' % (part_evaluation['score'], part_evaluation['maxScore'])
|
score = '%d / %3d' % (part_evaluation['score'], part_evaluation['maxScore'])
|
||||||
print('%43s | %9s | %-s' % (self.part_names[int(part) - 1], score, part_feedback))
|
print('%43s | %9s | %-s' % (self.part_names[int(index) - 1], score, part_feedback))
|
||||||
evaluation = response['evaluation']
|
evaluation = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]
|
||||||
total_score = '%d / %d' % (evaluation['score'], evaluation['maxScore'])
|
total_score = '%d / %d' % (evaluation['score'], evaluation['maxScore'])
|
||||||
print(' --------------------------------')
|
print(' --------------------------------')
|
||||||
print('%43s | %9s | %-s\n' % (' ', total_score, ' '))
|
print('%43s | %9s | %-s\n' % (' ', total_score, ' '))
|
||||||
@@ -71,18 +72,15 @@ class SubmissionBase:
|
|||||||
pickle.dump((self.login, self.token), f)
|
pickle.dump((self.login, self.token), f)
|
||||||
|
|
||||||
def request(self, parts):
|
def request(self, parts):
|
||||||
params = {
|
payload = {
|
||||||
'assignmentSlug': self.assignment_slug,
|
'assignmentKey': self.assignment_key,
|
||||||
|
'submitterEmail': self.login,
|
||||||
'secret': self.token,
|
'secret': self.token,
|
||||||
'parts': parts,
|
'parts': dict(eval(str(parts)))}
|
||||||
'submitterEmail': self.login}
|
headers = {}
|
||||||
|
|
||||||
params = urlencode({'jsonBody': json.dumps(params)}).encode("utf-8")
|
r = requests.post(self.submit_url, data=json.dumps(payload), headers=headers)
|
||||||
f = urlopen(self.submit_url, params)
|
return r.content
|
||||||
try:
|
|
||||||
return 0, f.read()
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for part_id in self.functions:
|
for part_id in self.functions:
|
||||||
|
|||||||
Reference in New Issue
Block a user