Commit 44738c16 by Vik Paruchuri

Pull templating and path assignment out of ML functions

parent 91b194c0
......@@ -11,7 +11,6 @@ import model_creator
import util_functions
def create(text,score,prompt_string,model_path):
model_path=util_functions.create_model_path(model_path)
results = {'errors': [],'created' : False}
try:
......@@ -22,15 +21,13 @@ def create(text,score,prompt_string,model_path):
feature_ext, classifier = model_creator.extract_features_and_generate_model(e_set)
except:
results['errors'].append("feature extraction and model creation failed.")
full_path=os.path.join(base_path,model_path)
util_functions.create_directory(full_path)
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, full_path)
results['created']=True
"""
try:
full_path=os.path.join(base_path,model_path)
util_functions.create_directory(full_path)
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, full_path)
results['created']=True
except:
results['errors'].append("could not write model to: {0}".format(model_path))
"""
return results
......
......@@ -25,62 +25,9 @@ log = logging.getLogger(__name__)
TEMPORARY_WANTS_CONFIG=True
feedback_template = u"""
<section>
<header>Feedback</header>
<div class="shortform">
<div class="result-output">
<p>Score: {score}</p>
<p>Number of potential problem areas identified: {problem_areas}</p>
</div>
</div>
<div class="longform">
<div class="result-output">
<div class="topicality">
Topicality: {topicality}
</div>
<div class="prompt_overlap">
Prompt Overlap : {prompt_overlap}
</div>
<div class="spelling">
Spelling: {spelling}
</div>
<div class="grammar">
Grammar: {grammar}
</div>
<div class="markup-text">
{markup_text}
</div>
</div>
</div>
</section>
"""
error_template = u"""
<section>
<div class="shortform">
<div class="result-errors">
There was an error with your submission. Please contact course staff.
</div>
</div>
<div class="longform">
<div class="result-errors">
{errors}
</div>
</div>
</section>
"""
def grade(grader_path,grader_config,submission,sandbox=None):
grader_path=os.path.join(base_path,util_functions.create_model_path(grader_path))
log.debug("Grader path: {0}\n Submission: {1}".format(grader_path,submission))
results = {'errors': [],'tests': [],'score': 0, 'feedback' : "", 'success' : False}
has_error=False
......@@ -125,20 +72,20 @@ def grade(grader_path,grader_config,submission,sandbox=None):
if tag is not 'markup_text':
problem_areas+=len(feedback[tag])>5
#Add feedback template to results
results['feedback']=feedback_template.format(
topicality=feedback['topicality'],
spelling=feedback['spelling'],
grammar=feedback['grammar'],
markup_text=feedback['markup_text'],
problem_areas=problem_areas,
score=results['score'],
prompt_overlap=feedback['prompt_overlap'],
)
#Add feedback to results
results['feedback']={
'topicality' : feedback['topicality'],
'spelling' : feedback['spelling'],
'grammar' : feedback['grammar'],
'markup_text' : feedback['markup_text'],
'problem_areas' : problem_areas,
'score' : results['score'],
'prompt_overlap' : feedback['prompt_overlap'],
}
else:
#If error, add errors to template.
results['feedback']=error_template.format(errors=' '.join(results['errors']))
#If error, success is False.
results['success']=False
return results
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment