private void MakeLinePlot([JetBrains.Annotations.NotNull] string fileName, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath, [JetBrains.Annotations.NotNull] List <double> values, [JetBrains.Annotations.NotNull] LoadTypeInformation lti) { var plotModel1 = new PlotModel(); if (Parameters.ShowTitle) { plotModel1.Title = plotName; } var linearAxis1 = new LinearAxis { Position = AxisPosition.Bottom, Title = "Timestep" }; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis { Title = lti.Name + " in " + lti.UnitOfPower }; plotModel1.Axes.Add(linearAxis2); plotModel1.IsLegendVisible = true; var lineSeries1 = new LineSeries { Title = lti.Name + " in " + lti.UnitOfPower }; for (var j = 0; j < values.Count; j++) { lineSeries1.Points.Add(new DataPoint(j, values[j])); } plotModel1.Series.Add(lineSeries1); Save(plotModel1, plotName, fileName, basisPath, CalcOption.HouseSumProfilesFromDetailedDats); }
private void MakeBoxPlot([JetBrains.Annotations.NotNull] string fileName, [JetBrains.Annotations.NotNull] string plotName, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath, [JetBrains.Annotations.NotNull] List <double> values, [JetBrains.Annotations.NotNull] LoadTypeInformation lti) { const int stepsize = 24 * 60; var dayEntries = new List <DayEntry>(); for (var i = 0; i < values.Count; i += stepsize) { var oneDay = new List <double>(); for (var j = 0; j < stepsize && i + j < values.Count; j++) { oneDay.Add(values[i + j]); } if (oneDay.Count > 5) { var min = oneDay.Min(); var max = oneDay.Max(); oneDay.Sort(); #pragma warning disable VSD0045 // The operands of a divisive expression are both integers and result in an implicit rounding. var idx = oneDay.Count / 2; #pragma warning restore VSD0045 // The operands of a divisive expression are both integers and result in an implicit rounding. var median = oneDay[idx]; dayEntries.Add(new DayEntry(min, max, median, Percentile(oneDay, 0.25), Percentile(oneDay, 0.75))); } } var plotModel1 = new PlotModel { LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.BottomCenter, IsLegendVisible = true }; if (Parameters.ShowTitle) { plotModel1.Title = plotName; } var linearAxis1 = new LinearAxis { Position = AxisPosition.Bottom, Title = "Day" }; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis { Title = lti.Name + " in " + lti.UnitOfPower }; plotModel1.Axes.Add(linearAxis2); var bps = new BoxPlotSeries(); for (var i = 0; i < dayEntries.Count; i++) { bps.Items.Add(new BoxPlotItem(i, dayEntries[i].MinValue, dayEntries[i].Percentile25, dayEntries[i].Median, dayEntries[i].Percentile75, dayEntries[i].MaxValue)); } plotModel1.Series.Add(bps); plotModel1.LegendBackground = OxyColor.FromArgb(200, 255, 255, 255); var fi = new FileInfo(fileName); var dstFileName = fi.Name.Insert(fi.Name.Length - 4, "MinMax."); Save(plotModel1, plotName, fileName, basisPath, CalcOption.HouseSumProfilesFromDetailedDats, dstFileName); }
public JsonDeviceProfiles(TimeSpan timeResolution, DateTime startTime, string loadTypeName, string unit, LoadTypeInformation loadTypeDefinition) { TimeResolution = timeResolution; StartTime = startTime; LoadTypeName = loadTypeName; Unit = unit; LoadTypeDefinition = loadTypeDefinition; }
public CalcLoadType([NotNull] string pName, [NotNull] string unitOfPower, [NotNull] string unitOfSum, double conversionFactor, bool showInCharts, StrGuid guid) : base(pName, guid) { UnitOfPower = unitOfPower; UnitOfSum = unitOfSum; ConversionFactor = conversionFactor; ShowInCharts = showInCharts; _fileName = AutomationUtili.CleanFileName(pName); while (_fileName.Contains(" ")) { _fileName = _fileName.Replace(" ", " "); } _lti = new LoadTypeInformation(Name, UnitOfSum, UnitOfPower, ConversionFactor, ShowInCharts, _fileName, Guid); _dto = new CalcLoadTypeDto(pName, unitOfPower, unitOfSum, conversionFactor, ShowInCharts, guid); }
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); }
public T MakeFile <T>([NotNull] string fileName, [NotNull] string description, bool displayResultFileEntry, ResultFileID rfid1, [NotNull] HouseholdKey householdKey, TargetDirectory targetDirectory, TimeSpan timeResolution, CalcOption enablingOption, [CanBeNull] LoadTypeInformation lti = null, [CanBeNull] PersonInformation pi = null, [CanBeNull] string additionalFileIndex = null) { if (string.IsNullOrWhiteSpace(fileName)) { throw new LPGException("Filename was empty"); } if (!HouseholdRegistry.IsHouseholdRegistered(householdKey)) { throw new LPGException("Forgotten Household Key: " + householdKey); } if (fileName.Contains("..")) { throw new LPGException("Filename with two dots. This looks bad. Please fix: " + fileName); } if (fileName.Contains(" ")) { throw new LPGException("Filename with two spaces. This looks bad. Please fix: " + fileName); } var rfid = rfid1; var cleanFileName = AutomationUtili.CleanFileName(fileName); string targetDir = GetFullPathForTargetdirectry(targetDirectory); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } var fileInfo = new FileInfo(Path.Combine(targetDir, cleanFileName)); if (fileInfo.FullName.Length > 250) { throw new LPGException("The result filename " + fileInfo.FullName + " was longer than 250 characters which is a problem for Windows. Maybe chose a shorter directory name or nest less deep and try again?"); } if (fileInfo.Exists) { throw new LPGException("The file " + fileInfo.Name + " already exists. Can't create it again!"); } bool tryagain; if (!_allValidIds.Contains((int)rfid)) { throw new LPGException("Invalid result file ID"); } do { try { if (typeof(T) == typeof(StreamWriter)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); #pragma warning disable S2930 // "IDisposables" should be disposed var sw = new StreamWriter(stream); #pragma warning restore S2930 // "IDisposables" should be disposed var ret = (T)(object)sw; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, sw, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(BinaryWriter)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); #pragma warning disable S2930 // "IDisposables" should be disposed var bw = new BinaryWriter(stream); #pragma warning restore S2930 // "IDisposables" should be disposed var ret = (T)(object)bw; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, bw, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(Stream)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); var ret = (T)(object)stream; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(FileStream)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); var ret = (T)(object)stream; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } throw new LPGException("Unknown stream type in Makefile<T>"); } catch (IOException ioe) { if (!Config.IsInUnitTesting) { var errormessage = "The file " + fileInfo.FullName + " could not be opened. The exact error message was:" + Environment.NewLine + ioe.Message + Environment.NewLine + Environment.NewLine; errormessage += " Maybe you forgot to close Excel? Press YES to try again!"; var dr = MessageWindowHandler.Mw.ShowYesNoMessage(errormessage, "Error opening file!"); if (dr == LPGMsgBoxResult.Yes) { tryagain = true; } else { tryagain = false; } } else { tryagain = false; } } } while (tryagain); throw new DataIntegrityException("Couldn't open file \"" + fileInfo.FullName + "\". Aborting."); }
public T MakeFile <T>(string fileName, string description, bool displayResultFileEntry, ResultFileID rfid1, HouseholdKey householdKey, TargetDirectory targetDirectory, TimeSpan timeResolution, CalcOption enablingOption, LoadTypeInformation lti = null, PersonInformation pi = null, string additionalFileIndex = null) => throw new NotImplementedException();