Beispiel #1
0
        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 void Run()
        {
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper disable twice AssignNullToNotNullAttribute
            ServiceRepository services = new ServiceRepository(null, null,
                                                               Logger, Config, new Random(1));
            var dbRaw = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var measuredRlmProfiles = dbRaw.Fetch <RlmProfile>();

            var dbHouse          = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice);
            var hausanschlusses  = dbHouse.Fetch <Hausanschluss>();
            var kleinwasserkraft = dbHouse.Fetch <KleinWasserkraft>();

            var dbdto = new DBDto(null, hausanschlusses, null, null, measuredRlmProfiles);

            /*KleinWasserkraft wk =new KleinWasserkraft("name",1,1,new List<int>(){1},1,"houseguid",
             *  "hausanschlussguid","sourceguid","standort","geschäftspartner","bezeichnung", "anlagennummer",
             *  "status","lastprofil");*/
            HouseComponentRo    hcro = new HouseComponentRo("myname", "PV", 1, 1, "status", "isns", "standort", 0);
            WasserkraftProvider wkp  = new WasserkraftProvider(services, Constants.PresentSlice, dbdto);

            foreach (var wasserkraft in kleinwasserkraft)
            {
                ProviderParameterDto pp = new ProviderParameterDto(wasserkraft, null, hcro);

                wkp.PrepareLoadProfileIfNeeded(pp);
                wkp.IsCorrectProvider(wasserkraft).Should().BeTrue();
                wkp.ProvideProfile(pp);
            }
        }
 public ProviderParameterDto([NotNull] IHouseComponent houseComponent,
                             [NotNull] string lpgDirectoryInfo,
                             [NotNull] HouseComponentRo houseComponentResultObject)
 {
     HouseComponent             = houseComponent;
     LPGDirectoryInfo           = lpgDirectoryInfo;
     HouseComponentResultObject = houseComponentResultObject;
 }
Beispiel #4
0
        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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public void RunTest()
        {
            Random rnd = new Random();
            // ReSharper disable twice AssignNullToNotNullAttribute
            ServiceRepository services            = new ServiceRepository(null, null, Logger, Config, rnd);
            var                     dbSrcProfiles = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var                     vdewvals      = dbSrcProfiles.Fetch <VDEWProfileValue>();
            var                     feiertage     = dbSrcProfiles.Fetch <FeiertagImport>();
            SLPProvider             slp           = new SLPProvider(2017, vdewvals, feiertage);
            DBDto                   dbDto         = new DBDto(new List <House>(), new List <Hausanschluss>(), new List <Car>(), new List <Household>(), new List <RlmProfile>());
            BusinessProfileProvider bpp           = new BusinessProfileProvider(services, Constants.PresentSlice, slp, dbDto);
            BusinessEntry           be            = new BusinessEntry(Guid.NewGuid().ToString(), "businessname", BusinessType.Brauerei, "housename");
            HouseComponentRo        hcro          = new HouseComponentRo("name", "type", 1, 1, "status", "", "standort", 0);
            ProviderParameterDto    parameeters   = new ProviderParameterDto(be, "", hcro);

            bpp.PrepareLoadProfileIfNeeded(parameeters);
            var prosumer = bpp.ProvideProfile(parameeters);

            Assert.NotNull(prosumer);
        }
        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());
            }
        }
        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")));
        }
Beispiel #10
0
        public void RunElectricCarProviderProvidingTest()
        {
            Config.LimitToScenarios.Add(Scenario.FromEnum(ScenarioEnum.Utopia));
            Config.LimitToYears.Add(2050);
            Config.InitializeSlices(Logger);
            Config.LpgPrepareMode = LpgPrepareMode.PrepareWithFullLpgLoad;
            var slice = (Config.Slices ?? throw new InvalidOperationException()).First(x =>
                                                                                       x.DstYear == 2050 && x.DstScenario == Scenario.FromEnum(ScenarioEnum.Utopia));

            // ReSharper disable twice AssignNullToNotNullAttribute
            var services   = new ServiceRepository(null, null, Logger, Config, new Random());
            var dbHouses   = services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice);
            var houses     = dbHouses.Fetch <House>();
            var has        = dbHouses.Fetch <Hausanschluss>();
            var households = dbHouses.Fetch <Household>();
            var cdes       = dbHouses.Fetch <CarDistanceEntry>();
            //SLPProvider slp = new SLPProvider(2017, vdewValues, feiertage);
            var   cars  = dbHouses.Fetch <Car>();
            DBDto dbdto = new DBDto(houses, has, cars, households, new List <RlmProfile>());
            CachingLPGProfileLoader clpl = new CachingLPGProfileLoader(Logger, dbdto);
            ElectricCarProvider     ecp  = new ElectricCarProvider(services, slice, dbdto, new List <HouseCreationAndCalculationJob>(), clpl);
            double sumenergyEstimates    = 0;
            double kilometers            = 0;
            double sumenergyProfiles     = 0;
            double carCount = 0;
            int    gascars  = 0;
            int    evs      = 0;
            int    count    = 0;

            foreach (var carDistanceEntry in cdes)
            {
                var car = cars.Single(x => x.Guid == carDistanceEntry.CarGuid);
                if (car.CarType == CarType.Electric)
                {
                    evs++;
                }
                else
                {
                    gascars++;
                }

                HouseComponentRo hcro = new HouseComponentRo(carDistanceEntry.Name,
                                                             carDistanceEntry.HouseComponentType.ToString(),
                                                             0,
                                                             0,
                                                             "",
                                                             carDistanceEntry.ISNsAsJson,
                                                             carDistanceEntry.Standort,
                                                             carDistanceEntry.EffectiveEnergyDemand);
                ProviderParameterDto ppd = new ProviderParameterDto(carDistanceEntry, Config.Directories.CalcServerLpgDirectory, hcro);
                ecp.PrepareLoadProfileIfNeeded(ppd);
                var prosumer = ecp.ProvideProfile(ppd);
                if (prosumer != null && prosumer.Profile != null)
                {
                    double energyEstimate = carDistanceEntry.EnergyEstimate;
                    sumenergyEstimates += energyEstimate;
                    kilometers         += carDistanceEntry.DistanceEstimate;
                    double profileEnergy = prosumer.Profile.EnergySum();
                    sumenergyProfiles += profileEnergy;
                    carCount++;
                }

                count++;
                if (count % 100 == 0)
                {
                    Info("Processed " + count + " / " + cdes.Count);
                }

                //profileEnergy.Should().BeInRange(energyEstimate, energyEstimate * 1.5);
            }

            double avgKilometers = kilometers / carCount;

            Info("gasoline cars: " + gascars);
            Info("ev cars: " + evs);
            Info("EnergyEstimateSum: " + sumenergyEstimates);
            Info("ProfileSum: " + sumenergyProfiles);
            Info("cars profiles made for " + carCount + " / " + cdes.Count);
            Info("Avg km per car: " + avgKilometers);
            Info("Avg Energy estimate per car: " + sumenergyEstimates / carCount);
            Info("Avg Energy profile per car: " + sumenergyProfiles / carCount);
        }