示例#1
0
        /// <summary>
        ///     Add every essential oil to list, that is assigned for specific search effect.
        ///     Calculate the EffectDegreeDiscomfortValue
        /// </summary>
        /// <author>Anna Krebs</author>
        /// <param name="searchEssentialOilItems"></param>
        /// <param name="essentialOilEffects"></param>
        /// <param name="searchedEffect"></param>
        /// <returns></returns>
        private async Task CreateSearchEssentialOilItemsListAsync(List <SearchEssentialOilItem> searchEssentialOilItems,
                                                                  IList <EssentialOilEffect> essentialOilEffects, SearchEffectItem searchedEffect)
        {
            foreach (var essentialOilEffect in essentialOilEffects)
            {
                // Get the essential oils according to the effect they are assigned to.
                var essentialOil = await Repository.GetByIdAsync(essentialOilEffect.EssentialOilId);

                // Create search essential oil item for each assigned essential oil that is assigned to a specific effect.
                var searchEssentialOilItem = new SearchEssentialOilItem();
                searchEssentialOilItem.EssentialOil   = essentialOil;
                searchEssentialOilItem.EssentialOilId = essentialOil.Id;
                searchEssentialOilItem.SearchEffectTextsInEssentialOil = searchedEffect.SearchEffectText;

                // Get the product of "Wirksamkeit" of effect and "Beschwerdeausmass" of each searched effect.
                searchEssentialOilItem.EffectDegreeDiscomfortValue =
                    essentialOilEffect.EffectDegree * searchedEffect.DiscomfortValue;

                // Add the essential oil to the list for the specific effect.
                searchEssentialOilItems.Add(searchEssentialOilItem);

                Log.Info(
                    $"Essential oil {searchEssentialOilItem.EssentialOil.Name} with id {searchEssentialOilItem.EssentialOilId} was found for effect with id {essentialOilEffect.EffectId} and effect degree {essentialOilEffect.EffectDegree}.");
            }
        }
示例#2
0
        /// <summary>
        ///     Calculates the Gewichtete Übereinstimmung.
        ///     E.g. 3 Sliders with inputted DiscomfortValue 4, 1, 2.
        ///     MaxEffectDegreeDiscomfortValue would be (4 * 4) + (1 * 4) + (2 * 4) = 28
        ///     EffectDegreeDiscomfortValue for oil with 3 matches and EffectDegree 3, 2, 4 would be (4 * 3) + (1 * 2) + (2 * 4) =
        ///     22
        ///     WeightedMatchValue for oil would be 100 / 28 * 22 = 79
        ///     EffectDegreeDiscomfortValue for oil with 2 matches and EffectDegree 2, 2 would be (4 * 2) + (1 * 2) = 10
        ///     WeightedMatchValue for oil would be 100 / 28 * 10 = 36
        ///     EffectDegreeDiscomfortValue for oil with 1 match and EffectDegree 4 would be (4 * 4) = 16
        ///     WeightedMatchValue for oil would be 100 / 28 * 16 = 57
        ///     EffectDegreeDiscomfortValue for another oil with 1 match and EffectDegree 3 would be (1 * 3) = 3
        ///     WeightedMatchValue for oil would be 100 / 28 * 3 = 11
        /// </summary>
        /// <author>Anna Krebs</author>
        /// <param name="resultItem"></param>
        /// <param name="maxEffectDegreeDiscomfortValue"></param>
        /// <returns></returns>
        public int CalculateWeightedMatchValue(SearchEssentialOilItem resultItem, int maxEffectDegreeDiscomfortValue)
        {
            // Calculate the weightedMatchValue in order to set the  progress bar.
            int weightedMatchValue;

            if (maxEffectDegreeDiscomfortValue != 0)
            {
                // E.g. 100 / 28 * 22 = 79
                var weightedMatchValueDouble = (double)100 / maxEffectDegreeDiscomfortValue *
                                               resultItem.EffectDegreeDiscomfortValue;
                weightedMatchValue = Convert.ToInt32(weightedMatchValueDouble);
            }
            else
            {
                Log.Error(
                    "An unexpected error occurred while CalculateWeightedMatchValue. MaxEffectDegreeDiscomfortValue is 0. Cannot divide by zero.");
                throw new DivideByZeroException(string.Format(Resources.Resources.Error_UnexpectedError,
                                                              Resources.Resources.Error_MaxEffectDegreeDiscomfortValueIsZero, resultItem.EssentialOil.Id));
            }

            Log.Info(
                $"CalculateWeightedMatchValue 100 /  maxEffectDegreeDiscomfortValue  * resultItem.EffectDegreeDiscomfortValue = weightedMatchValue -> 100 / {maxEffectDegreeDiscomfortValue} * {resultItem.EffectDegreeDiscomfortValue} = {weightedMatchValue} for essential oil item {resultItem.EssentialOil.Name} with id {resultItem.EssentialOilId}.");

            return(weightedMatchValue);
        }