Exemplo n.º 1
0
        private double ComputeAssasinValue(HeroStatisticItemAvg avg, HeroStatisticItemMin min, HeroStatisticItemMax max)
        {
            double dpsComponent  = (avg.dps - min.dps) / (max.dps - min.dps);
            double killComponent = (avg.killPerSec - min.killPerSec) / (max.killPerSec - min.killPerSec);

            return(dpsComponent * 0.7 + killComponent * 0.3);
        }
Exemplo n.º 2
0
        private void InitializeHeroStat(HeroStatisticItemAvg[] avgStat, HeroStatisticItemMin[] minStat, HeroStatisticItemMax[] maxStat)
        {
            for (int i = 0; i < minStat.Length; i++)
            {
                minStat[i] = new HeroStatisticItemMin();
                avgStat[i] = new HeroStatisticItemAvg();
                minStat[i].assistPerSec      = Double.MaxValue;
                minStat[i].campTakenPerSec   = Double.MaxValue;
                minStat[i].damageTakenPerSec = Double.MaxValue;
                minStat[i].deathPerSec       = Double.MaxValue;
                minStat[i].dps        = Double.MaxValue;
                minStat[i].expPerSec  = Double.MaxValue;
                minStat[i].hps        = Double.MaxValue;
                minStat[i].killPerSec = Double.MaxValue;
                minStat[i].sdps       = Double.MaxValue;
                minStat[i].sec        = Double.MaxValue;
                minStat[i].winrate    = 0;
            }

            for (int i = 0; i < maxStat.Length; i++)
            {
                maxStat[i] = new HeroStatisticItemMax();
                maxStat[i].assistPerSec      = Double.MinValue;
                maxStat[i].campTakenPerSec   = Double.MinValue;
                maxStat[i].damageTakenPerSec = Double.MinValue;
                maxStat[i].deathPerSec       = Double.MinValue;
                maxStat[i].dps        = Double.MinValue;
                maxStat[i].expPerSec  = Double.MinValue;
                maxStat[i].hps        = Double.MinValue;
                maxStat[i].killPerSec = Double.MinValue;
                maxStat[i].sdps       = Double.MinValue;
                maxStat[i].sec        = Double.MinValue;
                maxStat[i].winrate    = 0;
            }
        }
Exemplo n.º 3
0
        private double ComputeSupportValue(HeroStatisticItemAvg avg, HeroStatisticItemMin min, HeroStatisticItemMax max)
        {
            double assistComponent = (avg.assistPerSec - min.assistPerSec) /
                                     (max.assistPerSec - min.assistPerSec);
            double hpsComponent = (avg.hps - min.hps) /
                                  (max.hps - min.hps);

            return(assistComponent * 0.4 + hpsComponent * 0.6);
        }
Exemplo n.º 4
0
        private double ComputeWarriorValue(HeroStatisticItemAvg avg, HeroStatisticItemMin min, HeroStatisticItemMax max)
        {
            double dTakenComponent = (avg.damageTakenPerSec - min.damageTakenPerSec) /
                                     (max.damageTakenPerSec - min.damageTakenPerSec);
            double deathComponent = 1 - (avg.deathPerSec - min.deathPerSec) /
                                    (max.deathPerSec - min.deathPerSec);

            return(dTakenComponent * 0.7 + (1 - deathComponent) * 0.3);
        }
Exemplo n.º 5
0
        private double ComputeSpecValue(HeroStatisticItemAvg avg, HeroStatisticItemMin min, HeroStatisticItemMax max)
        {
            double campTakenComponent = (avg.campTakenPerSec - min.campTakenPerSec) /
                                        (max.campTakenPerSec - min.campTakenPerSec);
            double expComponent = (avg.expPerSec - min.expPerSec) /
                                  (max.expPerSec - min.expPerSec);
            double sdpsComponent = (avg.sdps - min.sdps) /
                                   (max.sdps - min.sdps);

            return(expComponent * 0.4 + sdpsComponent * 0.4 + campTakenComponent * 0.2);
        }
Exemplo n.º 6
0
        /// <summary>
        ///возвращает среднее минимальное и среднее макимальное рассчитанное из выборки всех героев
        /// </summary>
        /// <returns></returns>
        private Tuple <HeroStatisticItemMin, HeroStatisticItemMax> GetExtremumValues(HeroStatisticItemAvg[] avgStat)
        {
            HeroStatisticItemMin minStat = new HeroStatisticItemMin();
            HeroStatisticItemMax maxStat = new HeroStatisticItemMax();

            {
                minStat.assistPerSec      = Double.MaxValue;
                minStat.campTakenPerSec   = Double.MaxValue;
                minStat.damageTakenPerSec = Double.MaxValue;
                minStat.deathPerSec       = Double.MaxValue;
                minStat.dps        = Double.MaxValue;
                minStat.expPerSec  = Double.MaxValue;
                minStat.hps        = Double.MaxValue;
                minStat.killPerSec = Double.MaxValue;
                minStat.sdps       = Double.MaxValue;
                minStat.sec        = Double.MaxValue;
                minStat.winrate    = 0;
            }


            {
                maxStat.assistPerSec      = Double.MinValue;
                maxStat.campTakenPerSec   = Double.MinValue;
                maxStat.damageTakenPerSec = Double.MinValue;
                maxStat.deathPerSec       = Double.MinValue;
                maxStat.dps        = Double.MinValue;
                maxStat.expPerSec  = Double.MinValue;
                maxStat.hps        = Double.MinValue;
                maxStat.killPerSec = Double.MinValue;
                maxStat.sdps       = Double.MinValue;
                maxStat.sec        = Double.MinValue;
                maxStat.winrate    = 0;
            }

            for (int i = 0; i < avgStat.Length; i++)
            {
                if (avgStat[i].count == 0)
                {
                    continue;
                }
                minStat.assistPerSec      = Min(minStat.assistPerSec, avgStat[i].assistPerSec);
                minStat.campTakenPerSec   = Min(minStat.campTakenPerSec, avgStat[i].campTakenPerSec);
                minStat.damageTakenPerSec = Min(minStat.damageTakenPerSec, avgStat[i].damageTakenPerSec);
                minStat.deathPerSec       = Min(minStat.deathPerSec, avgStat[i].deathPerSec);
                minStat.dps        = Min(minStat.dps, avgStat[i].dps);
                minStat.expPerSec  = Min(minStat.expPerSec, avgStat[i].expPerSec);
                minStat.hps        = Min(minStat.hps, avgStat[i].hps);
                minStat.killPerSec = Min(minStat.killPerSec, avgStat[i].killPerSec);
                minStat.sdps       = Min(minStat.sdps, avgStat[i].sdps);
                minStat.sec        = Min(minStat.sec, avgStat[i].sec);

                maxStat.assistPerSec      = Max(maxStat.assistPerSec, avgStat[i].assistPerSec);
                maxStat.campTakenPerSec   = Max(maxStat.campTakenPerSec, avgStat[i].campTakenPerSec);
                maxStat.damageTakenPerSec = Max(maxStat.damageTakenPerSec, avgStat[i].damageTakenPerSec);
                maxStat.deathPerSec       = Max(maxStat.deathPerSec, avgStat[i].deathPerSec);
                maxStat.dps        = Max(maxStat.dps, avgStat[i].dps);
                maxStat.expPerSec  = Max(maxStat.expPerSec, avgStat[i].expPerSec);
                maxStat.hps        = Max(maxStat.hps, avgStat[i].hps);
                maxStat.killPerSec = Max(maxStat.killPerSec, avgStat[i].killPerSec);
                maxStat.sdps       = Max(maxStat.sdps, avgStat[i].sdps);
                maxStat.sec        = Max(maxStat.sec, avgStat[i].sec);
            }

            return(new Tuple <HeroStatisticItemMin, HeroStatisticItemMax>(minStat, maxStat));
        }
Exemplo n.º 7
0
        public override void Run(string[] args)
        {
            base.Run(args);
            Validate();
            rParser.Run(args);

            Statistic[] stat = new Statistic[rParser.MapCount + 1];

            HeroStatisticItemAvg[] avgStat = new HeroStatisticItemAvg[1000];
            HeroStatisticItemMin[] minStat = new HeroStatisticItemMin[1000];
            HeroStatisticItemMax[] maxStat = new HeroStatisticItemMax[1000];

            InitializeHeroStat(avgStat, minStat, maxStat);

            OpenSource(inputFolder);

            object data;
            int    i = 0;
            List <Tuple <int, int, HeroStatisticItem> > temps = new List <Tuple <int, int, HeroStatisticItem> >();
            Dictionary <Match, double> result = new Dictionary <Match, double>();

            Console.WriteLine("Парсинг матчей");
            int heroCount   = 0;
            int lastMatchId = -1;

            while ((data = ReadData()) != null)
            {
                var r = ParseData(data);
                if (r.Item1 == -1)
                {
                    continue;
                }

                if (lastMatchId == r.Item1)
                {
                    continue;
                }

                temps.Add(r);
                i++;

                r.Item3.sec = rParser.ReplayResult[temps[0].Item1].Item2;

                UpdateHeroStat(avgStat, minStat, maxStat, r);

                //собираем части воедино
                if (i == 10)
                {
                    i = 0;
                    bool flag = false;
                    for (int j = 0; j < 9; j++)
                    {
                        if (temps[j].Item1 != temps[j + 1].Item1)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag == true)
                    {
                        temps.Clear();
                        continue;
                    }

                    Match m = new Match();
                    m.Map = rParser.ReplayResult[temps[0].Item1].Item1;
                    m.ProbabilityToWin = 1;
                    int first_i = 0, second_i = 0;
                    for (int j = 0; j < temps.Count; j++)
                    {
                        if (temps[j].Item3.winrate == 1)
                        {
                            m.YourTeam[first_i++] = temps[j].Item2;
                        }
                        else
                        {
                            m.EnemyTeam[second_i++] = temps[j].Item2;
                        }
                        if (temps[j].Item2 > heroCount)
                        {
                            heroCount = temps[j].Item2;
                        }
                    }
                    //обратное
                    Match temp_m = new Match()
                    {
                        YourTeam  = m.EnemyTeam,
                        EnemyTeam = m.YourTeam,
                        Map       = m.Map
                    };
                    //пробуем добавить
                    //если запись уже есть
                    if (result.ContainsKey(m))
                    {
                        //усредняем вероятность
                        double used  = result[m];
                        double newer = m.ProbabilityToWin;
                        double rez   = (used + newer) / 2;
                        result[m] = rez;
                        Console.WriteLine(m.ToString() + " Уже существует");
                    }
                    //если есть противоречие
                    else if (result.ContainsKey(temp_m))
                    {
                        //усредняем вероятность
                        double used  = result[m];
                        double newer = 1 - m.ProbabilityToWin;
                        double rez   = (used + newer) / 2;
                        result[m] = rez;
                    }
                    else
                    {
                        result.Add(m, m.ProbabilityToWin);
                        if (result.Count % 100000 == 0)
                        {
                            Console.WriteLine("Уже обработано " + result.Count);
                        }
                    }
                    lastMatchId = temps.Last().Item1;
                    temps.Clear();
                }
            }

            ClearEmptyStat(ref avgStat, ref minStat, ref maxStat);
            ComputeAverage(avgStat);

            Tuple <HeroStatisticItemAvg[], HeroStatisticItemMin[], HeroStatisticItemMax[]> heroStat =
                new Tuple <HeroStatisticItemAvg[], HeroStatisticItemMin[], HeroStatisticItemMax[]>(avgStat, minStat, maxStat);

            Save(output, result, typeof(Dictionary <Match, double>));

            File.WriteAllText(statisticHeroOutput, JSonParser.Save(heroStat, typeof(Tuple <HeroStatisticItemAvg[], HeroStatisticItemMin[], HeroStatisticItemMax[]>)), Encoding.Default);

            Array.Resize(ref avgStat, 0);
            Array.Resize(ref minStat, 0);
            Array.Resize(ref maxStat, 0);

            for (int j = 0; j < stat.Length; j++)
            {
                stat[j] = new Statistic()
                {
                    Statictic = new StatisticItem()
                    {
                        Matches = new int[heroCount + 1],
                        Wins    = new int[heroCount + 1]
                    }
                };
            }

            Console.WriteLine("Расчет статистики матчей");
            ///считаем сколько матчей на каждой карте
            foreach (var it in rParser.ReplayResult)
            {
                stat[it.Value.Item1].Statictic.Ammount++;
            }

            //данные собраны,считаем статистику
            Console.WriteLine("Расчет статистики героев");

            foreach (var it in result)
            {
                Match cur = it.Key;
                for (int j = 0; j < 5; j++)
                {
                    stat[cur.Map].Statictic.Matches[cur.YourTeam[j]]++;
                    stat[cur.Map].Statictic.Wins[cur.YourTeam[j]]++;
                }
                for (int j = 0; j < 5; j++)
                {
                    stat[cur.Map].Statictic.Matches[cur.EnemyTeam[j]]++;
                }
            }

            File.WriteAllText(statisticOutput, JSonParser.Save(stat, typeof(Statistic[])), Encoding.Default);

            Console.WriteLine("Успешно спарсено " + result.Count + " записей");
        }
Exemplo n.º 8
0
        public void DeleterHeroTest()
        {
            List <Hero> heroesInput = new List <Hero>()
            {
                new Hero(0, "Unknown", 0, 0),
                new Hero(1, "FirstHero", (HeroGroup)3, (HeroSubGroup)2),
                new Hero(2, "WhoItIs?", (HeroGroup)(-1), (HeroSubGroup)2),
                new Hero(3, "Artanis", (HeroGroup)4, (HeroSubGroup)2)
            };

            List <Hero> heroesTarget = new List <Hero>()
            {
                new Hero(0, "FirstHero", (HeroGroup)3, (HeroSubGroup)2),
                new Hero(1, "Artanis", (HeroGroup)4, (HeroSubGroup)2)
            };

            HeroStatisticItemAvg[] heroesAvg = new HeroStatisticItemAvg[]
            {
                new HeroStatisticItemAvg()
                {
                    count = 0
                },
                new HeroStatisticItemAvg()
                {
                    count = 1
                },
                new HeroStatisticItemAvg()
                {
                    count = 0
                },
                new HeroStatisticItemAvg()
                {
                    count = 124124
                }
            };

            HeroStatisticItemMin[] heroesMin = new HeroStatisticItemMin[]
            {
                new HeroStatisticItemMin()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMin()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMin()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMin()
                {
                    assistPerSec = 0
                }
            };

            HeroStatisticItemMax[] heroesMax = new HeroStatisticItemMax[]
            {
                new HeroStatisticItemMax()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMax()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMax()
                {
                    assistPerSec = 0
                },
                new HeroStatisticItemMax()
                {
                    assistPerSec = 0
                }
            };

            List <int> unusedTarget = new List <int>()
            {
                2, 0
            };

            AutoParser.HParser = new AutoParser.HeroParser("", "")
            {
                Hero = heroesInput
            };
            AutoParser.RSParser = new AutoParser.ReplaySchemaParser("", "", "", "", "", "")
            {
                AvgStat = heroesAvg,
                MinStat = heroesMin,
                MaxStat = heroesMax
            };

            List <HeroStatisticItemAvg> avgList = heroesAvg.ToList();
            List <HeroStatisticItemMin> minList = heroesMin.ToList();
            List <HeroStatisticItemMax> maxList = heroesMax.ToList();

            var unusedOutput = GetUnusedHero(avgList);

            CollectionAssert.AreEqual(unusedTarget, unusedOutput);

            RemoveUnusedHero(avgList, minList, maxList, unusedOutput);

            Assert.AreEqual(avgList.Count, 2);
            Assert.AreEqual(minList.Count, 2);
            Assert.AreEqual(maxList.Count, 2);

            IndexateHeroes(avgList, minList, maxList);

            CollectionAssert.AreEqual(heroesInput, heroesTarget);
        }