private void MatchControls(BackgroundWorker backgroundWorker) { List <Match> addedMatches = new List <Match>(); using (var db = new MatchModel()) { db.Database.CommandTimeout = Int32.MaxValue; int val = 0; List <FullOdd> dbFullOdds = db.FullOdds.ToList(); List <MatchResult> dbMatchResults = db.MatchResults.ToList(); List <Team> dbTeams = db.Teams.ToList(); List <League> dbLeagues = db.Leagues.ToList(); List <Date> dates = db.Dates.ToList(); List <Time> dbTimes = db.Times.ToList(); string adaptedHomeTeamName; string adaptedAwayTeamName; int counter = 0; foreach (var analysedMatch in analysedMatches) { SetStoreStatus("Storing : " + analysedMatch.HomeTeamName + "-" + analysedMatch.AwayTeamName); FullOdd fullOdd = dbFullOdds.First(x => x.Value == analysedMatch.FullOdd); League league = dbLeagues.First(x => x.LeagueName == analysedMatch.LeagueName); adaptedHomeTeamName = analysedMatch.HomeTeamName.Replace(" ", "").ToLower(); adaptedAwayTeamName = analysedMatch.AwayTeamName.Replace(" ", "").ToLower(); Team homeTeam = dbTeams.First(x => x.AdaptedTeamName == adaptedHomeTeamName); Team awayTeam = dbTeams.First(x => x.AdaptedTeamName == adaptedAwayTeamName); Time time = dbTimes.First(x => x.StrTime == analysedMatch.MatchTime); MatchResult matchResult = dbMatchResults .First(x => x.FirstHalfHomeScore == analysedMatch.FhHomeScore && x.FirstHalfAwayScore == analysedMatch.FhAwayScore && x.MatchHomeScore == analysedMatch.MsHomeScore && x.MatchAwayScore == analysedMatch.MsAwayScore); Date date = dates.First(x => x.Day == analysedMatch.MatchDay && x.Month == analysedMatch.MatchMonth && x.Year == analysedMatch.MatchYear); Match match = new Match(); match.SetMatch(date, time, homeTeam, awayTeam, league, matchResult, fullOdd, analysedMatch.MatchCode); val = 10 + ((20 * ++counter) / analysedMatches.Count); addedMatches.Add(match); backgroundWorker.ReportProgress(val); } db.SaveChanges(); } newMatchIds = new HashSet <int>(addedMatches.Select(x => x.MatchId)); ImportReport.NewMatchCount = newMatchIds.Count; }
//----- private void LeagueControls() { SetStoreStatus("New League Controls"); using (var db = new MatchModel()) { HashSet <string> currentLeagueNames = new HashSet <string>(analysedMatches.Select(x => x.LeagueName).ToList()); List <string> dbLeagueNames = db.Leagues.Select(x => x.LeagueName).ToList(); HashSet <string> newLeagueNames = new HashSet <string>(currentLeagueNames.Except(dbLeagueNames)); List <League> newLeagues = new List <League>(); foreach (var newLeagueName in newLeagueNames) { newLeagues.Add(new League(newLeagueName)); } db.Leagues.AddRange(newLeagues); db.SaveChanges(); ImportReport.NewLeagueCount = newLeagues.Count; } }
//----- private void FullOddUpdateControls(BackgroundWorker backgroundWorker) { SetStoreStatus("Full Odd Controls"); try { using (var db = new MatchModel()) { List <FullOdd> dbFullOdds = db.FullOdds.AsParallel().ToList(); foreach (var dbFullOdd in dbFullOdds) { if (updatedFullOddOddCombIds.Keys.Contains(dbFullOdd.FullOddId)) { dbFullOdd.OddCombinationIds = string.Join("|", updatedFullOddOddCombIds[dbFullOdd.FullOddId]); } else if (dbFullOdd.OddCombinationIds != null && dbFullOdd.OddCombinationIds != "") { SortedSet <int> oddCombIds = new SortedSet <int>(); foreach (var item in dbFullOdd.OddCombinationIds.Split('|')) { oddCombIds.Add(int.Parse(item)); } dbFullOdd.OddCombinationIds = string.Join("|", oddCombIds.Except(removedIds)); } dbFullOdd.IntersectedResults = string.Join("|", fullOddResults[dbFullOdd.FullOddId]); } db.SaveChanges(); } } catch (Exception e) { string sds = e.ToString(); throw; } backgroundWorker.ReportProgress(90); }
public void ApplyMatchOperations(BackgroundWorker backgroundWorker) { int day = 0; int month = 0; int year = 0; var dailyAnalysedMatches = analysedMatches.GroupBy(x => new { x.MatchDay, x.MatchMonth, x.MatchYear }); using (var db = new MatchModel()) { foreach (var dateItem in dailyAnalysedMatches) { day = (int)dateItem.Key.MatchDay; month = (int)dateItem.Key.MatchMonth; year = (int)dateItem.Key.MatchYear; OldAnalysedMatchControls(db, day, month, year); foreach (var analysedMatch in dateItem) { db.AnalysedMatches.Add(analysedMatch); } } db.SaveChanges(); } }
private void FullOddControls() { SetStoreStatus("FullOdd Controls"); List <FullOdd> newFullOdds = new List <FullOdd>(); using (var db = new MatchModel()) { List <string> newOddValues = analysedMatches.Select(x => x.FullOdd).Except(db.FullOdds.AsParallel().Select(x => x.Value)).ToList(); foreach (var newOddValue in newOddValues) { newFullOdds.Add(new FullOdd(newOddValue)); } db.FullOdds.AddRange(newFullOdds); db.SaveChanges(); } newFullOddIdValues = new Dictionary <int, string[]>(); foreach (var newFullOdd in newFullOdds) { newFullOddIdValues.Add(newFullOdd.FullOddId, newFullOdd.Value.Split('|')); } ImportReport.NewFullOddCount = newFullOdds.Count; }
private void FillMatchFullOddCollections(BackgroundWorker backgroundWorker) { allFullOddValues = new Dictionary <int, string[]>(); fullOddResults = new Dictionary <int, HashSet <Result> >(); fullOddMatchCounts = new Dictionary <int, int>(); using (var db = new MatchModel()) { List <FullOdd> dbFullOdds = db.FullOdds.AsNoTracking().ToList(); foreach (var dbFullOdd in dbFullOdds) { allFullOddValues.Add(dbFullOdd.FullOddId, dbFullOdd.Value.Split('|')); fullOddMatchCounts.Add(dbFullOdd.FullOddId, dbFullOdd.Matches.Count); fullOddResults.Add(dbFullOdd.FullOddId, dbFullOdd.Matches.Skip(1) .Aggregate( new HashSet <Result>(dbFullOdd.Matches.First().MatchResult.GeneralResult.Results), (h, e) => { h.IntersectWith(e.MatchResult.GeneralResult.Results); return(h); } )); } } backgroundWorker.ReportProgress(60); }
private void PartialOddUpdateControls(BackgroundWorker backgroundWorker) { SetStoreStatus("Partial Odd Controls"); using (var db = new MatchModel()) { Dictionary <string, int> currentPartialOddValueIds = new Dictionary <string, int>(); Dictionary <PartialOddType, Dictionary <string, SortedSet <int> > > currentPartialOdds = new Dictionary <PartialOddType, Dictionary <string, SortedSet <int> > >(); Dictionary <PartialOddType, Dictionary <string, SortedSet <int> > > newPartialOdds = new Dictionary <PartialOddType, Dictionary <string, SortedSet <int> > >(); HashSet <int> updatedIds = new HashSet <int>(); List <PartialOdd> dbPartialOdds = db.PartialOdds.ToList(); foreach (var partialOddType in partialOddTypes) { currentPartialOdds.Add(partialOddType, new Dictionary <string, SortedSet <int> >()); newPartialOdds.Add(partialOddType, new Dictionary <string, SortedSet <int> >()); } foreach (var dbPartialOdd in dbPartialOdds) { List <string> strFullOddIds = dbPartialOdd.FullOddIds.Split('|').ToList(); List <int> intFullOddIDs = new List <int>(); foreach (var item in strFullOddIds) { intFullOddIDs.Add(int.Parse(item)); } currentPartialOddValueIds.Add(dbPartialOdd.OddValues, dbPartialOdd.PartialOddId); currentPartialOdds[(PartialOddType)dbPartialOdd.PartialOddType].Add(dbPartialOdd.OddValues, new SortedSet <int>(intFullOddIDs)); } backgroundWorker.ReportProgress(35); List <FullOdd> newFullOdds = db.FullOdds.AsParallel().Where(x => newFullOddIdValues.Keys.Contains(x.FullOddId)).ToList(); foreach (var newFullOdd in newFullOdds) { foreach (var tempPartialOdd in GetTempPartialOdds(newFullOdd.Value)) { string str = string.Join("|", tempPartialOdd.Value); if (!currentPartialOdds[tempPartialOdd.Key].ContainsKey(str)) { if (!newPartialOdds[tempPartialOdd.Key].ContainsKey(str)) { newPartialOdds[tempPartialOdd.Key].Add(str, new SortedSet <int>()); } newPartialOdds[tempPartialOdd.Key][str].Add(newFullOdd.FullOddId); } else { currentPartialOdds[tempPartialOdd.Key][str].Add(newFullOdd.FullOddId); updatedIds.Add(currentPartialOddValueIds[str]); } } } backgroundWorker.ReportProgress(40); foreach (var uptadedPartialOdd in dbPartialOdds.Where(x => updatedIds.Contains(x.PartialOddId))) { uptadedPartialOdd.FullOddIds = string.Join("|", currentPartialOdds[(PartialOddType)uptadedPartialOdd.PartialOddType][uptadedPartialOdd.OddValues]); } db.SaveChanges(); List <PartialOdd> newDbPartialOdds = new List <PartialOdd>(); foreach (var partialOddType in newPartialOdds) { int intPartialOddType = (int)partialOddType.Key; foreach (var oddValues in partialOddType.Value) { newDbPartialOdds.Add(new PartialOdd(intPartialOddType, oddValues.Key, string.Join("|", oddValues.Value))); } } db.PartialOdds.AddRange(newDbPartialOdds); db.SaveChanges(); ImportReport.NewPartialOddCount = newDbPartialOdds.Count; ImportReport.UpdatedPartialOddCount = updatedIds.Count; backgroundWorker.ReportProgress(45); } }
private void UpdateCurrentOddCombs(BackgroundWorker backgroundWorker) { updatedFullOddOddCombIds = new Dictionary <int, HashSet <int> >(); updatedOddCombvalues = new HashSet <string>(); using (var db = new MatchModel()) { List <OddCombination> oddCombs = db.OddCombinations.AsParallel().Where(x => processedOddCombResults.Keys.Contains(x.Value)).ToList(); int counter = 0; foreach (var oddComb in oddCombs) { counter++; updatedOddCombvalues.Add(oddComb.Value); int count = 0; foreach (var fullOddId in processedOddCombFullOddIds[oddComb.Value]) { count = count + fullOddMatchCounts[fullOddId]; if (!updatedFullOddOddCombIds.ContainsKey(fullOddId)) { updatedFullOddOddCombIds.Add(fullOddId, new HashSet <int>()); } updatedFullOddOddCombIds[fullOddId].Add(oddComb.OddCombinationId); } oddComb.ResultOrders = string.Join("|", processedOddCombResults[oddComb.Value]); oddComb.FullOddIds = string.Join("|", processedOddCombFullOddIds[oddComb.Value]); oddComb.MatchCount = count; if (counter % 10000 == 0) { db.SaveChanges(); } } db.SaveChanges(); ImportReport.UpdatedOddCombinationCount = counter; backgroundWorker.ReportProgress(75); } // try // { // // DataTable dataTable = new DataTable(); // dataTable.Columns.Add("OddCombinationId"); // dataTable.Columns.Add("ResultOrders"); // dataTable.Columns.Add("FullOddIds"); // dataTable.Columns.Add("MatchCount"); // updatedOddCombvalues = new HashSet<string>(); // foreach (var item in processedOddCombResults.Where(x => oddCombValueIds.Keys.Contains(x.Key))) // { // updatedOddCombvalues.Add(item.Key); // int id = oddCombValueIds[item.Key]; // int count = 0; // foreach (var fullOddId in processedOddCombFullOddIds[item.Key]) // { // count = count + fullOddMatchCounts[fullOddId]; // if (!updatedFullOddOddCombIds.ContainsKey(fullOddId)) // updatedFullOddOddCombIds.Add(fullOddId, new HashSet<int>()); // // updatedFullOddOddCombIds[fullOddId].Add(id); // } // dataTable.Rows.Add(id, string.Join("|", item.Value), string.Join("|", processedOddCombFullOddIds[item.Key]), count); // } // using (SQLiteConnection con = new SQLiteConnection(EmbedValueController.connectionString)) // { // using (SQLiteCommand cmd = new SQLiteCommand("Update_OddCombinations")) // { // cmd.CommandType = CommandType.StoredProcedure; // cmd.Connection = con; // cmd.Parameters.AddWithValue("@updateElement", dataTable); // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // } // } // ImportReport.UpdatedOddCombinationCount = dataTable.Rows.Count; // // } // catch (Exception e) // { // string sada = e.ToString(); // throw; // } }
private void SetLimits() { analyseLimitMap = new Dictionary <string, AnalyseLimitContanier>(); analyseLimits = new List <AnalyseLimitContanier>(); using (var db = new MatchModel()) { List <AnalyseLimit> dbAnalyseLimits = db.AnalyseLimits.AsNoTracking().ToList(); foreach (var dbAnalyseLimit in dbAnalyseLimits) { TextBox maxTextBox; TextBox minTextBox; switch (dbAnalyseLimit.LimitType) { case "oddCombMatchCount": maxTextBox = txtOddCombinationMatchMax; minTextBox = txtOddCombinationMatchMin; break; case "oddCombResultMatchCount": maxTextBox = txtOddCombinationResultMatchMax; minTextBox = txtOddCombinationResultMatchMin; break; case "oddCombFullOddCount": maxTextBox = txtOddCombinationFullOddMax; minTextBox = txtOddCombinationFullOddMin; break; case "oddCombResultFullOddCount": maxTextBox = txtOddCombinationResultFullOddMax; minTextBox = txtOddCombinationResultFullOddMin; break; case "partialOddMatchCount": maxTextBox = txtPartialOddMatchMax; minTextBox = txtPartialOddMatchMin; break; case "partialOddResultMatchCount": maxTextBox = txtPartialOddResultMatchMax; minTextBox = txtPartialOddResultMatchMin; break; case "partialOddFullOddCount": maxTextBox = txtPartialOddFullOddMax; minTextBox = txtPartialOddFullOddMin; break; case "partialOddResultFullOddCount": maxTextBox = txtPartialOddResultFullOddMax; minTextBox = txtPartialOddResultFullOddMin; break; default: maxTextBox = new TextBox(); minTextBox = new TextBox(); break; } AnalyseLimitContanier analyseLimitContanier = new AnalyseLimitContanier(dbAnalyseLimit.AnalyseLimitId, dbAnalyseLimit.LimitType, dbAnalyseLimit.MaxValue, dbAnalyseLimit.MinValue, maxTextBox, minTextBox); analyseLimits.Add(analyseLimitContanier); analyseLimitMap.Add(dbAnalyseLimit.LimitType, analyseLimitContanier); } } }