Пример #1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            DoublingVal dblVal = new DoublingVal();

            dblVal.rounds = 9;
            Console.WriteLine("On {0} rounds you spent {1:n} denars, ", dblVal.rounds, dblVal.spent);
        }
Пример #2
0
        private void doWorstSituation()
        {
            byte prevReceived, prevScored, received, scored;
            string q = @"SELECT * FROM dbo.history ORDER BY Country,League,Season,Team,Round";
            ulong totalGames = 0;
            DoublingVal dblVal = new DoublingVal();

            prevReceived = prevScored = 0;
            DoublingXForm.dblKey = DoublingXForm.prevDblKey = new DoublingKey();
            using (SqlDataReader reader = new SqlCommand(q, this.connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    DoublingXForm.dblKey.Country = reader["Country"].ToString();
                    DoublingXForm.dblKey.League = reader["League"].ToString();
                    DoublingXForm.dblKey.Season = reader["Season"].ToString();
                    DoublingXForm.dblKey.Team = reader["Team"].ToString();
                    DoublingXForm.round = (byte)reader["Round"];
                    DoublingXForm.date = (DateTime)reader["Date"];
                    scored = (byte)reader["Scored"];
                    received = (byte)reader["Received"];
                    if (!DoublingXForm.dblDict.ContainsKey(DoublingXForm.dblKey))
                    {
                        dblVal.finish(true);
                        dblVal = new DoublingVal();
                        DoublingXForm.lstDblVal = new List<DoublingVal>();
                    }
                    if (received - prevReceived != scored - prevScored)
                    {
                        if (dblVal.rounds == 0)
                        {
                            dblVal.startRound = DoublingXForm.round;
                            dblVal.startDate = DoublingXForm.date;
                        }
                        dblVal.rounds++;
                    }
                    else
                    {
                        dblVal.finish(false);
                        dblVal = new DoublingVal();
                    }
                    DoublingXForm.prevDblKey = DoublingXForm.dblKey;
                    DoublingXForm.prevRound = DoublingXForm.round;
                    DoublingXForm.prevDate = DoublingXForm.date;
                    prevScored = scored;
                    prevReceived = received;
                    totalGames++;
                }
                dblVal.finish(true);
            }

            Dictionary<DoublingKey, List<DoublingVal>> newDblDict = new Dictionary<DoublingKey, List<DoublingVal>>();
            foreach (var kvp in DoublingXForm.dblDict)
                newDblDict[kvp.Key] = (from item in kvp.Value orderby item.rounds descending select item).ToList<DoublingVal>();
            var orderedDblDict = from item in newDblDict orderby item.Value[0].rounds descending select item;

            int badOnes = 0, count = DoublingXForm.dblDict.Count, i = 0, n1 = 0, n2 = 20, progress = 0, totalRuns = 0;
            foreach (var kvp in orderedDblDict)
            {
                if (++i >= n1 && i <= n2)
                {
                    progress = (int)((double)(i) / count * 100);
                    backgroundWorker.ReportProgress(progress, new BGReport(String.Format("{0}", kvp.Key)));
                }
                foreach (DoublingVal val in kvp.Value)
                {
                    if (i >= n1 && i <= n2) backgroundWorker.ReportProgress(progress, new BGReport(String.Format("{0}", val), val.rounds > 9 ? Brushes.Red : Brushes.Black));
                    if (val.rounds > 9) badOnes++;
                    totalRuns++;
                }
            }
            Console.WriteLine("Total games: {0}, Total runs: {1}, Total Teams: {2}, Bad Ones: {3}", totalGames, totalRuns, count, badOnes);
        }
Пример #3
0
 private void btnTest_Click(object sender, EventArgs e)
 {
     DoublingVal dblVal = new DoublingVal();
     dblVal.rounds = 9;
     Console.WriteLine("On {0} rounds you spent {1:n} denars, ", dblVal.rounds, dblVal.spent);
 }
Пример #4
0
        private void doWorstSituation()
        {
            byte        prevReceived, prevScored, received, scored;
            string      q          = @"SELECT * FROM dbo.history ORDER BY Country,League,Season,Team,Round";
            ulong       totalGames = 0;
            DoublingVal dblVal     = new DoublingVal();

            prevReceived         = prevScored = 0;
            DoublingXForm.dblKey = DoublingXForm.prevDblKey = new DoublingKey();
            using (SqlDataReader reader = new SqlCommand(q, this.connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    DoublingXForm.dblKey.Country = reader["Country"].ToString();
                    DoublingXForm.dblKey.League  = reader["League"].ToString();
                    DoublingXForm.dblKey.Season  = reader["Season"].ToString();
                    DoublingXForm.dblKey.Team    = reader["Team"].ToString();
                    DoublingXForm.round          = (byte)reader["Round"];
                    DoublingXForm.date           = (DateTime)reader["Date"];
                    scored   = (byte)reader["Scored"];
                    received = (byte)reader["Received"];
                    if (!DoublingXForm.dblDict.ContainsKey(DoublingXForm.dblKey))
                    {
                        dblVal.finish(true);
                        dblVal = new DoublingVal();
                        DoublingXForm.lstDblVal = new List <DoublingVal>();
                    }
                    if (received - prevReceived != scored - prevScored)
                    {
                        if (dblVal.rounds == 0)
                        {
                            dblVal.startRound = DoublingXForm.round;
                            dblVal.startDate  = DoublingXForm.date;
                        }
                        dblVal.rounds++;
                    }
                    else
                    {
                        dblVal.finish(false);
                        dblVal = new DoublingVal();
                    }
                    DoublingXForm.prevDblKey = DoublingXForm.dblKey;
                    DoublingXForm.prevRound  = DoublingXForm.round;
                    DoublingXForm.prevDate   = DoublingXForm.date;
                    prevScored   = scored;
                    prevReceived = received;
                    totalGames++;
                }
                dblVal.finish(true);
            }

            Dictionary <DoublingKey, List <DoublingVal> > newDblDict = new Dictionary <DoublingKey, List <DoublingVal> >();

            foreach (var kvp in DoublingXForm.dblDict)
            {
                newDblDict[kvp.Key] = (from item in kvp.Value orderby item.rounds descending select item).ToList <DoublingVal>();
            }
            var orderedDblDict = from item in newDblDict orderby item.Value[0].rounds descending select item;

            int badOnes = 0, count = DoublingXForm.dblDict.Count, i = 0, n1 = 0, n2 = 20, progress = 0, totalRuns = 0;

            foreach (var kvp in orderedDblDict)
            {
                if (++i >= n1 && i <= n2)
                {
                    progress = (int)((double)(i) / count * 100);
                    backgroundWorker.ReportProgress(progress, new BGReport(String.Format("{0}", kvp.Key)));
                }
                foreach (DoublingVal val in kvp.Value)
                {
                    if (i >= n1 && i <= n2)
                    {
                        backgroundWorker.ReportProgress(progress, new BGReport(String.Format("{0}", val), val.rounds > 9 ? Brushes.Red : Brushes.Black));
                    }
                    if (val.rounds > 9)
                    {
                        badOnes++;
                    }
                    totalRuns++;
                }
            }
            Console.WriteLine("Total games: {0}, Total runs: {1}, Total Teams: {2}, Bad Ones: {3}", totalGames, totalRuns, count, badOnes);
        }