protected override FileProcessingResult MakeOnePlot(ResultFileEntry srcEntry)
        {
            string plotName = "Devices " + srcEntry.HouseholdKey + " " + srcEntry.LoadTypeInformation?.Name;

            Profiler.StartPart(Utili.GetCurrentMethodAndClass());
            var lti = srcEntry.LoadTypeInformation;

            if (lti == null)
            {
                throw new LPGException("LTI was null");
            }

            var timestep         = srcEntry.TimeResolution;
            var unitName         = lti.Name + " in " + lti.UnitOfPower + string.Empty;
            var yaxisLabel       = ChartLocalizer.Get().GetTranslation(unitName);
            var conversionfactor = lti.ConversionFaktor;

            if (srcEntry.FullFileName == null)
            {
                throw new LPGException("filename was null");
            }
            GetFirstAndLastDate(srcEntry.FullFileName, out DateTime first, out var last);
            var selectedDateTimes = new List <DateTime>();
            var r       = new Random();
            var allDays = new List <DateTime>();
            var curr    = first;

            while (curr <= last)
            {
                allDays.Add(curr);
                curr = curr.AddDays(1);
            }
            for (var i = 0; i < DaysToMake && allDays.Count > 0; i++)
            {
                var idx = r.Next(allDays.Count);
                selectedDateTimes.Add(allDays[idx]);
                allDays.RemoveAt(idx);
            }
            selectedDateTimes.Sort();
            //var tagFiles =_Parameters.BaseDirectory.GetFiles(Constants.DeviceTaggingSetFileName);
            var taggingSets = DeviceTaggingSetList.Read(_srls);
            var x           = ReadAllDays(srcEntry, conversionfactor, selectedDateTimes,
                                          taggingSets, plotName, Parameters.BaseDirectory,
                                          yaxisLabel, timestep);

            Profiler.StopPart(Utili.GetCurrentMethodAndClass());
            return(x);
        }
        private static void MakeBarCharts([ItemNotNull][JetBrains.Annotations.NotNull] List <AffTagEntry> entries, [JetBrains.Annotations.NotNull] string dstDirectory)
        {
            var personNames = entries.Select(x => x.PersonName.Trim()).Distinct().ToList();
            // make absolute values
            var        plotModel1 = MakePlotmodel(personNames, "Simulationszeit in Prozent");
            var        tagNames   = entries.Select(x => x.AffTagName).Distinct().ToList();
            OxyPalette p;

            if (tagNames.Count < 2)
            {
                p = OxyPalettes.Hue64;
            }
            else
            {
                p = OxyPalettes.HueDistinct(tagNames.Count);
            }
            var personSums = new Dictionary <string, double>();

            foreach (var personName in personNames)
            {
                var sum = entries.Where(x => x.PersonName == personName).Select(x => x.Value).Sum();
                personSums.Add(personName, sum);
            }

            for (var i = 0; i < tagNames.Count; i++)
            {
                var tag           = tagNames[i];
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    XAxisKey        = "N",
                    StrokeThickness = 1,
                    Title           = ChartLocalizer.Get().GetTranslation(tag),
                    LabelPlacement  = LabelPlacement.Middle,
                    StrokeColor     = OxyColors.White,
                    FillColor       = p.Colors[i]
                };
                foreach (var personName in personNames)
                {
                    var te = entries.FirstOrDefault(x => x.AffTagName == tag && x.PersonName == personName);
                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value / personSums[te.PersonName] * 100));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel1.Series.Add(columnSeries2);
            }
            const string fileName = "MergedAffordanceTaggingSet.WoBleibtDieZeit.Absolute.pdf";

            OxyPDFCreator.Run(plotModel1, fileName);
            foreach (var tagName in tagNames)
            {
                var plotModel2    = MakePlotmodel(personNames, "Anteil an der Gesamtzeit in Prozent");
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 1,
                    StrokeColor     = OxyColors.White,
                    XAxisKey        = "N",
                    Title           = ChartLocalizer.Get().GetTranslation(tagName),
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = OxyColors.LightBlue
                };
                var averageValue =
                    entries.Where(x => x.AffTagName == tagName)
                    .Select(x => x.Value / personSums[x.PersonName] * 100)
                    .Average();
                var ls = new LineSeries
                {
                    Color = OxyColors.Red,
                    Title = "Durchschnitt"
                };
                for (var i = 0; i < personNames.Count; i++)
                {
                    var personName = personNames[i];
                    ls.Points.Add(new DataPoint(i, averageValue));
                    var te =
                        entries.FirstOrDefault(x => x.AffTagName == tagName && x.PersonName == personName);

                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value / personSums[personName] * 100));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel2.Series.Add(columnSeries2);
                plotModel2.Series.Add(ls);
                var cleanTag    = AutomationUtili.CleanFileName(tagName);
                var relfileName = Path.Combine(dstDirectory,
                                               "MergedAffordanceTaggingSet.WoBleibtDieZeit." + cleanTag + ".pdf");
                OxyPDFCreator.Run(plotModel2, relfileName);
            }
        }
        private void MakeChartFromDay([JetBrains.Annotations.NotNull] string fileName, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath, [JetBrains.Annotations.NotNull] string yaxisLabel,
                                      TimeSpan timestep,
                                      [ItemNotNull][JetBrains.Annotations.NotNull] List <string> headers,
                                      [JetBrains.Annotations.NotNull] DayEntry day,
                                      [JetBrains.Annotations.NotNull] DeviceTaggingSetInformation taggingSet,
                                      bool makePng)
        {
            // process results
            var columns = new List <MyColumn>();

            for (var i = 0; i < headers.Count; i++)
            {
                var header = headers[i];
                columns.Add(new MyColumn(header, i, taggingSet, basisPath, FFT, _calcParameters));
            }
            foreach (var valueArr in day.Values)
            {
                foreach (var column in columns)
                {
                    column.Values.Add(valueArr[column.Column]);
                    column.Sum += valueArr[column.Column];
                }
            }
            columns.RemoveAt(0); // remove first two columns with the time stamps
            columns.RemoveAt(0);
            var newColumns = new List <MyColumn>();
            var tags       = columns.Select(x => x.Tag).Distinct().ToList();
            var tagNumber  = 0;

            foreach (var tag in tags)
            {
                var myc = new MyColumn(tag, tagNumber++, null, basisPath, FFT, _calcParameters);
                newColumns.Add(myc);
            }
            for (var j = 0; j < columns[0].Values.Count; j++)
            {
                foreach (var newColumn in newColumns)
                {
                    var colsForTag = columns.Where(x => x.Tag == newColumn.RawName).ToList();
                    var sum        = colsForTag.Sum(x => x.Values[j]);
                    newColumn.Values.Add(sum);
                }
                var newSum = newColumns.Sum(x => x.Values[j]);
                var oldsum = columns.Sum(x => x.Values[j]);
                if (Math.Abs(newSum - oldsum) > 0.001)
                {
                    throw new LPGException("Missing values");
                }
            }
            foreach (var column in newColumns)
            {
                column.Sum = column.Values.Sum();
            }
            newColumns.Sort((x, y) => y.Sum.CompareTo(x.Sum));
            var plotModel1 = new PlotModel
            {
                // general
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,

                LegendPosition = LegendPosition.BottomCenter
            };

            if (Config.MakePDFCharts)
            {
                plotModel1.LegendFontSize  = Parameters.PDFFontSize;
                plotModel1.DefaultFontSize = Parameters.PDFFontSize;
            }
            if (Config.SpecialChartFontSize != null)
            {
                plotModel1.LegendFontSize  = Config.SpecialChartFontSize.Value;
                plotModel1.DefaultFontSize = Config.SpecialChartFontSize.Value;
            }
            if (Parameters.ShowTitle)
            {
                plotModel1.Title = plotName;
            }
            var dateTimeAxis = new DateTimeAxis
            {
                Position       = AxisPosition.Bottom,
                StringFormat   = "dd.MM. HH:mm",
                MajorStep      = 0.25,
                MaximumPadding = 0.05
            };

            plotModel1.Axes.Add(dateTimeAxis);

            // axes
            var linearAxis2 = new LinearAxis
            {
                AbsoluteMinimum = 0,
                MaximumPadding  = 0.06,
                MinimumPadding  = 0,
                Title           = yaxisLabel
            };

            plotModel1.Axes.Add(linearAxis2);
            // data
            var p = OxyPalettes.Hue64;

            if (newColumns.Count > 1)
            {
                p = OxyPalettes.Jet(newColumns.Count);
            }

            var currentTime = new TimeSpan(0);

            for (var i = 0; i < newColumns.Count; i++)
            {
                // main columns
                var column        = newColumns[i];
                var columnSeries2 = new AreaSeries
                {
                    StrokeThickness = 0,
                    Title           = ChartLocalizer.Get().GetTranslation(column.RawName)
                };
                for (var j = 0; j < column.Values.Count; j++)
                {
                    currentTime = currentTime.Add(timestep);
                    double sum = 0;
                    for (var k = i - 1; k >= 0; k--)
                    {
                        sum += newColumns[k].Values[j];
                    }
                    var dt     = day.Times[j];
                    var bottom = new DataPoint(DateTimeAxis.ToDouble(dt), sum);
                    columnSeries2.Points.Add(bottom);
                    var top = new DataPoint(DateTimeAxis.ToDouble(dt), sum + column.Values[j]);
                    columnSeries2.Points2.Add(top);
                }
                columnSeries2.Color2 = p.Colors[i];
                columnSeries2.Color  = p.Colors[i];
                columnSeries2.Fill   = p.Colors[i];
                plotModel1.Series.Add(columnSeries2);
            }
            var thisname = fileName + "." + taggingSet.Name + "." + day.Day.Year + "." + day.Day.Month + "." +
                           day.Day.Day;

            Save(plotModel1, plotName, thisname, basisPath, CalcOption.DeviceProfilesIndividualHouseholds, makePng: makePng);
        }
        private PlotModel MakeChart([JetBrains.Annotations.NotNull] string plotName,
                                    [ItemNotNull][JetBrains.Annotations.NotNull] List <Entry> entries,
                                    bool showTitle,
                                    [CanBeNull] LoadTypeInformation lti)
        {
            var days = new HashSet <string>();

            foreach (var entry in entries)
            {
                days.Add(entry.Day);
            }

            var    seasons      = entries.Select(x => x.Season).Distinct().ToList();
            var    maxTimeValue = 0;
            double maxVal       = 0;

            foreach (var entry in entries)
            {
                if (entry.Values.Count > maxTimeValue)
                {
                    maxTimeValue = entry.Values.Count;
                }
                if (entry.Values.Max() > maxVal)
                {
                    maxVal = entry.Values.Max();
                }
            }
            seasons.Sort();
            var plotModel1 = new PlotModel
            {
                LegendPosition    = LegendPosition.BottomCenter,
                LegendPlacement   = LegendPlacement.Outside,
                LegendOrientation = LegendOrientation.Horizontal
            };
            var strokeThickness = 1;

            if (Config.MakePDFCharts)
            {
                plotModel1.DefaultFontSize = Parameters.PDFFontSize;
                plotModel1.LegendFontSize  = Parameters.PDFFontSize;
                strokeThickness            = 1;
            }
            if (showTitle)
            {
                plotModel1.Title = plotName;
            }
            var linearAxis1 = new TimeSpanAxis
            {
                Position = AxisPosition.Bottom
            };
            var min = entries.Select(x => x.Values.Min()).Min();

            if (min > 0)
            {
                min = -0.0001;
            }

            linearAxis1.Minimum        = 0;
            linearAxis1.MinimumPadding = 0;
            linearAxis1.MinorTickSize  = 0;
            linearAxis1.MaximumPadding = 0.03;
            linearAxis1.MajorStep      = 60 * 60 * 6;
            plotModel1.Axes.Add(linearAxis1);
            double start = 0;
            var    step  = 1.0 / days.Count;

            foreach (var day in days)
            {
                var ls = new LineSeries();
                ls.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(new TimeSpan(0)), 0));
                ls.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(new TimeSpan(24, 0, 0)), 0));
                ls.Color    = OxyColors.LightGray;
                ls.YAxisKey = day;
                plotModel1.Series.Add(ls);
            }
            foreach (var daytype in days)
            {
                var linearAxis2 = new LinearAxis
                {
                    StartPosition = start,
                    EndPosition   = start + step * 0.95,
                    Key           = daytype,
                    Title         = ChartLocalizer.Get().GetTranslation(daytype + " in " + lti?.UnitOfPower),
                    MinorTickSize = 0
                };
                linearAxis1.Minimum        = min;
                linearAxis2.MinimumPadding = 0.005;
                linearAxis2.MaximumPadding = 0.1;
                linearAxis2.Maximum        = maxVal;
                plotModel1.Axes.Add(linearAxis2);

                var ls = new LineSeries
                {
                    StrokeThickness = 0.5,
                    Color           = OxyColors.Black,
                    YAxisKey        = daytype
                };
                ls.Points.Add(new DataPoint(0, 0));
                ls.Points.Add(new DataPoint(maxTimeValue, 0));
                start += step;
            }
            var colorList = new List <OxyColor>
            {
                OxyColors.Green,
                OxyColors.Red,
                OxyColors.Blue
            };
            var seasonColors = new Dictionary <string, int>();
            var seasonCount  = 0;

            foreach (var season in seasons)
            {
                seasonColors.Add(season, seasonCount);
                seasonCount++;
            }
            var labeledSeasons = new List <string>();

            for (var i = 0; i < entries.Count; i++)
            {
                var ts     = new TimeSpan(0);
                var oneDay = new TimeSpan(24, 0, 0);
#pragma warning disable VSD0045 // The operands of a divisive expression are both integers and result in an implicit rounding.
                var stepsize = new TimeSpan(oneDay.Ticks / entries[i].Values.Count);
#pragma warning restore VSD0045 // The operands of a divisive expression are both integers and result in an implicit rounding.
                var lineSeries1 = new LineSeries();
                var seasonLabel = ChartLocalizer.Get().GetTranslation(entries[i].Season);
                if (!labeledSeasons.Contains(seasonLabel))
                {
                    lineSeries1.Title = seasonLabel;
                    labeledSeasons.Add(seasonLabel);
                }
                lineSeries1.YAxisKey = entries[i].Day;
                var seasonColor = seasonColors[entries[i].Season];
                lineSeries1.Color           = colorList[seasonColor];
                lineSeries1.StrokeThickness = strokeThickness;
                for (var j = 0; j < entries[i].Values.Count; j++)
                {
                    lineSeries1.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(ts), entries[i].Values[j]));
                    ts = ts.Add(stepsize);
                }
                plotModel1.Series.Add(lineSeries1);
            }

            return(plotModel1);
        }
Пример #5
0
        protected override FileProcessingResult MakeOnePlot(ResultFileEntry rfe)
        {
            string plotName = "Affordance Tagging Set " + rfe.HouseholdNumberString;

            Profiler.StartPart(Utili.GetCurrentMethodAndClass());
            var    consumption = new Dictionary <string, List <double> >();
            var    colNames    = new Dictionary <int, string>();
            var    colSums     = new Dictionary <int, double>();
            double totalSum    = 0;

            if (rfe.FullFileName == null)
            {
                throw new LPGException("filename was null");
            }
            using (var sr = new StreamReader(rfe.FullFileName)) {
                // read data
                var header = sr.ReadLine();
                if (header == null)
                {
                    throw new LPGException("Readline failed.");
                }
                var colheaders = header.Split(Parameters.CSVCharacterArr, StringSplitOptions.None);
                for (var index = 1; index < colheaders.Length; index++)
                {
                    if (colheaders[index].Length > 0)
                    {
                        colNames.Add(index, colheaders[index]);
                        colSums.Add(index - 1, 0);
                    }
                }
                while (!sr.EndOfStream)
                {
                    var s = sr.ReadLine();
                    if (s == null)
                    {
                        throw new LPGException("Readline failed.");
                    }
                    var cols = s.Split(Parameters.CSVCharacterArr, StringSplitOptions.None);
                    var list = new List <double>();
                    consumption.Add(cols[0], list);

                    for (var index = 1; index < cols.Length - 1; index++)
                    {
                        var d = Convert.ToDouble(cols[index], CultureInfo.CurrentCulture);
                        list.Add(d);
                        totalSum += d;
                    }
                }
            }
            var plotModel1 = new PlotModel
            {
                // general
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,
                LegendPosition        = LegendPosition.BottomCenter,
                LegendSymbolMargin    = 20
            };
            var labelFontSize = 11;
            var pngOffset     = 0.1;

            // in the pdfs the vertical text gets moved a little. this is the offset in the png to counter that.
            if (Config.MakePDFCharts)
            {
                plotModel1.DefaultFontSize = Parameters.PDFFontSize;
                plotModel1.LegendFontSize  = Parameters.PDFFontSize;
                labelFontSize = 16;
                pngOffset     = 0;
            }
            if (Parameters.ShowTitle)
            {
                plotModel1.Title = plotName;
            }
            // axes
            var categoryAxis1 = new CategoryAxis
            {
                MinorStep      = 1,
                MaximumPadding = 0.02,
                GapWidth       = 1,
                FontSize       = 18
            };

            foreach (var s in colNames.Values)
            {
                categoryAxis1.Labels.Add(ChartLocalizer.Get().GetTranslation(s));
            }
            plotModel1.Axes.Add(categoryAxis1);
            var linearAxis1 = new LinearAxis
            {
                AbsoluteMinimum = 0,
                MaximumPadding  = 0.03,
                MinimumPadding  = 0,
                MinorTickSize   = 0
            };

            linearAxis1.MajorStep *= 2;
            linearAxis1.Title      = ChartLocalizer.Get().GetTranslation("Time in Percent");
            plotModel1.Axes.Add(linearAxis1);

            OxyPalette p;

            if (consumption.Count > 1)
            {
                p = OxyPalettes.HueDistinct(consumption.Count);
            }
            else
            {
                p = OxyPalettes.Hue64;
            }
            // generate plot
            var colheight = totalSum / consumption.Values.First().Count;
            var count     = 0;

            foreach (var keyValuePair in consumption)
            {
                // main columns
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 0.5,
                    StrokeColor     = OxyColors.White,
                    Title           = ChartLocalizer.Get().GetTranslation(keyValuePair.Key),
                    LabelPlacement  = LabelPlacement.Middle
                };
                var col = 0;
                foreach (var minutes in keyValuePair.Value)
                {
                    var d  = minutes / colheight * 100;
                    var ci = new ColumnItem(d);
                    columnSeries2.Items.Add(ci);

                    if (d > 15)
                    {
                        {
                            var textAnnotation1 = new RectangleAnnotation
                            {
                                Text = minutes.ToString("N0", CultureInfo.CurrentCulture) + " min (" +
                                       d.ToString("N1", CultureInfo.CurrentCulture) + " %)",
                                TextHorizontalAlignment = HorizontalAlignment.Left,
                                TextVerticalAlignment   = VerticalAlignment.Top,
                                StrokeThickness         = 0,
                                MinimumY     = colSums[col],
                                MaximumY     = colSums[col] + d,
                                MinimumX     = col + 0.28 + pngOffset,
                                MaximumX     = col + 0.40 + pngOffset,
                                Fill         = OxyColors.Transparent,
                                TextRotation = 270,
                                FontSize     = labelFontSize
                            };
                            plotModel1.Annotations.Add(textAnnotation1);
                        }
                        {
                            var textAnnotation1 = new RectangleAnnotation();
                            var shortendName    = ChartLocalizer.Get().GetTranslation(keyValuePair.Key);
                            if (shortendName.Length > 20)
                            {
                                shortendName = shortendName.Substring(0, 17) + "...";
                            }
                            textAnnotation1.Text = shortendName.Trim();
                            textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Left;
                            textAnnotation1.TextVerticalAlignment   = VerticalAlignment.Top;
                            textAnnotation1.StrokeThickness         = 0;
                            textAnnotation1.MinimumY     = colSums[col];
                            textAnnotation1.MaximumY     = colSums[col] + d;
                            textAnnotation1.MinimumX     = col + 0.20 + pngOffset;
                            textAnnotation1.MaximumX     = col + 0.30 + pngOffset;
                            textAnnotation1.Fill         = OxyColors.Transparent;
                            textAnnotation1.TextRotation = 270;
                            textAnnotation1.FontSize     = labelFontSize;
                            plotModel1.Annotations.Add(textAnnotation1);
                        }
                    }
                    colSums[col] += d;
                    col++;
                }
                columnSeries2.FillColor = p.Colors[count];
                count++;
                plotModel1.Series.Add(columnSeries2);
            }
            Save(plotModel1, plotName, rfe.FullFileName, Parameters.BaseDirectory, CalcOption.HouseholdContents);
            Profiler.StopPart(Utili.GetCurrentMethodAndClass());
            return(FileProcessingResult.ShouldCreateFiles);
        }
Пример #6
0
        private static void MakeBarCharts([JetBrains.Annotations.NotNull] string setName, [ItemNotNull][JetBrains.Annotations.NotNull] List <TagEntry> entries, [JetBrains.Annotations.NotNull] string dstDirectory)
        {
            var householdNames = entries.Select(x => x.HouseholdName.Trim()).Distinct().ToList();
            // make absolute values
            var plotModel1 = MakePlotmodel(householdNames,
                                           ChartLocalizer.Get().GetTranslation("Electricity") + " in kWh");
            var        tagNames = entries.Select(x => x.TagName).Distinct().ToList();
            OxyPalette p;

            if (tagNames.Count < 2)
            {
                p = OxyPalettes.Hue64;
            }
            else
            {
                p = OxyPalettes.HueDistinct(tagNames.Count);
            }
            for (var i = 0; i < tagNames.Count; i++)
            {
                var tag = tagNames[i];

                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 1,
                    StrokeColor     = OxyColors.White,
                    Title           = ChartLocalizer.Get().GetTranslation(tag),
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = p.Colors[i]
                };
                foreach (var householdName in householdNames)
                {
                    var te = entries.FirstOrDefault(x => x.TagName == tag && x.HouseholdName == householdName);
                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel1.Series.Add(columnSeries2);
            }
            var fileName = "MergedDeviceTagging." + setName + ".pdf";

            OxyPDFCreator.Run(plotModel1, fileName);
            var hhSums = new Dictionary <string, double>();

            foreach (var householdName in householdNames)
            {
                var sum = entries.Where(x => x.HouseholdName == householdName).Select(x => x.Value).Sum();
                hhSums.Add(householdName, sum);
            }
            foreach (var tagName in tagNames)
            {
                var plotModel2    = MakePlotmodel(householdNames, "Anteil am Gesamtverbrauch in Prozent");
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 1,
                    StrokeColor     = OxyColors.White,
                    Title           = ChartLocalizer.Get().GetTranslation(tagName),
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = OxyColors.LightBlue
                };
                foreach (var householdName in householdNames)
                {
                    var te =
                        entries.FirstOrDefault(x => x.TagName == tagName && x.HouseholdName == householdName);

                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value / hhSums[householdName] * 100));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel2.Series.Add(columnSeries2);
                var cleanTag    = AutomationUtili.CleanFileName(tagName);
                var relfileName = Path.Combine(dstDirectory,
                                               "MergedDeviceTagging." + setName + "." + cleanTag + ".pdf");
                OxyPDFCreator.Run(plotModel2, relfileName);
            }
        }
Пример #7
0
        private void MakeBarCharts([JetBrains.Annotations.NotNull] ResultFileEntry rfe, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath,
                                   [JetBrains.Annotations.NotNull] Dictionary <string, List <TagEntry> > consumption)
        {
            Profiler.StartPart(Utili.GetCurrentMethodAndClass());
            foreach (var pair in consumption)
            {
                var hasReferenceValue = pair.Value.Any(x => x.ReferenceValues.Count > 0);
                if (!hasReferenceValue)
                {
                    continue;
                }
                var plotModel1 = new PlotModel();
                pair.Value.Sort((x, y) => x.Value.CompareTo(y.Value));
                plotModel1.LegendBorderThickness = 0;
                plotModel1.LegendOrientation     = LegendOrientation.Horizontal;
                plotModel1.LegendPlacement       = LegendPlacement.Outside;
                plotModel1.LegendPosition        = LegendPosition.BottomCenter;
                var labelFontSize = 12;
                if (Config.MakePDFCharts)
                {
                    plotModel1.DefaultFontSize = Parameters.PDFFontSize;
                    plotModel1.LegendFontSize  = Parameters.PDFFontSize;
                    labelFontSize = 16;
                }
                plotModel1.LegendSymbolMargin = 20;
                if (Parameters.ShowTitle)
                {
                    plotModel1.Title = plotName;
                }

                var categoryAxis1 = new CategoryAxis
                {
                    MinorStep = 1,
                    Minimum   = -0.5
                };
                categoryAxis1.Labels.Add(ChartLocalizer.Get().GetTranslation("Simulated"));
                var firstEntry     = pair.Value[0];
                var referenceCount = firstEntry.ReferenceHeaders.Count;
                for (var i = 0; i < referenceCount; i++)
                {
                    categoryAxis1.Labels.Add(ChartLocalizer.Get().GetTranslation(firstEntry.ReferenceHeaders[i]));
                }
                categoryAxis1.GapWidth       = 1;
                categoryAxis1.MaximumPadding = 0.02;
                categoryAxis1.Position       = AxisPosition.Left;
                plotModel1.Axes.Add(categoryAxis1);

                var sum1 = pair.Value.Select(x => x.Value).Sum();
                var sums = new List <double>();
                foreach (var entry in pair.Value)
                {
                    for (var i = 0; i < entry.ReferenceValues.Count; i++)
                    {
                        if (sums.Count < i + 1)
                        {
                            sums.Add(0);
                        }
                        sums[i] += entry.ReferenceValues[i];
                    }
                }
                var    sum2        = sums.Max();
                var    totalSum    = Math.Max(sum1, sum2);
                string s2          = rfe.LoadTypeInformation?.Name ?? "";
                var    linearAxis1 = new LinearAxis
                {
                    AbsoluteMinimum = 0,
                    MaximumPadding  = 0.02,
                    MinimumPadding  = 0,
                    MajorStep       = totalSum / 5,
                    MinorTickSize   = 0,
                    Position        = AxisPosition.Bottom,
                    Title           = ChartLocalizer.Get().GetTranslation(s2) + " in " + rfe.LoadTypeInformation?.UnitOfSum +
                                      string.Empty
                };
                plotModel1.Axes.Add(linearAxis1);
                OxyPalette p;
                if (pair.Value.Count > 1)
                {
                    p = OxyPalettes.HueDistinct(pair.Value.Count);
                }
                else
                {
                    p = OxyPalettes.Hue64;
                }
                var colSums = new Dictionary <int, double>
                {
                    { 0, 0 },
                    { 1, 0 }
                };
                var count = 0;
                foreach (var tagentry in pair.Value)
                {
                    var columnSeries2 = new BarSeries
                    {
                        FillColor = p.Colors[count]
                    };
                    count++;
                    columnSeries2.IsStacked       = true;
                    columnSeries2.StackGroup      = "1";
                    columnSeries2.StrokeThickness = 1;
                    columnSeries2.StrokeColor     = OxyColor.FromArgb(255, 255, 255, 255);
                    columnSeries2.StrokeThickness = 0.1;
                    columnSeries2.Title           = ChartLocalizer.Get().GetTranslation(tagentry.TagName);
                    columnSeries2.LabelPlacement  = LabelPlacement.Middle;
                    var coli = new BarItem(tagentry.Value);
                    columnSeries2.Items.Add(coli);
                    foreach (var referenceValue in tagentry.ReferenceValues)
                    {
                        var coli2 = new BarItem(referenceValue);
                        columnSeries2.Items.Add(coli2);
                    }
                    var col = 0;
                    if (tagentry.Value / sum1 > 0.2)
                    {
                        var d         = tagentry.Value;
                        var valuetext = d.ToString("N0", CultureInfo.CurrentCulture) + " " + rfe.LoadTypeInformation?.UnitOfSum + " (" +
                                        (d / sum1 * 100).ToString("N1", CultureInfo.CurrentCulture) + " %)";
                        SetRectangelAnnotation(col, colSums, plotModel1, valuetext, d, 0.25, 0.35, labelFontSize);
                        var shortendName = ChartLocalizer.Get().GetTranslation(tagentry.TagName).Trim();
                        if (shortendName.Length > 20)
                        {
                            shortendName = shortendName.Substring(0, 17) + "...";
                        }
                        SetRectangelAnnotation(col, colSums, plotModel1, shortendName, d, 0.35, 0.45, labelFontSize);
                    }
                    col++;
                    double refValue = 0;
                    if (tagentry.ReferenceValues.Count > 0)
                    {
                        refValue = tagentry.ReferenceValues[0];
                    }
                    if (refValue / sum2 > 0.15)
                    {
                        var valueText = refValue.ToString("N0", CultureInfo.CurrentCulture) + " " + rfe.LoadTypeInformation?.UnitOfSum +
                                        " (" + (refValue / sum2 * 100).ToString("N1", CultureInfo.CurrentCulture) +
                                        " %)";
                        SetRectangelAnnotation(col, colSums, plotModel1, valueText, refValue, 0.25, 0.35,
                                               labelFontSize);
                        var labelText = ChartLocalizer.Get().GetTranslation(tagentry.TagName);
                        SetRectangelAnnotation(col, colSums, plotModel1, labelText, refValue, 0.35, 0.45,
                                               labelFontSize);
                    }
                    colSums[0] += tagentry.Value;
                    if (tagentry.ReferenceValues.Count > 0)
                    {
                        colSums[1] += tagentry.ReferenceValues[0];
                    }
                    plotModel1.Series.Add(columnSeries2);
                }
                var fi           = new FileInfo(rfe.FullFileName);
                var modifiedName = fi.Name.Substring(0, fi.Name.Length - 3) + AutomationUtili.CleanFileName(pair.Key) +
                                   ".bars";
                if (fi.DirectoryName == null)
                {
                    throw new LPGException("File was not assigned to a directory");
                }

                var cleanedfullname = Path.Combine(fi.DirectoryName, modifiedName);
                Save(plotModel1, plotName, cleanedfullname, basisPath, CalcOption.HouseholdContents);
            }
            Profiler.StopPart(Utili.GetCurrentMethodAndClass());
        }
        private static void MakeGeneralBarChart([ItemNotNull][JetBrains.Annotations.NotNull] List <AffordanceEntry> entries, [JetBrains.Annotations.NotNull] string dstDir)
        {
            var householdNames = entries.Select(x => x.HouseholdName.Trim()).Distinct().ToList();
            // make absolute values
            var plotModel1 = MakePlotmodel(householdNames,
                                           ChartLocalizer.Get().GetTranslation("Electricity") + " in kWh");
            var affNames = entries.Select(x => x.AffordanceName).Distinct().ToList();

            affNames.Sort((x, y) => string.Compare(x, y, StringComparison.Ordinal));
            OxyPalette p;

            if (affNames.Count < 2)
            {
                p = OxyPalettes.Hue64;
            }
            else
            {
                p = OxyPalettes.HueDistinct(affNames.Count);
            }
            for (var i = 0; i < affNames.Count; i++)
            {
                var tag           = affNames[i];
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 1,
                    StrokeColor     = OxyColors.White,
                    Title           = ChartLocalizer.Get().GetTranslation(tag),
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = p.Colors[i]
                };
                foreach (var householdName in householdNames)
                {
                    var te =
                        entries.FirstOrDefault(x => x.AffordanceName == tag && x.HouseholdName == householdName);
                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel1.Series.Add(columnSeries2);
            }

            var fileName = Path.Combine(dstDir, "MergedAffordanceEnergyUse.pdf");

            OxyPDFCreator.Run(plotModel1, fileName);
            var hhSums     = new Dictionary <string, double>();
            var households = entries.Select(x => x.HouseholdName).Distinct().ToList();

            foreach (var household in households)
            {
                var sum = entries.Where(x => x.HouseholdName == household).Select(x => x.Value).Sum();
                hhSums.Add(household, sum);
            }
            foreach (var affordanceName in affNames)
            {
                var plotModel2 = MakePlotmodel(householdNames, "Anteil am Gesamtverbrauch in Prozent");
                plotModel2.LegendFontSize = Fontsize;
                var columnSeries2 = new ColumnSeries
                {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 1,
                    Title           = ChartLocalizer.Get().GetTranslation(affordanceName),
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = OxyColors.LightBlue
                };
                var averageValue =
                    entries.Where(x => x.AffordanceName == affordanceName)
                    .Select(x => x.Value / hhSums[x.HouseholdName] * 100)
                    .Average();
                var ls = new LineSeries
                {
                    Color = OxyColors.Red,
                    Title = "Durchschnitt"
                };
                for (var i = 0; i < householdNames.Count; i++)
                {
                    var householdName = householdNames[i];
                    ls.Points.Add(new DataPoint(i, averageValue));
                    var te =
                        entries.FirstOrDefault(
                            x => x.AffordanceName == affordanceName && x.HouseholdName == householdName);

                    if (te != null)
                    {
                        columnSeries2.Items.Add(new ColumnItem(te.Value / hhSums[householdName] * 100));
                    }
                    else
                    {
                        columnSeries2.Items.Add(new ColumnItem(0));
                    }
                }
                plotModel2.Series.Add(columnSeries2);
                plotModel2.Series.Add(ls);
                var cleanTag    = AutomationUtili.CleanFileName(affordanceName);
                var relfileName = Path.Combine(dstDir, "MergedAffordanceTaggingEnergyUse." + cleanTag + ".pdf");
                OxyPDFCreator.Run(plotModel2, relfileName);
            }
        }
Пример #9
0
        private void DrawChart([JetBrains.Annotations.NotNull] HouseholdKeyEntry hhkey,
                               [JetBrains.Annotations.NotNull] Dictionary <string, List <double> > energyUsesPerPersonByAfforcance,
                               [ItemNotNull][JetBrains.Annotations.NotNull] List <string> persons,
                               [JetBrains.Annotations.NotNull] CalcLoadTypeDto lti)
        {
            string plotName   = "Affordance Energy Use Per Person " + hhkey.HHKey.Key + " " + lti.Name;
            var    plotModel1 = new PlotModel {
                // general
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,
                LegendPosition        = LegendPosition.BottomCenter,
                LegendMargin          = 10,
                LegendItemAlignment   = HorizontalAlignment.Left
            };
            var labelfontsize = 14;

            if (Config.MakePDFCharts)
            {
                plotModel1.DefaultFontSize = Parameters.PDFFontSize;
                plotModel1.LegendFontSize  = 16;
                labelfontsize = 18;
            }

            if (Parameters.ShowTitle)
            {
                plotModel1.Title = plotName;
            }

            // axes
            var categoryAxis1 = new CategoryAxis {
                MinorStep = 1,
                GapWidth  = 1,
                Position  = AxisPosition.Left
            };
            OxyPalette p;

            if (energyUsesPerPersonByAfforcance.Count > 1)
            {
                p = OxyPalettes.HueDistinct(energyUsesPerPersonByAfforcance.Count);
            }
            else
            {
                p = OxyPalettes.Hue64;
            }

            foreach (var personName in persons)
            {
                categoryAxis1.Labels.Add(ChartLocalizer.Get().GetTranslation(personName));
            }

            plotModel1.Axes.Add(categoryAxis1);
            string s2 = lti.Name + " in " + lti.UnitOfSum;

            var linearAxis1 = new LinearAxis {
                AbsoluteMinimum = 0,
                MaximumPadding  = 0.03,
                MinimumPadding  = 0,
                MinorTickSize   = 0,
                Position        = AxisPosition.Bottom,
                Title           = ChartLocalizer.Get().GetTranslation(s2)
            };

            plotModel1.Axes.Add(linearAxis1);
            // generate plot
            var count = 0;
            Dictionary <int, double> colSums2 = new Dictionary <int, double>();
            Dictionary <int, double> colSums  = new Dictionary <int, double>();

            for (int i = 0; i < persons.Count; i++)
            {
                colSums.Add(i, 0);
                colSums2.Add(i, 0);
            }

            foreach (var pair in energyUsesPerPersonByAfforcance)
            {
                // main columns
                var columnSeries2 = new BarSeries {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 0.1,
                    StrokeColor     = OxyColors.White,
                    Title           = pair.Key, //affordance name
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = p.Colors[count++]
                };
                var col = 0;
                foreach (var d in pair.Value)
                {
                    //energy use values
                    var coli = new BarItem(d);
                    colSums2[col] += d;
                    columnSeries2.Items.Add(coli);
                    col++;
                }

                plotModel1.Series.Add(columnSeries2);
            }

            foreach (var pair in energyUsesPerPersonByAfforcance)
            {
                var col = 0;
                foreach (var d in pair.Value)
                {
                    if (d / colSums2[col] > 0.2)
                    {
                        {
                            var textAnnotation1 = new RectangleAnnotation();
                            var shortendName    = pair.Key;
                            if (shortendName.Length > 30)
                            {
                                shortendName = shortendName.Substring(0, 30) + "...";
                            }

                            textAnnotation1.Text     = shortendName;
                            textAnnotation1.MinimumX = colSums[col];
                            textAnnotation1.MaximumX = colSums[col] + d;
                            textAnnotation1.MinimumY = col + 0.35;
                            textAnnotation1.MaximumY = col + 0.45;
                            textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Left;
                            textAnnotation1.TextVerticalAlignment   = VerticalAlignment.Middle;
                            textAnnotation1.FontSize        = labelfontsize;
                            textAnnotation1.StrokeThickness = 0;
                            textAnnotation1.Fill            = OxyColors.White;
                            plotModel1.Annotations.Add(textAnnotation1);
                        }
                        {
                            var textAnnotation2 = new RectangleAnnotation {
                                Text = d.ToString("N1", CultureInfo.CurrentCulture) + " " + lti.UnitOfSum,
                                TextHorizontalAlignment = HorizontalAlignment.Left,
                                TextVerticalAlignment   = VerticalAlignment.Middle,
                                MinimumX        = colSums[col],
                                MaximumX        = colSums[col] + d,
                                MinimumY        = col + 0.25,
                                MaximumY        = col + 0.35,
                                Fill            = OxyColors.White,
                                FontSize        = labelfontsize,
                                StrokeThickness = 0
                            };

                            plotModel1.Annotations.Add(textAnnotation2);
                        }
                    }

                    colSums[col] += d;
                    col++;
                }
            }

            Save(plotModel1, plotName, "AffordanceEnergyUsePerPerson." + hhkey.HHKey + "." + lti.FileName + ".png", Parameters.BaseDirectory, CalcOption.AffordanceEnergyUse);
        }
        public void MakeIntervalBars([JetBrains.Annotations.NotNull] ResultFileEntry srcResultFileEntry, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath,
                                     [ItemNotNull][JetBrains.Annotations.NotNull] List <Tuple <string, double> > consumption,
                                     [JetBrains.Annotations.NotNull] ChartTaggingSet taggingSet,
                                     [JetBrains.Annotations.NotNull] string newFileNameSuffix,
                                     bool showTitle,
                                     [JetBrains.Annotations.NotNull] GenericChartBase gcb, CalcOption sourceOption)
        {
            var fontsize = 48;

            if (consumption.Count <= 20)
            {
                fontsize = 22;
            }
            if (consumption.Count > 20 && consumption.Count <= 30)
            {
                fontsize = 16;
            }
            if (consumption.Count > 30 && consumption.Count <= 40)
            {
                fontsize = 14;
            }
            if (consumption.Count > 40 && consumption.Count <= 50)
            {
                fontsize = 12;
            }
            if (consumption.Count > 50)
            {
                fontsize = 10;
            }
            if (!Config.MakePDFCharts)
            {
                fontsize = (int)(fontsize * 0.8);
            }
            var unit       = "min";
            var xaxislabel = "Time Consumption in Percent";

            if (srcResultFileEntry.LoadTypeInformation != null)
            {
                var lti = srcResultFileEntry.LoadTypeInformation;
                if (!lti.ShowInCharts)
                {
                    return;
                }
                unit       = lti.UnitOfSum;
                xaxislabel = lti.Name + " in Percent";
            }
            consumption.Sort((x, y) => y.Item2.CompareTo(x.Item2));
            OxyPalette p;

            if (consumption.Count > 1)
            {
                if (taggingSet.Categories.Count > 1)
                {
                    p = OxyPalettes.HueDistinct(taggingSet.Categories.Count);
                }
                else
                {
                    p = OxyPalettes.Hue64;
                }
            }
            else
            {
                p = OxyPalettes.Hue64;
            }
            var plotModel1 = new PlotModel
            {
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Vertical,
                LegendPlacement       = LegendPlacement.Inside,
                LegendPosition        = LegendPosition.TopLeft,
                PlotAreaBorderColor   = OxyColors.White,
                LegendFontSize        = fontsize,
                LegendSymbolMargin    = 25
            };

            if (showTitle)
            {
                plotModel1.Title = plotName;
            }
            if (Config.MakePDFCharts)
            {
                plotModel1.DefaultFontSize = fontsize;
            }
            var ca = new CategoryAxis
            {
                Position       = AxisPosition.Left,
                GapWidth       = 0,
                MaximumPadding = 0.03,
                MajorTickSize  = 0
            };

            plotModel1.Axes.Add(ca);
            var la = new LinearAxis
            {
                Minimum        = 0,
                MinimumPadding = 0,
                Title          = ChartLocalizer.Get().GetTranslation(xaxislabel),
                Position       = AxisPosition.Bottom,
                MinorTickSize  = 0
            };

            plotModel1.Axes.Add(la);
            var caSub = new CategoryAxis
            {
                StartPosition = 0.5,
                EndPosition   = 1,
                Position      = AxisPosition.Left,
                Key           = "Sub",
                GapWidth      = 0.3,
                MajorTickSize = 0,
                MinorTickSize = 0
            };

            plotModel1.Axes.Add(caSub);
            double runningSum   = 0;
            var    row          = 0;
            var    sum          = consumption.Select(x => x.Item2).Sum();
            var    allBarSeries = new Dictionary <string, IntervalBarSeries>();
            var    ba           = new BarSeries
            {
                YAxisKey          = "Sub",
                LabelFormatString = "{0:N1} %"
            };

            foreach (var s in taggingSet.Categories)
            {
                caSub.Labels.Add(ChartLocalizer.Get().GetTranslation(s));
                var ibs = new IntervalBarSeries();
                // ibs.Title =
                var coloridx = taggingSet.GetCategoryIndexOfCategory(s);
                ibs.FillColor       = p.Colors[coloridx];
                ibs.StrokeThickness = 0;
                ibs.FontSize        = fontsize;
                allBarSeries.Add(s, ibs);
                double categorysum = 0;
                foreach (var tuple in consumption)
                {
                    if (taggingSet.AffordanceToCategories[tuple.Item1] == s)
                    {
                        categorysum += tuple.Item2;
                    }
                }
                var percent = categorysum / sum * 100;
                var bai     = new BarItem(percent)
                {
                    Color = p.Colors[coloridx]
                };
                ba.Items.Add(bai);
            }
            plotModel1.Series.Add(ba);
            foreach (var tuple in consumption)
            {
                var percentage = tuple.Item2 / sum * 100;
                var name       = ChartLocalizer.Get().GetTranslation(tuple.Item1.Trim());
                if (name.Length > 100)
                {
                    name = name.Substring(0, 97) + "...";
                }
                var textAnnotation1 = new TextAnnotation
                {
                    StrokeThickness = 0,
                    FontSize        = fontsize,
                    Padding         = new OxyThickness(10, 0, 10, 0)
                };
                var txtValue = tuple.Item2.ToString("N1", CultureInfo.CurrentCulture);
                if (srcResultFileEntry.LoadTypeInformation == null)
                {
                    var ts = TimeSpan.FromMinutes(tuple.Item2);
                    txtValue = ts.ToString();
                }
                textAnnotation1.Text = " " + name + " (" + txtValue + " " + unit + ", " +
                                       (tuple.Item2 / sum * 100).ToString("N1", CultureInfo.CurrentCulture) + " %)   ";
                if (runningSum < 50)
                {
                    textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Left;
                    textAnnotation1.TextPosition            = new DataPoint(runningSum + percentage, row - 0.6);
                }
                else
                {
                    textAnnotation1.TextPosition            = new DataPoint(runningSum, row - 0.5);
                    textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Right;
                }
                plotModel1.Annotations.Add(textAnnotation1);
                var item     = new IntervalBarItem(runningSum, runningSum + percentage);
                var category = taggingSet.AffordanceToCategories[tuple.Item1];
                allBarSeries[category].Items.Add(item);
                foreach (var pair in allBarSeries)
                {
                    if (pair.Key != category)
                    {
                        pair.Value.Items.Add(new IntervalBarItem(0, 0));
                    }
                }
                ca.Labels.Add(string.Empty);
                runningSum += percentage;
                row++;
            }
            foreach (var pair in allBarSeries)
            {
                plotModel1.Series.Add(pair.Value);
            }
            gcb.Save(plotModel1, plotName, srcResultFileEntry.FullFileName + newFileNameSuffix, basisPath, sourceOption); // ".interval"
        }