def test_minimize_score_with_worsened_symptom(integration_db):
    """
    Minimize ingredients contained in Recipe[0] are:

    saury fish:  10  (ref. 10)
    cabbage:  200  (ref. 30|200 )
    fish:  30   (ref: 20 )

    this time the formula would be:
    saury-fish (ignored) - (60 * 1.5) - (30 * 1.5)
    """
    from datetime import datetime

    integration_db.patient_symptoms.insert_one({
        'symptom_id':
        TAGS[0]['tag_id'],
        'patient_id':
        PATIENT['_id'],
        'created_at':
        datetime(2019, 10, 15),
        'updated_at':
        datetime(2019, 10, 15),
        'symptoms_scale':
        7
    })

    assert_equal_objects(
        MinimizedScore(RECIPES[0]['_id'], PATIENT['_id']).worsen_ingredients,
        ['saury fish', 'cabbage', 'fish', 'komatsuna', 'pak choi'])
    assert MinimizedScore(RECIPES[0]['_id'], PATIENT['_id']).value == -135
Esempio n. 2
0
 def test_worsen_ingredients_called_only_once(self, mocker):
     worsen = mocker.patch('saana_lib.patient.SymptomsProgress.worsen',
                           new_callable=mocker.PropertyMock,
                           return_value=list())
     klass = MinimizedScore(recipe_id(), patient_id())
     for i in range(3):
         _ = klass.worsen_ingredients
     worsen.assert_called_once_with()
Esempio n. 3
0
 def test_minimize_score_value(self, worsen_symptom_ingredients):
     mocked_method, mocker = worsen_symptom_ingredients
     mocker.patch('saana_lib.score.MinimizedScore.ingredient_set',
                  new_callable=mocker.PropertyMock,
                  return_value=[('t5bv', 2, {
                      'min1': 2,
                      'min2': 4
                  }), ('a3dw', 30, 10)])
     assert MinimizedScore(recipe_id(), patient_id()).value == -60
Esempio n. 4
0
    def score(self):
        val = constants.DEFAULT_RECOMMENDATION_SCORE
        val += AvoidScore(self._recipe_id, self._patient_id).value
        val += MinimizedScore(self._recipe_id, self._patient_id).value
        val += PrioritizedScore(self._recipe_id, self._patient_id).value
        #   TODO CHECK MST_NUTRIENTS
        #        val += NutrientScore(self._recipe_id, self._patient_id).value

        return val
def test_minimize_score(integration_db):
    """
    Minimize ingredients contained in Recipe[0] are:

    saury fish:  10  (ref. 10)
    cabbage:  200  (ref. 30|200 )
    fish:  30   (ref: 20 )

    formula:  saury-fish (ignored) - 60 - 30
    """
    assert MinimizedScore(RECIPES[0]['_id'], PATIENT['_id']).value == -90
Esempio n. 6
0
    def test_ingredient_score_value(self, mocker):
        worsened_symptoms = mocker.patch(
            'saana_lib.patient.SymptomsProgress.worsen',
            new_callable=mocker.PropertyMock,
            return_value={
                'carrot': [1, 2],
                'saury fish': [7, 3]
            })

        worsen_ingredients = MinimizedScore(recipe_id(),
                                            patient_id()).worsen_ingredients
        assert len(worsen_ingredients) == 2
        assert 'carrot' in worsen_ingredients
        worsened_symptoms.assert_called_once_with()
Esempio n. 7
0
    def test_one_minimize_ingredient_in_recipe(self, mocker):
        minimize_all = mocker.patch(
            'saana_lib.recommendation.MinimizeIngredients.all',
            new_callable=mocker.PropertyMock,
            return_value={
                'seaweed': {
                    'min1': 0,
                    'min2': 2
                },
                'fish': 2
            })
        ingredients_id_quantity = mocker.patch(
            'saana_lib.recipe.Recipe.ingredients_name_quantity',
            new_callable=mocker.PropertyMock,
            return_value={
                'cabbage': 20,
                'fish': 3
            })

        res = list(MinimizedScore(obj_id(), obj_id()).ingredient_set)
        assert res == [('fish', 3, 2)]
        assert ingredients_id_quantity.call_count == 1
        minimize_all.assert_called_once_with()