Example #1
0
        private void ProcessDossierFile(string dossierFilePath, DataTable table, string playerName)
        {
            //System.Diagnostics.Stopwatch digSW = new Stopwatch();
            //digSW.Start();
            string tempFile = Guid.NewGuid().ToString();

            try
            {
                //start dosier decrypt
                Process process = new Process();
                process.StartInfo.CreateNoWindow = false;
                process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                process.StartInfo.FileName       = _ApplicationPath + "\\python\\wotdc2j.exe";
                process.StartInfo.Arguments      = String.Format(@"""{0}"" ""{1}\\{2}""", dossierFilePath, WOTHelper.GetTempFolder(), tempFile);
                process.Start();
                process.WaitForExit();
                process.Dispose();

                string file = File.ReadAllText(String.Format("{0}\\{1}", WOTHelper.GetTempFolder(), tempFile));
                //File.Delete(String.Format("{0}\\{1}", WOTHelper.GetTempFolder(), tempFile));
                //File.Delete(dossierFilePath);

                var serializer = new JavaScriptSerializer();
                serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                dynamic obj = serializer.Deserialize(file, typeof(object));

                foreach (var item in obj.tanks)
                {
                    DataRow row = table.NewRow();
                    row.SetField("PlayerName", playerName);
                    row.SetField("Tank", tankDesc.Description((int)item.countryid, (int)item.tankid));
                    row.SetField("LastPlayed", new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds((int)item.updated).AddHours(TimeZoneInfo.Local.BaseUtcOffset.Hours));
                    row.SetField("BattleCount", (int)item.tankdata.battlesCount);
                    row.SetField("Victories", (int)item.tankdata.wins);
                    row.SetField("Defeats", (int)item.tankdata.losses);
                    row.SetField("Draws", (int)item.tankdata.battlesCount - ((int)item.tankdata.wins + (int)item.tankdata.losses));
                    row.SetField("Survived", (int)item.tankdata.survivedBattles);
                    row.SetField("Destroyed", (int)item.tankdata.frags);
                    row.SetField("Detected", (int)item.tankdata.spotted);
                    row.SetField("HitRatio", (double.IsNaN((double)item.tankdata.hits / (double)item.tankdata.shots) ? 0 : (double)item.tankdata.hits / (double)item.tankdata.shots) * 100);
                    row.SetField("Damage", (int)item.tankdata.damageDealt);
                    row.SetField("CapturePoints", (int)item.tankdata.capturePoints);
                    row.SetField("DefencePoints", (int)item.tankdata.droppedCapturePoints);
                    row.SetField("TotalExperience", (int)item.tankdata.xp);
                    row.SetField("AvgExperience", (double)item.tankdata.xp / (double)item.tankdata.battlesCount);
                    row.SetField("AvgDamage", (double)item.tankdata.damageDealt / (double)item.tankdata.battlesCount);
                    row.SetField("AvgDamage", (double)item.tankdata.damageDealt / (double)item.tankdata.battlesCount);
                    row.SetField("Hits", (int)item.tankdata.hits);
                    row.SetField("Shots", (int)item.tankdata.shots);
                    table.Rows.Add(row);
                }

                ((IDisposable)obj).Dispose();
            }
            catch
            {
            }
            finally
            {
                File.Delete(String.Format("{0}\\{1}", WOTHelper.GetTempFolder(), tempFile));
                File.Delete(dossierFilePath);
            }

            // digSW.Stop();
            // _messages.Add("Diagnostics : Dossier Processing Finished in " + digSW.ElapsedMilliseconds + " miliseconds");
        }
Example #2
0
        private static void TankChart(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);

            TankDescriptions tankDesc = new TankDescriptions(new MessageQueue());
            Series           series1  = null;

            foreach (string tank in gFields.InnerText.Split('|'))
            {
                series1            = new Series(tankDesc.Description(int.Parse(tank.Split('_')[0]), int.Parse(tank.Split('_')[1])), 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(GetTankStatValue(tank, 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 = false;



            // Hide the legend (if necessary).
            chartControl.Legend.Visible             = true;
            chartControl.Legend.Font                = new System.Drawing.Font("Tahoma", float.Parse(UserSettings.HTMLCellFont), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            chartControl.Legend.AlignmentVertical   = LegendAlignmentVertical.BottomOutside;
            chartControl.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center;
            chartControl.Legend.EquallySpacedItems  = true;
            chartControl.Legend.Direction           = LegendDirection.LeftToRight;


            // 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;
        }