Commit 44738c16 by Vik Paruchuri

Pull templating and path assignment out of ML functions

parent 91b194c0
...@@ -11,7 +11,6 @@ import model_creator ...@@ -11,7 +11,6 @@ import model_creator
import util_functions import util_functions
def create(text,score,prompt_string,model_path): def create(text,score,prompt_string,model_path):
model_path=util_functions.create_model_path(model_path)
results = {'errors': [],'created' : False} results = {'errors': [],'created' : False}
try: try:
...@@ -22,15 +21,13 @@ def create(text,score,prompt_string,model_path): ...@@ -22,15 +21,13 @@ def create(text,score,prompt_string,model_path):
feature_ext, classifier = model_creator.extract_features_and_generate_model(e_set) feature_ext, classifier = model_creator.extract_features_and_generate_model(e_set)
except: except:
results['errors'].append("feature extraction and model creation failed.") results['errors'].append("feature extraction and model creation failed.")
try:
full_path=os.path.join(base_path,model_path) full_path=os.path.join(base_path,model_path)
util_functions.create_directory(full_path) util_functions.create_directory(full_path)
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, full_path) model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, full_path)
results['created']=True results['created']=True
"""
except: except:
results['errors'].append("could not write model to: {0}".format(model_path)) results['errors'].append("could not write model to: {0}".format(model_path))
"""
return results return results
......
...@@ -25,62 +25,9 @@ log = logging.getLogger(__name__) ...@@ -25,62 +25,9 @@ log = logging.getLogger(__name__)
TEMPORARY_WANTS_CONFIG=True 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): 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} results = {'errors': [],'tests': [],'score': 0, 'feedback' : "", 'success' : False}
has_error=False has_error=False
...@@ -125,20 +72,20 @@ def grade(grader_path,grader_config,submission,sandbox=None): ...@@ -125,20 +72,20 @@ def grade(grader_path,grader_config,submission,sandbox=None):
if tag is not 'markup_text': if tag is not 'markup_text':
problem_areas+=len(feedback[tag])>5 problem_areas+=len(feedback[tag])>5
#Add feedback template to results #Add feedback to results
results['feedback']=feedback_template.format( results['feedback']={
topicality=feedback['topicality'], 'topicality' : feedback['topicality'],
spelling=feedback['spelling'], 'spelling' : feedback['spelling'],
grammar=feedback['grammar'], 'grammar' : feedback['grammar'],
markup_text=feedback['markup_text'], 'markup_text' : feedback['markup_text'],
problem_areas=problem_areas, 'problem_areas' : problem_areas,
score=results['score'], 'score' : results['score'],
prompt_overlap=feedback['prompt_overlap'], 'prompt_overlap' : feedback['prompt_overlap'],
) }
else: else:
#If error, add errors to template. #If error, success is False.
results['feedback']=error_template.format(errors=' '.join(results['errors'])) results['success']=False
return results 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