示例#1
0
        /// <summary>
        /// add's data to the chart. At least one set of data is needed to create the chart, when supplying multiple sets of data a multi-bar column charts is created.
        /// Number of columns and the columns label's are determined from the first set of data only.
        /// </summary>
        public void AddDataSet(DataSet data)
        {
            //add dataset
            DataSets.Add(data);

            //keep track of items
            NumberOfColumns = DataSets.First().Data.Count;
            BarsPerColumn   = DataSets.Count;
        }
示例#2
0
        public DataChart(Dictionary <string, List <StockDataSet <T> > > dataSets, StockDataFile file, StockSession session)
        {
            this.DataSets = dataSets;
            this.File     = file;
            this.Session  = session;
            this.Start    = File.Start;
            this.End      = File.End;

            // Load the dummy data
            var dummySrc = DataSets.First().Value[0];

            dummySrc.Load(session);
            DataSets.First().Value[1].Load(session);    // Work-around so that the processing state is reset if this symbol is loaded again in the future
            DummyData = new StockDataSet <T>(dummySrc.Symbol, dummySrc.Start, dummySrc.File);
            DummyData.DataSet.Initialize(dummySrc.DataSet.InternalArray);

            // Create the surface used to draw the plot
            Plot = new NPlot.Swf.InteractivePlotSurface2D();
            Plot.SurfacePadding      = 0;
            Plot.SmoothingMode       = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Plot.ShowCoordinates     = false;
            Plot.XAxis1              = new Axis();
            Plot.YAxis1              = new Axis();
            Plot.XAxis1.HideTickText = true;
            //stockPricePlot.XAxis1.NumberFormat = " h";
            Plot.XAxis1.AxisColor      = System.Drawing.Color.Transparent;
            Plot.YAxis1.HideTickText   = true;
            Plot.YAxis1.Color          = System.Drawing.Color.Transparent;
            Plot.PlotBackColor         = GuiStyle.DARK_GREY;
            Plot.Canvas.HandleCreated += (sender, e) =>
            {
                Plot.Canvas.BackColor = Plot.Canvas.Parent.BackColor;
                //SetChartData(Source);
            };

            // Set the time axis as default
            this.XAxis                = "Time";
            this.XAxisGetValue        = getExpressionEvaluator(this.XAxis);
            this.TimeAxis             = new TradingDateTimeAxis(Plot.XAxis1);
            TimeAxis.StartTradingTime = new TimeSpan(9, 30, 0);
            TimeAxis.EndTradingTime   = new TimeSpan(16, 0, 0);
            TimeAxis.WorldMin         = (double)(file.Start).Ticks;
            TimeAxis.WorldMax         = (double)(file.End).Ticks;
            Plot.XAxis1               = TimeAxis;

            Plot.Refresh();
        }
示例#3
0
        public override string CreateHTML()
        {
            //bail out if no data
            if (NumberOfColumns < 1)
            {
                return(string.Empty);
            }

            StringBuilder charthtml = new StringBuilder();
            int           barwidth  = 100 / (NumberOfColumns * BarsPerColumn);

            //start with the bars
            charthtml.AppendLine(string.Format("<tr class=\"{0} columns\">", Name));
            for (int column = 0; column < NumberOfColumns; column++)
            {
                for (int bar = 0; bar < BarsPerColumn; bar++)
                {
                    if (column < DataSets[bar].Data.Count) //dont try to fetch non-existing data
                    {
                        //calculate height ratio
                        double height_ratio = DataSets[bar].Data.OrderByDescending(item => item.Item3).First().Item3 /
                                              100.00;

                        // surrounding table-cell
                        charthtml.Append(string.Format("<td style=\"vertical-align: bottom; width: {0}%; height: {1}px;\">",
                                                       barwidth, ChartHeight));
                        // the actual bar as div
                        charthtml.Append(string.Format(
                                             "<div class=\"{0} {1}\" style=\"width: 100%; height: {2}%\"></div>", Name,
                                             DataSets[bar].Name, (int)(DataSets[bar].Data[column].Item3 / height_ratio)));
                        charthtml.AppendLine("</td>");
                    }
                    else //empty cell
                    {
                        charthtml.AppendLine("<td></td>");
                    }
                }

                //empty cell as padding between columns
                if (column < NumberOfColumns - 1)
                {
                    charthtml.AppendLine("<td></td>");
                }
            }

            charthtml.AppendLine("</tr>");

            //row for labels, based on the labels provided in the first DataSet
            charthtml.AppendLine(string.Format("<tr class=\"{0} labels\" style=\"height: 0;\">", Name));
            for (int label = 0; label < NumberOfColumns; label++)
            {
                charthtml.Append(string.Format("<td colspan={0} class=\"{1} label\">", BarsPerColumn, Name));
                charthtml.AppendFormat("{0}", DataSets.First().Data[label].Item1);
                charthtml.AppendLine("</td>");

                //empty cell as padding between columns
                if (label < NumberOfColumns - 1)
                {
                    charthtml.AppendLine("<td></td>");
                }
            }

            charthtml.AppendLine("</tr>");

            //rows for value-text
            for (int row = 0; row < BarsPerColumn; row++)
            {
                charthtml.AppendLine(string.Format("<tr class=\"{0} values\" style=\"height: 0;\">", Name));
                for (int column = 0; column < NumberOfColumns; column++)
                {
                    if (column < DataSets[row].Data.Count) //dont try to fetch non-existing data
                    {
                        charthtml.Append(string.Format("<td colspan={0} class=\"{1} {2}\">", BarsPerColumn, Name,
                                                       DataSets[row].Name));
                        charthtml.AppendFormat("{0}", DataSets[row].Data[column].Item2);
                        charthtml.AppendLine("</td>");
                    }
                    else //empty cell
                    {
                        charthtml.AppendLine(string.Format("<td colspan={0}></td>", BarsPerColumn));
                    }

                    //empty cell as padding between columns
                    if (column < NumberOfColumns - 1)
                    {
                        charthtml.AppendLine("<td></td>");
                    }
                }

                charthtml.AppendLine("</tr>");
            }

            //wrap in table tags
            charthtml.Insert(0,
                             string.Format("<table class=\"{0}\" style=\"height: {1}px; width: 100%;\">{2}", Name, ChartHeight,
                                           Environment.NewLine));
            charthtml.AppendLine("</table>");

            return(charthtml.ToString());
        }
        internal DataFile Construct(string FilePath)
        {
            this.Name     = Path.GetFileName(FilePath);
            this.DataSets = new HashSet <DataSet>();
            var RawLines = File.ReadAllLines(FilePath);
            var LockThis = new object();

            this.IsALog = false;
            if (FilePath.EndsWith("HandleServer.dll.log", StringComparison.InvariantCultureIgnoreCase))
            {
                this.IsALog = true;
                var DataSetNames = new string[10] {
                    "GetObjectsToDelete", "GetCivData", "GetCivCacheData", "CountEnemyInArea", "CountPlayerInArea", "AddObjectToDelete", "AddObjectsData", "DeleteObjects", "AddCivWayPos", "AssignCivNames"
                };
                Parallel.ForEach(DataSetNames, new ParallelOptions {
                    MaxDegreeOfParallelism = DataSetNames.Length
                }, CurDataSetName =>
                {
                    var CurDataSet = new DataSet(CurDataSetName);
                    lock (LockThis)
                    {
                        DataSets.Add(CurDataSet);
                    }
                    double CurValue;
                    for (int i2 = 0; i2 < RawLines.Length; i2++)
                    {
                        CurValue = GetValue(RawLines[i2], CurDataSetName, ": ", "ms", 0);
                        if (CurValue > -1)
                        {
                            CurDataSet.DataValues.Add(CurValue);
                        }
                    }
                    if (CurDataSet.DataValues.Count > 0)
                    {
                        CurDataSet.AVGValue = Math.Round(CurDataSet.DataValues.Average(), 3, MidpointRounding.AwayFromZero);
                        CurDataSet.MaxValue = CurDataSet.DataValues.Max();
                    }
                    if (CurDataSet.MaxValue == 0)
                    {
                        DataSets.Remove(CurDataSet);
                    }
                });
            }
            else if (FilePath.EndsWith("HandleServer_Standalone.Perf.log", StringComparison.InvariantCultureIgnoreCase))
            {
                var DataSetNames = new HashSet <DataSetName>();
                DataSetNames.Add(new DataSetName("Durchschnittlich gecached", "(", "%)", 2));
                DataSetNames.Add(new DataSetName("Durchschnittlich nicht gecached", "(", "%)", 3));
                DataSetNames.Add(new DataSetName("Empfangene Datenmenge", " ", "MB", 2));
                DataSetNames.Add(new DataSetName("Gesendete Datenmenge", " ", "MB", 3));
                DataSetNames.Add(new DataSetName("Bandbreite", "AVG Bandwidth: ", "Kbit/s", 0));
                Parallel.ForEach(DataSetNames, new ParallelOptions {
                    MaxDegreeOfParallelism = DataSetNames.Count
                }, CurDataSetName =>
                {
                    var CurDataSet = new DataSet(CurDataSetName.Name);
                    lock (LockThis)
                    {
                        DataSets.Add(CurDataSet);
                    }
                    double CurValue;
                    for (int i2 = 0; i2 < RawLines.Length; i2++)
                    {
                        CurValue = GetValue(RawLines[i2], CurDataSetName.SecondCut, CurDataSetName.FirstCut, CurDataSetName.SecondCut, CurDataSetName.CutType);
                        if (CurValue > -1)
                        {
                            CurDataSet.DataValues.Add(CurValue);
                        }
                    }
                    if (CurDataSet.DataValues.Count > 0)
                    {
                        CurDataSet.AVGValue = Math.Round(CurDataSet.DataValues.Average(), 3, MidpointRounding.AwayFromZero);
                        CurDataSet.MaxValue = CurDataSet.DataValues.Max();
                    }
                    if (CurDataSet.MaxValue == 0)
                    {
                        DataSets.Remove(CurDataSet);
                    }
                });
            }
            else if (FilePath.EndsWith(".rpt", StringComparison.InvariantCultureIgnoreCase))
            {
                var DataSetNames = new HashSet <DataSetName>();
                DataSetNames.Add(new DataSetName("Einheiten", "Einheiten: ", " DavonLokalOhne", 0));
                DataSetNames.Add(new DataSetName("Lokale Einheiten (Keine Zivilisten)", " DavonLokalOhneZivs: ", " Spieler: ", 0));
                DataSetNames.Add(new DataSetName("Lokale Einheiten", " DavonLokal: ", " Spieler: ", 0));
                DataSetNames.Add(new DataSetName("Spieler", " Spieler: ", " Objekte: ", 0));
                DataSetNames.Add(new DataSetName("Objekte", " Objekte: ", " FPS: ", 0));
                DataSetNames.Add(new DataSetName("FPS", " FPS: ", " Schleifen: ", 0));
                DataSetNames.Add(new DataSetName("Schleifen", " Schleifen: ", " Skripte: ", 0));
                DataSetNames.Add(new DataSetName("Skriptthreads", " Skripte: [", "]", 1));
                Parallel.ForEach(DataSetNames, new ParallelOptions {
                    MaxDegreeOfParallelism = DataSetNames.Count
                }, CurDataSetName =>
                {
                    var CurDataSet = new DataSet(CurDataSetName.Name);
                    lock (LockThis)
                    {
                        DataSets.Add(CurDataSet);
                    }
                    double CurValue;
                    for (int i2 = 0; i2 < RawLines.Length; i2++)
                    {
                        CurValue = GetValue(RawLines[i2], CurDataSetName.FirstCut, CurDataSetName.FirstCut, CurDataSetName.SecondCut, CurDataSetName.CutType);
                        if (CurValue > -1)
                        {
                            CurDataSet.DataValues.Add(CurValue);
                        }
                    }
                    if (CurDataSet.DataValues.Count > 0)
                    {
                        CurDataSet.AVGValue = Math.Round(CurDataSet.DataValues.Average(), 3, MidpointRounding.AwayFromZero);
                        CurDataSet.MaxValue = CurDataSet.DataValues.Max();
                    }
                    if (CurDataSet.MaxValue == 0)
                    {
                        DataSets.Remove(CurDataSet);
                    }
                });
                if ((DataSets.Any(i => i.Name.Equals("Skriptthreads"))) && (DataSets.Any(i => i.Name.Equals("FPS"))))
                {
                    var CurCustomDataSet = new DataSet("Rechenzeit(ms) pro Skriptthread & Sekunde");
                    DataSets.Add(CurCustomDataSet);
                    var FPSSet     = DataSets.First(i => i.Name.Equals("FPS"));
                    var ThreadsSet = DataSets.First(i => i.Name.Equals("Skriptthreads"));
                    Parallel.For(0, FPSSet.DataValues.Count, new ParallelOptions {
                        MaxDegreeOfParallelism = FPSSet.DataValues.Count
                    }, i =>
                    {
                        if ((ThreadsSet.DataValues.Count > i) && (FPSSet.DataValues[i] > 0) && (ThreadsSet.DataValues[i] > 0))
                        {
                            lock (LockThis)
                            {
                                CurCustomDataSet.DataValues.Add(Math.Round((FPSSet.DataValues[i] * 3) / ThreadsSet.DataValues[i], 1, MidpointRounding.AwayFromZero));
                            }
                        }
                    });
                    CurCustomDataSet.AVGValue = Math.Round(CurCustomDataSet.DataValues.Average(), 3, MidpointRounding.AwayFromZero);
                    CurCustomDataSet.MaxValue = CurCustomDataSet.DataValues.Max();
                    if (CurCustomDataSet.MaxValue == 0)
                    {
                        DataSets.Remove(CurCustomDataSet);
                    }
                }
            }
            return(this);
        }