Ejemplo n.º 1
0
        public void CalculateFitness(BloodTestViewModel BTVM)
        {
            text         = "";
            fitnessGrade = 100;
            if (avgDic == null)
            {
                avgDic  = contextIndv.GetAvgRating();
                aceList = contextIndv.getAllEffects();
            }
            double amountPerComp    = EXECPTION / (double)BTVM.BTC.Count;
            double amountPerMed     = NUM_OF_MEDICATIONS / (double)(indivSize - 1);
            double amountOnPres     = MEDICAL_PRESCRIPTION / (double)genomeList.Count;
            double amountOnPlan     = IN_HEALTH_PLAN / (double)genomeList.Count;
            double amountOnFeedback = FEEDBACK / (double)genomeList.Count;
            int    countGoods       = 0;

            for (int i = 0; i < BTVM.BTC.Count; i++)
            {
                double min   = 0;
                double max   = 0;
                double value = 0;
                if (BTVM.UserGender.Equals("M"))
                {
                    min = BTVM.BTC[i].BOAComp.MenMin;
                    max = BTVM.BTC[i].BOAComp.MenMax;
                }
                else if (BTVM.UserGender.Equals("F"))
                {
                    if (BTVM.IsPregnant.Equals("N"))
                    {
                        min = BTVM.BTC[i].BOAComp.WomenMin;
                        max = BTVM.BTC[i].BOAComp.WomenMax;
                    }
                    else
                    {
                        min = BTVM.BTC[i].BOAComp.PregnantMin;
                        max = BTVM.BTC[i].BOAComp.PregnantMax;
                    }
                }
                value = BTVM.BTC[i].btData.Value;
                if (value > min && value < max)
                {
                    countGoods++;
                }
                if (value < min)
                {
                    text = text + "<li>מחסור ב " + BTVM.BTC[i].BOAComp.BOA_Name + "</li>";
                }
                else if (value > max)
                {
                    text = text + "<li>עודף ב " + BTVM.BTC[i].BOAComp.BOA_Name + "</li>";
                }
                hashMed = new HashSet <int>();
                for (int j = 0; j < genomeList.Count; j++)
                {
                    if (!hashMed.Contains(genomeList[j].med.SomID))
                    {
                        for (int k = 0; k < aceList.Count; k++)
                        {
                            if (aceList[k].ACEM_BOA_ID == BTVM.BTC[i].BOAComp.BOA_ID && aceList[k].ACEM_SOM_ID == genomeList[j].med.SomID)
                            {
                                value = value + aceList[k].Effect * ((max - min) / 100);
                            }
                            //value = BTVM.BTC[i].btData.Value + contextIndv.GetEffectOnComp(BTVM.BTC[i].BOAComp.BOA_ID, genomeList[j].med.SomID) * ((max - min) / 100);
                        }
                        hashMed.Add(genomeList[j].med.SomID);
                    }
                }
                if (value < 0)
                {
                    value = 0.000000000001;
                }
                double avg = (min + max) / 2;
                if (value < min)
                {
                    fitnessGrade = fitnessGrade - ((1 - (value / avg)) * amountPerComp);
                }
                else if (value > max)
                {
                    fitnessGrade = fitnessGrade - ((1 - (avg / value)) * amountPerComp);
                }
            }
            for (int i = 0; i < genomeList.Count; i++)
            {
                if (genomeList[i].med.InHealthPlan.ToString().Equals("N"))
                {
                    fitnessGrade = fitnessGrade - amountOnPlan;
                }
                if (genomeList[i].med.WithMedicalPrescription.ToString().Equals("Y"))
                {
                    fitnessGrade = fitnessGrade - amountOnPres;
                }
                double avgRating = 5;
                avgDic.TryGetValue(genomeList[i].med.SomID, out double avgRate);
                if (avgRate != 0)
                {
                    avgRating = avgRate;
                }
                fitnessGrade = fitnessGrade - (amountOnFeedback / MAXRATING * (MAXRATING - avgRating));
            }
            fitnessGrade = fitnessGrade - amountPerMed * (hashMed.Count - 1); // 30% of fitness
            if (countGoods == BTVM.BTC.Count)
            {
                noExecptions = true;
                text         = "כל הבדיקות יצאו תקינות!";
            }
        }