public void Save([JetBrains.Annotations.NotNull] PlotModel plotModel1, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] string csvFullFileName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath, CalcOption enablingOption, [CanBeNull] string newDstFileName = null, bool makePng = true) { if (plotName.Contains("\\") || plotName.Trim().Length == 0 || plotName.Contains(".")) { throw new LPGException("Plotname is messed up. Please report!"); } var fiCsv = new FileInfo(csvFullFileName.Replace("/", " ")); var destinationFileName = fiCsv.Name; if (newDstFileName != null) { destinationFileName = newDstFileName; } destinationFileName = destinationFileName.Replace(".csv", string.Empty); destinationFileName += ".png"; destinationFileName = AutomationUtili.CleanFileName(destinationFileName); if (fiCsv.DirectoryName == null) { throw new LPGException("Directory name was null. This is a bug. Please report."); } var fi = new FileInfo(Path.Combine(basisPath.FullName, "Charts", destinationFileName)); if (makePng) { if (fi.Exists) { throw new LPGException("File already exists?!? " + fi.FullName); } FFT.RegisterFile(fi.Name, "Plot for " + plotName, true, ResultFileID.Chart, Constants.GeneralHouseholdKey, TargetDirectory.Charts, enablingOption, fi.Name); PngExporter.Export(plotModel1, fi.FullName, _parameters.Width, _parameters.Height, OxyColor.FromArgb(255, 255, 255, 255), _parameters.Dpi); } if (Config.MakePDFCharts) { var pdfChartName = fi.FullName.Substring(0, fi.FullName.Length - 4); pdfChartName += ".pdf"; FFT.RegisterFile(pdfChartName, "PDF Plot for " + plotName, true, ResultFileID.Chart, Constants.GeneralHouseholdKey, TargetDirectory.Charts, enablingOption, pdfChartName); OxyPDFCreator.Run(plotModel1, pdfChartName); } }
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 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); } }
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); } }