public void RunPVProviderTestForAllEntries() { ServiceRepository services = new ServiceRepository(null, null, Logger, Config, new Random(1)); var slice = new ScenarioSliceParameters(Scenario.FromEnum(ScenarioEnum.Utopia), 2050, null); var dbHouse = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var pventries = dbHouse.Fetch <PvSystemEntry>(); var has = dbHouse.Fetch <Hausanschluss>(); var dbdto = new DBDto(null, has, null, null, null); PVProfileProvider pvp = new PVProfileProvider(services, slice, dbdto); foreach (var entry in pventries) { HouseComponentRo hcro = new HouseComponentRo("myname", "PV", 1, 1, "status", "isns", "standort", 0); ProviderParameterDto pp = new ProviderParameterDto(entry, null, hcro); pvp.PrepareLoadProfileIfNeeded(pp); var prosumer = pvp.ProvideProfile(pp); if (prosumer?.Profile == null) { throw new FlaException("No profile"); } if (Math.Abs(prosumer.Profile.EnergySum() - entry.EffectiveEnergyDemand) > 0.1) { throw new FlaException("Invalid profile: missing energy: should be " + entry.EffectiveEnergyDemand + " but was " + prosumer.Profile.EnergySum()); } Info("Profile generated correctly."); } }
public DhwProvider([NotNull] ServiceRepository services, [NotNull] ScenarioSliceParameters slice, [NotNull] DBDto dbDto) : base( nameof(DhwProvider), services, slice) { _dbDto = dbDto; _dhw = new DhwProfileGenerator(); }
public HeatingProvider([NotNull] ServiceRepository services, [NotNull] ScenarioSliceParameters slice, [NotNull] DBDto dbDto) : base( nameof(HeatingProvider), services, slice) { _dbDto = dbDto; var dbRaw = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var temperatures = dbRaw.Fetch <TemperatureProfileImport>(); var temp = temperatures.Single(x => x.Jahr == slice.DstYear); Profile temperaturProfileHourly = new Profile(temp.Profile ?? throw new FlaException("Missing profile")); _hpg = new HeatpumpProfileGenerator(temperaturProfileHourly, 15, 20, MyLogger); }
public PVProfileProvider([NotNull] ServiceRepository services, [NotNull] ScenarioSliceParameters slice, [NotNull] DBDto dbDto) : base(nameof(PVProfileProvider), services, slice) { _dbDto = dbDto; DevelopmentStatus.Add("use the correct weather year profile for the generation"); DevelopmentStatus.Add("instead of commenting out, check if all angles & right weather file based on key. If not right, clear table and regenerate"); Directory.SetCurrentDirectory(Services.RunningConfig.Directories.SamDirectory); Info("SSC Version number = " + API.Version()); Info("SSC bBuild Information = " + API.BuildInfo()); var dbPV = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.ProfileGeneration, Slice, DatabaseCode.PvProfiles); _saveableEntries = SaveableEntry <Profile> .GetSaveableEntry(dbPV, SaveableEntryTableType.PVGeneration, MyLogger); _saveableEntries.MakeTableForListOfFieldsIfNotExists(true); }
public void RunPVProviderTest() { // ReSharper disable AssignNullToNotNullAttribute var dbdto = new DBDto(null, null, null, null, null); // ReSharper restore AssignNullToNotNullAttribute // ReSharper disable twice AssignNullToNotNullAttribute ServiceRepository services = new ServiceRepository(null, null, Logger, Config, new Random(1)); PVProfileProvider pvp = new PVProfileProvider(services, Constants.PresentSlice, dbdto); PvSystemEntry pve = new PvSystemEntry("houseguid", "pvguid", "haguid", "myname", "pv123", 2017); pve.PVAreas = new List <PVSystemArea> { new PVSystemArea(30, 30, 1000) }; HouseComponentRo hcro = new HouseComponentRo("myname", "PV", 1, 1, "status", "isns", "standort", 0); ProviderParameterDto pp = new ProviderParameterDto(pve, null, hcro); pvp.PrepareLoadProfileIfNeeded(pp); }
public CoolingProvider([NotNull] ServiceRepository services, [NotNull] ScenarioSliceParameters slice, [NotNull] DBDto dbDto) : base(nameof(CoolingProvider), services, slice) { _dbDto = dbDto; // TODO: init properly, read profiles var dbRaw = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var temperatures = dbRaw.Fetch <TemperatureProfileImport>(); var temp = temperatures.Single(x => x.Jahr == slice.DstYear); Profile temperaturProfileHourly = new Profile(temp.Profile ?? throw new FlaException("missing profile")); _coolingProfileGeneratorsByType.Add(AirConditioningType.Residential, new CoolingProfileGenerator(temperaturProfileHourly, 23, 21, MyLogger)); _coolingProfileGeneratorsByType.Add(AirConditioningType.Commercial, new CoolingProfileGenerator(temperaturProfileHourly, 18, 17, MyLogger)); _coolingProfileGeneratorsByType.Add(AirConditioningType.Industrial, new CoolingProfileGenerator(temperaturProfileHourly, 12, 10, MyLogger)); }
public void Run() { PrepareUnitTest(); // ReSharper disable AssignNullToNotNullAttribute ServiceRepository sp = new ServiceRepository(null, null, Logger, Config, new Random()); // ReSharper restore AssignNullToNotNullAttribute var slice = Constants.PresentSlice; var dbHouse = sp.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var airconditioningEntries = dbHouse.Fetch <AirConditioningEntry>(); var hausanschlusses = dbHouse.Fetch <Hausanschluss>(); DBDto dbDto = new DBDto(new List <House>(), hausanschlusses, new List <Car>(), new List <Household>(), new List <RlmProfile>()); CoolingProvider hp = new CoolingProvider(sp, slice, dbDto); Info("total hse: " + airconditioningEntries.Count); Profile sumProfile = Profile.MakeConstantProfile(0, "Sum", Profile.ProfileResolution.QuarterHour); foreach (var entry in airconditioningEntries) { (entry.HouseComponentType == HouseComponentType.Cooling).Should().BeTrue(); hp.IsCorrectProvider(entry).Should().BeTrue(); HouseComponentRo hro = new HouseComponentRo(string.Empty, string.Empty, 1, 1, string.Empty, string.Empty, string.Empty, 0); ProviderParameterDto ppd = new ProviderParameterDto(entry, string.Empty, hro); hp.PrepareLoadProfileIfNeeded(ppd); var prof = hp.ProvideProfile(ppd); if (prof != null) { if (prof.Profile == null) { throw new FlaException("Profile was null"); } prof.Profile.EnergySum().Should().BeApproximately(entry.EffectiveEnergyDemand, entry.EffectiveEnergyDemand * 0.1); sumProfile = sumProfile.Add(prof.Profile.Values); } } string fn = WorkingDirectory.Combine("Profiletest_cooling.xlsx"); XlsxDumper.DumpProfilesToExcel(fn, 2050, 15, new ProfileWorksheetContent("Sum", "Last", 240, sumProfile)); Info("Wrote to " + fn); }
public void Run() { PrepareUnitTest(); // ReSharper disable AssignNullToNotNullAttribute ServiceRepository sp = new ServiceRepository(null, null, Logger, Config, new Random()); // ReSharper restore AssignNullToNotNullAttribute var utopiaSlice = new ScenarioSliceParameters(Scenario.FromEnum(ScenarioEnum.Utopia), 2050, null); var dbHouse = sp.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, utopiaSlice); var heatingSystemEntries = dbHouse.Fetch <HeatingSystemEntry>(); var hausanschlusses = dbHouse.Fetch <Hausanschluss>(); DBDto dbDto = new DBDto(new List <House>(), hausanschlusses, new List <Car>(), new List <Household>(), new List <RlmProfile>()); HeatingProvider hp = new HeatingProvider(sp, utopiaSlice, dbDto); Info("total hse: " + heatingSystemEntries.Count); Profile sumProfile = Profile.MakeConstantProfile(0, "Sum", Profile.ProfileResolution.QuarterHour); foreach (var entry in heatingSystemEntries) { (entry.HouseComponentType == HouseComponentType.Heating).Should().BeTrue(); hp.IsCorrectProvider(entry).Should().BeTrue(); HouseComponentRo hro = new HouseComponentRo("", "", 1, 1, "", "", "", 0); ProviderParameterDto ppd = new ProviderParameterDto(entry, "", hro); hp.PrepareLoadProfileIfNeeded(ppd); var prof = hp.ProvideProfile(ppd); if (prof != null) { if (prof.Profile == null) { throw new FlaException("Profile was null"); } prof.Profile.EnergySum().Should().BeApproximately(entry.EffectiveEnergyDemand / 3, entry.EffectiveEnergyDemand * 0.1); sumProfile = sumProfile.Add(prof.Profile.Values); } } var fn = Path.Combine(WorkingDirectory.Dir, "Profiletest.xlsx"); XlsxDumper.DumpProfilesToExcel(fn, 2050, 15, new ProfileWorksheetContent("Sum", "Last", 240, sumProfile)); }
public void TestProfileCreation() { SqlConnectionPreparer ms = new SqlConnectionPreparer(Config); var dbHouses = ms.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice); var pvEntries = dbHouses.Fetch <PvSystemEntry>(); if (pvEntries.Count == 0) { throw new FlaException("No PVEntries"); } var houseGuids = pvEntries.Select(x => x.HouseGuid).Distinct().Take(10).ToList(); // ReSharper disable AssignNullToNotNullAttribute ServiceRepository sp = new ServiceRepository(null, null, Logger, Config, new Random()); // ReSharper restore AssignNullToNotNullAttribute // ReSharper disable AssignNullToNotNullAttribute var dbdto = new DBDto(null, dbHouses.Fetch <Hausanschluss>(), null, null, null); // ReSharper restore AssignNullToNotNullAttribute PVProfileProvider pvp = new PVProfileProvider(sp, Constants.PresentSlice, dbdto); var hcrc = new HouseComponentRo("name", "type", 1, 1, "status", "", "standort", 0); foreach (string houseGuid in houseGuids) { var pse = pvEntries.Single(x => x.HouseGuid == houseGuid); ProviderParameterDto parameters = new ProviderParameterDto(pse, "dummydir", hcrc); pvp.PrepareLoadProfileIfNeeded(parameters); } foreach (string houseGuid in houseGuids) { var pse = pvEntries.Single(x => x.HouseGuid == houseGuid); ProviderParameterDto parameters = new ProviderParameterDto(pse, "dummydir", hcrc); var result = pvp.ProvideProfile(parameters); Info("Got a profile with " + result?.Profile?.EnergySum()); } }
private ProviderCollection MakeDiContrainer([NotNull] ScenarioSliceParameters parameters, [NotNull][ItemNotNull] List <string> developmentStatus, [NotNull][ItemNotNull] List <Hausanschluss> hausanschlusses, [NotNull][ItemNotNull] List <House> houses, [NotNull][ItemNotNull] List <HouseCreationAndCalculationJob> districts, [NotNull] SLPProvider slpProvider, [NotNull] DBDto dbdto) { ContainerBuilder builder = new ContainerBuilder(); var mainAssembly = Assembly.GetAssembly(typeof(MainBurgdorfStatisticsCreator)); builder.RegisterAssemblyTypes(mainAssembly).Where(t => t.GetInterfaces().Contains(typeof(ILoadProfileProvider))).AsSelf() .As <ILoadProfileProvider>(); builder.RegisterType <ProviderCollection>().SingleInstance(); builder.RegisterType <CachingLPGProfileLoader>().SingleInstance(); builder.Register(x => _services.Logger).As <ILogger>(); builder.Register(x => _services).As <ServiceRepository>(); builder.Register(x => hausanschlusses).SingleInstance(); builder.Register(x => houses).SingleInstance(); builder.Register(x => districts).SingleInstance(); builder.Register(x => parameters).SingleInstance(); builder.Register(x => slpProvider).SingleInstance(); builder.Register(x => dbdto).SingleInstance(); var container = builder.Build(); ProviderCollection loadProfileProviders = container.Resolve <ProviderCollection>(); foreach (var provider in loadProfileProviders.Providers) { foreach (var dev in provider.DevelopmentStatus) { developmentStatus.Add(provider.Name + ": " + dev); } } return(loadProfileProviders); }
public void ProcessAllHouses([NotNull] ScenarioSliceParameters parameters, [NotNull] Func <string, ScenarioSliceParameters, bool, string> makeAndRegisterFullFilename, ProcessingMode processingMode, [NotNull][ItemNotNull] List <string> developmentStatus) { if (!Directory.Exists(_processingResultPathForProfiles)) { Directory.CreateDirectory(_processingResultPathForProfiles); Thread.Sleep(500); } else { var dstDi = new DirectoryInfo(_processingResultPathForProfiles); var files = dstDi.GetFiles(); Info("Cleaning " + files.Length + " files from result directory " + _processingResultPathForProfiles); foreach (var file in files) { file.Delete(); } } var dbHouses = _services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, parameters); Info("using house db in " + dbHouses.ConnectionString); var houses = dbHouses.Fetch <House>(); HouseComponentRepository hcr = new HouseComponentRepository(dbHouses); var households = dbHouses.Fetch <Household>(); var hausanschlusses = dbHouses.Fetch <Hausanschluss>(); var cars = dbHouses.Fetch <Car>(); var dbRaw = _services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var measuredRlmProfiles = dbRaw.Fetch <RlmProfile>(); DBDto dbdto = new DBDto(houses, hausanschlusses, cars, households, measuredRlmProfiles); ProsumerComponentResultArchiver pra = new ProsumerComponentResultArchiver(Stage.ProfileGeneration, parameters, processingMode, _services); var trafokreiseToProcess = PrepareListOfTrafokreiseToProcess(hausanschlusses); List <HouseCreationAndCalculationJob> districts = new List <HouseCreationAndCalculationJob>(); var vdewValues = dbRaw.Fetch <VDEWProfileValue>(); var feiertage = dbRaw.Fetch <FeiertagImport>(); var slpProvider = new SLPProvider(parameters.DstYear, vdewValues, feiertage); var loadProfileProviders = MakeDiContrainer(parameters, developmentStatus, hausanschlusses, houses, districts, slpProvider, dbdto); if (processingMode == ProcessingMode.Collecting) { ClearAllExistingExportProfiles(); } var lpgDirectoryInfo = GetLPGCalcDirectoryInfo(parameters); ProfileGenerationRo pgRo = new ProfileGenerationRo(); DateTime startTime = DateTime.Now; DateTime lastLog = DateTime.Now; Info("Processing " + houses.Count + " houses."); Info("Processing mode is " + processingMode); List <string> brokenLpgDirectories = new List <string>(); List <string> brokenLpgJsons = new List <string>(); Dictionary <string, List <HouseComponentEntry> > houseComponentsByObjectID = BuildDictionaryByObjektID(houses, hcr, hausanschlusses, pgRo, out var numberOfcomponents); int processedComponents = 0; Stopwatch swCollecting = new Stopwatch(); Stopwatch swWriting = new Stopwatch(); Dictionary <string, int> numberOfEmptyProsumers = new Dictionary <string, int>(); HashSet <string> validHouseGuids = houses.Select(x => x.Guid).ToHashSet(); foreach (KeyValuePair <string, List <HouseComponentEntry> > pair in houseComponentsByObjectID) { var houseProsumers = new List <Prosumer>(); //erst alle profile einsammeln / vorbereiten swCollecting.Start(); foreach (var component in pair.Value) { processedComponents++; if (processedComponents % 1000 == 0) { Info(processingMode + " processed Components " + processedComponents + " / " + numberOfcomponents); } ProviderParameterDto ppdto = new ProviderParameterDto(component.Component, lpgDirectoryInfo.FullName, pgRo[component.Component]); var provider = loadProfileProviders.GetCorrectProvider(component.Component); pgRo[component.Component].UsedProvider = provider.Name; if (processingMode == ProcessingMode.Preparing) { provider.PrepareLoadProfileIfNeeded(ppdto); } if (processingMode == ProcessingMode.Collecting) { if (trafokreiseToProcess.Contains(component.Hausanschluss.Trafokreis)) { Prosumer p = provider.ProvideProfile(ppdto); //Todo: add up profile per trafokreis, profile per provider etc right here if (p != null) { // some providers that are not ready will return null if (p.Profile?.EnergyOrPower != EnergyOrPower.Energy) { throw new FlaException("Got a power profile from " + provider.Name); } CheckProfileIntegrity(p, provider, component.Component, validHouseGuids); // ReSharper disable once AssignNullToNotNullAttribute pgRo[component.Component].AddProsumerInformation(p); houseProsumers.Add(p); pra.Archive(p); } else { if (!numberOfEmptyProsumers.ContainsKey(provider.Name)) { numberOfEmptyProsumers.Add(provider.Name, 0); } numberOfEmptyProsumers[provider.Name]++; } } } } swCollecting.Stop(); //dann alles rausschreiben swWriting.Start(); if (processingMode == ProcessingMode.Collecting) { var generationProsumers = houseProsumers.Where(x => x.GenerationOrLoad == GenerationOrLoad.Generation).ToList(); var loadProsumers = houseProsumers.Where(x => x.GenerationOrLoad == GenerationOrLoad.Load).ToList(); var component = pair.Value[0]; if (loadProsumers.Count > 0) { Prosumer summedProsumer = GetSummedProsumer(loadProsumers, component.Hausanschluss.Trafokreis); var haros = pgRo.HausanschlussByObjectId(pair.Key); double maxPower = summedProsumer.Profile?.MaxPower() ?? 0; foreach (var haro in haros) { haro.MaximumPower = maxPower; } WriteSumLineToCsv(summedProsumer, component.Hausanschluss.Trafokreis, GenerationOrLoad.Load); } if (generationProsumers.Count > 0) { var sumProfile = GetSummedProsumer(generationProsumers, component.Hausanschluss.Trafokreis); WriteSumLineToCsv(sumProfile, component.Hausanschluss.Trafokreis, GenerationOrLoad.Generation); // ReSharper disable once PossibleNullReferenceException } } swWriting.Stop(); ReportProgress(startTime, processedComponents, numberOfcomponents, parameters, ref lastLog, swCollecting, swWriting); } Info("Finished processing all components, finishing up now. Duration: " + (DateTime.Now - startTime).TotalMinutes.ToString("F2") + " minutes"); Info("collecting took " + swCollecting.Elapsed + " and writing took " + swWriting.Elapsed); foreach (var pair in numberOfEmptyProsumers) { Info("NumberOfEmptyProsumers for " + pair.Key + " was " + pair.Value); } if (processingMode == ProcessingMode.Preparing) { DateTime endtime = new DateTime(parameters.DstYear, 12, 31); string houseJobDirectory = Path.Combine(_services.RunningConfig.Directories.HouseJobsDirectory, parameters.DstScenario.ToString(), parameters.DstYear.ToString()); DirectoryInfo houseJobDi = new DirectoryInfo(houseJobDirectory); WriteDistrictsForLPG(districts, houseJobDi, _services.Logger, parameters, endtime, pgRo); } else { DateTime startSavingToDB = DateTime.Now; pra.FinishSavingEverything(); Info("Finished writing prosumers to db. Duration: " + (DateTime.Now - startSavingToDB).TotalMinutes.ToString("F2") + " minutes"); } pra.Dispose(); var excelFiles = WriteExcelResultFiles(parameters, makeAndRegisterFullFilename, processingMode, pgRo); if (_services.RunningConfig.CollectFilesForArchive) { SaveToArchiveDirectory(parameters, excelFiles, _services.StartingTime, _services.RunningConfig); } WriteBrokenLpgCalcCleanupBatch(parameters, makeAndRegisterFullFilename, processingMode, brokenLpgDirectories, brokenLpgJsons); if (processingMode == ProcessingMode.Collecting) { foreach (var provider in loadProfileProviders.Providers) { provider.DoFinishCheck(); } } }