protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto) { Module.SetPrint(0); //var relevantPotentials = _pvPotentials.Where(x => x.HouseGuid == houseComponent.HouseGuid); PvSystemEntry entry = (PvSystemEntry)ppdto.HouseComponent; if (_dbDto.Hausanschlusse == null) { throw new FlaException("hausanschlüsse were not initalized"); } if (_dbDto.Hausanschlusse.Count == 0) { throw new FlaException("not a single hausanschluss"); } Hausanschluss hausanschluss = _dbDto.Hausanschlusse.FirstOrDefault(x => x.Guid == entry.HausAnschlussGuid); if (hausanschluss == null) { throw new FlaException("No hausanschluss found for guid: " + entry.HausAnschlussGuid); } if (hausanschluss.ObjectID.ToLower().Contains("leuchte")) { throw new FlaException("PV anlage an einer leuchte! " + hausanschluss.ObjectID + " - " + entry.Name); } //TODO: change this to use pv system areas from the pvsystem entry Profile sumProf = Profile.MakeConstantProfile(0, ppdto.HouseComponent.Name, Profile.ProfileResolution.QuarterHour); if (Math.Abs(entry.PVAreas.Sum(x => x.Energy) - entry.EffectiveEnergyDemand) > 0.1) { throw new FlaException("Sum of the pv areas did not match pv entry sum"); } foreach (var area in entry.PVAreas) { var key = MakeKeyFromPVArea(area); var keystr = key.GetKey(); var areaProfiles = _saveableEntries.LoadAllOrMatching("Name", keystr); if (areaProfiles.Count != 1) { throw new FlaException("Invalid count"); } var areaProfile = areaProfiles[0]; areaProfile.EnergyOrPower = EnergyOrPower.Energy; areaProfile = areaProfile.ScaleToTargetSum(area.Energy, entry.Name, out var _); sumProf = sumProf.Add(areaProfile, entry.Name); } if (Math.Abs(Slice.PVCurtailToXPercent) < 0.00001) { throw new FlaException("Found curtailment to 0"); } if (sumProf.EnergySum() < 0) { throw new FlaException("Negative PV Power"); } if (Slice.PVCurtailToXPercent < 1) { sumProf = sumProf.LimitPositiveToPercentageOfMax(Slice.PVCurtailToXPercent); } var prosumer = new Prosumer(entry.HouseGuid, entry.Name, HouseComponentType.Photovoltaik, entry.SourceGuid, entry.FinalIsn, entry.HausAnschlussGuid, hausanschluss.ObjectID, GenerationOrLoad.Generation, hausanschluss.Trafokreis, Name, "PV Profile") { Profile = sumProf }; if (Math.Abs(Slice.PVCurtailToXPercent - 1) < 0.01 && Math.Abs(sumProf.EnergySum() - entry.EffectiveEnergyDemand) > 0.1) { throw new FlaException("PV Energy result is wrong"); } return(prosumer); }