private Dictionary <int, OnlineEnergyFileRow> MakeSumsPerMonth([NotNull] CalcLoadTypeDto dstLoadType, [ItemNotNull][NotNull] List <OnlineEnergyFileRow> energyFileRows, DateTime curDate, [NotNull] OnlineEnergyFileRow sum, int rowlength) { var calcParameters = Repository.CalcParameters; var sumsPerMonth = new Dictionary <int, OnlineEnergyFileRow>(); double runningtotal = 0; foreach (var efr in energyFileRows) { curDate += calcParameters.InternalStepsize; sum.AddValues(efr); if (Config.IsInUnitTesting && Config.ExtraUnitTestChecking) { runningtotal += efr.SumFresh(); } if (Config.IsInUnitTesting && Config.ExtraUnitTestChecking && Math.Abs(runningtotal - sum.SumFresh()) > 0.000001) { throw new LPGException("Unknown bug while generating the device totals. Sums don't match."); } if (!sumsPerMonth.ContainsKey(curDate.Month)) { var ts = new TimeStep(0, 0, true); sumsPerMonth.Add(curDate.Month, new OnlineEnergyFileRow(ts, new List <double>(new double[rowlength]), dstLoadType)); } sumsPerMonth[curDate.Month].AddValues(efr); } return(sumsPerMonth); }
public void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] EnergyFileColumns efc) { var calcParameters = Repository.CalcParameters; var dsc = new DateStampCreator(calcParameters); var externalfactor = (int) (calcParameters.ExternalStepsize.TotalSeconds / calcParameters.InternalStepsize.TotalSeconds); if (externalfactor == 1) { return; } var externalFileName = calcParameters.ExternalStepsize.TotalSeconds.ToString(CultureInfo.InvariantCulture); StreamWriter sumfile = null; if (calcParameters.IsSet(CalcOption.SumProfileExternalEntireHouse)) { sumfile = _fft.MakeFile <StreamWriter>("SumProfiles_" + externalFileName + "s." + dstLoadType.Name + ".csv", "Sum energy profiles for " + externalFileName + "s " + dstLoadType.Name, true, ResultFileID.CSVSumProfileExternal, Constants.GeneralHouseholdKey, TargetDirectory.Results, calcParameters.InternalStepsize, CalcOption.SumProfileExternalEntireHouse, dstLoadType.ConvertToLoadTypeInformation()); sumfile.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + "Sum [" + dstLoadType.UnitOfSum + "]"); } StreamWriter normalfile = null; if (calcParameters.IsSet(CalcOption.DeviceProfileExternalEntireHouse)) { normalfile = _fft.MakeFile <StreamWriter>("DeviceProfiles_" + externalFileName + "s." + dstLoadType.Name + ".csv", "Device energy profiles for " + externalFileName + "s " + dstLoadType.Name, true, ResultFileID.DeviceProfileCSVExternal, Constants.GeneralHouseholdKey, TargetDirectory.Results, calcParameters.InternalStepsize, CalcOption.DeviceProfileExternalEntireHouse, dstLoadType.ConvertToLoadTypeInformation()); normalfile.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + efc.GetTotalHeaderString(dstLoadType, null)); } if (calcParameters.IsSet(CalcOption.DeviceProfileExternalEntireHouse) || calcParameters.IsSet(CalcOption.SumProfileExternalEntireHouse)) { for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor) { var efr = new OnlineEnergyFileRow(energyFileRows[outerIndex]); if (!efr.Timestep.DisplayThisStep) { continue; } for (var innerIndex = outerIndex + 1; innerIndex < externalfactor + outerIndex && innerIndex < energyFileRows.Count; innerIndex++) { var efr2 = energyFileRows[innerIndex]; efr.AddValues(efr2); } var sb = new StringBuilder(); dsc.GenerateDateStampForTimestep(efr.Timestep, sb); if (calcParameters.IsSet(CalcOption.DeviceProfileExternalEntireHouse)) { var normalstr = sb + efr.GetEnergyEntriesAsString(true, dstLoadType, null, calcParameters.CSVCharacter) .ToString(); if (normalfile == null) { throw new LPGException("File is null. Please report."); } normalfile.WriteLine(normalstr); } if (calcParameters.IsSet(CalcOption.SumProfileExternalEntireHouse)) { if (sumfile == null) { throw new LPGException("File is null. Please report."); } sumfile.WriteLine(sb + (efr.SumCached * dstLoadType.ConversionFactor).ToString(Config.CultureInfo)); } } } }
public void RunIndividualHouseholds([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] EnergyFileColumns efc, [NotNull] HouseholdKey hhnum) { var calcParameters = Repository.CalcParameters; var dsc = new DateStampCreator(calcParameters); var externalfactor = (int) (calcParameters.ExternalStepsize.TotalSeconds / calcParameters.InternalStepsize.TotalSeconds); if (externalfactor == 1) { return; } var externalFileName = calcParameters.ExternalStepsize.TotalSeconds.ToString(CultureInfo.InvariantCulture); var columns = (from entry in efc.ColumnEntriesByColumn[dstLoadType].Values where entry.HouseholdKey == hhnum select entry.Column).ToList(); var hhname = "." + hhnum + "."; StreamWriter sumfile = null; if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholds)) { sumfile = _fft.MakeFile <StreamWriter>( "SumProfiles_" + externalFileName + "s" + hhname + dstLoadType.Name + ".csv", "Summed up energy profile for all devices for " + dstLoadType.Name + " for " + hhname + " for " + externalFileName + "s", true, ResultFileID.ExternalSumsForHouseholds, hhnum, TargetDirectory.Results, calcParameters.ExternalStepsize, CalcOption.SumProfileExternalIndividualHouseholds, dstLoadType.ConvertToLoadTypeInformation()); sumfile.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + "Sum [" + dstLoadType.UnitOfSum + "]"); } StreamWriter normalfile = null; if (calcParameters.IsSet(CalcOption.DeviceProfileExternalIndividualHouseholds)) { normalfile = _fft.MakeFile <StreamWriter>( "DeviceProfiles_" + externalFileName + "s" + hhname + dstLoadType.Name + ".csv", "Energy use by each device in each Timestep for " + dstLoadType.Name + " for " + hhname, true, ResultFileID.DeviceProfileCSVExternalForHouseholds, hhnum, TargetDirectory.Results, calcParameters.ExternalStepsize, CalcOption.DeviceProfileExternalIndividualHouseholds, dstLoadType.ConvertToLoadTypeInformation()); normalfile.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + efc.GetTotalHeaderString(dstLoadType, columns)); } StreamWriter jsonfile = null; List <double> valuesForJsonExport = new List <double>(); if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholdsAsJson)) { jsonfile = _fft.MakeFile <StreamWriter>( "SumProfiles_" + externalFileName + "s" + hhname + dstLoadType.Name + ".json", "Summed up energy profile for all devices for " + dstLoadType.Name + " for " + hhname + " for " + externalFileName + "s as json", true, ResultFileID.ExternalSumsForHouseholdsJson, hhnum, TargetDirectory.Results, calcParameters.ExternalStepsize, CalcOption.SumProfileExternalIndividualHouseholdsAsJson, dstLoadType.ConvertToLoadTypeInformation()); } if (calcParameters.IsSet(CalcOption.DeviceProfileExternalIndividualHouseholds) || calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholds) || calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholdsAsJson)) { for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor) { var efr = new OnlineEnergyFileRow(energyFileRows[outerIndex]); if (!efr.Timestep.DisplayThisStep) { continue; } for (var innerIndex = outerIndex + 1; innerIndex < externalfactor + outerIndex && innerIndex < energyFileRows.Count; innerIndex++) { var efr2 = energyFileRows[innerIndex]; efr.AddValues(efr2); } var sb = new StringBuilder(); dsc.GenerateDateStampForTimestep(efr.Timestep, sb); if (calcParameters.IsSet(CalcOption.DeviceProfileExternalIndividualHouseholds)) { var normalstr = sb.ToString() + efr.GetEnergyEntriesAsString(true, dstLoadType, columns, calcParameters.CSVCharacter); if (normalfile == null) { throw new LPGException("File was null. Please report."); } normalfile.WriteLine(normalstr); } if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholds) || calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholdsAsJson)) { double sum = efr.GetSumForCertainCols(columns) * dstLoadType.ConversionFactor; if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholds)) { var sumstring = sb.ToString() + sum; if (sumfile == null) { throw new LPGException("File was null. Please report."); } sumfile.WriteLine(sumstring); } if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholdsAsJson)) { valuesForJsonExport.Add(sum); } } } if (calcParameters.IsSet(CalcOption.SumProfileExternalIndividualHouseholdsAsJson)) { if (jsonfile == null) { throw new LPGException("Jsonfile was null"); } jsonfile.WriteLine(JsonConvert.SerializeObject(valuesForJsonExport, Formatting.Indented)); } } }