Esempio n. 1
0
        public void RunMultiyearTestSingleColumn()
        {
            PrepareUnitTest();
            string fn = WorkingDirectory.Combine("trend3.xlsx");

            Config.LimitToScenarios.Clear();
            Config.InitializeSlices(Logger);
            MultiyearTrend trend = new MultiyearTrend();
            Random         rnd   = new Random();

            if (Config.Slices == null)
            {
                throw new FlaException("No slices");
            }
            trend[Constants.PresentSlice].AddValue("MyValue", 50, DisplayUnit.Stk);
            foreach (var slice in Config.Slices)
            {
                if (slice.DstScenario != Scenario.FromEnum(ScenarioEnum.Nep))
                {
                    continue;
                }

                trend[slice].AddValue("MyValue", rnd.Next(100), DisplayUnit.Stk);
            }

            XlsxDumper.DumpMultiyearTrendToExcel(fn, trend);
            Info("Wrote to " + fn);
            Process.Start(fn);
        }
Esempio n. 2
0
        public void RunMultiyearTest()
        {
            PrepareUnitTest();
            string fn = WorkingDirectory.Combine("trend.xlsx");

            Config.LimitToScenarios.Clear();
            Config.InitializeSlices(Logger);
            MultiyearMultiVariableTrend trend = new MultiyearMultiVariableTrend();
            Random rnd = new Random();

            if (Config.Slices == null)
            {
                throw new FlaException("No slices");
            }
            trend[Constants.PresentSlice].AddValue("MyValue", "mycategory", 50, DisplayUnit.Stk);
            trend[Constants.PresentSlice].AddValue("MyValue", "mycategory2", 50, DisplayUnit.Stk);
            foreach (var slice in Config.Slices)
            {
                Info("Slice " + slice);
                trend[slice].AddValue("MyValue", "mycategory", rnd.Next(100), DisplayUnit.Stk);
                trend[slice].AddValue("MyValue", "mycategory2", rnd.Next(100), DisplayUnit.Stk);
            }

            XlsxDumper.DumpMultiyearMultiVariableTrendToExcel(fn, trend);
            Info("Wrote to " + fn);
            Process.Start(fn);
        }
        public void RunSingleAcTest()
        {
            PrepareUnitTest();
            // ReSharper disable AssignNullToNotNullAttribute
            ServiceRepository services = new ServiceRepository(null, null, Logger, Config, new Random());
            // ReSharper restore AssignNullToNotNullAttribute
            var dbRaw        = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var temperatures = dbRaw.Fetch <TemperatureProfileImport>();

            Profile temperaturProfileHourly = new Profile(temperatures[0].Profile ?? throw new FlaException("was null"));
            //make heatpumpprofile
            var          chp       = new CoolingProfileGenerator(temperaturProfileHourly, 27, 24, Logger);
            Random       rnd       = new Random();
            var          hpcp      = CoolingCalculationParameters.MakeDefaults();
            const double energyuse = 20000;
            var          hpr       = chp.Run(hpcp, energyuse, rnd);

            hpr.GetEnergyDemandProfile().Values.Sum().Should().BeApproximately(energyuse * 0.333, 100);
            Profile houseEnergy             = new Profile("House Energy", hpr.HouseEnergyTracker.AsReadOnly(), EnergyOrPower.Energy);
            Profile heatPumpEnergysupply    = new Profile("Heat pump Energy supply", hpr.CoolingEnergySupply.AsReadOnly(), EnergyOrPower.Energy);
            Profile temperatureProfile15Min = new Profile("Temperatures", hpr.AvgTemperatures15Min.ToList().AsReadOnly(), EnergyOrPower.Energy);

            string         file     = WorkingDirectory.Combine("coolingrofile_Single.xlsx");
            List <Profile> profiles = new List <Profile>();

            profiles.Add(temperatureProfile15Min);
            profiles.Add(houseEnergy);
            profiles.Add(heatPumpEnergysupply);
            XlsxDumper.DumpProfilesToExcel(file, 2050, 15, new ProfileWorksheetContent("Sheet1", "Last", profiles));
        }
        public void RunTest()
        {
            PrepareUnitTest();
            RowCollection rc = new RowCollection("mysheet", "MySheet");
            var           rb = RowBuilder.Start("t1", "mytxt").Add("blub", 1).Add("blub2", 1);

            rc.Add(rb);
            var rb2 = RowBuilder.Start("t1", "mytxt").Add("blub", 1).Add("blub5", 1);

            rc.Add(rb2);
            XlsxDumper.WriteToXlsx(WorkingDirectory.Combine("t.xlsx"), rc);
        }
Esempio n. 5
0
        public void LoadFileEntriesTest()
        {
            PrepareUnitTest();
            FileEntryLoader fel = new FileEntryLoader();
            string          dir = WorkingDirectory.Combine(@"HouseholdLoadProfileProviderTests.InitializeTestCase\results\HouseJob.trafokreis\housename\Results.General.sqlite");

            fel.LoadFiles(dir);
            Assert.True(fel.Files.Count > 0);
            foreach (KeyValuePair <HouseholdKey, FileEntry> pair in fel.Files)
            {
                Logger.Info(pair.Value.FullFilename, Stage.Testing, nameof(FileEntryLoaderTest));
            }
        }
Esempio n. 6
0
        public async ValueTask DisposeAsync()
        {
            var exts = new[] { ".md", ".exe" };
            await WorkingDirectory.Combine(ID).DeleteDirectory();

            Profiles.Do(p =>
            {
                foreach (var ext in exts)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), p + ext);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            });
        }
        public void RunSave()
        {
            RunningConfig settings = RunningConfig.MakeDefaults();

            settings.MyOptions.Clear();
            settings.MyOptions.Add(Options.ReadFromExcel);
            settings.StagesToExecute.Clear();
            settings.StagesToExecute.Add(Stage.ScenarioCreation);
            settings.InitializeSlices(Logger);
            WorkingDirectory wd   = new WorkingDirectory(Logger, settings);
            string           path = wd.Combine("calcsettings.json");

            settings.SaveThis(path);
            RunningConfig loadedSettings = RunningConfig.Load(path);

            Assert.Equal(settings.MyOptions.Count, loadedSettings.MyOptions.Count);
            Assert.Equal(settings.StagesToExecute.Count, loadedSettings.StagesToExecute.Count);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        public void Run()
        {
            PrepareUnitTest();
            ProfileGenerationRo ro = new ProfileGenerationRo();
            var resultFile         = WorkingDirectory.Combine("TestFile.Tree.xlsx");

            Logger.Info("Dumping to " + resultFile, Stage.Testing, nameof(ResultObjectTester));
            ro.DumpToExcel(resultFile, XlsResultOutputMode.Tree);

            var resultFile2 = WorkingDirectory.Combine("TestFile.FullLine.xlsx");

            Logger.Info("Dumping to " + resultFile2, Stage.Testing, nameof(ResultObjectTester));
            ro.DumpToExcel(resultFile2, XlsResultOutputMode.FullLine);

            var resultFile3 = WorkingDirectory.Combine("TestFile.Trafo.xlsx");

            Logger.Info("Dumping to " + resultFile3, Stage.Testing, nameof(ResultObjectTester));
            ro.DumpToExcel(resultFile3, XlsResultOutputMode.ByTrafoStationTree);
        }
        public void RunMultiHpTest()
        {
            PrepareUnitTest();
            // ReSharper disable twice AssignNullToNotNullAttribute
            ServiceRepository services = new ServiceRepository(null, null, Logger, Config, new Random());
            var dbRaw   = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var dbHouse = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses,
                                                                               new ScenarioSliceParameters(Scenario.FromEnum(ScenarioEnum.Utopia), 2050, null));
            var     temperatures            = dbRaw.Fetch <TemperatureProfileImport>();
            var     heatPumpEntries         = dbHouse.Fetch <HeatingSystemEntry>();
            Profile temperaturProfileHourly = new Profile(temperatures[0].Profile ?? throw new FlaException("was null"));
            Random  rnd = new Random();
            //make heatpumpprofile
            Profile        houseEnergy             = Profile.MakeConstantProfile(0, "House Energy", Profile.ProfileResolution.QuarterHour);
            Profile        heatPumpEnergysupply    = Profile.MakeConstantProfile(0, "Heat pump Energy supply", Profile.ProfileResolution.QuarterHour);
            Profile        heatPumpEnergyDemand    = Profile.MakeConstantProfile(0, "Heat pump Energy Demand", Profile.ProfileResolution.QuarterHour);
            Profile        temperatureProfile15Min = null;
            List <Profile> allHouseDemandProfiles  = new List <Profile>();

            foreach (var entry in heatPumpEntries)
            {
                HeatpumpProfileGenerator chp = new HeatpumpProfileGenerator(temperaturProfileHourly, 15, 20, Logger);
                var hpcp = HeatpumpCalculationParameters.MakeDefaults();
                hpcp.StartingTimeStepEvenings           = (21 * 4) + rnd.Next(12);
                hpcp.StoppingTimeStepMorning            = (4 * 4) + rnd.Next(12);
                hpcp.HouseMinimumEnergyTriggerinPercent = 0.70 - rnd.NextDouble() * 0.2;
                hpcp.TargetMaximumRuntimePerDay         = 16 + rnd.NextDouble() * 4;
                hpcp.TimingMode        = HeatPumpTimingMode.OverTheEntireDay;
                hpcp.StartLevelPercent = 1 - rnd.NextDouble() * .5;
                HeatPumpResult hpr    = chp.Run(hpcp, entry.EffectiveEnergyDemand, rnd);
                var            result = hpr.GetEnergyDemandProfile();
                result.Name += entry.Standort;
                allHouseDemandProfiles.Add(result);
                result.Values.Sum().Should().BeApproximately(entry.EffectiveEnergyDemand * .333, entry.EffectiveEnergyDemand * 0.1);
                heatPumpEnergyDemand = heatPumpEnergyDemand.Add(result, heatPumpEnergyDemand.Name);
                houseEnergy          = houseEnergy.Add(hpr.HouseEnergyTracker.AsReadOnly());
                heatPumpEnergysupply = heatPumpEnergysupply.Add(hpr.HeatpumpEnergySupply.AsReadOnly());
                if (temperatureProfile15Min == null)
                {
                    temperatureProfile15Min = new Profile("Temperatures", hpr.DailyAvgTemperatures15Min.ToList().AsReadOnly(), EnergyOrPower.Energy);
                }
            }

            allHouseDemandProfiles.Sort((x, y) => y.EnergySum().CompareTo(x.EnergySum()));
            var profilesToShow  = allHouseDemandProfiles.Take(5).ToList();
            var profilesToMerge = allHouseDemandProfiles.Skip(6).ToList();
            var mergedProfiles  = allHouseDemandProfiles[5].Add(profilesToMerge, "MergedProfiles");

            if (temperatureProfile15Min == null)
            {
                throw new FlaException("no temperatures");
            }

            ProfileWorksheetContent biggestConsumers = new ProfileWorksheetContent("Biggest Consumers", "Last", profilesToShow);

            biggestConsumers.Profiles.Add(mergedProfiles);
            string fullFileName = WorkingDirectory.Combine("heatpump_profiles_multi-WithChart.xlsx");

            XlsxDumper.DumpProfilesToExcel(fullFileName,
                                           2017,
                                           15,
                                           new ProfileWorksheetContent("Energy Demand", "Last", 240, heatPumpEnergyDemand),
                                           new ProfileWorksheetContent("Energy Supply", "Energieversorgung", 240, heatPumpEnergysupply),
                                           new ProfileWorksheetContent("Temperatures", "Temperatur", 240, temperatureProfile15Min),
                                           new ProfileWorksheetContent("House Energy", "Haus Energiegehalt", 240, houseEnergy),
                                           biggestConsumers);
            //WriteProfilesToExcel(temperatureProfile15Min, houseEnergy, heatPumpEnergysupply,file);
        }
        public void RunTest()
        {
            CompositeResolver.RegisterAndSetAsDefault(NativeDateTimeResolver.Instance, StandardResolver.Instance);
            PrepareUnitTest();
            Config.Directories.ResultStorageDirectory = WorkingDirectory.Dir;
            Config.Directories.CalcServerLpgDirectory = WorkingDirectory.Dir;

            // ReSharper disable twice AssignNullToNotNullAttribute

            HouseCreationAndCalculationJob hcj = new HouseCreationAndCalculationJob(Scenario.Present().ToString(), "2017", "trafokreis");
            HouseData     hd  = new HouseData("houseguid", "HT01", 1000, 1000, "houseName");
            HouseholdData hhd = new HouseholdData("householdguid",
                                                  2000,
                                                  ElectricCarUse.UseElectricCar,
                                                  "householdname",
                                                  ElectricCarProvider.ChargingStationSet,
                                                  ElectricCarProvider.TransportationDevicesOneCar,
                                                  ElectricCarProvider.TravelRouteSet,
                                                  new List <TransportationDistanceModifier>(),
                                                  HouseholdDataSpecifictionType.ByPersons);

            hd.Households.Add(hhd);
            hhd.UseElectricCar          = ElectricCarUse.UseElectricCar;
            hhd.TransportationDeviceSet = ElectricCarProvider.TransportationDevicesOneCar;
            hhd.TravelRouteSet          = ElectricCarProvider.TravelRouteSet;
            hhd.ChargingStationSet      = ElectricCarProvider.ChargingStationSet;

            hhd.HouseholdDataPersonSpecification = new HouseholdDataPersonSpecification(new List <PersonData> {
                new PersonData(30, Gender.Male)
            });
            hcj.House = hd;

            List <HouseCreationAndCalculationJob> houseJobs = new List <HouseCreationAndCalculationJob>();

            houseJobs.Add(hcj);
            FileHelpers.CopyRec(Config.Directories.LPGReleaseDirectory, WorkingDirectory.Dir, Logger, true);
            var endTime = new DateTime(Constants.PresentSlice.DstYear, 1, 10);
            ProfileGenerationRo pgro = new ProfileGenerationRo();

            HouseProcessor.WriteDistrictsForLPG(houseJobs,
                                                WorkingDirectory.DirDi,
                                                Logger,
                                                Constants.PresentSlice,
                                                endTime,
                                                pgro);
            string districtsDir = WorkingDirectory.Combine("Districts");
            var    districtsDi  = new DirectoryInfo(districtsDir);
            var    files        = districtsDi.GetFiles("*.json");

            void RunOneFile(FileInfo myfi)
            {
                ProcessStartInfo psi = new ProcessStartInfo();

                psi.FileName         = WorkingDirectory.Combine("simulationengine.exe");
                psi.UseShellExecute  = true;
                psi.WorkingDirectory = WorkingDirectory.Dir;
                psi.Arguments        = "ProcessHouseJob  -j \"" + myfi.FullName + "\"";
                Info("running " + psi.FileName + " " + psi.Arguments);
                using (Process p = new Process()) {
                    p.StartInfo = psi;
                    p.Start();
                    p.WaitForExit();
                }
            }

            foreach (var housejob in files)
            {
                RunOneFile(housejob);
            }

            DBDto dbDto = new DBDto(new List <House>(), new List <Hausanschluss>(), new List <Car>(), new List <Household>(), new List <RlmProfile>());
            CachingLPGProfileLoader ca = new CachingLPGProfileLoader(Logger, dbDto);
            List <int> isns            = new List <int>();

            isns.Add(10);
            CarDistanceEntry cde = new CarDistanceEntry("houseguid",
                                                        "householdguid",
                                                        "carguid",
                                                        20,
                                                        20,
                                                        isns,
                                                        10,
                                                        "haguid",
                                                        "sourceguid",
                                                        "cdename",
                                                        CarType.Electric);
            HouseComponentRo      hcro = new HouseComponentRo("housecomponent", "componeenttype", 1000, 200, "processingstatus", "isns", "standort", 0);
            ProviderParameterDto  ppd  = new ProviderParameterDto(cde, WorkingDirectory.Dir, hcro);
            SqlConnectionPreparer scp  = new SqlConnectionPreparer(Config);
            MyDb db = scp.GetDatabaseConnection(Stage.Testing, Constants.PresentSlice);
            SaveableEntry <Profile> sa = SaveableEntry <Profile> .GetSaveableEntry(db, SaveableEntryTableType.LPGProfile, Logger);

            sa.MakeTableForListOfFieldsIfNotExists(true);
            string dstDir = Path.Combine(WorkingDirectory.Dir, hcj.Trafokreis, hcj.House.Name);

            FileHelpers.CopyRec(WorkingDirectory.Combine("Results"), dstDir, Logger, true);

            //normal electricity test and cache test
            Info("================== ");
            Info("electricity");
            Info("================== ");
            var profElec1 = ca.LoadLPGProfile(ppd,
                                              hcj.Trafokreis,
                                              "Electricity",
                                              sa,
                                              hhd.HouseholdGuid,
                                              out var profsource,
                                              hcj.House.Name,
                                              Config,
                                              true);

            Info("Source: " + profsource);
            Assert.NotNull(profElec1);
            Assert.NotNull(profsource);

            var profElecCache = ca.LoadLPGProfile(ppd,
                                                  hcj.Trafokreis,
                                                  "Electricity",
                                                  sa,
                                                  hhd.HouseholdGuid,
                                                  out var profsourceCache,
                                                  hcj.House.Name,
                                                  Config,
                                                  true);

            Info("Source 2: " + profsourceCache);
            Assert.NotNull(profsourceCache);
            Assert.NotNull(profsource);
            profElec1.Should().BeEquivalentTo(profElecCache, options => options.Excluding(ctx => ctx.SelectedMemberPath.EndsWith("BinaryProfile")));


            //Car Charging Electricity electricity test and cache test
            Info("================== ");
            Info("Car Charging Electricity electricity");
            Info("================== ");
            SaveableEntry <Profile> sa2 = SaveableEntry <Profile> .GetSaveableEntry(db, SaveableEntryTableType.EvProfile, Logger);

            sa2.MakeCleanTableForListOfFields(true);
            var prof2 = ca.LoadLPGProfile(ppd,
                                          hcj.Trafokreis,
                                          "Car Charging Electricity",
                                          sa2,
                                          hhd.HouseholdGuid,
                                          out var profsource2,
                                          hcj.House.Name,
                                          Config,
                                          true);

            Info("Source Wp 1: " + profsource2);
            Assert.NotNull(prof2);
            Assert.NotNull(profsource2);

            var prof3 = ca.LoadLPGProfile(ppd,
                                          hcj.Trafokreis,
                                          "Car Charging Electricity",
                                          sa2,
                                          hhd.HouseholdGuid,
                                          out var profsource3,
                                          hcj.House.Name,
                                          Config,
                                          true);

            Info("Source Wp 2: " + profsource3);
            Assert.NotNull(prof3);
            Assert.NotNull(profsource3);

            prof2.Should().BeEquivalentTo(prof3, options => options.Excluding(ctx =>
                                                                              ctx.SelectedMemberPath.EndsWith("BinaryProfile")));
        }