Exemplo n.º 1
0
        private static bool SaveChangesInDB(Team team, EntityState entityState)
        {
            using (MatchesContext db = new MatchesContext())
            {
                switch (entityState)
                {
                case EntityState.Added:
                    db.Entry <Team>(team).State = EntityState.Added;
                    break;

                case EntityState.Modified:
                    db.Entry <Team>(team).State = EntityState.Modified;
                    break;

                case EntityState.Deleted:
                    db.Entry <Team>(team).State = EntityState.Deleted;
                    break;

                default: return(false);
                }
                if (db.SaveChanges() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public override async ValueTask Process(MatchesContext matchesContext)
        {
            Console.WriteLine("Repairing `MatchID` to ensure it is consistent with timestamps.");

            List <Match> matches = await matchesContext.GetMatchesAsync().ToListAsync();

            int id = 1;

            foreach (Match match in matches)
            {
                if (match.ID != id)
                {
                    Match newMatch = new Match(match)
                    {
                        ID = id
                    };

                    matchesContext.Matches.Remove(match);
                    await matchesContext.Matches.AddAsync(newMatch);
                }

                id++;
            }

            Console.WriteLine("Repaired match IDs.");
        }
Exemplo n.º 3
0
        public async Task UpdateStorageAsync()
        {
            isActive = true;

            foreach (var league in leagues)
            {
                if (!isActive)
                {
                    OnCompleted?.Invoke(this);
                    return;
                }

                await parser.UpdatePartAsync(league);
            }
            isActive = false;

            using (MatchesContext db = new MatchesContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        foreach (var row in db.Matches)
                        {
                            foreach (var coeff in db.Coeffs)
                            {
                                db.Coeffs.Remove(coeff);
                            }

                            db.Matches.Remove(row);
                        }


                        foreach (var row in list)
                        {
                            db.Matches.Add(row);
                        }

                        foreach (var row in coeffs)
                        {
                            db.Coeffs.Add(row);
                        }

                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }


            OnCompleted?.Invoke(this);
        }
Exemplo n.º 4
0
        public object LoadCoeffs(string teams)
        {
            object data;

            using (MatchesContext db = new MatchesContext())
            {
                db.Coeffs.Where(p => p.Holder.Teams == teams).Load();
                data = db.Coeffs.Local.ToBindingList();
            }

            return(data);
        }
Exemplo n.º 5
0
        public void GetDataFromUrl()
        {
            int        howManyRequestsAtATime = 10;
            HttpSocket socket        = new HttpSocket();
            var        matchDataList = new List <MatchData>();

            Console.WriteLine("Total matches to request: {0}", IDMatches.Count);
            while (IDMatches.Count > 0)
            {
                var idMatches = TakeAndRemove(IDMatches, howManyRequestsAtATime);

                var urls      = GetListOfUrls(idMatches);
                var tasks     = urls.Select(socket.GetAsync).ToArray();
                var completed = Task.Factory.ContinueWhenAll(tasks, completedTasks =>
                {
                    foreach (var result in completedTasks.Select(t => t.Result))
                    {
                        if (!string.IsNullOrEmpty(result))
                        {
                            MatchData match = JsonConvert.DeserializeObject <MatchData>(result);
                            matchDataList.Add(match);
                        }
                    }
                });
                completed.Wait();
            }

            foreach (MatchData match in matchDataList)
            {
                if (match != null)
                {
                    AddMatch(match);
                }
            }

            MatchesContext.Configuration.AutoDetectChangesEnabled = false;
            MatchesContext.Configuration.ValidateOnSaveEnabled    = false;
            int count = 0;

            foreach (InitialDataUpload.Models.Match match in Matches)
            {
                MatchesContext.Matches.Add(match);
                count++;

                if (count % 100 == 0)
                {
                    count = 0;
                    MatchesContext.SaveChanges();
                }
            }

            MatchesContext.SaveChanges();
        }
Exemplo n.º 6
0
        public override async ValueTask Process(MatchesContext matchesContext)
        {
            IAsyncEnumerable <(Match Match, int SR)> matches = matchesContext.GetMatchesByOutcomeAsync(Role, Outcome);
            IAsyncEnumerable <int> srs = Change
                ? matches.Where(result => result.SR != 0).Select(result => Math.Abs(result.SR))
                : matches.Select(result => result.Match.SR);

            double average = await srs.DefaultIfEmpty().AverageAsync();

            Console.WriteLine(average == 0d
                ? $"No or not enough historic SR data for outcome '{Outcome}'."
                : $"Average historic SR for outcome '{Outcome}': {average:0}");
        }
Exemplo n.º 7
0
        public override async ValueTask Process(MatchesContext matchesContext)
        {
            List <Match> total = await matchesContext.GetMatchesByRoleAsync(Role).ToListAsync();

            IAsyncEnumerable <(Match Match, int Change)> wins = matchesContext.GetMatchesByOutcomeAsync(total.ToAsyncEnumerable(), Outcome.Win);

            double sumWins = await wins.CountAsync();

            double sumTotal = total.Count;

            double winRate           = sumWins / sumTotal;
            double percentageWinRate = winRate * 100d;

            Console.WriteLine($"Winrate for {Role} is: {percentageWinRate:0.00}%");
        }
Exemplo n.º 8
0
 // GET: Custom
 public ActionResult Index()
 {
     ViewBag.Message = "Это находится в контроллере Custom метод Index";
     using (MatchesContext db = new MatchesContext())
     {
         List <Team> models = new List <Team>();
         foreach (var item in db.Teams)
         {
             models.Add(new Team()
             {
                 TeamName = item.TeamName, City = item.City, Id = item.Id
             });
         }
         return(View(models));
     }
 }
Exemplo n.º 9
0
        public override async ValueTask Process(MatchesContext matchesContext)
        {
            IAsyncEnumerable <Match> matches = matchesContext.GetMatchesByRoleAsync(Role);

            if (!await matches.AnyAsync())
            {
                Console.WriteLine("No historic match data.");
            }
            else
            {
                using IXLWorkbook workbook = ConstructSpreadsheet(await matches.ToListAsync());

                string filePath = Path.GetFullPath($"{Name}_{Role}.xlsx");
                workbook.SaveAs(filePath);
                Console.WriteLine($"Successfully exported match data to \"{filePath}\"");
            }
        }
        public override ValueTask Process(MatchesContext matchesContext)
        {
            Match match = matchesContext.Matches.FirstOrDefault(match => match.ID == MatchID)
                          ?? throw new ArgumentOutOfRangeException(nameof(MatchID), $"Given {nameof(MatchID)} does not exist in database.");

            ProcessingFinishedMessage = $"[OLD] {Display.TableDisplay(match)}\r\n";

            switch (MatchHeader)
            {
            case Match.Header.Timestamp when DateTime.TryParse(Value, out DateTime result):
                match.Timestamp = result;

                break;

            case Match.Header.Entropic when bool.TryParse(Value, out bool result):
                match.Entropic = result;

                break;

            case Match.Header.SR when int.TryParse(Value, out int result):
                match.SR = result;

                break;

            case Match.Header.Role when Enum.TryParse(typeof(Role), Value, true, out object?result) && result is Role role:
                match.Role = role;

                break;

            case Match.Header.Map when Enum.TryParse(typeof(Map), Value, true, out object?result) && result is Map map:
                match.Map = map;

                break;

            case Match.Header.Comment:
                match.Comment = Value;
                break;

            default:
                throw new ArgumentException("Type mismatch between header and value.", nameof(Value));
            }

            ProcessingFinishedMessage += $"[NEW] {Display.TableDisplay(match)}\r\n";

            return(default);
Exemplo n.º 11
0
 public static IList <Team> GetTeamsCollection()
 {
     if (TeamsCollection == null)
     {
         TeamsCollection = new List <Team>();
         using (MatchesContext db = new MatchesContext())
         {
             foreach (var item in db.Teams)
             {
                 TeamsCollection.Add(new Team()
                 {
                     TeamName = item.TeamName, City = item.City, Id = item.Id
                 });
             }
         }
         return(TeamsCollection);
     }
     else
     {
         return(TeamsCollection);
     }
 }