public static LRTKey getOtherKey(LRTKey lrtKey)
 {
     LRTKey newLrtKey = (LRTKey)lrtKey.MemberwiseClone();
     newLrtKey.OtherTeam = lrtKey.Team;
     newLrtKey.Team = lrtKey.OtherTeam;
     return newLrtKey;
 }
Example #2
0
        public static LRTKey getOtherKey(LRTKey lrtKey)
        {
            LRTKey newLrtKey = (LRTKey)lrtKey.MemberwiseClone();

            newLrtKey.OtherTeam = lrtKey.Team;
            newLrtKey.Team      = lrtKey.OtherTeam;
            return(newLrtKey);
        }
Example #3
0
        protected int insert(SqlDataReader reader, LRTKey lrtKey, Power power)
        {
            SqlCommand modifyCmd = new SqlCommand(@"UPDATE dbo.history SET PrevAvgStrength=@PrevAvgStrength WHERE ID=@ID", Connection);

            modifyCmd.Parameters.AddWithValue("@PrevAvgStrength", power.PrevAvgStrength);
            modifyCmd.Parameters.AddWithValue("@ID", reader[0]);
            return(modifyCmd.ExecuteNonQuery());
        }
Example #4
0
        // overrided Equals and GetHashCode for speed optimization
        public override bool Equals(object obj)
        {
            LRTKey o = (LRTKey)obj;

            return(this.Round == o.Round && this.Country.Equals(o.Country) && this.Team.Equals(o.Team) && this.Season.Equals(o.Season));
        }
Example #5
0
        public void process()
        {
            byte thisPyramidLvl, prevPyramidLvl;

            double[] rates = mainForm.getExcelRates(15);
            int      i;
            string   prevCountry = "", prevPyramidKey = "", prevSeason = "", prevTeam = "", whDebug = "";
            Dictionary <LRTKey, Power> dict = new Dictionary <LRTKey, Power>();
            List <byte> lstStreingth        = new List <byte>();
            LRTKey      lrtKey = new LRTKey();

            mainForm.backgroundWorker.ReportProgress(10, new BGReport("  Preparing PrevAvgStrength ..."));

            //whDebug = " WHERE Country='Argentina' AND Season='2009/10' AND Team='Aldosivi' AND Round<=18";
            using (SqlDataReader reader = new SqlCommand("SELECT * FROM dbo.history" + whDebug + " ORDER BY Country,Team,Season,Round", this.Connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    lrtKey.Country   = reader["Country"].ToString();
                    lrtKey.League    = reader["League"].ToString();
                    lrtKey.OtherTeam = reader["OtherTeam"].ToString();
                    lrtKey.Round     = (byte)reader["Round"];
                    lrtKey.Season    = reader["Season"].ToString();
                    lrtKey.Team      = reader["Team"].ToString();
                    if (lrtKey.Country != prevCountry)
                    {
                        mainForm.backgroundWorker.ReportProgress(25, new BGReport(String.Format("  Updating {0} ...", lrtKey.Country)));
                    }
                    if (prevTeam != lrtKey.Team)
                    {
                        lstStreingth.Clear();
                    }
                    else if (prevSeason != lrtKey.Season)
                    {
                        thisPyramidLvl = Leagues.PyramidLevels[lrtKey.Country + "," + lrtKey.League];
                        prevPyramidLvl = Leagues.PyramidLevels[prevPyramidKey];
                        if (thisPyramidLvl > prevPyramidLvl)
                        {   // relegated
                            for (i = 0; i < lstStreingth.Count; i++)
                            {
                                if (lstStreingth[i] < 80)
                                {
                                    lstStreingth[i] = (byte)(lstStreingth[i] + 20);
                                }
                            }
                        }
                        else if (thisPyramidLvl < prevPyramidLvl)
                        {   // promoted
                            for (i = 0; i < lstStreingth.Count; i++)
                            {
                                if (lstStreingth[i] > 20)
                                {
                                    lstStreingth[i] = (byte)(lstStreingth[i] - 20);
                                }
                            }
                        }
                    }

                    insert(reader, lrtKey, new Power(reader, rates, ref lstStreingth));

                    prevCountry    = lrtKey.Country;
                    prevPyramidKey = lrtKey.Country + "," + lrtKey.League;
                    prevSeason     = lrtKey.Season;
                    prevTeam       = lrtKey.Team;
                }
            }
        }
 protected int insert(SqlDataReader reader, LRTKey lrtKey, Power power)
 {
     SqlCommand modifyCmd = new SqlCommand(@"UPDATE dbo.history SET PrevAvgStrength=@PrevAvgStrength WHERE ID=@ID", Connection);
     modifyCmd.Parameters.AddWithValue("@PrevAvgStrength", power.PrevAvgStrength);
     modifyCmd.Parameters.AddWithValue("@ID", reader[0]);
     return modifyCmd.ExecuteNonQuery();
 }
        public void process()
        {
            byte thisPyramidLvl, prevPyramidLvl;
            double[] rates = mainForm.getExcelRates(15);
            int i;
            string prevCountry = "", prevPyramidKey = "", prevSeason = "", prevTeam = "", whDebug = "";
            Dictionary<LRTKey, Power> dict = new Dictionary<LRTKey, Power>();
            List<byte> lstStreingth = new List<byte>();
            LRTKey lrtKey = new LRTKey();

            mainForm.backgroundWorker.ReportProgress(10, new BGReport("  Preparing PrevAvgStrength ..."));

            //whDebug = " WHERE Country='Argentina' AND Season='2009/10' AND Team='Aldosivi' AND Round<=18";
            using (SqlDataReader reader = new SqlCommand("SELECT * FROM dbo.history" + whDebug + " ORDER BY Country,Team,Season,Round", this.Connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    lrtKey.Country = reader["Country"].ToString();
                    lrtKey.League = reader["League"].ToString();
                    lrtKey.OtherTeam = reader["OtherTeam"].ToString();
                    lrtKey.Round = (byte)reader["Round"];
                    lrtKey.Season = reader["Season"].ToString();
                    lrtKey.Team = reader["Team"].ToString();
                    if (lrtKey.Country != prevCountry)
                        mainForm.backgroundWorker.ReportProgress(25, new BGReport(String.Format("  Updating {0} ...", lrtKey.Country)));
                    if (prevTeam != lrtKey.Team) lstStreingth.Clear();
                    else if (prevSeason != lrtKey.Season)
                    {
                        thisPyramidLvl = Leagues.PyramidLevels[lrtKey.Country + "," + lrtKey.League];
                        prevPyramidLvl = Leagues.PyramidLevels[prevPyramidKey];
                        if (thisPyramidLvl > prevPyramidLvl)
                        {   // relegated
                            for (i = 0; i < lstStreingth.Count; i++)
                            {
                                if (lstStreingth[i] < 80) lstStreingth[i] = (byte)(lstStreingth[i] + 20);
                            }
                        }
                        else if (thisPyramidLvl < prevPyramidLvl)
                        {   // promoted
                            for (i = 0; i < lstStreingth.Count; i++)
                            {
                                if (lstStreingth[i] > 20) lstStreingth[i] = (byte)(lstStreingth[i] - 20);
                            }
                        }
                    }

                    insert(reader, lrtKey, new Power(reader, rates, ref lstStreingth));

                    prevCountry = lrtKey.Country;
                    prevPyramidKey = lrtKey.Country + "," + lrtKey.League;
                    prevSeason = lrtKey.Season;
                    prevTeam = lrtKey.Team;
                }
            }
        }
        public static Dictionary<LRTKey, Power> getHistoryDict(SqlConnection connection)
        {
            string q = "SELECT * FROM dbo.history WHERE grStrength IS NOT NULL ORDER BY Country,League,Season,Team,Round";
            Dictionary<LRTKey, Power> dict = new Dictionary<LRTKey, Power>();
            LRTKey lrtKey = new LRTKey();

            using (SqlDataReader reader = new SqlCommand(q, connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    lrtKey.Country = reader["Country"].ToString();
                    lrtKey.League = reader["League"].ToString();
                    lrtKey.OtherTeam = reader["OtherTeam"].ToString();
                    lrtKey.Round = (byte)reader["Round"];
                    lrtKey.Season = reader["Season"].ToString();
                    lrtKey.Team = reader["Team"].ToString();
                    dict[lrtKey] = new Power(reader);
                }
            }
            return dict;
        }