public override string ToString() { var sb = new StringBuilder(); _dsc.GenerateDateStampForTimestep(Timestep, sb); foreach (var desirevalue in _storageValues) { sb.Append(desirevalue.ToString("0.0000", Config.CultureInfo)); sb.Append(_csvChar); } return(sb.ToString()); }
public void CheckForCriticalThreshold([NotNull] CalcPerson person, [NotNull] TimeStep time, [NotNull] FileFactoryAndTracker fft, [NotNull] HouseholdKey householdKey) { if (time.ExternalStep < 0 && !time.ShowSettling) { return; } var builder = new StringBuilder(); foreach (var calcDesire in Desires) { if (calcDesire.Value.CriticalThreshold > 0) { if (calcDesire.Value.Value < calcDesire.Value.CriticalThreshold) { builder.Append("1"); } else { builder.Append("0"); } builder.Append(_calcRepo.CalcParameters.CSVCharacter); } } if (builder.Length > 0) { var sb = new StringBuilder(); _dsc.GenerateDateStampForTimestep(time, sb); if (_sw == null) { var personNumber = _persons.Count; _persons.Add(new Tuple <string, HouseholdKey>(person.Name, householdKey), personNumber); _sw = fft.MakeFile <StreamWriter>( "CriticalThresholdViolations." + householdKey + "." + person + ".csv", "Lists the critical threshold violations for " + person, true, ResultFileID.CriticalThresholdViolations, householdKey, TargetDirectory.Debugging, _calcRepo.CalcParameters.InternalStepsize, CalcOption.CriticalViolations, null, person.MakePersonInformation()); var header = _dsc.GenerateDateStampHeader(); foreach (var calcDesire in Desires) { if (calcDesire.Value.CriticalThreshold > 0) { #pragma warning disable CC0039 // Don't concatenate strings in loops header += calcDesire.Value.Name; header += _calcRepo.CalcParameters.CSVCharacter; #pragma warning restore CC0039 // Don't concatenate strings in loops } } if (_sw == null) { throw new LPGException("SW was null"); } _sw.WriteLine(header); } sb.Append(builder); _sw.WriteLine(sb); } }
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)); } } }