private void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] IFileFactoryAndTracker fft) { var calcParameters = Repository.CalcParameters; var dailyValues = new Dictionary <int, Dictionary <int, double> >(); var dailyValuesbyMonth = new Dictionary <int, Dictionary <int, Dictionary <int, double> > >(); var dailyValuesbySeason = new Dictionary <int, Dictionary <int, double> >(); var dayCount = new Dictionary <DayOfWeek, int>(); var seasonDayCount = new Dictionary <int, int>(); ReadFile(energyFileRows, dailyValues, dailyValuesbyMonth, dailyValuesbySeason, dayCount, seasonDayCount); var resultfile = fft.MakeFile <StreamWriter>("WeekdayProfiles." + dstLoadType.Name + ".csv", "Averaged profiles for each weekday for " + dstLoadType.Name, true, ResultFileID.WeekdayLoadProfileID, Constants.GeneralHouseholdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.WeekdayProfiles, dstLoadType.ConvertToLoadTypeInformation()); var valuecount = WriteNormalPart(dstLoadType, resultfile, dailyValues, dayCount); WriteByMonth(resultfile, dailyValuesbyMonth, valuecount); WriteBySeason(resultfile, valuecount, dailyValuesbySeason, seasonDayCount); resultfile.Flush(); resultfile.Close(); }
protected override void PerformActualStep(IStepParameters parameters) { LoadtypeStepParameters p = (LoadtypeStepParameters)parameters; var dsc = new DateStampCreator(Repository.CalcParameters); var dstLoadType = p.LoadType; var householdKey = Constants.GeneralHouseholdKey; var calcParameters = Repository.CalcParameters; var efc = Repository.ReadEnergyFileColumns(Constants.GeneralHouseholdKey); var deviceProfileCsv = _fft.MakeFile <StreamWriter>("DeviceProfiles." + dstLoadType.Name + ".csv", "Energy use by each device in each Timestep for " + dstLoadType.Name + " for the entire house", true, ResultFileID.DeviceProfileCSV, householdKey, TargetDirectory.Results, calcParameters.InternalStepsize, CalcOption.DeviceProfilesHouse, dstLoadType.ConvertToLoadTypeInformation()); deviceProfileCsv.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + efc.GetTotalHeaderString(dstLoadType, null)); foreach (var efr in p.EnergyFileRows) { if (!efr.Timestep.DisplayThisStep) { continue; } var time = dsc.MakeTimeString(efr.Timestep); var individual = time + efr.GetEnergyEntriesAsString(true, dstLoadType, null, calcParameters.CSVCharacter); deviceProfileCsv.WriteLine(individual); } deviceProfileCsv.Flush(); }
protected override void PerformActualStep(IStepParameters parameters) { LoadtypeStepParameters p = (LoadtypeStepParameters)parameters; var dsc = new DateStampCreator(Repository.CalcParameters); var calcParameters = Repository.CalcParameters; CalcLoadTypeDto dstLoadType = p.LoadType; var householdKey = Constants.GeneralHouseholdKey; var sumfile = _fft.MakeFile <StreamWriter>("SumProfiles." + dstLoadType.Name + ".csv", "Summed up energy profile for all devices for " + dstLoadType.Name, true, ResultFileID.CSVSumProfile, householdKey, TargetDirectory.Results, calcParameters.InternalStepsize, CalcOption.HouseSumProfilesFromDetailedDats, dstLoadType.ConvertToLoadTypeInformation()); sumfile.WriteLine(dstLoadType.Name + "." + dsc.GenerateDateStampHeader() + "Sum [" + dstLoadType.UnitOfSum + "]"); foreach (var efr in p.EnergyFileRows) { if (!efr.Timestep.DisplayThisStep) { continue; } var time = dsc.MakeTimeString(efr.Timestep); var sumstring = time + (efr.SumCached * dstLoadType.ConversionFactor).ToString(Config.CultureInfo); sumfile.WriteLine(sumstring); } }
/* * public void RunIndividualHouseholdsPolysun([JetBrains.Annotations.NotNull] CalcLoadTypeDto dstLoadType, * [JetBrains.Annotations.NotNull][ItemNotNull] List<OnlineEnergyFileRow> energyFileRows, [JetBrains.Annotations.NotNull] FileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] EnergyFileColumns efc) * { * var fifteenmin = new TimeSpan(0, 15, 0); * var externalfactor = * (int) (fifteenmin.TotalSeconds / _calcParameters.InternalStepsize.TotalSeconds); * if (externalfactor == 1) { * return; * } * var externalFileName = fifteenmin.TotalSeconds.ToString(CultureInfo.InvariantCulture); * var householdNumbers = * (efc.ColumnEntriesByColumn[dstLoadType].Values.Select(entry => entry.HouseholdKey)).Distinct() * .ToList(); * var householdNames = Repository.HouseholdKeys; * Dictionary<HouseholdKey, string> householdNamesByKey = new Dictionary<HouseholdKey, string>(); * foreach (HouseholdKeyEntry entry in householdNames) { * householdNamesByKey.Add(entry.HouseholdKey,entry.HouseholdName); * } * if (householdNumbers.Count > 1) { * foreach (var hhnum in householdNumbers) { * if (!householdNamesByKey.ContainsKey(hhnum)) { * continue; * } * var columns = * (from entry in efc.ColumnEntriesByColumn[dstLoadType].Values * where entry.HouseholdKey == hhnum * select entry.Column).ToList(); * var hhname = "." + hhnum + "."; * * var sumfile = * fft.MakeFile<StreamWriter>( * "ImportProfile_" + externalFileName + "s" + hhname + dstLoadType.Name + ".csv", * "Summed up energy profile without timestamp for " + externalFileName + "s " + * dstLoadType.Name + " and HH" + hhnum, true, * ResultFileID.PolysunImportFileHH, hhnum, TargetDirectory.Results, fifteenmin, * dstLoadType.ConvertToLoadTypeInformation()); * WritePolysunHeader(sumfile, householdNamesByKey[hhnum], dstLoadType); * var timestepcount = 0; * var ts = TimeSpan.Zero; * for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor) { * var efr = energyFileRows[outerIndex]; * if (!efr.Timestep.DisplayThisStep) { * continue; * } * double sum = 0; * * for (var innerIndex = outerIndex; * innerIndex < outerIndex + externalfactor && innerIndex < energyFileRows.Count; * innerIndex++) { * var efr2 = energyFileRows[innerIndex]; * sum += efr2.GetSumForCertainCols(columns); * timestepcount++; * ts = ts.Add(_calcParameters.InternalStepsize); * } * sum = sum * dstLoadType.ConversionFactor; * var normalstr = ts.TotalSeconds + _calcParameters.CSVCharacter + * sum.ToString("N4", CultureInfo.InvariantCulture); * sumfile.WriteLine(normalstr); * } * if (timestepcount != energyFileRows.Count) { * throw new LPGException("Importfilecreator seems to be broken! Please report!"); * } * } * } * }*/ public void RunPolysun([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows, [NotNull] IFileFactoryAndTracker fft, [NotNull] string housename) { var calcParameters = Repository.CalcParameters; var fifteenMin = new TimeSpan(0, 15, 0); var externalfactor = (int)(fifteenMin.TotalSeconds / calcParameters.InternalStepsize.TotalSeconds); if (externalfactor == 1) { return; } var externalFileName = fifteenMin.TotalSeconds.ToString(CultureInfo.InvariantCulture); var sumfile = fft.MakeFile <StreamWriter>("ImportProfile." + externalFileName + "s." + dstLoadType.Name + ".csv", "Sum energy profile with timestamp for import in Polysun " + externalFileName + "s " + dstLoadType.Name, true, ResultFileID.PolysunImportFile, Constants.GeneralHouseholdKey, TargetDirectory.Results, fifteenMin, CalcOption.PolysunImportFiles, dstLoadType.ConvertToLoadTypeInformation()); //var count = energyFileRows[0].EnergyEntries.Count; var ts = TimeSpan.Zero; //var timestepcount = 0; WritePolysunHeader(sumfile, housename, dstLoadType); for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor) { var efrOuter = energyFileRows[outerIndex]; if (!efrOuter.Timestep.DisplayThisStep) { continue; } double sum = 0; for (var innerIndex = outerIndex; innerIndex < outerIndex + externalfactor && innerIndex < energyFileRows.Count; innerIndex++) { var efr2 = energyFileRows[innerIndex]; sum += efr2.SumCached; // timestepcount++; } var sumPower = sum * dstLoadType.ConversionFactor; // change to power var normalstr = ts.TotalSeconds + calcParameters.CSVCharacter + sumPower.ToString("N8", CultureInfo.InvariantCulture); sumfile.WriteLine(normalstr); } // if (timestepcount != energyFileRows.Count) { //this does not consider the hidden time steps // throw new LPGException("Importfilecreator seems to be broken! Please report!"); //} sumfile.Flush(); }
private void WriteAffordanceTags() { if (Repository.CalcParameters.IsSet(CalcOption.HouseholdContents)) { using (var swTagSet = _fft.MakeFile <StreamWriter>("AffordanceTags.txt", "All Affordances with tags", false, ResultFileID.AffordanceTagsFile, Constants.GeneralHouseholdKey, TargetDirectory.Root, Repository.CalcParameters.InternalStepsize, CalcOption.HouseholdContents)) { foreach (var taggingSet in Repository.AffordanceTaggingSets) { swTagSet.WriteLine("###"); swTagSet.WriteLine(taggingSet.Name); swTagSet.WriteLine("###"); foreach (var tag in taggingSet.AffordanceToTagDict) { swTagSet.WriteLine(tag.Key + Repository.CalcParameters.CSVCharacter + tag.Value); } } } } }
protected override void PerformActualStep(IStepParameters parameters) { HouseholdStepParameters hhp = (HouseholdStepParameters)parameters; var entry = hhp.Key; if (entry.KeyType != HouseholdKeyType.Household) { return; } var householdKey = entry.HHKey; _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass()); Logger.Info("Starting to complete list of actions for each person at each time step for statistical analysis..."); var activitiesPerPerson = ReadActivities(householdKey); //var fileIdx = 0; if (activitiesPerPerson.Count == 0) { throw new LPGException("There were no activities for any person in the household " + householdKey.Key); } var affs = ReadActivities(householdKey); var sactionEntries = _repository.ReadSingleTimestepActionEntries(householdKey); Dictionary <BodilyActivityLevel, List <int> > personCountByActivity = new Dictionary <BodilyActivityLevel, List <int> >(); foreach (BodilyActivityLevel bal in Enum.GetValues(typeof(BodilyActivityLevel))) { personCountByActivity.Add(bal, new List <int>(new int[_repository.CalcParameters.OfficalTimesteps])); } foreach (var singleTimestepActionEntry in sactionEntries) { var aff = affs[singleTimestepActionEntry.ActionEntryGuid]; personCountByActivity[aff.BodilyActivityLevel][singleTimestepActionEntry.TimeStep]++; } foreach (var pair in personCountByActivity) { JsonSumProfile jsp = new JsonSumProfile("Person Count for Activity Level " + pair.Key.ToString() + " " + householdKey.Key, Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime, "Person Count for - " + pair.Key.ToString(), "", null, hhp.Key); foreach (var val in pair.Value) { jsp.Values.Add(val); } var sumfile = _fft.MakeFile <StreamWriter>("BodilyActivityLevel." + pair.Key + "." + householdKey.Key + ".json", "Bodily Activity Level for " + pair.Key + " in the household " + householdKey.Key, true, ResultFileID.BodilyActivityJsons, householdKey, TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.BodilyActivityStatistics, null, null, pair.Key.ToString()); sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented)); sumfile.Flush(); } _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass()); }
private static StreamWriter GetWriter([JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] HouseholdKey householdKey, [JetBrains.Annotations.NotNull] CalcParameters calcParameters) => fft .MakeFile <StreamWriter>("LocationStatistics." + householdKey + ".csv", "How much time the people are spending at each Location", true, ResultFileID.LocationStatistic, householdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.LocationsFile);
private void WriteMonthlyDeviceSums([NotNull] IFileFactoryAndTracker fft, [NotNull] CalcLoadTypeDto dstLoadType, [NotNull] Dictionary <StrGuid, Dictionary <int, double> > values, [NotNull] Dictionary <StrGuid, string> deviceNamesPerID, [NotNull] HouseholdKey key) { var calcParameters = Repository.CalcParameters; var devicesums = fft.MakeFile <StreamWriter>("DeviceSums_Monthly." + dstLoadType.Name + "." + key.Key + ".csv", "Summed up " + dstLoadType.Name + " use per device per Month", true, ResultFileID.DeviceSumsPerMonth, key, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.TotalsPerDevice, dstLoadType.ConvertToLoadTypeInformation()); var sb = new StringBuilder(); sb.Append("Device name"); sb.Append(calcParameters.CSVCharacter); var firstmonth = values.Keys.First(); foreach (var monthAndValue in values[firstmonth]) { sb.Append(monthAndValue.Key); sb.Append(calcParameters.CSVCharacter); } devicesums.WriteLine(sb); var monthSums = new Dictionary <int, double>(); foreach (var keyValuePair in values) { var s = string.Empty; s += deviceNamesPerID[keyValuePair.Key]; s += calcParameters.CSVCharacter; foreach (var monthValue in keyValuePair.Value) { s += monthValue.Value * dstLoadType.ConversionFactor + calcParameters.CSVCharacter; if (!monthSums.ContainsKey(monthValue.Key)) { monthSums.Add(monthValue.Key, 0); } monthSums[monthValue.Key] += monthValue.Value; } devicesums.WriteLine(s); } var sumstr = "Sums" + calcParameters.CSVCharacter; foreach (var keyValuePair in monthSums) { sumstr += keyValuePair.Value * dstLoadType.ConversionFactor + calcParameters.CSVCharacter; } devicesums.WriteLine(sumstr); devicesums.Flush(); }
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); }
private void MakeTotalsPerDeviceTaggingSet([NotNull] IFileFactoryAndTracker fft, [NotNull] CalcLoadTypeDto dstLoadType, [ItemNotNull][NotNull] List <DeviceTaggingSetInformation> deviceTaggingSets, [NotNull] Dictionary <string, double> deviceEnergyDict, [NotNull] HouseholdKey hhkey) { var calcParameters = Repository.CalcParameters; using (var file = fft.MakeFile <StreamWriter>("DeviceTaggingSet." + dstLoadType.FileName + "." + hhkey.Key + ".csv", "Summed up energy use into the AffordanceToCategories in the device tagging sets for " + dstLoadType.Name, true, ResultFileID.DeviceTaggingSetFiles, hhkey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.TotalsPerDevice, dstLoadType.ConvertToLoadTypeInformation())) { foreach (var tagSet in deviceTaggingSets) { file.WriteLine("-----"); file.WriteLine(tagSet.Name); var energyUsePerTag = new Dictionary <string, double>(); double sum = 0; foreach (var keyValuePair in deviceEnergyDict) { var device = keyValuePair.Key; if (!tagSet.TagByDeviceName.ContainsKey(device)) { tagSet.TagByDeviceName.Add(device, device); } var tag = tagSet.TagByDeviceName[device]; if (!energyUsePerTag.ContainsKey(tag)) { energyUsePerTag.Add(tag, 0); } energyUsePerTag[tag] += keyValuePair.Value; sum += keyValuePair.Value; } file.WriteLine("Tag" + calcParameters.CSVCharacter + "Energy Used [" + dstLoadType.UnitOfSum + "]" + calcParameters.CSVCharacter + "Percentage" + calcParameters.CSVCharacter + "Reference Value" + calcParameters.CSVCharacter); foreach (var tag in energyUsePerTag) { var referenceValue = string.Empty; var key = DeviceTaggingSetInformation.MakeKey(dstLoadType.Name, tag.Key); if (tagSet.ReferenceValues.ContainsKey(key)) { referenceValue = tagSet.ReferenceValues[key].ToString(Config.CultureInfo); } file.WriteLine(tag.Key + calcParameters.CSVCharacter + tag.Value * dstLoadType.ConversionFactor + calcParameters.CSVCharacter + (tag.Value / sum).ToString("0.0000", Config.CultureInfo) + calcParameters.CSVCharacter + referenceValue + calcParameters.CSVCharacter); } file.WriteLine(); file.WriteLine("Sum" + calcParameters.CSVCharacter + sum * dstLoadType.ConversionFactor + calcParameters.CSVCharacter + "1" + calcParameters.CSVCharacter); } } }
private void BuildActivationsPerHours([NotNull] IFileFactoryAndTracker fft, [NotNull] HouseholdKey householdKey, [NotNull][ItemNotNull] List <CalcAffordanceTaggingSetDto> taggingSets, [NotNull][ItemNotNull] List <ActionEntry> actionEntries) { var calcParameters = Repository.CalcParameters; var activitiesPerHour = new Dictionary <string, Dictionary <string, int[]> >(); var activitiesPerWeekday = new Dictionary <string, Dictionary <string, int[]> >(); foreach (ActionEntry ase in actionEntries) { if (!activitiesPerHour.ContainsKey(ase.PersonName)) { activitiesPerHour.Add(ase.PersonName, new Dictionary <string, int[]>()); activitiesPerWeekday.Add(ase.PersonName, new Dictionary <string, int[]>()); } if (!activitiesPerHour[ase.PersonName].ContainsKey(ase.AffordanceName)) { activitiesPerHour[ase.PersonName].Add(ase.AffordanceName, new int[24]); activitiesPerWeekday[ase.PersonName].Add(ase.AffordanceName, new int[7]); } var hour = ase.DateTime.Hour; var weekday = (int)ase.DateTime.DayOfWeek; activitiesPerHour[ase.PersonName][ase.AffordanceName][hour]++; activitiesPerWeekday[ase.PersonName][ase.AffordanceName][weekday]++; } using (var sw = fft.MakeFile <StreamWriter>("ActivationsPerHour." + householdKey + ".csv", "Activations per hour", true, ResultFileID.ActivationsPerHour, householdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.ActivationsPerHour)) { foreach (var person in activitiesPerHour) { sw.WriteLine(person.Key); var s = new StringBuilder(); s.Append("Hour").Append(calcParameters.CSVCharacter); for (var i = 0; i < 24; i++) { s.Append(i).Append(calcParameters.CSVCharacter); } sw.WriteLine(s); var sb = new StringBuilder(); foreach (var device in person.Value) { sb.Clear(); sb.Append(device.Key); for (var i = 0; i < 24; i++) { sb.Append(calcParameters.CSVCharacter); sb.Append(device.Value[i].ToString(CultureInfo.InvariantCulture)); } sw.WriteLine(sb); } } } using (var sw = fft.MakeFile <StreamWriter>("ExecutedActionsOverviewCount." + householdKey + ".csv", "Overview of the executed actions", true, ResultFileID.ExecutedActionsOverview, householdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.ActivationsPerHour)) { foreach (var person in activitiesPerHour) { sw.WriteLine("-----"); sw.WriteLine(person.Key); var header = new StringBuilder(); header.Append("Actions").Append(calcParameters.CSVCharacter).Append("Times of execution in the simulation period") .Append(calcParameters.CSVCharacter); foreach (var weekday in Enum.GetValues(typeof(DayOfWeek))) { header.Append(weekday).Append(calcParameters.CSVCharacter); } foreach (var set in taggingSets) { header.Append(set.Name).Append(calcParameters.CSVCharacter); } sw.WriteLine(header); var alllines = new List <List <string> >(); foreach (var device in person.Value) { var elements = new List <string> { device.Key }; var total = 0; for (var i = 0; i < 24; i++) { total += device.Value[i]; } elements.Add(total.ToString(Config.CultureInfo)); foreach (var weekday in Enum.GetValues(typeof(DayOfWeek))) { elements.Add(activitiesPerWeekday[person.Key][device.Key][(int)weekday].ToString(Config.CultureInfo)); } foreach (var set in taggingSets) { elements.Add(set.AffordanceToTagDict[device.Key]); } alllines.Add(elements); } alllines.Sort(Comparison); foreach (var allline in alllines) { var builder = new StringBuilder(); foreach (var s1 in allline) { builder.Append(s1).Append(calcParameters.CSVCharacter); } sw.WriteLine(builder); } } } }
protected override void PerformActualStep([JetBrains.Annotations.NotNull] IStepParameters parameters) { HouseholdStepParameters hhp = (HouseholdStepParameters)parameters; if (hhp.Key.KeyType != HouseholdKeyType.Household) { return; } if (!Repository.CalcParameters.TransportationEnabled) { return; } var hhkey = hhp.Key.HHKey; ReadActivities(hhkey, out var statebyDevice, out var siteByDevice, out var socByDevice, out var drivingDistanceByDevice); foreach (var soc in socByDevice) { //state of charge JsonSumProfile jsp = new JsonSumProfile("State of Charge for " + soc.Key + " " + hhkey.Key, Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime, "State of charge - " + soc.Key, "", null, hhp.Key); foreach (var entry in soc.Value) { if (entry.Time.DisplayThisStep) { jsp.Values.Add(entry.Val); } } var sumfile = _fft.MakeFile <StreamWriter>("Soc." + soc.Key + "." + hhkey.Key + ".json", "SOC Values for " + soc.Key + " in the household " + hhkey.Key, true, ResultFileID.JsonTransportSoc, hhkey, TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.TansportationDeviceJsons, null, null, soc.Key); sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented)); sumfile.Flush(); } foreach (var soc in drivingDistanceByDevice) { //driving distance JsonSumProfile jsp = new JsonSumProfile("Driving Distance for " + soc.Key + " " + hhkey.Key, Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime, "Driving Distance - " + soc.Key, "", null, hhp.Key); foreach (var entry in soc.Value) { if (entry.Time.DisplayThisStep) { jsp.Values.Add(entry.Val); } } var sumfile = _fft.MakeFile <StreamWriter>("DrivingDistance." + soc.Key + "." + hhkey.Key + ".json", "Driving Distance for " + soc.Key + " in the household " + hhkey.Key, true, ResultFileID.JsonTransportDrivingDistance, hhkey, TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.TansportationDeviceJsons, null, null, soc.Key); sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented)); sumfile.Flush(); } foreach (var soc in statebyDevice) { //driving distance JsonEnumProfile jsp = new JsonEnumProfile("Car State for " + soc.Key + " " + hhkey.Key, Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime, "Car State - " + soc.Key, "", null, hhp.Key); foreach (var entry in soc.Value) { if (entry.Time.DisplayThisStep) { jsp.Values.Add(entry.Category); } } var sumfile = _fft.MakeFile <StreamWriter>("Carstate." + soc.Key + "." + hhkey.Key + ".json", "Car State for " + soc.Key + " in the household " + hhkey.Key, true, ResultFileID.JsonTransportDeviceState, hhkey, TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.TansportationDeviceJsons, null, null, soc.Key); sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented)); sumfile.Flush(); } foreach (var soc in siteByDevice) { //driving distance JsonEnumProfile jsp = new JsonEnumProfile("Car Location for " + soc.Key + " " + hhkey.Key, Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime, "Car Location - " + soc.Key, "", null, hhp.Key); foreach (var entry in soc.Value) { if (entry.Time.DisplayThisStep) { jsp.Values.Add(entry.Category); } } var sumfile = _fft.MakeFile <StreamWriter>("CarLocation." + soc.Key + "." + hhkey.Key + ".json", "Car Location for " + soc.Key + " in the household " + hhkey.Key, true, ResultFileID.JsonTransportDeviceLocation, hhkey, TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.TansportationDeviceJsons, null, null, soc.Key); sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented)); sumfile.Flush(); } }
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)); } } } }
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 RunTimePerAffordance( [NotNull] Dictionary <string, Dictionary <string, Dictionary <string, int> > > affordanceTaggingSetByPersonByTagTimeUse, [NotNull] string householdName, [NotNull][ItemNotNull] List <CalcHouseholdPlanDto> householdPlans, [NotNull] IFileFactoryAndTracker fft, [NotNull] HouseholdKey householdKey, [NotNull] Dictionary <Tuple <HouseholdKey, int>, StreamWriter> fileNumberTracker) { var calcParameters = Repository.CalcParameters; var simduration = calcParameters.OfficialEndTime - calcParameters.OfficialStartTime; var timefactor = 8760 / simduration.TotalHours; foreach (var calcHouseholdPlan in householdPlans) { if (householdName.StartsWith(calcHouseholdPlan.HouseholdName, StringComparison.Ordinal)) { var cleanedName = AutomationUtili.CleanFileName(calcHouseholdPlan.Name).Replace(".", "_"); var fileName = "HouseholdPlan.Times." + cleanedName + "." + householdKey + ".csv"; var fileNumber = fileNumberTracker.Count; var sw = fft.MakeFile <StreamWriter>(fileName, "Comparison of the household plan and the reality", true, ResultFileID.HouseholdPlanTime, householdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.HouseholdPlan, null, null, calcHouseholdPlan.Name + "_" + fileNumber); sw.WriteLine("##### Time per Affordance #####"); fileNumberTracker.Add(new Tuple <HouseholdKey, int>(householdKey, calcHouseholdPlan.ID), sw); var timeByTagByPerson = affordanceTaggingSetByPersonByTagTimeUse[calcHouseholdPlan.TaggingSetName]; foreach (var personTagList in timeByTagByPerson) { var personName = personTagList.Key; sw.WriteLine("----- Time Use for " + personName + " -----"); var c = calcParameters.CSVCharacter; sw.WriteLine("Tag" + c + "Time in Simulation [h]" + c + "Time in Simulation for 365d [h]" + c + "Planned time"); var timePerTag = personTagList.Value; var plannedTimePerTag = calcHouseholdPlan.PersonTagTimeUsePlan[personName]; var plannedWithOthers = new Dictionary <string, TimeSpan>(); foreach (var keyValuePair in plannedTimePerTag) { plannedWithOthers.Add(keyValuePair.Key, keyValuePair.Value); } foreach (var keyValuePair in timePerTag) { if (!plannedWithOthers.ContainsKey(keyValuePair.Key)) { plannedWithOthers.Add(keyValuePair.Key, new TimeSpan(0)); } } foreach (var keyValuePair in plannedWithOthers) { var s = keyValuePair.Key + c; double realValueHours = 0; if (timePerTag.ContainsKey(keyValuePair.Key)) { var minutes = timePerTag[keyValuePair.Key]; realValueHours = minutes / 60.0; } s += realValueHours + c; s += realValueHours * timefactor + c; s += keyValuePair.Value.TotalHours + c; double percentage = -1; if (Math.Abs(keyValuePair.Value.TotalHours) > Constants.Ebsilon) { percentage = realValueHours / keyValuePair.Value.TotalHours; } s += percentage; if (Math.Abs(realValueHours) > Constants.Ebsilon || Math.Abs(keyValuePair.Value.TotalSeconds) > Constants.Ebsilon) { sw.WriteLine(s); } } } // found a plan } } }
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(); }