Skip to content

Commit

Permalink
Added try-finally to ensure Profiler.StopPart is called
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNeuroth committed Oct 12, 2021
1 parent c3fecf2 commit c1e5433
Showing 1 changed file with 55 additions and 44 deletions.
99 changes: 55 additions & 44 deletions ChartCreator2/OxyCharts/SumProfilesExternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,66 @@ public SumProfilesExternal([JetBrains.Annotations.NotNull] ChartCreationParamete

protected override FileProcessingResult MakeOnePlot(ResultFileEntry rfe)
{
Profiler.StartPart(Utili.GetCurrentMethodAndClass());
string plotName = "Sum Profile for " + rfe.HouseholdNumberString + " " + rfe.LoadTypeInformation?.Name;
var values = new List<double>();
if (rfe.FullFileName == null)
try
{
throw new LPGException("filename was null");
}
using (var sr = new StreamReader(rfe.FullFileName)) {
sr.ReadLine();
while (!sr.EndOfStream) {
var s = sr.ReadLine();
if (s == null) {
throw new LPGException("Readline failed");
}
var cols = s.Split(Parameters.CSVCharacterArr, StringSplitOptions.None);
var col = cols[cols.Length - 1];
var success = double.TryParse(col, out var d);
if (!success) {
throw new LPGException("Double Trouble!");
Profiler.StartPart(Utili.GetCurrentMethodAndClass());
string plotName = "Sum Profile for " + rfe.HouseholdNumberString + " " + rfe.LoadTypeInformation?.Name;
var values = new List<double>();
if (rfe.FullFileName == null)
{
throw new LPGException("filename was null");
}
using (var sr = new StreamReader(rfe.FullFileName))
{
sr.ReadLine();
while (!sr.EndOfStream)
{
var s = sr.ReadLine();
if (s == null)
{
throw new LPGException("Readline failed");
}
var cols = s.Split(Parameters.CSVCharacterArr, StringSplitOptions.None);
var col = cols[cols.Length - 1];
var success = double.TryParse(col, out var d);
if (!success)
{
throw new LPGException("Double Trouble!");
}
values.Add(d);
}
values.Add(d);
}
}
var plotModel1 = new PlotModel();
if (Parameters.ShowTitle) {
plotModel1.Title = plotName;
}
var linearAxis1 = new LinearAxis
{
Position = AxisPosition.Bottom
};
plotModel1.Axes.Add(linearAxis1);
linearAxis1.Title = "Day";
var linearAxis2 = new LinearAxis
{
Title = rfe.LoadTypeInformation?.Name + " in " + rfe.LoadTypeInformation?.UnitOfPower
};
plotModel1.Axes.Add(linearAxis2);
plotModel1.IsLegendVisible = false;
var lineSeries1 = new LineSeries
var plotModel1 = new PlotModel();
if (Parameters.ShowTitle)
{
plotModel1.Title = plotName;
}
var linearAxis1 = new LinearAxis
{
Position = AxisPosition.Bottom
};
plotModel1.Axes.Add(linearAxis1);
linearAxis1.Title = "Day";
var linearAxis2 = new LinearAxis
{
Title = rfe.LoadTypeInformation?.Name + " in " + rfe.LoadTypeInformation?.UnitOfPower
};
plotModel1.Axes.Add(linearAxis2);
plotModel1.IsLegendVisible = false;
var lineSeries1 = new LineSeries
{
Title = "Energy"
};
for (var j = 0; j < values.Count; j++)
{
lineSeries1.Points.Add(new DataPoint(j, values[j]));
}
plotModel1.Series.Add(lineSeries1);
Save(plotModel1, plotName, rfe.FullFileName, Parameters.BaseDirectory, CalcOption.SumProfileExternalIndividualHouseholds);
} finally
{
Title = "Energy"
};
for (var j = 0; j < values.Count; j++) {
lineSeries1.Points.Add(new DataPoint(j, values[j]));
Profiler.StopPart(Utili.GetCurrentMethodAndClass());
}
plotModel1.Series.Add(lineSeries1);
Save(plotModel1, plotName, rfe.FullFileName, Parameters.BaseDirectory,CalcOption.SumProfileExternalIndividualHouseholds);
Profiler.StopPart(Utili.GetCurrentMethodAndClass());
return FileProcessingResult.ShouldCreateFiles;
}
}
Expand Down

0 comments on commit c1e5433

Please sign in to comment.