Example #1
0
    double Compute(Recipe recipe)
    {
        var composition = Composition.Blend(new List <Composition>()
        {
            almondsComposition.Dose(recipe.almondsDose),
            cashewsComposition.Dose(recipe.cashewsDose),
            coconutComposition.Dose(recipe.coconutDose),
            oatComposition.Dose(recipe.oatDose),
            peanutsComposition.Dose(recipe.peanutsDose),
            riceComposition.Dose(recipe.riceDose),
            soyComposition.Dose(recipe.soyDose),
            yellowPeasComposition.Dose(recipe.yellowPeasDose),
        });


        almondsField.text    = string.Format("{0}g", (recipe.almondsDose * 100).ToString());
        cashewsField.text    = string.Format("{0}g", (recipe.cashewsDose * 100).ToString());
        coconutField.text    = string.Format("{0}g", (recipe.coconutDose * 100).ToString());
        oatField.text        = string.Format("{0}g", (recipe.oatDose * 100).ToString());
        peanutsField.text    = string.Format("{0}g", (recipe.peanutsDose * 100).ToString());
        riceField.text       = string.Format("{0}g", (recipe.riceDose * 100).ToString());
        soyField.text        = string.Format("{0}g", (recipe.soyDose * 100).ToString());
        yellowPeasField.text = string.Format("{0}g", (recipe.yellowPeasDose * 100).ToString());

        var distance   = cowMilk.SimilarityScoreWith(composition);
        var similarity = (distance > MAX_DISTANCE ? 0 : (MAX_DISTANCE - distance) * 100 / MAX_DISTANCE);

        distanceField.text   = distance.ToString();
        similarityField.text = string.Format("{0}%", similarity);

        return(distance);
    }