private void ApplySmartGridstuff([JetBrains.Annotations.NotNull] Dictionary <string, List <Prosumer> > dictionary, [JetBrains.Annotations.NotNull] string trafokreis, [JetBrains.Annotations.NotNull] ChangableProfile smartLoad, [JetBrains.Annotations.NotNull] ChangableProfile smartGeneration, [JetBrains.Annotations.NotNull] RowCollection smartGridPointValues, [JetBrains.Annotations.NotNull] SmartGridInformation summedSgi, [JetBrains.Annotations.NotNull] ScenarioSliceParameters smartSlice) { trafokreis = FilenameHelpers.CleanUmlaute(trafokreis); var loadFilename = MakeAndRegisterFullFilename(trafokreis + ".load.csv", smartSlice, false); var generationFilename = MakeAndRegisterFullFilename(trafokreis + ".generation.csv", smartSlice, false); using (StreamWriter loadsw = new StreamWriter(loadFilename)) { using (StreamWriter generationsw = new StreamWriter(generationFilename)) { foreach (var ha in dictionary) { var loadsum = ChangableProfile.FromProfile(Profile.MakeConstantProfile(0, "Sum", Profile.ProfileResolution.QuarterHour)); var gensum = ChangableProfile.FromProfile(Profile.MakeConstantProfile(0, "Sum", Profile.ProfileResolution.QuarterHour)); foreach (var prosumer in ha.Value) { if (prosumer.GenerationOrLoad == GenerationOrLoad.Load) { loadsum.Add(prosumer.Profile ?? throw new FlaException()); } else { gensum.Subtract(prosumer.Profile ?? throw new FlaException()); } } RowBuilder rb = RowBuilder.Start("Hausanschluss", ha.Key); smartGridPointValues.Add(rb); var loadProfile = loadsum.ToProfile(); rb.Add("Load Energy Sum [kWh]", loadProfile.EnergySum()); var genProfile = gensum.ToProfile(); rb.Add("Generation Energy Sum [kWh]", genProfile.EnergySum()); rb.Add("Number of Prosumers", ha.Value.Count); var sum = loadProfile.Add(genProfile, "sum"); double storagesizeLoad = //Math.Abs(sum.MakeDailyAverages().Values.Max()) * 24 * 4 * 1.5; loadProfile.EnergySum() / 1000 * 4; double storageSizeGen = Math.Abs(genProfile.EnergySum()) / 1000 * 4; double storagesize = Math.Max(storageSizeGen, storagesizeLoad); sum = ProfileSmoothing.FindBestPowerReductionRatio(sum, storagesize, out _, out var reductionFactor, 0.7); //if (reductionFactor > 0.99) { // storagesize = 0; //} summedSgi.NumberOfReductionFactors++; summedSgi.SummedReductionFactor += reductionFactor; summedSgi.TotalStorageSize += storagesize; summedSgi.NumberOfProsumers++; rb.Add("Trafokreis", trafokreis); rb.Add("Faktor", reductionFactor); rb.Add("Storage Size", storagesize); var positive = sum.GetOnlyPositive("positive"); smartLoad.Add(positive); var negative = sum.GetOnlyNegative("negative"); smartGeneration.Add(negative); rb.Add("Energy Sum Size", storagesize); string csvhakey = ha.Value.First().Isn + ";SM-Pros;MAXMEASUREDVALUE;" + ha.Key + ";"; if (positive.EnergySum() > 0) { loadsw.WriteLine(csvhakey + positive.GetCSVLine()); } if (negative.EnergySum() < 0) { var generation = negative.MultiplyWith(-1, "generation"); generationsw.WriteLine(csvhakey + generation.GetCSVLine()); } //positive.GetCSVLine() } loadsw.Close(); generationsw.Close(); } } if (smartSlice.DstYear == 2050) { FileInfo lfn = new FileInfo(loadFilename); if (lfn.Length > 0) { SaveToArchiveDirectory(loadFilename, RelativeDirectory.Load, smartSlice); } var gfn = new FileInfo(generationFilename); if (gfn.Length > 0) { SaveToArchiveDirectory(generationFilename, RelativeDirectory.Generation, smartSlice); } } }