def test_save(self):
     eval_id = Evaluation.create('Edit Test Name', self.card_id).id()
     category1_id = EvalCategory.create('Eval Save Test Cat 1', self.card_id).id()
     category2_id = EvalCategory.create('Eval Save Test Cat 2', self.card_id).id()
     item1_id = EvalItem.create('Eval Save Test Item 1', category1_id).id()
     item2_id = EvalItem.create('Eval Save Test Item 2', category1_id).id()
     item3_id = EvalItem.create('Eval Save Test Item 3', category2_id).id()
     text_line1_id = TextLine.create('Eval Save Test Text Line 1', self.card_id).id()
     text_line2_id = TextLine.create('Eval Save Test Text Line 2', self.card_id).id()
     
     response = self.testapp.post('/eval/%d/save' % eval_id, 
         {'comments': 'Comments', 
          'item_%d_score' % item1_id: '1', 
          'item_%d_score' % item2_id: '2', 
          'item_%d_score' % item3_id: '3',
          'text_%d_value' % text_line1_id: 'Text 1',
          'text_%d_value' % text_line2_id: 'Text 2',
         }
     )
     self.assertRedirect('/eval/\d*/fill$', response)
     eval = Evaluation.find_by_id(eval_id)
     data = eval.all_data()
     self.assertEqual('Comments', data['comments'])
     self.assertEqual('1', data['items'][item1_id])
     self.assertEqual('2', data['items'][item2_id])
     self.assertEqual('3', data['items'][item3_id])
     self.assertEqual('Text 1', data['text'][text_line1_id])
     self.assertEqual('Text 2', data['text'][text_line2_id])
Ejemplo n.º 2
0
def classification():
    log.info(msg='/machine-learning/classification - has been entered...')
    if request.method == 'GET':
        log.info('/evaluation - Request-method: "{method}"'.format(
            method=request.method))

        resp = Evaluation.evaluate()
        if not resp:
            return jsonify({'status': 'not found'}), 404

        return jsonify(resp)

    if request.method == 'POST':

        log.info('classify - Request-method: "{method}"'.format(
            method=request.method))
        data = request.form.to_dict()
        validator = Validator(schema_type='classification')
        validator.validate(data)

        if validator.validated:
            log.info('request has been validated')
            resp = Classification().predict_class(req=data)
            if not resp:
                return jsonify({'status': 'bad request'}), 400
        else:
            log.info('validation of request failed')
            return jsonify({'status': 'validation failed'}), 422

        return jsonify(resp), 202
 def test_preview(self):
     e = Evaluation.create('Preview Test Name', self.card_id)
     category1_id = EvalCategory.create('Eval Preview Test Cat 1', self.card_id).id()
     category2_id = EvalCategory.create('Eval Preview Test Cat 2', self.card_id).id()
     item1_id = EvalItem.create('Eval Preview Test Item 1', category1_id).id()
     item2_id = EvalItem.create('Eval Preview Test Item 2', category1_id).id()
     item3_id = EvalItem.create('Eval Preview Test Item 3', category2_id).id()
     text_line1_id = TextLine.create('Eval Preview Test Text Line 1', self.card_id).id()
     text_line2_id = TextLine.create('Eval Preview Test Text Line 2', self.card_id).id()
     response = self.testapp.get('/eval/%d/preview' % e.id())
     self.assertSuccess(response)
 def create_or_update(self, evaluation_id, value):
     evaluation = Evaluation.find_by_id(evaluation_id)
     
     data = CommentData.gql('WHERE evaluation = :1', evaluation).fetch(1)
     if len(data) == 0:
         data = CommentData(parent=self.report_key())
         data.evaluation = evaluation
     else:
         data = data[0]
     
     data.value = value
     return data.put()
         
 def create_or_update(self, text_line_id, evaluation_id, value):
     line = TextLine.find_by_id(text_line_id)
     evaluation = Evaluation.find_by_id(evaluation_id)
     
     data = TextLineData.gql('WHERE text_line = :1 AND evaluation = :2', line, evaluation).fetch(1)
     if len(data) == 0:
         data = TextLineData(parent=self.report_key())
         data.text_line = line
         data.evaluation = evaluation
     else:
         data = data[0]
     
     data.value = value
     return data.put()
         
 def create_or_update(self, eval_item_id, evaluation_id, value):
     item = EvalItem.find_by_id(eval_item_id)
     evaluation = Evaluation.find_by_id(evaluation_id)
     
     data = EvalItemData.gql('WHERE eval_item = :1 AND evaluation = :2', item, evaluation).fetch(1)
     if len(data) == 0:
         data = EvalItemData(parent=self.report_key())
         data.eval_item = item
         data.evaluation = evaluation
     else:
         data = data[0]
     
     data.value = value
     return data.put()
         
 def save(self, eval_id):
     eval = Evaluation.find_by_id(int(eval_id))
     if eval.card.is_authorized():
         for cat in eval.card.categories():
             for item in cat.items():
                 val = self.request.get('item_%s_score' % item.key().id())
                 if val is not None:
                     EvalItemData.create_or_update(item.key().id(), int(eval_id), val)
         for line in eval.card.text_lines():
             val = self.request.get('text_%s_value' % line.key().id())
             if val is not None:
                 TextLineData.create_or_update(line.key().id(), int(eval_id), val)
         val = self.request.get('comments')
         if val is not None:
             CommentData.create_or_update(int(eval_id), val)
         return webapp2.redirect_to('eval-fill', eval_id=int(eval_id))
Ejemplo n.º 8
0
def create_evaluations():
    logger.info('create_evaluations')

    evaluations_by_name = {}

    evaluations_by_name["claim / 2"] = Evaluation(
        info=
        "It describes an observation in a way that is consistent with available data and does not leave out any relevant element of context or it is a theory that has been well tested in scientific studies and generates expected observations that are confirmed by actual observations",
        label="Very High",
        type="claim",
        value=2)

    evaluations_by_name["claim / 1"] = Evaluation(
        info=
        "It needs some clarification or additional information to be fully accurate or it presents a theory that is well tested in scientific studies, but its formulation in the claim might overstate the confidence scientists actually have in the theory or slightly distort what can be predicted based on the theory",
        label="High",
        type="claim",
        value=1)

    evaluations_by_name["claim / 0"] = Evaluation(
        info="It leaves out important information or is made out of context",
        label="Neutral",
        type="claim",
        value=0)

    evaluations_by_name["claim / -1"] = Evaluation(
        info=
        "It is made without backing from an adequate reference or the available evidence does not support the statement or it contains an element of truth but leaves the reader with a false understanding of reality",
        label="Low",
        type="claim",
        value=-1)

    evaluations_by_name["claim / -2"] = Evaluation(info="It is clearly wrong",
                                                   label="Very Low",
                                                   type="claim",
                                                   value=-2)

    evaluations_by_name["article / 2"] = Evaluation(
        info=
        "No inaccuracies, fairly represents the state of scientific knowledge, well argued and documented, references are provided for key elements. The article provides insights to the reader about scientific mechanisms and implications, as well as limitations and important unknowns surrounding the evidence.",
        label="Very High",
        type="article",
        value=2)

    evaluations_by_name["article / 1"] = Evaluation(
        info=
        "The article does not contain scientific inaccuracies and its conclusion follows from the evidence provided. While more detail would have been useful, readers are still accurately informed of the science.",
        label="High",
        type="article",
        value=1)

    evaluations_by_name["article / 0"] = Evaluation(
        info=
        "No significant errors, but not enough insight either to inform the reader.",
        type="article",
        label="Neutral",
        value=0)

    evaluations_by_name["article / -1"] = Evaluation(
        info=
        "The article contains significant scientific inaccuracies or misleading statements.",
        label="Low",
        type="article",
        value=-1)

    evaluations_by_name["article / -2"] = Evaluation(
        info=
        "The article contains major scientific inaccuracies for key facts supporting argumentation, and/or omits important information, and/or presents logical flaws in using information to reach conclusions.",
        label="Very Low",
        type="article",
        value=-2)

    evaluations_by_name["article / NA"] = Evaluation(
        info=
        "The article does not build on scientifically verifiable information (e.g. it is mostly about policy, politics or opinions).",
        label="Not applicable",
        type="article",
        value=None)

    ApiHandler.save(*evaluations_by_name.values())

    logger.info('created {} evaluations'.format(len(evaluations_by_name)))

    return evaluations_by_name
 def preview(self, eval_id):
     eval = Evaluation.find_by_id(int(eval_id))
     if eval.card.is_authorized():
         template = JinjaEnv.get().get_template('templates/eval/preview.html')
         self.response.out.write(template.render({'eval': eval, 'data': eval.all_data()}))
 def add(self, card_id):
     card = ReportCard.find_by_id(int(card_id))
     if card.is_authorized():
         Evaluation.create(self.request.get('name'), int(card_id))
         return webapp2.redirect_to('eval-list', card_id=int(card_id))
Ejemplo n.º 11
0
 def evaluations(self):
     from models.evaluation import Evaluation
     items = Evaluation.gql("WHERE card = :1 ORDER BY name ASC", self).fetch(100)
     return items
 def test_fill(self):
     e = Evaluation.create('Edit Test Name', self.card_id)
     response = self.testapp.get('/eval/%d/fill' % e.id())
     self.assertSuccess(response)