private static Dictionary <StrGuid, Dictionary <int, double> > MakeSumPerMonthPerDeviceID( [NotNull] CalcLoadTypeDto dstLoadType, [NotNull] EnergyFileColumns efc, [NotNull] Dictionary <int, OnlineEnergyFileRow> sumsPerMonth, [NotNull] out Dictionary <int, ColumnEntry> columns) { var sumPerMonthPerDeviceID = new Dictionary <StrGuid, Dictionary <int, double> >(); columns = efc.ColumnEntriesByColumn[dstLoadType]; foreach (var onlineEnergyFileRow in sumsPerMonth) { var month = onlineEnergyFileRow.Key; //var monthsum = onlineEnergyFileRow.Value; foreach (var pair in columns) { var ce = pair.Value; if (!sumPerMonthPerDeviceID.ContainsKey(ce.DeviceGuid)) { sumPerMonthPerDeviceID.Add(ce.DeviceGuid, new Dictionary <int, double>()); } if (!sumPerMonthPerDeviceID[ce.DeviceGuid].ContainsKey(month)) { sumPerMonthPerDeviceID[ce.DeviceGuid].Add(month, 0); } sumPerMonthPerDeviceID[ce.DeviceGuid][month] += sumsPerMonth[month].EnergyEntries[pair.Key]; } } return(sumPerMonthPerDeviceID); }
private void MakeSumsForJson([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] EnergyFileColumns efc, [NotNull] HouseholdKey key) { var calcParameters = Repository.CalcParameters; var dsc = new DateStampCreator(calcParameters); if (!efc.ColumnEntriesByColumn.ContainsKey(dstLoadType)) { return; } var cols = efc.ColumnEntriesByColumn[dstLoadType]; var tdp = new Dictionary <int, TotalsPerDeviceEntry>(); foreach (var pair in cols) { var tpde = new TotalsPerDeviceEntry(key, pair.Value.CalcDeviceDto, dstLoadType); tdp.Add(pair.Key, tpde); } foreach (var row in energyFileRows) { if (!row.Timestep.DisplayThisStep) { continue; } var month = dsc.MakeDateFromTimeStep(row.Timestep).Month; foreach (var pair in cols) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (row.EnergyEntries[pair.Key] == 0) { continue; } tdp[pair.Key].AddConsumptionValue(month, row.EnergyEntries[pair.Key]); } } foreach (var value in tdp.Values) { value.Value *= value.Loadtype.ConversionFactor; value.NegativeValues *= value.Loadtype.ConversionFactor; value.PositiveValues *= value.Loadtype.ConversionFactor; } _inputDataLogger.SaveList(tdp.Values.ToList().ConvertAll(x => (IHouseholdKey)x)); }
/* * public double CalculateTotal([JetBrains.Annotations.NotNull][ItemNotNull] List<OnlineEnergyFileRow> energyFileRows, [JetBrains.Annotations.NotNull] CalcLoadTypeDto dstLoadType, * [JetBrains.Annotations.NotNull] Dictionary<CalcLoadTypeDto, double> allSums, int numberOfPersons) * { * throw new LPGNotImplementedException("calculate house totals"); * /* //if (!_files.ContainsKey(Constants.TotalsKey)) { * //WriteHeader(_fft, Constants.TotalsKey); * //} * double total = 0; * var min = double.MaxValue; * var max = double.MinValue; * foreach (var efr in energyFileRows) { * var sum = efr.SumCached; * if (sum < min) { * min = sum; * } * if (sum > max) { * max = sum; * } * total += sum; * } * //WriteToGeneralFile(total, dstLoadType, min, max, numberOfPersons); * if (!allSums.ContainsKey(dstLoadType)) { * allSums.Add(dstLoadType, 0); * } * * //var hhe = Repository.TotalInformation.HouseholdEntries.FirstOrDefault(x => x.HouseholdKey == Constants.TotalsKey); * //if (hhe == null) {hhe = new TotalsInformation.HouseholdEntry{Name = "HouseSum" * // }; * // Repository.TotalInformation.HouseholdEntries.Add(hhe); * } * hhe.HouseholdKey = Constants.TotalsKey; * var lte = new TotalsInformation.LoadTypeEntry(dstLoadType.ConvertToLoadTypeInformation(), total * dstLoadType.ConversionFactor); * hhe.LoadTypeEntries.Add(lte); * * allSums[dstLoadType] += total * dstLoadType.ConversionFactor; * return total; * }*/ public void RunIndividualHouseholds([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] EnergyFileColumns efc, [NotNull] Dictionary <CalcLoadTypeDto, double> allSums) { var householdKeys = efc.ColumnEntriesByColumn[dstLoadType].Values.Select(entry => entry.HouseholdKey).Distinct() .ToList(); // if (householdKeys.Count > 1) { foreach (var hhnum in householdKeys) { //if (!_files.ContainsKey(hhnum)) { // WriteHeader(fft, hhnum); // } // var sw = _files[hhnum]; var columns = efc.ColumnEntriesByColumn[dstLoadType] .Values.Where(entry => entry.HouseholdKey == hhnum) .Select(entry => entry.Column).ToList(); double totalSum = 0; var min = double.MaxValue; var max = double.MinValue; foreach (var efr in energyFileRows) { if (!efr.Timestep.DisplayThisStep) { continue; } var sum = efr.GetSumForCertainCols(columns); if (sum < min) { min = sum; } if (sum > max) { max = sum; } totalSum += sum; } /* * var s = dstLoadType.Name + _calcParameters.CSVCharacter; * s += totalSum + _calcParameters.CSVCharacter; * s += dstLoadType.UnitOfPower + "*" + * _calcParameters.InternalStepsize.TotalSeconds + * " seconds" + _calcParameters.CSVCharacter; * s += totalSum * dstLoadType.ConversionFactor + _calcParameters.CSVCharacter + * dstLoadType.UnitOfSum; * /* * s += _calcParameters.CSVCharacter + * totalSum * dstLoadType.ConversionFactor / totaldays + * _calcParameters.CSVCharacter + dstLoadType.UnitOfSum; * * s += _calcParameters.CSVCharacter + min + * _calcParameters.CSVCharacter + dstLoadType.UnitOfPower; * s += _calcParameters.CSVCharacter + max + * _calcParameters.CSVCharacter + dstLoadType.UnitOfPower;*/ // sw.WriteLine(s); if (!allSums.ContainsKey(dstLoadType)) { allSums.Add(dstLoadType, 0); } allSums[dstLoadType] += totalSum * dstLoadType.ConversionFactor; /* * var hhe = Repository.TotalInformation.HouseholdEntries.FirstOrDefault(x => x.HouseholdKey == hhnum); * if (hhe == null) { * hhe = new TotalsInformation.HouseholdEntry(); * var entry =Repository.HouseholdKeys.FirstOrDefault(x => x.HouseholdKey == hhnum); * if (entry!= null) { * hhe.Name = entry.HouseholdName; * if (hhnum.Key.StartsWith("HH",StringComparison.CurrentCulture)) { * hhe.PureName = hhe.Name?.Substring(0, hhe.Name.Length - hhnum.Key.Length).Trim(); * } * } * else { * throw new LPGException("Unknown household key"); * } * hhe.HouseholdKey = hhnum; * //Repository.TotalInformation.HouseholdEntries.Add(hhe); * //if (_repository.CalcParameters.IsSet(CalcOption.TotalsPerLoadtype)) * //{ * //todo: check alternative sums * // var sw = _fft.MakeFile<StreamWriter>(Constants.TotalsJsonName, "Totals per load type as JSON", false, * //ResultFileID.TotalsJson, Constants.GeneralHouseholdKey, TargetDirectory.Reports, * //_repository.CalcParameters.InternalStepsize); * //_repository.TotalInformation.WriteResultEntries(sw); * //sw.Close(); * } * } * //var lte = new TotalsInformation.LoadTypeEntry(dstLoadType.ConvertToLoadTypeInformation(), totalSum * dstLoadType.ConversionFactor); * //hhe.LoadTypeEntries.Add(lte); * } * //}*/ } }
private void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] IFileFactoryAndTracker fft, [NotNull] EnergyFileColumns efc, [NotNull] Dictionary <CalcLoadTypeDto, Dictionary <StrGuid, double> > loadTypeTodeviceIDToAverageLookup, [ItemNotNull][NotNull] List <DeviceTaggingSetInformation> deviceTaggingSets, [NotNull] Dictionary <string, string> deviceNameToCategory, [NotNull] Dictionary <string, double> deviceEnergyDict, [NotNull] HouseholdKey key) { if (!efc.ColumnEntriesByColumn.ContainsKey(dstLoadType)) { //for this load type for this house there are no column, so nothing to do return; } var calcParameters = Repository.CalcParameters; var rowlength = energyFileRows[0].EnergyEntries.Count; var ts = new TimeStep(0, 0, true); var sum = new OnlineEnergyFileRow(ts, new List <double>(new double[rowlength]), dstLoadType); var curDate = calcParameters.OfficialStartTime; var sumsPerMonth = MakeSumsPerMonth(dstLoadType, energyFileRows, curDate, sum, rowlength); /* * if (Config.IsInUnitTesting && Config.ExtraUnitTestChecking) { * if (!double.IsNaN(previousTotal) && Math.Abs(sum.SumFresh - previousTotal) > 0.000001) { * throw new LPGException("Unknown bug while generating the device totals. Sums don't match."); * } * }*/ var sumPerMonthPerDeviceID = MakeSumPerMonthPerDeviceID(dstLoadType, efc, sumsPerMonth, out var columns); var sumsPerDeviceID = new Dictionary <StrGuid, double>(); var deviceNamesPerID = new Dictionary <StrGuid, string>(); var sumPerDeviceName = new Dictionary <string, double>(); foreach (var pair in columns) { var ce = pair.Value; if (!sumsPerDeviceID.ContainsKey(ce.DeviceGuid)) { sumsPerDeviceID.Add(ce.DeviceGuid, 0); deviceNamesPerID.Add(ce.DeviceGuid, ce.Name); } if (!sumPerDeviceName.ContainsKey(ce.Name)) { sumPerDeviceName.Add(ce.Name, 0); } sumPerDeviceName[ce.Name] += sum.EnergyEntries[pair.Key]; sumsPerDeviceID[ce.DeviceGuid] += sum.EnergyEntries[pair.Key]; } MakeTotalsPerDeviceTaggingSet(fft, dstLoadType, deviceTaggingSets, deviceEnergyDict, key); var builder = new StringBuilder(); foreach (var calcDeviceTaggingSet in deviceTaggingSets) { if (calcDeviceTaggingSet.LoadTypesForThisSet.Any(x => x.Name == dstLoadType.Name)) { builder.Append(calcDeviceTaggingSet.Name).Append(calcParameters.CSVCharacter); } } var taggingsetHeader = builder.ToString(); var devicesums = fft.MakeFile <StreamWriter>("DeviceSums." + dstLoadType.Name + "." + key.Key + ".csv", "Summed up " + dstLoadType.Name + " use per device and comparison with statistical values", true, ResultFileID.DeviceSums, key, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.TotalsPerDevice, dstLoadType.ConvertToLoadTypeInformation()); var calcDuration = calcParameters.OfficialEndTime - calcParameters.OfficialStartTime; var amountofYears = calcDuration.TotalDays / 365.0; var sb = new StringBuilder(); sb.Append("Device name"); sb.Append(calcParameters.CSVCharacter); sb.Append("Usage sum in this simulation [").Append(dstLoadType.UnitOfSum).Append("]"); sb.Append(calcParameters.CSVCharacter); sb.Append("Usage sum in this simulation linear extrapolated to 1 year [").Append(dstLoadType.UnitOfSum).Append("]"); sb.Append(calcParameters.CSVCharacter); sb.Append("Comparison Value from the device entry [").Append(dstLoadType.UnitOfSum).Append("]"); sb.Append(calcParameters.CSVCharacter); sb.Append("Percentage of the comparison value [1 = 100%]"); sb.Append(calcParameters.CSVCharacter); sb.Append("Device Category"); sb.Append(calcParameters.CSVCharacter); sb.Append(taggingsetHeader); devicesums.WriteLine(sb); double devicesum = 0; double extrapolatedSum = 0; double comparsionvaluessum = 0; foreach (var keyValuePair in sumsPerDeviceID) { var s = string.Empty; s += deviceNamesPerID[keyValuePair.Key]; s += calcParameters.CSVCharacter; s += keyValuePair.Value * dstLoadType.ConversionFactor; devicesum += keyValuePair.Value; //deviceSums.AddDeviceSum(deviceNamesPerID[keyValuePair.Key],devicesum,dstLoadType); s += calcParameters.CSVCharacter; var extrapolatedValue = keyValuePair.Value * dstLoadType.ConversionFactor / amountofYears; s += extrapolatedValue; extrapolatedSum += keyValuePair.Value / amountofYears; s += calcParameters.CSVCharacter; double defaultvalue = 0; if (loadTypeTodeviceIDToAverageLookup.ContainsKey(dstLoadType)) { if (loadTypeTodeviceIDToAverageLookup[dstLoadType].ContainsKey(keyValuePair.Key)) { defaultvalue = loadTypeTodeviceIDToAverageLookup[dstLoadType][keyValuePair.Key]; } } s += defaultvalue; comparsionvaluessum += defaultvalue; s += calcParameters.CSVCharacter; if (Math.Abs(defaultvalue) > Constants.Ebsilon) { s += extrapolatedValue / defaultvalue; } else { s += 0; } s += calcParameters.CSVCharacter; var devicename = deviceNamesPerID[keyValuePair.Key]; var deviceCategory = "(no category)"; if (deviceNameToCategory.ContainsKey(devicename)) { deviceCategory = deviceNameToCategory[devicename]; } s += deviceCategory; s += calcParameters.CSVCharacter; var tags = string.Empty; foreach (var calcDeviceTaggingSet in deviceTaggingSets) { if (calcDeviceTaggingSet.LoadTypesForThisSet.Any(x => x.Name == dstLoadType.Name)) { var deviceName = deviceNamesPerID[keyValuePair.Key]; if (calcDeviceTaggingSet.TagByDeviceName.ContainsKey(deviceName)) { tags += calcDeviceTaggingSet.TagByDeviceName[deviceName] + calcParameters.CSVCharacter; } else { tags += Constants.UnknownTag + calcParameters.CSVCharacter; } } } devicesums.WriteLine(s + tags); } var sumstr = "Sums"; sumstr += calcParameters.CSVCharacter; sumstr += devicesum * dstLoadType.ConversionFactor; sumstr += calcParameters.CSVCharacter; sumstr += extrapolatedSum * dstLoadType.ConversionFactor; sumstr += calcParameters.CSVCharacter; sumstr += comparsionvaluessum; devicesums.WriteLine(sumstr); devicesums.Flush(); WriteMonthlyDeviceSums(fft, dstLoadType, sumPerMonthPerDeviceID, deviceNamesPerID, key); }
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)); } } }
private void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] EnergyFileColumns efc) { var calcParameters = Repository.CalcParameters; var comma = calcParameters.CSVCharacter; var entries = new Dictionary <string, List <double> >(); var sums = new List <double>(); var columns = efc.ColumnEntriesByColumn[dstLoadType].Values.ToList(); var curline = 0; foreach (var efr in energyFileRows) { for (var i = 0; i < columns.Count; i++) { var name = columns[i].Name; if (!entries.ContainsKey(name)) { entries.Add(name, new List <double>()); } if (entries[name].Count > curline) { entries[name][curline] += efr.EnergyEntries[i]; } else { entries[name].Add(efr.EnergyEntries[i]); } } sums.Add(efr.SumCached); curline++; } foreach (var keyValuePair in entries) { if (keyValuePair.Value.Count != sums.Count) { throw new LPGException("Uneven Timestep count while creating the duration curves. This is a bug!"); } } sums.Sort((x, y) => y.CompareTo(x)); var ts = new TimeSpan(0, 0, 0); var timestep = 0; // sums var sumfile = _fft.MakeFile <StreamWriter>("DurationCurve." + dstLoadType.Name + ".csv", "Summed up household duration curve for " + dstLoadType.Name, true, ResultFileID.DurationCurveSums, Constants.GeneralHouseholdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.DurationCurve, dstLoadType.ConvertToLoadTypeInformation()); sumfile.WriteLine("Timestep" + comma + "Time span" + comma + "Sum [" + dstLoadType.UnitOfPower + "]"); var sumsb = new StringBuilder(); foreach (var sum in sums) { sumsb.Clear(); sumsb.Append(timestep); sumsb.Append(comma); sumsb.Append(ts); sumsb.Append(comma); sumsb.Append(sum); sumfile.WriteLine(sumsb.ToString()); timestep++; ts = ts.Add(calcParameters.InternalStepsize); } sumfile.Close(); // individual devices var normalfile = _fft.MakeFile <StreamWriter>("DeviceDurationCurves." + dstLoadType.Name + ".csv", "Duration curve for each device for " + dstLoadType.Name, true, ResultFileID.DurationCurveDevices, Constants.GeneralHouseholdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.DurationCurve, dstLoadType.ConvertToLoadTypeInformation()); var header = string.Empty; foreach (var keyValuePair in entries) { header += keyValuePair.Key + " [" + dstLoadType.UnitOfPower + "]" + comma; } normalfile.WriteLine(dstLoadType.Name + ".Time" + comma + "Time span" + comma + header); foreach (var keyValuePair in entries) { keyValuePair.Value.Sort(); } timestep = 0; ts = new TimeSpan(0, 0, 0); var sb = new StringBuilder(); var values = entries.Values.ToArray(); for (var i = 0; i < sums.Count; i++) { sb.Clear(); sb.Append(timestep); sb.Append(comma); sb.Append(ts); sb.Append(comma); for (var index = 0; index < values.Length; index++) { sb.Append(values[index][i].ToString(Config.CultureInfo)); sb.Append(comma); } normalfile.WriteLine(sb.ToString()); timestep++; ts = ts.Add(calcParameters.InternalStepsize); } normalfile.Close(); }
private void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] IFileFactoryAndTracker fft, [NotNull] EnergyFileColumns efcs) { var calcParameters = Repository.CalcParameters; var comma = calcParameters.CSVCharacter; var dailyMinute = new Dictionary <string, double[]>(); var dailyEnergys = new Dictionary <string, double[]>(); var dailyEnergysByDay = new Dictionary <DayOfWeek, Dictionary <string, double[]> >(); var efc = efcs.ColumnEntriesByColumn[dstLoadType]; var headerNames = new List <string>(); var dayofWeekDaycount = new Dictionary <DayOfWeek, int>(); foreach (DayOfWeek value in Enum.GetValues(typeof(DayOfWeek))) { dailyEnergysByDay.Add(value, new Dictionary <string, double[]>()); dayofWeekDaycount.Add(value, 0); } foreach (var colEntry in efc) { if (!dailyMinute.ContainsKey(colEntry.Value.Name)) { dailyMinute.Add(colEntry.Value.Name, new double[1440]); dailyEnergys.Add(colEntry.Value.Name, new double[1440]); headerNames.Add(colEntry.Value.Name); foreach (DayOfWeek value in Enum.GetValues(typeof(DayOfWeek))) { dailyEnergysByDay[value].Add(colEntry.Value.Name, new double[1440]); } } } var curTime = calcParameters.OfficialStartTime; var curDate = calcParameters.OfficialStartTime; var daycount = 0; foreach (var efr in energyFileRows) { // calculate the time step var timestep = (int)((curTime - curDate).TotalSeconds / 60.0); // 60s in one minute // for each column make sums for (var i = 0; i < efr.EnergyEntries.Count; i++) { var name = efc[i].Name; if (efr.EnergyEntries[i] > 0 && efc[i].LocationName != "(autonomous device)") // don't count standby for the time { dailyMinute[name][timestep]++; } dailyEnergysByDay[curTime.DayOfWeek][name][timestep] += efr.EnergyEntries[i]; dailyEnergys[name][timestep] += efr.EnergyEntries[i]; } curTime += calcParameters.InternalStepsize; if (curDate.Day != curTime.Day) { dayofWeekDaycount[curDate.DayOfWeek]++; curDate = new DateTime(curTime.Year, curTime.Month, curTime.Day); daycount++; } } var resultfileMinute = fft.MakeFile <StreamWriter>("TimeOfUseProfiles." + dstLoadType.Name + ".csv", "Time of Use Profiles for all devices with " + dstLoadType.Name, true, ResultFileID.TimeOfUse, Constants.GeneralHouseholdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.TimeOfUsePlot, dstLoadType.ConvertToLoadTypeInformation()); var resultfileEnergy = fft.MakeFile <StreamWriter>( "TimeOfUseEnergyProfiles." + dstLoadType.Name + ".csv", "Time of Use Profiles with the power consumption for all devices with " + dstLoadType.Name, true, ResultFileID.TimeOfUseEnergy, Constants.GeneralHouseholdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.TimeOfUsePlot, dstLoadType.ConvertToLoadTypeInformation()); var headerdays = string.Empty; foreach (var colEntry in headerNames) { headerdays += colEntry + comma; } var header = dstLoadType.Name + ".Time" + comma + "Calender" + comma; if (calcParameters.WriteExcelColumn) { header += "Calender for Excel" + comma; } header += headerdays; resultfileMinute.WriteLine(header); resultfileEnergy.WriteLine(header); for (var i = 0; i < 1440; i++) { var time = MakeWriteableString(i); var time2 = new StringBuilder(time.ToString()); foreach (var colEntry in dailyMinute) { var value = colEntry.Value[i]; time.Append(value); time.Append(comma); } resultfileMinute.WriteLine(time); foreach (var colEntry in dailyEnergys) { var value = colEntry.Value[i]; time2.Append(value / daycount); time2.Append(comma); } resultfileEnergy.WriteLine(time2); } foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek))) { resultfileEnergy.WriteLine(); resultfileEnergy.WriteLine("----"); resultfileEnergy.WriteLine(day.ToString()); resultfileEnergy.WriteLine("----"); resultfileEnergy.WriteLine(); resultfileEnergy.WriteLine(header); for (var i = 0; i < 1440; i++) { var time = MakeWriteableString(i); foreach (var colEntry in dailyEnergysByDay[day]) { var value = colEntry.Value[i]; time.Append(value / dayofWeekDaycount[day]); time.Append(comma); } resultfileEnergy.WriteLine(time); } } resultfileMinute.Flush(); resultfileMinute.Close(); resultfileEnergy.Flush(); resultfileEnergy.Close(); }