示例#1
0
        public void ProduceStatPlots(Size canvasSize, String outDir, bool savePlots, bool saveStats, bool saveStatPlots)
        {
            GraphItem graphItem = new GraphItem();

            graphItem.mMarkerFillColor    = Color.Red;
            graphItem.mMarkerOutlineColor = Color.Black;
            graphItem.mMarkerSize         = 4.0f;
            graphItem.mMarkerOutlineSize  = 1.0f;
            graphItem.mMarkerShape        = GraphMarker.Circle;
            graphItem.mTrendLine          = true;
            graphItem.mTrendLineColor     = Color.Blue;
            graphItem.mTrendLineSize      = 1.0f;

            // Get monthly statistics
            MultipleTimeseries[] stats = mMultipleTimeseries.getStatistics();

            // Save statistics and statistic plots
            for (int i = 0; i < stats.Length; ++i)
            {
                // Plot stats
                if (saveStats)
                {
                    stats[i].writeToFile(outDir + Path.DirectorySeparatorChar + "Stats_" + (i + 1).ToString("0000") + ".csv");
                }

                if (savePlots)
                {
                    // Plot timeseries
                    Graph graph = new Graph(mMultipleTimeseries, canvasSize, mMultipleTimeseries[i].SiteId + " Timeseries", "Time", "Amount");
                    graph.addData(new GraphItem(graphItem, i, ""));
                    graph.setSize(new Size(2048, 2048));
                    graph.setHorizontalAxis(mMultipleTimeseries.getStartDate(), mMultipleTimeseries.getEndDate());
                    graph.setVerticalAxis(0, mMultipleTimeseries[i].getMax());
                    graph.getGraph().Save(outDir + Path.DirectorySeparatorChar + "Timeseries_" + (i + 1).ToString("0000") + ".png", System.Drawing.Imaging.ImageFormat.Png);
                }

                if (saveStatPlots)
                {
                    Graph graph = new Graph(stats[i], canvasSize, mMultipleTimeseries[i].SiteId + " Statistics", "Month", "Amount", true);
                    graph.addData(new GraphItem(graphItem, 1, "Mean"));
                    graph.addData(new GraphItem(graphItem, 2, "Min"));
                    graph.addData(new GraphItem(graphItem, 3, "Max"));
                    graph.setSize(new Size(2048, 2048));
                    graph.setHorizontalAxis(stats[i].getStartDate(), stats[i].getEndDate().AddMonths(-1));
                    graph.setVerticalAxis(0, mMultipleTimeseries[i].getMax());
                    graph.getGraph().Save(outDir + Path.DirectorySeparatorChar + "Stats_" + (i + 1).ToString("0000") + "_MeanMinMax.png", System.Drawing.Imaging.ImageFormat.Png);

                    graph = new Graph(stats[i], canvasSize, mMultipleTimeseries[i].SiteId + " Statistics", "Month", "Amount", true);
                    graph.addData(new GraphItem(graphItem, 4, "10%"));
                    graph.addData(new GraphItem(graphItem, 5, "25%"));
                    graph.addData(new GraphItem(graphItem, 6, "50%"));
                    graph.addData(new GraphItem(graphItem, 7, "75%"));
                    graph.addData(new GraphItem(graphItem, 8, "90%"));
                    graph.setSize(new Size(2048, 2048));
                    graph.setHorizontalAxis(stats[i].getStartDate(), stats[i].getEndDate().AddMonths(-1));
                    graph.setVerticalAxis(0, mMultipleTimeseries[i].getMax());
                    graph.getGraph().Save(outDir + Path.DirectorySeparatorChar + "Stats_" + (i + 1).ToString("0000") + "_10-25-50-75-90.png", System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
示例#2
0
        public Bitmap ProducePlot(Size canvasSize)
        {
            GraphItem graphItem = new GraphItem();

            graphItem.mMarkerFillColor    = Color.Red;
            graphItem.mMarkerOutlineColor = Color.Black;
            graphItem.mMarkerSize         = 4.0f;
            graphItem.mMarkerOutlineSize  = 1.0f;
            graphItem.mMarkerShape        = GraphMarker.Circle;
            graphItem.mTrendLine          = true;
            graphItem.mTrendLineColor     = Color.Blue;
            graphItem.mTrendLineSize      = 1.0f;

            Graph graph = new Graph(mMultipleTimeseries, canvasSize, "Timeseries", "Time", "Amount");

            graph.setHorizontalAxis(mMultipleTimeseries.getStartDate(), mMultipleTimeseries.getEndDate());
            graph.setVerticalAxis(0, mMultipleTimeseries.getMax());
            graph.setSize(new Size(2048, 2048));

            for (int i = 0; i < mMultipleTimeseries.getColumns(); ++i)
            {
                graph.addData(new GraphItem(graphItem, i, ""));
            }

            return(graph.getGraph());
        }
示例#3
0
文件: Structs.cs 项目: zenwalk/gridda
        public bool Equals(GraphItem p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((mStationIndex == p.mStationIndex) && (mName == p.mName));
        }
示例#4
0
文件: Structs.cs 项目: zenwalk/gridda
        public GraphItem(GraphItem graphItem, int stationIndex, String name)
        {
            mStationIndex = stationIndex;
            mName         = name;

            mMarkerFillColor    = graphItem.mMarkerFillColor;
            mMarkerOutlineColor = graphItem.mMarkerOutlineColor;
            mMarkerSize         = graphItem.mMarkerSize;
            mMarkerOutlineSize  = graphItem.mMarkerOutlineSize;
            mMarkerShape        = graphItem.mMarkerShape;

            mTrendLineColor = graphItem.mTrendLineColor;
            mTrendLine      = graphItem.mTrendLine;
            mTrendLineSize  = graphItem.mTrendLineSize;
        }
示例#5
0
文件: Graph.cs 项目: zenwalk/gridda
 public void removeData(GraphItem graphItem)
 {
     if (mGraphItems.Contains(graphItem))
     {
         mGraphItems.Remove(graphItem);
     }
     else
     {
         List <GraphItem> toRemove = new List <GraphItem>();
         foreach (GraphItem searchItem in mGraphItems)
         {
             if (searchItem.mStationIndex == graphItem.mStationIndex)
             {
                 toRemove.Add(searchItem);
             }
         }
         foreach (GraphItem removeItem in toRemove)
         {
             mGraphItems.Remove(removeItem);
         }
     }
 }
示例#6
0
文件: Graph.cs 项目: zenwalk/gridda
        public void editData(GraphItem oldGraphItem, GraphItem graphItem)
        {
            int index = mGraphItems.IndexOf(oldGraphItem);

            if (index == -1)
            {
                foreach (GraphItem searchItem in mGraphItems)
                {
                    if (searchItem.mStationIndex == oldGraphItem.mStationIndex)
                    {
                        index = mGraphItems.IndexOf(searchItem);
                    }
                }
            }

            if (index != -1)
            {
                mGraphItems.RemoveAt(index);

                mGraphItems.Insert(index, graphItem);
            }
        }
示例#7
0
文件: Graph.cs 项目: zenwalk/gridda
        public void editLine(GraphItem graphItem, bool drawLine)
        {
            int index = mGraphItems.IndexOf(graphItem);

            if (index == -1)
            {
                foreach (GraphItem searchItem in mGraphItems)
                {
                    if (searchItem.mStationIndex == graphItem.mStationIndex)
                    {
                        index = mGraphItems.IndexOf(searchItem);
                    }
                }
            }

            if (index != -1)
            {
                mGraphItems.RemoveAt(index);

                graphItem.mTrendLine = drawLine;
                mGraphItems.Insert(index, graphItem);
            }
        }
示例#8
0
文件: Graph.cs 项目: zenwalk/gridda
        public void editLineColor(GraphItem graphItem, Color graphColor)
        {
            int index = mGraphItems.IndexOf(graphItem);

            if (index == -1)
            {
                foreach (GraphItem searchItem in mGraphItems)
                {
                    if (searchItem.mStationIndex == graphItem.mStationIndex)
                    {
                        index = mGraphItems.IndexOf(searchItem);
                    }
                }
            }

            if (index != -1)
            {
                mGraphItems.RemoveAt(index);

                graphItem.mTrendLineColor = graphColor;
                mGraphItems.Insert(index, graphItem);
            }
        }
示例#9
0
文件: Graph.cs 项目: zenwalk/gridda
 public void addData(GraphItem graphItem)
 {
     mGraphItems.Add(graphItem);
 }
示例#10
0
文件: Graph.cs 项目: zenwalk/gridda
        private void DrawTimeseries(GraphItem graphItem, Graphics graphObj)
        {
            if (graphItem.mStationIndex < mDataset.getColumns())
            {
                Point[] points     = new Point[mDataset.getRows()];
                int     numMissing = 0;

                // Draw timeseries
                float width        = graphItem.mMarkerSize;
                float markerOffset = width * 0.5f;
                bool  circle       = graphItem.mMarkerShape == GraphMarker.Circle;

                if (mPlotAccumulative)
                {
                    float accumulative = 0.0f;
                    if (mDataset.mTimeUnit == TimeUnit.mo)
                    {
                        for (int i = 0; i < mDataset.getRows(); ++i)
                        {
                            points[i - numMissing].X = convertToGraphCoords(mDataset + i);
                            //if (points[i - numMissing].X > mGraphSize.Width || points[i - numMissing].X < 0)
                            //{
                            //    numMissing++;
                            //    continue;
                            //}

                            accumulative            += mDataset[graphItem.mStationIndex, i];
                            points[i - numMissing].Y = mGraphSize.Height - convertToGraphCoords(accumulative);

                            //if (points[i - numMissing].Y > mGraphSize.Height || points[i - numMissing].Y < 0 || mDataset[graphItem.mStationIndex, i] < 0)
                            if (mDataset[graphItem.mStationIndex, i] < 0)
                            {
                                numMissing++;
                                accumulative -= mDataset[graphItem.mStationIndex, i];
                                continue;
                            }
                        }
                    }
                    else// for hourly and daily, use more efficient offsetting since hours and days will have a uniform distance on the x-axis
                    {
                        float offset = getTimeToSpaceOffset(mDataset.getStartDate());
                        float unit   = getTimeToSpaceUnit(mDataset.getStartDate(), mDataset + 1);
                        for (int i = 0; i < mDataset.getRows(); ++i)
                        {
                            //points[i].X = convertToGraphCoords(mDataset + i);
                            points[i - numMissing].X = getGraphXCoord(i, offset, unit);
                            //if (points[i - numMissing].X > mGraphSize.Width || points[i - numMissing].X < 0)
                            //{
                            //    numMissing++;
                            //    continue;
                            //}

                            accumulative            += mDataset[graphItem.mStationIndex, i];
                            points[i - numMissing].Y = mGraphSize.Height - convertToGraphCoords(accumulative);

                            //if (points[i - numMissing].Y > mGraphSize.Height || points[i - numMissing].Y < 0 || mDataset[graphItem.mStationIndex, i] < 0)
                            if (mDataset[graphItem.mStationIndex, i] < 0)
                            {
                                numMissing++;
                                accumulative -= mDataset[graphItem.mStationIndex, i];
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    if (mDataset.mTimeUnit == TimeUnit.mo)
                    {
                        for (int i = 0; i < mDataset.getRows(); ++i)
                        {
                            points[i].X = convertToGraphCoords(mDataset + i);
                            points[i].Y = mGraphSize.Height - convertToGraphCoords(mDataset[graphItem.mStationIndex, i]);
                        }
                    }
                    else// for hourly and daily, use more efficient offsetting since hours and days will have a uniform distance on the x-axis
                    {
                        float offset = getTimeToSpaceOffset(mDataset.getStartDate());
                        float unit   = getTimeToSpaceUnit(mDataset.getStartDate(), mDataset + 1);
                        for (int i = 0; i < mDataset.getRows(); ++i)
                        {
                            //points[i].X = convertToGraphCoords(mDataset + i);
                            points[i].X = getGraphXCoord(i, offset, unit);
                            points[i].Y = mGraphSize.Height - convertToGraphCoords(mDataset[graphItem.mStationIndex, i]);
                        }
                    }
                }

                // Draw line
                if (graphItem.mTrendLine)
                {
                    Point[] trimPoints = new Point[points.Length - numMissing];
                    Array.Copy(points, trimPoints, points.Length - numMissing);

                    graphObj.DrawLines(new Pen(graphItem.mTrendLineColor, graphItem.mTrendLineSize), trimPoints);
                }

                // Set line and data colors
                Pen   myPen   = new Pen(graphItem.mMarkerOutlineColor, graphItem.mMarkerOutlineSize);
                Brush myBrush = new SolidBrush(graphItem.mMarkerFillColor);
                if (circle)
                {
                    for (int i = 0; i < points.Length - numMissing; ++i)
                    {
                        graphObj.FillEllipse(myBrush, points[i].X - markerOffset, points[i].Y - markerOffset, width, width);
                        graphObj.DrawEllipse(myPen, points[i].X - markerOffset, points[i].Y - markerOffset, width, width);
                    }
                }
                else
                {
                    for (int i = 0; i < points.Length - numMissing; ++i)
                    {
                        graphObj.FillRectangle(myBrush, points[i].X - markerOffset, points[i].Y - markerOffset, width, width);
                        graphObj.DrawRectangle(myPen, points[i].X - markerOffset, points[i].Y - markerOffset, width, width);
                    }
                }
            }
        }