Exemple #1
0
        private static void OverallChart(string playerName, string chartID, GraphFields gFields, ChartControl chartControl)
        {
            chartControl.Series.Clear();
            chartControl.Titles.Clear();
            Player         player         = new PlayerListing(new MessageQueue()).GetPlayer(playerName);
            DossierManager dossierManager = new DossierManager(player.PlayerID, player.WatchFile, player.Monitor, new MessageQueue(), null);

            DateTime endFile   = dossierManager.FormatTextDate(dossierManager.GetCurrentPlayerFile().ToString());
            DateTime startFile = dossierManager.FormatTextDate(dossierManager.GetCurrentPlayerFile().ToString()).AddDays((gFields.Period + 1) * -1);

            Dictionary <Int32, Int32> files         = dossierManager.GetAllFilesForPlayer();
            Dictionary <Int32, Int32> selectedFiles = (from d in files
                                                       where dossierManager.FormatTextDate(d.Key.ToString()) >= startFile && dossierManager.FormatTextDate(d.Key.ToString()) <= endFile
                                                       select d).ToDictionary(x => x.Key, x => x.Value);

            Series series1 = new Series(gFields.Caption, ViewType.Line);

            series1.Label.Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLCellFont), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            foreach (KeyValuePair <Int32, Int32> file in selectedFiles.OrderBy(x => x.Key))
            {
                Dossier  dossierFile  = new Dossier(file.Value, player.PlayerID, new MessageQueue());
                WOTStats dossierStats = dossierFile.GetStats();
                series1.Points.Add(new SeriesPoint(dossierManager.FormatTextDate(file.Key.ToString()), Math.Round(GetStatValue(gFields.DataField, dossierStats), 2)));
            }



            // Add the series to the chart.
            chartControl.Series.Add(series1);

            // Set the numerical argument scale types for the series,
            // as it is qualitative, by default.
            series1.ArgumentScaleType            = ScaleType.DateTime;
            series1.Label.ResolveOverlappingMode = ResolveOverlappingMode.HideOverlapped;

            // Access the view-type-specific options of the series.
            ((LineSeriesView)series1.View).LineMarkerOptions.Kind = MarkerKind.Circle;
            ((LineSeriesView)series1.View).LineStyle.DashStyle    = DashStyle.Solid;

            // Access the type-specific options of the diagram.
            ((XYDiagram)chartControl.Diagram).EnableAxisXZooming = true;

            // Hide the legend (if necessary).
            chartControl.Legend.Visible = false;


            // Add a title to the chart (if necessary).
            chartControl.Titles.Add(new ChartTitle());
            chartControl.Titles[0].Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLHeaderFont), System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            chartControl.Titles[0].Text = gFields.Caption;
            chartControl.Titles.Add(new ChartTitle());
            chartControl.Titles[1].Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLHeaderFont) - 1.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            chartControl.Titles[1].Text = startFile.ToString(UserSettings.DateFormat) + " to " + endFile.ToString(UserSettings.DateFormat);
            chartControl.Titles.Add(new ChartTitle());
            chartControl.Titles[2].Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLHeaderFont) - 3, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            chartControl.Titles[2].Text = gFields.DataField;

            XYDiagram diagram = (XYDiagram)chartControl.Diagram;

            switch (gFields.Period)
            {
            case 7:
                diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day;
                diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;
                break;

            case 14:
                diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day;
                diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;
                break;

            case 92:
            case 184:
            case 365:
                diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Month;
                diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;
                diagram.AxisX.Label.TextPattern = "MMM yy";
                break;

            default:
                diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Week;
                diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;
                break;
            }


            diagram.AxisX.Label.Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLCellFont), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            diagram.AxisY.Label.Font = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLCellFont), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));


            diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
            diagram.AxisY.NumericScaleOptions.AutoGrid   = true;
            diagram.AxisY.DateTimeScaleOptions.AutoGrid  = true;
        }
Exemple #2
0
        private void ReloadDossier(DossierManager sender)
        {
            try
            {
                if (dictPlayers.Count > 0)
                {
                    DossierManager dm = (DossierManager)sender;
                    Dossier fileB = new Dossier(dm.GetFileB(), dm.GetPlayerName, _message);
                    Dossier fileA = new Dossier(dm.GetFileA(), dm.GetPlayerName, _message);

                    _currentStatsFile[dm.GetPlayerID.Replace("_", "*")] = new WOTCompare(fileB.GetStats(), fileA.GetStats());

                    CreateWebPage(_currentPage, _currentPlayer);
                }
            }
            catch (Exception ex)
            {
                _message.Add("Error: cannot refresh dossier file. - " + ex.Message);
            }
        }
        private void CreateRecentBattle(MemoryTables mt)
        {
            //try
            //{
            Dossier  fileB     = new Dossier(GetCurrentPlayerFile(), _playerName, _messages);
            WOTStats stats     = fileB.GetStats();
            double   avgTier   = stats.AverageTier;
            double   vics      = stats.Victory_Percentage;
            double   defPoints = stats.AverageDefencePoints;

            List <string> cur = (from x in  mt.GetTable("File_Total").AsEnumerable()
                                 select x["foLastBattleTime"].ToString()).ToList();
            List <string> saved;
            DataTable     currentRecord;
            DataTable     Kills;

            using (IDBHelpers db = new DBHelpers(WOTHelper.GetDBPath(_playerName), false))
            {
                saved = (from x in  db.GetDataTable("select foLastBattleTime from File_Total").AsEnumerable()
                         select x["foLastBattleTime"].ToString()).ToList();

                currentRecord = db.GetDataTable(@"select
                                  case when T2.bpBattleMode = 7 then 7 else 15 end as bpBattleMode, T1.cmID, T1.cmCountryID, T1.cmTankID, T1.cmUpdated, (T2.bpBattleCount) bpBattleCount, (t2.bpSpotted) bpSpotted,  (t2.bpHits) bpHits,  (t2.bpMaxFrags) bpMaxFrags,  (t2.bpMaxXP) bpMaxXP,  (t2.bpWins) bpWins,  (t2.bpCapturePoints) bpCapturePoints,  (t2.bpLosses) bpLosses,
                                   (t2.bpSurvivedBattles) bpSurvivedBattles, min(T4.foBattleLifeTime) foBattleLifeTime,  (t2.bpDefencePoints) bpDefencePoints, min(t4.foLastBattleTime) foLastBattleTime,  (t2.bpDamageReceived) bpDamageReceived,  (t2.bpShots) bpShots,  (t2.bpWinAndSurvive) bpWinAndSurvive,  (t2.bpFrags8P) bpFrags8P,
                                    (t2.bpXP) bpXP,                                   
                                    (t2.bpDamageDealt) bpDamageDealt,  
                                    (t2.bpDamageAssistedRadio) bpDamageAssistedRadio,  
                                    (t2.bpDamageAssistedTracks) bpDamageAssistedTracks,  
                                    (t2.bpMileage) bpMileage, 
                                    (t2.bpRatingEffWeight)/(t2.bpBattleCount) bpRatingEff,  
                                    (t2.bpRatingBRWeight)/(t2.bpBattleCount) bpRatingBR,  
                                    (t2.bpRatingWN7Weight)/(t2.bpBattleCount) bpRatingWN7,  
                                    (t2.bpRatingWN8Weight)/(t2.bpBattleCount) bpRatingWN8,  
                                   (t2.bpFrags) bpFrags, t4.foTreesCut, t3.faMarkOfMastery
                                  from File_TankDetails T1
                                  inner join File_Battles T2
                                  on T1.cmID = T2.bpParentID
                                  inner join File_Achievements T3
                                  on T1.cmID = T3.faParentID
                                  inner join File_Total T4
                                  on T1.cmID = T4.foParentID
                                  where cmFileID =  " + GetCurrentPlayerFileKey() + " group by T2.bpBattleMode, T1.cmID, T1.cmCountryID, T1.cmTankID, T1.cmUpdated, t4.foTreesCut, t3.faMarkOfMastery");

                Kills = db.GetDataTable(String.Format(@"select fgParentID, fgCountryID, fgTankID, sum(fgValue) kills from File_TankDetails
                                                                                            inner join File_FragList
                                                                                            on cmID = fgParentID
                                                                                            where cmFileID = {0}
                                                                                            group by  fgParentID, fgCountryID, fgTankID", GetCurrentPlayerFileKey()));
            }

            List <string> diff        = cur.Except(saved).ToList();
            RecentBattles lb          = new RecentBattles(GetPlayerName, _messages);
            var           battleCheck = from x in mt.GetTable("File_TankDetails").AsEnumerable()
                                        join y in mt.GetTable("File_Battles").AsEnumerable()
                                        on x.GetSafeInt("cmID") equals y.GetSafeInt("bpParentID")
                                        join z in mt.GetTable("File_Total").AsEnumerable()
                                        on x.GetSafeInt("cmID") equals z.GetSafeInt("foParentID")
                                        join d in diff
                                        on z["foLastBattleTime"].ToString() equals d
                                        group y by new { ID = x.GetSafeInt("cmID"), countryID = x.GetSafeInt("cmCountryID"), tankID = x.GetSafeInt("cmTankID"), battleTime = z["foLastBattleTime"].ToString(), BattleMode = y["bpBattleMode"] } into tank
                          select new
            {
                ID                   = tank.Key.ID,
                CountryID            = tank.Key.countryID,
                TankID               = tank.Key.tankID,
                BattleTime           = tank.Key.battleTime,
                BattleCount          = tank.Sum(y => y.GetSafeInt("bpBattleCount")),
                Hits                 = tank.Sum(y => y.GetSafeInt("bpHits")),
                Shots                = tank.Sum(y => y.GetSafeInt("bpShots")),
                Victory              = tank.Sum(y => y.GetSafeInt("bpWins")),
                Losses               = tank.Sum(y => y.GetSafeInt("bpLosses")),
                Survived             = tank.Sum(y => y.GetSafeInt("bpSurvivedBattles")),
                DefencePoints        = tank.Sum(y => y.GetSafeInt("bpDefencePoints")),
                CapturePoints        = tank.Sum(y => y.GetSafeInt("bpCapturePoints")),
                Spotted              = tank.Sum(y => y.GetSafeInt("bpSpotted")),
                DamageDealt          = tank.Sum(y => y.GetSafeInt("bpDamageDealt")),
                DamageAssistedRadio  = tank.Sum(y => y.GetSafeInt("bpDamageAssistedRadio")),
                DamageAssistedTracks = tank.Sum(y => y.GetSafeInt("bpDamageAssistedTracks")),
                DamageReceived       = tank.Sum(y => y.GetSafeInt("bpDamageReceived")),
                Kills                = tank.Sum(y => y.GetSafeInt("bpFrags")),
                Mileage              = tank.Sum(y => y.GetSafeInt("bpMileage")),
                RatingEff            = tank.Sum(y => y.GetSafeInt("bpRatingEff")),
                RatingBR             = tank.Sum(y => y.GetSafeInt("bpRatingBR")),
                RatingWN7            = tank.Sum(y => y.GetSafeInt("bpRatingWN7")),
                RatingWN8            = tank.Sum(y => y.GetSafeInt("bpRatingWN8")),
                XPReceived           = tank.Sum(y => y.GetSafeInt("bpXP")),
                BattleMode           = int.Parse(tank.Key.BattleMode.ToString())
            };



            if (currentRecord.Rows.Count > 0)
            {
                foreach (var item in battleCheck)
                {
                    //WOTHelper.AddToLog("BM 1: " + item.BattleMode);
                    DataRow dr = currentRecord.Select(String.Format("cmCountryID = {0} and cmTankID = {1} and bpBattleMode = {2}", item.CountryID, item.TankID, item.BattleMode)).DefaultIfEmpty(null).FirstOrDefault();

                    if (dr != null)
                    {
                        if (item.BattleCount - dr.GetSafeInt("bpBattleCount") > 0)
                        {
                            int           i        = 0;
                            List <string> newKills = new List <string>();
                            foreach (DataRow killRow in mt.GetTable("File_FragList").Select("fgParentID = " + item.ID))
                            {
                                DataRow dr_oldKills = Kills.Select(String.Format(@"fgParentID = {0} and  fgCountryID = {1} and fgTankID = {2}", dr.GetSafeInt("cmID"), killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID"))).FirstOrDefault();
                                if (dr_oldKills != null)
                                {
                                    if (killRow.GetSafeInt("fgValue") > dr_oldKills.GetSafeInt("kills"))
                                    {
                                        newKills.Add(String.Format("{0}:{1}_{2}", i, killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID")));
                                        i++;
                                    }
                                }
                                else
                                {
                                    newKills.Add(String.Format("{0}:{1}_{2}", i, killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID")));
                                    i++;
                                }
                            }

                            int vic = 0;
                            if (item.Victory - dr.GetSafeInt("bpWins") > 0)
                            {
                                vic = 0;
                            }
                            else if (item.Losses - dr.GetSafeInt("bpLosses") > 0)
                            {
                                vic = 1;
                            }
                            else
                            {
                                vic = 2;
                            }
                            //WOTHelper.AddToLog("ASD: " + dr.GetSafeInt("bpRatingWN8"));
                            lb.Add(int.Parse(item.BattleTime), new RecentBattle()
                            {
                                CountryID              = item.CountryID,
                                TankID                 = item.TankID,
                                Battles                = item.BattleCount - dr.GetSafeInt("bpBattleCount"),
                                BattleTime             = int.Parse(item.BattleTime),
                                Hits                   = item.Hits - dr.GetSafeInt("bpHits"),
                                Shot                   = item.Shots - dr.GetSafeInt("bpShots"),
                                Victory                = vic,
                                Survived               = item.Survived - dr.GetSafeInt("bpSurvivedBattles"),
                                DefencePoints          = item.DefencePoints - dr.GetSafeInt("bpDefencePoints"),
                                CapturePoints          = item.CapturePoints - dr.GetSafeInt("bpCapturePoints"),
                                Spotted                = item.Spotted - dr.GetSafeInt("bpSpotted"),
                                DamageDealt            = item.DamageDealt - dr.GetSafeInt("bpDamageDealt"),
                                DamageAssistedRadio    = item.DamageAssistedRadio - dr.GetSafeInt("bpDamageAssistedRadio"),
                                DamageAssistedTracks   = item.DamageAssistedTracks - dr.GetSafeInt("bpDamageAssistedTracks"),
                                DamageReceived         = item.DamageReceived - dr.GetSafeInt("bpDamageReceived"),
                                Kills                  = item.Kills - dr.GetSafeInt("bpFrags"),
                                Mileage                = item.Mileage - dr.GetSafeInt("bpMileage"),
                                RatingEff              = item.RatingEff - dr.GetSafeInt("bpRatingEff"),
                                RatingBR               = item.RatingBR - dr.GetSafeInt("bpRatingBR"),
                                RatingWN7              = item.RatingWN7 - dr.GetSafeInt("bpRatingWN7"),
                                RatingWN8              = item.RatingWN8 - dr.GetSafeInt("bpRatingWN8"),
                                XPReceived             = item.XPReceived - dr.GetSafeInt("bpXP"),
                                OriginalBattleCount    = item.BattleCount - dr.GetSafeInt("bpBattleCount"),
                                FragList               = string.Join(";", newKills.ToArray().Take(15)),
                                GlobalAvgTier          = avgTier,
                                GlobalWinPercentage    = vics,
                                GlobalAvgDefencePoints = defPoints,
                                BattleMode             = item.BattleMode,
                                DBEntry                = false
                            });

                            lb.Save();
                        }
                    }
                    else
                    {
                        int           i        = 0;
                        List <string> newKills = new List <string>();
                        WOTHelper.AddToLog("BM 2: " + item.BattleMode);
                        dr = currentRecord.Select(String.Format("cmCountryID = {0} and cmTankID = {1} and bpBattleMode <> '{2}'", item.CountryID, item.TankID, item.BattleMode)).DefaultIfEmpty(null).FirstOrDefault();

                        if (dr != null)
                        {
                            foreach (DataRow killRow in mt.GetTable("File_FragList").Select("fgParentID = " + item.ID))
                            {
                                DataRow dr_oldKills = Kills.Select(String.Format(@"fgParentID = {0} and  fgCountryID = {1} and fgTankID = {2}", dr.GetSafeInt("cmID"), killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID"))).FirstOrDefault();
                                if (dr_oldKills != null)
                                {
                                    if (killRow.GetSafeInt("fgValue") > dr_oldKills.GetSafeInt("kills"))
                                    {
                                        newKills.Add(String.Format("{0}:{1}_{2}", i, killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID")));
                                        i++;
                                    }
                                }
                                else
                                {
                                    newKills.Add(String.Format("{0}:{1}_{2}", i, killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID")));
                                    i++;
                                }
                            }
                        }
                        else
                        {
                            foreach (DataRow killRow in mt.GetTable("File_FragList").Select("fgParentID = " + item.ID))
                            {
                                newKills.Add(String.Format("{0}:{1}_{2}", i, killRow.GetSafeInt("fgCountryID"), killRow.GetSafeInt("fgTankID")));
                                i++;
                            }
                        }
                        int vic = 0;
                        if (item.Victory - 0 > 0)
                        {
                            vic = 0;
                        }
                        else if (item.Losses - 0 > 0)
                        {
                            vic = 1;
                        }
                        else
                        {
                            vic = 2;
                        }

                        lb.Add(int.Parse(item.BattleTime), new RecentBattle()
                        {
                            CountryID              = item.CountryID,
                            TankID                 = item.TankID,
                            Battles                = item.BattleCount,
                            BattleTime             = int.Parse(item.BattleTime),
                            Hits                   = item.Hits,
                            Shot                   = item.Shots,
                            Victory                = vic,
                            Survived               = item.Survived,
                            DefencePoints          = item.DefencePoints,
                            CapturePoints          = item.CapturePoints,
                            Spotted                = item.Spotted,
                            DamageDealt            = item.DamageDealt,
                            DamageAssistedRadio    = item.DamageAssistedRadio,
                            DamageAssistedTracks   = item.DamageAssistedTracks,
                            DamageReceived         = item.DamageReceived,
                            Kills                  = item.Kills,
                            Mileage                = item.Mileage,
                            XPReceived             = item.XPReceived,
                            OriginalBattleCount    = item.BattleCount,
                            FragList               = string.Join(";", newKills.ToArray().Take(15)),
                            GlobalAvgTier          = avgTier,
                            GlobalWinPercentage    = vics,
                            GlobalAvgDefencePoints = defPoints,
                            BattleMode             = item.BattleMode,
                            RatingEff              = item.RatingEff,
                            RatingBR               = item.RatingBR,
                            RatingWN7              = item.RatingWN7,
                            RatingWN8              = item.RatingWN8,
                            DBEntry                = false
                        });

                        lb.Save();
                    }
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    _messages.Add(String.Format("Error : Cannot create last battle ({0}) - {1}", GetPlayerName, ex.Message));
            //}
        }