/// <summary> /// PrevAvgStrength depends on: /// 1). current result /// 2). field /// 3). OtherTeam previous grLevel /// </summary> protected byte?getStrength2(RoundValue prevRVal, KeyValuePair <string, HistoryValue> kvp) { bool isHome = kvp.Value.Field == "HOME"; int? result = kvp.Value.ScoreH - kvp.Value.ScoreA; return((byte)(mainForm.excel.getByte(((char)((result == 0 ? 'H' : 'C') + (isHome ? 0 : 1))).ToString() + ( (isHome && result >= 0 || !isHome && result > 0 ? MainForm.XLSXHOMEWINDRAWY : MainForm.XLSXAWAYWINDRAWY) + (prevRVal.tDict.ContainsKey(kvp.Value.OtherTeam) ? (int)prevRVal.tDict[kvp.Value.OtherTeam].grLevel : 5) )) * 100)); }
protected byte?getStrength1(RoundValue prevRVal, KeyValuePair <string, HistoryValue> kvp) { bool isHome = kvp.Value.Field == "HOME"; int? result = kvp.Value.ScoreH - kvp.Value.ScoreA; result = result > 0 ? 0 : result < 0 ? 2 : 1; StringBuilder excelCell = new StringBuilder(((char)((isHome ? 'C' : 'E') + 7 * result)).ToString()); excelCell.Append(3 + 6 * prevRVal.tDict[isHome ? kvp.Value.OtherTeam : kvp.Key].grLevel + prevRVal.tDict[isHome ? kvp.Key : kvp.Value.OtherTeam].grLevel); return((byte)((mainForm.excel.getByte(excelCell.ToString()) + 100) / 2)); }
public RoundValue(RoundValue rVal) { this.maxPoints = rVal.maxPoints; this.minPoints = rVal.minPoints; this.tDict = new Dictionary<string, HistoryValue>(); }
/// <summary> /// PrevAvgStrength depends on: /// 1). current result /// 2). field /// 3). OtherTeam previous grLevel /// </summary> protected byte? getStrength2(RoundValue prevRVal, KeyValuePair<string, HistoryValue> kvp) { bool isHome = kvp.Value.Field == "HOME"; int? result = kvp.Value.ScoreH - kvp.Value.ScoreA; return (byte)(mainForm.excel.getByte(((char)((result == 0 ? 'H' : 'C') + (isHome ? 0 : 1))).ToString() + ( (isHome && result >= 0 || !isHome && result > 0 ? MainForm.XLSXHOMEWINDRAWY : MainForm.XLSXAWAYWINDRAWY) + (prevRVal.tDict.ContainsKey(kvp.Value.OtherTeam) ? (int)prevRVal.tDict[kvp.Value.OtherTeam].grLevel : 5) )) * 100); }
protected byte? getStrength1(RoundValue prevRVal, KeyValuePair<string,HistoryValue> kvp) { bool isHome = kvp.Value.Field == "HOME"; int? result = kvp.Value.ScoreH - kvp.Value.ScoreA; result = result > 0 ? 0 : result < 0 ? 2 : 1; StringBuilder excelCell = new StringBuilder(((char)((isHome ? 'C' : 'E') + 7 * result)).ToString()); excelCell.Append(3 + 6 * prevRVal.tDict[isHome ? kvp.Value.OtherTeam : kvp.Key].grLevel + prevRVal.tDict[isHome ? kvp.Key : kvp.Value.OtherTeam].grLevel); return (byte)((mainForm.excel.getByte(excelCell.ToString()) + 100) / 2); }
public void process() { byte i, round; float grDiff; int aI = 1, progress; string progressTitle; string q = @"SELECT Country,League,Season,Round,Date,HomeTeam,AwayTeam,ScoreH,ScoreA FROM dbo.archive ORDER BY Country,League,Season,Round"; ArchiveKey aKey = new ArchiveKey(); Dictionary<ArchiveKey, Dictionary<int, RoundValue>> aDict = new Dictionary<ArchiveKey, Dictionary<int, RoundValue>>(); Dictionary<ArchiveKey, Dictionary<int, RoundValue>> newADict = new Dictionary<ArchiveKey, Dictionary<int, RoundValue>>(); HistoryValue hVal; RoundValue rVal; SqlCommand selectCmd; SqlDataReader reader; mainForm.backgroundWorker.ReportProgress(0, new BGReport(" Building aDict ...")); History.errDict = new Dictionary<ArchiveKey, string>(); using (reader = new SqlCommand(q, this.Connection).ExecuteReader()) { while (reader.Read()) { aKey.Country = reader["Country"].ToString(); aKey.League = reader["League"].ToString(); aKey.Season = reader["Season"].ToString(); round = (byte)reader["Round"]; if (!aDict.ContainsKey(aKey)) aDict[aKey] = new Dictionary<int, RoundValue>(); else if (aDict[aKey].ContainsKey(round)) { rVal = aDict[aKey][round]; rVal.calc(reader, aDict[aKey]); aDict[aKey][round] = rVal; continue; } aDict[aKey][round] = new RoundValue(reader, aDict[aKey]); } } mainForm.backgroundWorker.ReportProgress(10, new BGReport(" Inserting/Updating records ...")); foreach (var aKVP in aDict) { newADict[aKVP.Key] = new Dictionary<int, RoundValue>(); selectCmd = new SqlCommand("SELECT TOP 1 Country FROM dbo.history WHERE Country=@Country AND League=@League AND Season=@Season", this.Connection); selectCmd.Parameters.AddWithValue("@Country", aKVP.Key.Country); selectCmd.Parameters.AddWithValue("@League", aKVP.Key.League); selectCmd.Parameters.AddWithValue("@Season", aKVP.Key.Season); using (reader = selectCmd.ExecuteReader()) progressTitle = reader.HasRows ? " Updating " : " Inserting "; progress = (int)((double)(aI++) / aDict.Count * 80) + 10; mainForm.backgroundWorker.ReportProgress(progress, new BGReport(progressTitle + aKVP.Key + " ...")); if (History.errDict.ContainsKey(aKVP.Key)) mainForm.backgroundWorker.ReportProgress(progress, new BGReport(History.errDict[aKVP.Key], System.Drawing.Brushes.Red)); foreach (var rKVP in aKVP.Value) { var orderedEnum = from item in rKVP.Value.tDict let diff = item.Value.SumScored - item.Value.SumReceived orderby item.Value.Points descending, diff descending select item; rVal = new RoundValue(rKVP.Value); grDiff = (float)(rVal.maxPoints - rVal.minPoints) / 4; i = 1; foreach (var kvp in orderedEnum) { hVal = kvp.Value; hVal.Position = i++; hVal.grLevel = (byte)(Math.Round((rVal.maxPoints - hVal.Points) / grDiff) + 1); if (rKVP.Key == 1) hVal.grStrength = 50; else { //hVal.grStrength = getStrength1(newADict[aKVP.Key][rKVP.Key - 1], kvp); //Console.Write("{0} -> {1}). ", rKVP.Key - 1, rKVP.Key); hVal.grStrength = getStrength2(newADict[aKVP.Key][rKVP.Key - 1], kvp); //Console.WriteLine(", PrevAvgStrength:{0}", hVal.grStrength); } if (insert(aKVP.Key, rKVP.Key, kvp.Key, hVal) == 0) Console.WriteLine("something is wrong [History.process]"); //Console.WriteLine("{0}:{1}, {2}, P:{3}({4},{5})", aKVP.Key, rKVP.Key, kvp.Key, hVal.Points, hVal.grLevel, hVal.grStrength); rVal.tDict[kvp.Key] = hVal; } newADict[aKVP.Key][rKVP.Key] = rVal; //Console.WriteLine("-- {0} --\n", rKVP.Value); } } }
public RoundValue(RoundValue rVal) { this.maxPoints = rVal.maxPoints; this.minPoints = rVal.minPoints; this.tDict = new Dictionary <string, HistoryValue>(); }
public void process() { byte i, round; float grDiff; int aI = 1, progress; string progressTitle; string q = @"SELECT Country,League,Season,Round,Date,HomeTeam,AwayTeam,ScoreH,ScoreA FROM dbo.archive ORDER BY Country,League,Season,Round"; ArchiveKey aKey = new ArchiveKey(); Dictionary <ArchiveKey, Dictionary <int, RoundValue> > aDict = new Dictionary <ArchiveKey, Dictionary <int, RoundValue> >(); Dictionary <ArchiveKey, Dictionary <int, RoundValue> > newADict = new Dictionary <ArchiveKey, Dictionary <int, RoundValue> >(); HistoryValue hVal; RoundValue rVal; SqlCommand selectCmd; SqlDataReader reader; mainForm.backgroundWorker.ReportProgress(0, new BGReport(" Building aDict ...")); History.errDict = new Dictionary <ArchiveKey, string>(); using (reader = new SqlCommand(q, this.Connection).ExecuteReader()) { while (reader.Read()) { aKey.Country = reader["Country"].ToString(); aKey.League = reader["League"].ToString(); aKey.Season = reader["Season"].ToString(); round = (byte)reader["Round"]; if (!aDict.ContainsKey(aKey)) { aDict[aKey] = new Dictionary <int, RoundValue>(); } else if (aDict[aKey].ContainsKey(round)) { rVal = aDict[aKey][round]; rVal.calc(reader, aDict[aKey]); aDict[aKey][round] = rVal; continue; } aDict[aKey][round] = new RoundValue(reader, aDict[aKey]); } } mainForm.backgroundWorker.ReportProgress(10, new BGReport(" Inserting/Updating records ...")); foreach (var aKVP in aDict) { newADict[aKVP.Key] = new Dictionary <int, RoundValue>(); selectCmd = new SqlCommand("SELECT TOP 1 Country FROM dbo.history WHERE Country=@Country AND League=@League AND Season=@Season", this.Connection); selectCmd.Parameters.AddWithValue("@Country", aKVP.Key.Country); selectCmd.Parameters.AddWithValue("@League", aKVP.Key.League); selectCmd.Parameters.AddWithValue("@Season", aKVP.Key.Season); using (reader = selectCmd.ExecuteReader()) progressTitle = reader.HasRows ? " Updating " : " Inserting "; progress = (int)((double)(aI++) / aDict.Count * 80) + 10; mainForm.backgroundWorker.ReportProgress(progress, new BGReport(progressTitle + aKVP.Key + " ...")); if (History.errDict.ContainsKey(aKVP.Key)) { mainForm.backgroundWorker.ReportProgress(progress, new BGReport(History.errDict[aKVP.Key], System.Drawing.Brushes.Red)); } foreach (var rKVP in aKVP.Value) { var orderedEnum = from item in rKVP.Value.tDict let diff = item.Value.SumScored - item.Value.SumReceived orderby item.Value.Points descending, diff descending select item; rVal = new RoundValue(rKVP.Value); grDiff = (float)(rVal.maxPoints - rVal.minPoints) / 4; i = 1; foreach (var kvp in orderedEnum) { hVal = kvp.Value; hVal.Position = i++; hVal.grLevel = (byte)(Math.Round((rVal.maxPoints - hVal.Points) / grDiff) + 1); if (rKVP.Key == 1) { hVal.grStrength = 50; } else { //hVal.grStrength = getStrength1(newADict[aKVP.Key][rKVP.Key - 1], kvp); //Console.Write("{0} -> {1}). ", rKVP.Key - 1, rKVP.Key); hVal.grStrength = getStrength2(newADict[aKVP.Key][rKVP.Key - 1], kvp); //Console.WriteLine(", PrevAvgStrength:{0}", hVal.grStrength); } if (insert(aKVP.Key, rKVP.Key, kvp.Key, hVal) == 0) { Console.WriteLine("something is wrong [History.process]"); } //Console.WriteLine("{0}:{1}, {2}, P:{3}({4},{5})", aKVP.Key, rKVP.Key, kvp.Key, hVal.Points, hVal.grLevel, hVal.grStrength); rVal.tDict[kvp.Key] = hVal; } newADict[aKVP.Key][rKVP.Key] = rVal; //Console.WriteLine("-- {0} --\n", rKVP.Value); } } }