Esempio n. 1
0
        public async Task <ActionResult> Compare(CompareStatisticModel model)
        {
            try
            {
                if (model != null)
                {
                    model = await runCompare(model);
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                // just redisplay the form if something failed.
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
        }
Esempio n. 2
0
        // GET: LoadCompare
        public ActionResult LoadCompare(int id, int MinFTR = 0)
        {
            CompareStatisticModel model = new CompareStatisticModel();
            ScrapedMatches        match = new ScrapedMatches();
            // Create Cachekey from parameters
            var CACHEKEY = $"cacheKey:MatchId={id}-MinFTR={MinFTR}";

            // If we have object in cache, return it
            if (Cache.Exists(CACHEKEY))
            {
                model = (CompareStatisticModel)Cache.Get(CACHEKEY);
            }
            else
            {
                match = _dataWorker.GetScrapedMatch(id);

                if (match != null)
                {
                    if (MinFTR == 5)
                    {
                        model = JsonConvert.DeserializeObject <CompareStatisticModel>(match.Json5MinFTR);
                    }
                    else if (MinFTR == 4)
                    {
                        model = JsonConvert.DeserializeObject <CompareStatisticModel>(match.Json4MinFTR);
                    }
                    else
                    {
                        model = JsonConvert.DeserializeObject <CompareStatisticModel>(match.Json);
                    }
                }

                // Save in cache
                if (!string.IsNullOrEmpty(CACHEKEY) && !Cache.Exists(CACHEKEY))
                {
                    int storeTime = 1000 * 3600 * 24 * 2; // store 2 days
                    Cache.Store(CACHEKEY, model, storeTime);
                }
            }

            model.ScrapeMatchId      = id;
            model.MinFullTeamRanking = MinFTR;
            return(View(model));
        }
Esempio n. 3
0
        public void GenerateSuggestedMaps(ref CompareStatisticModel model)
        {
            if (model.Teams.Count == 2)
            {
                foreach (var period in model.Teams[0].TeamStatistics)
                {
                    var PeriodName = period.Period;
                    foreach (var map in period.Maps)
                    {
                        FindMatchingMaps(map, PeriodName, model.Teams[1]);
                    }
                }


                foreach (var period in model.Teams[1].TeamStatistics)
                {
                    var PeriodName = period.Period;
                    foreach (var map in period.Maps)
                    {
                        FindMatchingMaps(map, PeriodName, model.Teams[0]);
                    }
                }
            }
        }
Esempio n. 4
0
        public async Task <CompareStatisticModel> runCompare(CompareStatisticModel model)
        {
            try
            {
                if (model != null)
                {
                    if (!string.IsNullOrEmpty(model.MatchUrl) || model.Team1Id > 0 || model.Team2Id > 0)
                    {
                        if (!string.IsNullOrEmpty(model.MatchUrl))
                        {
                            Program.MatchUrl = model.MatchUrl;
                            var result = _program.GetTeamIdsFromUrl(model.MatchUrl);

                            model.Team1Id        = result.Item1;
                            model.Team2Id        = result.Item2;
                            model.ExpectedLineUp = _program.GetTeamLineup(model.MatchUrl, model.Team1Id, model.Team2Id);
                        }
                        else
                        {
                            model.ExpectedLineUp = new ExpectedLineUp();
                        }
                        if (model.Team1Id > 0)
                        {
                            var secondaryTeamId = _dataWorker.GetSecondaryTeamId(model.Team1Id);

                            if (model.Scrape)
                            {
                                await _program.GetTeamDetails(model.Team1Id);
                            }

                            var logo = CheckIfLogoExist(model.Team1Id);
                            model.Teams.Add(await _dataWorker.GetTeamPeriodStatistics(model.Team1Id, model.PeriodSelection, model.ExpectedLineUp, secondaryTeamId, model.NoCache, model.MinFullTeamRanking, _program.Team1Rank, logo));
                        }
                        if (model.Team2Id > 0)
                        {
                            var secondaryTeamId = _dataWorker.GetSecondaryTeamId(model.Team2Id);

                            if (model.Scrape)
                            {
                                await _program.GetTeamDetails(model.Team2Id);
                            }
                            var logo = CheckIfLogoExist(model.Team2Id);
                            model.Teams.Add(await _dataWorker.GetTeamPeriodStatistics(model.Team2Id, model.PeriodSelection, model.ExpectedLineUp, secondaryTeamId, model.NoCache, model.MinFullTeamRanking, _program.Team2Rank, logo));
                        }

                        if (model.Teams != null && model.Teams.Count > 0)
                        {
                            _dataWorker.GenerateSuggestedMaps(ref model);
                        }


                        if (model != null)
                        {
                            ScrapedMatches scrapedMatch = new ScrapedMatches();
                            scrapedMatch.SportName = "CS:GO";
                            scrapedMatch.Event     = model.ExpectedLineUp.EventName;
                            scrapedMatch.MatchId   = model.ExpectedLineUp.MatchId;
                            scrapedMatch.Start     = model.ExpectedLineUp.Start;
                            scrapedMatch.MatchUrl  = model.MatchUrl;
                            scrapedMatch.Name      = $"{model.Teams[0].TeamName} - {model.Teams[1].TeamName}";
                            if (model.MinFullTeamRanking == 4)
                            {
                                scrapedMatch.Json4MinFTR = JsonConvert.SerializeObject(model);
                            }
                            else if (model.MinFullTeamRanking == 5)
                            {
                                scrapedMatch.Json5MinFTR = JsonConvert.SerializeObject(model);
                            }
                            else
                            {
                                scrapedMatch.Json = JsonConvert.SerializeObject(model);
                            }
                            _dataWorker.AddScrapedMatch(scrapedMatch, model.MinFullTeamRanking);
                        }
                    }
                }


                return(model);
            }
            catch (Exception ex)
            {
                // just redisplay the form if something failed.
                ModelState.AddModelError("", ex.Message);
                return(new CompareStatisticModel());
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> SendToCompare(string url)
        {
            var scrapedmatchid = 0;

            try
            {
                var PeriodSelection = new List <string>();
                PeriodSelection.Add("3");
                PeriodSelection.Add("6");
                var model = new CompareStatisticModel();

                if (!url.Contains("http://www.hltv.org/"))
                {
                    model.MatchUrl = "http://www.hltv.org/" + url;
                }
                else
                {
                    model.MatchUrl = url;
                }


                model.Scrape          = true;
                model.PeriodSelection = PeriodSelection;

                // ******* Get Ids and teamlineup *******
                if (url.Length > 0)
                {
                    var result = _program.GetTeamIdsFromUrl(model.MatchUrl);
                    model.Team1Id        = result.Item1;
                    model.Team2Id        = result.Item2;
                    model.ExpectedLineUp = _program.GetTeamLineup(model.MatchUrl, model.Team1Id, model.Team2Id);
                }

                // ******* Scrape *******
                if (model.Team1Id > 0)
                {
                    if (model.Scrape)
                    {
                        await _program.GetTeamDetails(model.Team1Id);
                    }
                }
                if (model.Team2Id > 0)
                {
                    if (model.Scrape)
                    {
                        await _program.GetTeamDetails(model.Team2Id);
                    }
                }

                if (model.Team1Id > 0 && model.Team2Id > 0)
                {
                    var secondaryTeam1Id = _dataWorker.GetSecondaryTeamId(model.Team1Id);
                    var secondaryTeam2Id = _dataWorker.GetSecondaryTeamId(model.Team2Id);
                    model.HeadToHead = _dataWorker.GetHeadToHeadMatches(model.Team1Id, model.Team2Id);
                    var Team1Form = _dataWorker.GetTeamForm(model.Team1Id);
                    var Team2Form = _dataWorker.GetTeamForm(model.Team2Id);

                    List <int> FTR = new List <int> {
                        0, 4, 5
                    };
                    List <Tuple <int, string> > jsonlist = new List <Tuple <int, string> >();

                    // ******* Create model result for each MinFtr and save as json *******
                    foreach (int ftr in FTR)
                    {
                        model.Teams = new List <TeamStatisticPeriodModel>();
                        var logo = CheckIfLogoExist(model.Team1Id);
                        model.Teams.Add(await _dataWorker.GetTeamPeriodStatistics(model.Team1Id, model.PeriodSelection, model.ExpectedLineUp, secondaryTeam1Id, model.NoCache, ftr, _program.Team1Rank, logo));
                        var logo2 = CheckIfLogoExist(model.Team2Id);
                        model.Teams.Add(await _dataWorker.GetTeamPeriodStatistics(model.Team2Id, model.PeriodSelection, model.ExpectedLineUp, secondaryTeam2Id, model.NoCache, ftr, _program.Team2Rank, logo2));
                        if (model.Teams != null && model.Teams.Count > 0)
                        {
                            _dataWorker.GenerateSuggestedMaps(ref model);
                            if (model.Teams.Count > 1)
                            {
                                model.Teams[0].Form = Team1Form;
                                model.Teams[1].Form = Team2Form;
                            }
                        }
                        if (model != null)
                        {
                            jsonlist.Add(new Tuple <int, string>(ftr, JsonConvert.SerializeObject(model)));
                        }
                    }

                    // ******* If we have any json result we create ScrapedMatch and fill in info *******
                    if (jsonlist.Count > 0)
                    {
                        ScrapedMatches scrapedMatch = new ScrapedMatches();
                        scrapedMatch.SportName = "CS:GO";
                        scrapedMatch.Event     = model.ExpectedLineUp.EventName;
                        scrapedMatch.MatchId   = model.ExpectedLineUp.MatchId;
                        scrapedMatch.Start     = model.ExpectedLineUp.Start;
                        scrapedMatch.MatchUrl  = model.MatchUrl;
                        scrapedMatch.Team1Id   = model.Teams[0].TeamId;
                        scrapedMatch.Team1Name = model.Teams[0].TeamName;
                        scrapedMatch.Team1Logo = CheckIfLogoExist(model.Teams[0].TeamId);
                        scrapedMatch.Team2Id   = model.Teams[1].TeamId;
                        scrapedMatch.Team2Name = model.Teams[1].TeamName;
                        scrapedMatch.Team2Logo = CheckIfLogoExist(model.Teams[1].TeamId);
                        scrapedMatch.Name      = $"{model.Teams[0].TeamName} - {model.Teams[1].TeamName}";
                        if (jsonlist.Any(p => p.Item1 == 4))
                        {
                            scrapedMatch.Json4MinFTR = jsonlist.Single(p => p.Item1 == 4).Item2;
                        }
                        if (jsonlist.Any(p => p.Item1 == 5))
                        {
                            scrapedMatch.Json5MinFTR = jsonlist.Single(p => p.Item1 == 5).Item2;
                        }
                        if (jsonlist.Any(p => p.Item1 == 0))
                        {
                            scrapedMatch.Json = jsonlist.Single(p => p.Item1 == 0).Item2;
                        }
                        scrapedmatchid = _dataWorker.AddScrapedMatch(scrapedMatch, -1);
                    }
                }
            }
            catch (Exception ex)
            {
                // Do nothing
            }

            return(RedirectToAction("LoadCompare", new { id = scrapedmatchid, MinFTR = 0 }));
        }