protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto)
        {
            BuildingInfrastructure be = (BuildingInfrastructure)ppdto.HouseComponent;

            if (be.HouseComponentType == HouseComponentType.Infrastructure)
            {
                Hausanschluss ha = _dbDto.Hausanschlusse.Single(x => x.Guid == be.HausAnschlussGuid);
                var           pa = new Prosumer(be.HouseGuid,
                                                be.Standort ?? "nameless house infrastructure",
                                                be.HouseComponentType,
                                                be.SourceGuid,
                                                be.FinalIsn,
                                                be.HausAnschlussGuid,
                                                ha.ObjectID,
                                                GenerationOrLoad.Load,
                                                ha.Trafokreis, Name, "Flat House Infrastructure");
                pa.Profile = Profile.MakeConstantProfile(be.EffectiveEnergyDemand, "Flat House Infrastucture", Profile.ProfileResolution.QuarterHour);
                if (pa.Profile.EnergyOrPower == EnergyOrPower.Power)
                {
                    pa.Profile = pa.Profile.ConvertFromPowerToEnergy();
                }

                pa.SumElectricityPlanned = be.EffectiveEnergyDemand;
                return(pa);
            }
            throw new FlaException("No profile could be created");
        }
        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 Prosumer ProvideProfile([NotNull] ProviderParameterDto parameters)
        {
            _sw.Start();
            var p = ProvidePrivateProfile(parameters);

            _sw.Stop();
            return(p);
        }
        protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto)
        {
            BusinessEntry be = (BusinessEntry)ppdto.HouseComponent;

            if (be.BusinessType == BusinessType.Unknown)
            {
                throw new FlaException("unknown business type");
            }

            ppdto.HouseComponentResultObject.BusinessCategory = be.BusinessType.ToString();
            //string profileToUse = GetCorrectProfile(be.BusinessType);
            if (be.HouseComponentType == HouseComponentType.BusinessNoLastgangLowVoltage)
            {
                Hausanschluss ha      = _dbDto.Hausanschlusse.Single(x => x.Guid == be.HausAnschlussGuid);
                var           profile = GetCorrectProfile(be.BusinessType, be.EffectiveEnergyDemand, be);
                var           pa      = new Prosumer(be.HouseGuid,
                                                     be.Standort,
                                                     be.HouseComponentType,
                                                     be.Guid,
                                                     be.FinalIsn,
                                                     be.HausAnschlussGuid,
                                                     ha.ObjectID,
                                                     GenerationOrLoad.Load,
                                                     ha.Trafokreis,
                                                     Name,
                                                     profile.Name);
                pa.Profile = profile;
                pa.SumElectricityPlanned = be.EffectiveEnergyDemand;
                return(pa);
            }

            if (be.HouseComponentType == HouseComponentType.BusinessNoLastgangHighVoltage)
            {
                Hausanschluss ha      = _dbDto.Hausanschlusse.Single(x => x.Guid == be.HausAnschlussGuid);
                var           profile = GetCorrectProfile(be.BusinessType, be.EffectiveEnergyDemand, be);
                var           pa      = new Prosumer(be.HouseGuid,
                                                     be.Standort,
                                                     be.HouseComponentType,
                                                     be.Guid,
                                                     be.FinalIsn,
                                                     be.HausAnschlussGuid,
                                                     ha.ObjectID,
                                                     GenerationOrLoad.Load,
                                                     ha.Trafokreis,
                                                     Name,
                                                     profile.Name);
                pa.Profile = GetCorrectProfile(be.BusinessType, be.EffectiveEnergyDemand, be);
                pa.SumElectricityPlanned = be.EffectiveEnergyDemand;
                ppdto.HouseComponentResultObject.ProcessingStatus = "High Voltage Supplied Business without RLM";
                return(pa);
            }

            throw new FlaException("No profile could be created");
        }
        protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto)
        {
            Prosumer prosumer;
            var      ha = _dbDto.Hausanschlusse.Single(x => x.Guid == ppdto.HouseComponent.HausAnschlussGuid);

            var household = (Household)ppdto.HouseComponent;

            if (Math.Abs(household.EffectiveEnergyDemand) < 0.00001)
            {
                throw new FlaException("Household without energy demand: " + household.Name);
            }

            if (Services.RunningConfig.CheckForLpgCalcResult)
            {
                try {
                    prosumer = ProvideLPGProfile(ppdto, ha, household);

                    if (prosumer != null && prosumer.Profile != null)
                    {
                        if (Math.Abs(prosumer.Profile.EnergySum() - household.EffectiveEnergyDemand) > 0.000001)
                        {
                            prosumer.Profile = prosumer.Profile.ScaleToTargetSum(household.EffectiveEnergyDemand,
                                                                                 prosumer.Profile.Name,
                                                                                 out var factor);
                            ppdto.HouseComponentResultObject.AdjustmentFactor = factor;
                            if (factor > 2)
                            {
                                throw new HarmlessFlaException("LPG Scaling factor > 2");
                            }

                            if (prosumer.Profile.Values.Max() > 2.5)
                            {
                                throw new HarmlessFlaException("LPG Peak Load was over 10 kW");
                            }
                        }

                        ppdto.HouseComponentResultObject.ProcessingStatus = "LPG Profile";
                        return(prosumer);
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                    Error(ex.Message);
                    ppdto.HouseComponentResultObject.ErrorMessage = ex.Message;
                }
            }

            prosumer = MakeSlpProfile(household, ha);
            ppdto.HouseComponentResultObject.ProcessingStatus = "H0 Profile";
            return(prosumer);
        }
        protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto)
        {
            Prosumer prosumer;
            var      carDistanceEntry = (CarDistanceEntry)ppdto.HouseComponent;

            ppdto.HouseComponentResultObject.CarStatus            = "Electric";
            ppdto.HouseComponentResultObject.CommutingDistance    = carDistanceEntry.CommutingDistance;
            ppdto.HouseComponentResultObject.OtherDrivingDistance = carDistanceEntry.FreizeitDistance;
            var car = _dbDto.Cars.Single(x => x.Guid == carDistanceEntry.CarGuid);

            if (car.CarType != CarType.Electric)
            {
                ppdto.HouseComponentResultObject.CarStatus     = "Not electric, ignored";
                ppdto.HouseComponentResultObject.ProfileEnergy = 0;
                return(null);
            }

            if (car.RequiresProfile == CarProfileRequirement.NoProfile)
            {
                ppdto.HouseComponentResultObject.CarStatus     = "Preexisting electric car, ignored";
                ppdto.HouseComponentResultObject.ProfileEnergy = 0;
                return(null);
            }

            var ha        = _dbDto.Hausanschlusse.Single(x => x.Guid == ppdto.HouseComponent.HausAnschlussGuid);
            var household = _dbDto.Households.First(x => x.Guid == carDistanceEntry.HouseholdGuid);

            if (Services.RunningConfig.CheckForLpgCalcResult)
            {
                try {
                    prosumer = ProvideLPGProfile(ppdto, ha, household, carDistanceEntry);
                    if (prosumer != null)
                    {
                        ppdto.HouseComponentResultObject.ProcessingStatus = "LPG Profile";
                        ppdto.HouseComponentResultObject.CarStatus        = "Electric, LPG Profile";
                        return(prosumer);
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                    Error(ex.Message);
                }
            }

            prosumer = MakeFlatProfile(carDistanceEntry, ha, household);
            ppdto.HouseComponentResultObject.ProcessingStatus = "Flat Profile";
            ppdto.HouseComponentResultObject.CarStatus        = "Electric, flat profile";
            return(prosumer);
        }
        private Prosumer ProvideLPGProfile([NotNull] ProviderParameterDto parameters,
                                           [NotNull] Hausanschluss ha,
                                           [NotNull] Household household,
                                           [NotNull] CarDistanceEntry carDistanceEntry)
        {
            string prosumerName = household.Name;
            string sourceGuid   = household.SourceGuid;
            string householdKey = household.HouseholdKey;
            long   isn          = household.FinalIsn;

            try {
                var prosumer = _lpgProfileLoader.LoadProsumer(parameters,
                                                              ha,
                                                              prosumerName,
                                                              carDistanceEntry.HouseComponentType,
                                                              LoadtypetoSearchFor,
                                                              _saveableEntry,
                                                              sourceGuid,
                                                              householdKey,
                                                              household.HouseGuid,
                                                              isn,
                                                              Services.RunningConfig);
                if (prosumer == null)
                {
                    return(null);
                }

                if (prosumer.Profile == null)
                {
                    throw new FlaException("Profile was null");
                }

                parameters.HouseComponentResultObject.ActualDrivingDistance = prosumer.Profile.EnergySum() / 15.0 * 100;
                return(prosumer);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                Error(ex.Message);
                parameters.HouseComponentResultObject.ErrorMessage = ex.Message;
            }

            return(null);
        }
        private Prosumer ProvideLPGProfile([NotNull] ProviderParameterDto parameters, [NotNull] Hausanschluss ha, [NotNull] Household household)
        {
            string prosumerName = household.Name;
            const HouseComponentType houseComponentType = HouseComponentType.Household;
            string sourceGuid   = household.SourceGuid;
            string householdKey = household.HouseholdKey;
            long   isn          = household.FinalIsn;

            return(_lpgloader.LoadProsumer(parameters,
                                           ha,
                                           prosumerName,
                                           houseComponentType,
                                           LoadtypetoSearchFor,
                                           _saveableEntry,
                                           sourceGuid,
                                           householdKey,
                                           household.HouseGuid,
                                           isn,
                                           Services.RunningConfig));
        }
Beispiel #9
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 bool PrepareLoadProfileIfNeeded([NotNull] ProviderParameterDto parameters)
        {
            CarDistanceEntry cde = (CarDistanceEntry)parameters.HouseComponent;
            Car myCar            = _dbDto.Cars.Single(x => x.Guid == cde.CarGuid);

            parameters.HouseComponentResultObject.CarStatus = "Gasoline, not analyzed further";

            if (myCar.RequiresProfile == CarProfileRequirement.NoProfile)
            {
                return(true);
            }

            Hausanschluss ha = _dbDto.Hausanschlusse.Single(x => x.Guid == cde.HausAnschlussGuid);

            parameters.HouseComponentResultObject.CarStatus            = "Electric";
            parameters.HouseComponentResultObject.CommutingDistance    = cde.CommutingDistance;
            parameters.HouseComponentResultObject.OtherDrivingDistance = cde.FreizeitDistance;
            Household flaHousehold = _dbDto.Households.FirstOrDefault(x => x.Guid == cde.HouseholdGuid);

            if (flaHousehold == null)
            {
                parameters.HouseComponentResultObject.CarStatus += ", no household";
                throw new FlaException("no household found");
            }

            var house = _dbDto.Houses.FirstOrDefault(x => x.HouseGuid == cde.HouseGuid);

            if (house == null)
            {
                throw new FlaException("no house found");
            }

            HouseholdData householdData = null;

            if (_housesToBeCreated.Count > 0)
            {
                var houseJob = _housesToBeCreated.FirstOrDefault(x => x.House.HouseGuid == ha.HouseGuid);
                if (houseJob == null)
                {
                    parameters.HouseComponentResultObject.CarStatus += ", no house";

                    throw new FlaException("no house found");
                }

                householdData = houseJob.House.Households.FirstOrDefault(x => x.HouseholdGuid == flaHousehold.HouseholdKey);
                if (householdData == null)
                {
                    parameters.HouseComponentResultObject.CarStatus += ", no household guid";
                    throw new FlaException("no household for household guid " + cde.HouseholdGuid);
                }


                //set lpg parameters
                householdData.UseElectricCar = ElectricCarUse.UseElectricCar;

                //find number of cars
                var householdCars = _dbDto.Cars.Where(x => x.HouseholdGuid == cde.HouseholdGuid).ToList();
                switch (householdCars.Count)
                {
                case 1:
                    //use lpg profile for a single car
                    householdData.TransportationDeviceSet = TransportationDevicesTwoCar;
                    break;

                case 2:
                    //use lpg profile for a single car
                    householdData.TransportationDeviceSet = TransportationDevicesTwoCar;
                    break;

                case 3:
                    // use lpg profile for a single car
                    // todo: fix this and put in the right transportation device set
                    householdData.TransportationDeviceSet = TransportationDevicesTwoCar;
                    break;

                case 4:
                    //use lpg profile for a single car
                    //todo: fix this and put in the right transportation device set
                    householdData.TransportationDeviceSet = TransportationDevicesTwoCar;
                    break;

                default: throw new FlaException("Household with " + householdCars.Count + " cars is missing");
                }

                householdData.TravelRouteSet     = TravelRouteSet;
                householdData.ChargingStationSet = ChargingStationSet;
                if (householdData.TransportationDistanceModifiers == null)
                {
                    householdData.TransportationDistanceModifiers = new List <TransportationDistanceModifier>();
                }

                householdData.TransportationDistanceModifiers.Add(new TransportationDistanceModifier("Work", "Car", cde.CommutingDistance * 1000));
                householdData.TransportationDistanceModifiers.Add(new TransportationDistanceModifier("Entertainment",
                                                                                                     "Car",
                                                                                                     cde.FreizeitDistance * 1000));
                parameters.HouseComponentResultObject.CarStatus += ", asking for repare with distances commuting: " + cde.CommutingDistance +
                                                                   ", free time: " + cde.FreizeitDistance + " km";
            }

            if (Services.RunningConfig.LpgPrepareMode == LpgPrepareMode.PrepareWithFullLpgLoad)
            {
                Profile lpgProfile = null;
                try {
                    lpgProfile = _lpgProfileLoader.LoadLPGProfile(parameters,
                                                                  ha.Trafokreis,
                                                                  LoadtypetoSearchFor,
                                                                  _saveableEntry,
                                                                  flaHousehold.HouseholdKey,
                                                                  out _,
                                                                  house.ComplexName,
                                                                  Services.RunningConfig);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                    Error("trying to load lpg profile: " + ex.Message);
                    parameters.HouseComponentResultObject.LPGErrors = "trying to load lpg profile failed: " + ex.Message;
                }

                // ReSharper disable PossibleNullReferenceException
                if (_housesToBeCreated.Count > 0)
                {
                    if (lpgProfile != null)
                    {
                        householdData.IsCarProfileCalculated = true;
                        parameters.HouseComponentResultObject.ProcessingStatus = "Found LPG profile on full check";
                    }
                    else
                    {
                        householdData.IsCarProfileCalculated = false;
                        parameters.HouseComponentResultObject.ProcessingStatus = "Missing LPG profile on full check";
                    }
                }
                // ReSharper restore PossibleNullReferenceException
            }
            else if (Services.RunningConfig.LpgPrepareMode == LpgPrepareMode.PrepareWithOnlyNamecheck)
            {
                // ReSharper disable PossibleNullReferenceException
                if (_housesToBeCreated.Count > 0)
                {
                    if (_saveableEntry.CheckForName(flaHousehold.HouseholdKey, Services.Logger))
                    {
                        householdData.IsHouseholdProfileCalculated             = true;
                        parameters.HouseComponentResultObject.ProcessingStatus = "Found LPG profile on name check";
                    }
                    else
                    {
                        householdData.IsHouseholdProfileCalculated             = false;
                        parameters.HouseComponentResultObject.ProcessingStatus = "Miissing LPG profile on name check";
                    }
                }
                // ReSharper restore PossibleNullReferenceException
            }
            else
            {
                throw new FlaException("Unknown lpg prepare mode");
            }

            return(true);
        }
        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")));
        }
 protected abstract Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto);
 public bool PrepareLoadProfileIfNeeded([NotNull] ProviderParameterDto parameters) => true;
Beispiel #14
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);
        }
        public bool PrepareLoadProfileIfNeeded([NotNull] ProviderParameterDto parameters)
        {
            if (parameters.HouseComponent.HouseComponentType != HouseComponentType.Household)
            {
                throw new FlaException("Was not household: " + parameters.HouseComponent.HouseComponentType);
            }

            Household     hh       = (Household)parameters.HouseComponent;
            Hausanschluss ha       = _dbDto.Hausanschlusse.Single(x => x.Guid == hh.HausAnschlussGuid);
            var           houseJob = _housesToBeCreated.FirstOrDefault(x => x.House.HouseGuid == hh.HouseGuid);

            if (houseJob == null)
            {
                var flahouse = _dbDto.Houses.Single(x => x.Guid == hh.HouseGuid);
                houseJob       = new HouseCreationAndCalculationJob(Slice.DstScenario.ToString(), Slice.DstYear.ToString(), ha.Trafokreis);
                houseJob.House = new HouseData(hh.HouseGuid, "HT01", 0, 0, flahouse.ComplexName);
                _housesToBeCreated.Add(houseJob);
            }

            HouseholdData hd = new HouseholdData(hh.HouseholdKey,
                                                 hh.EffectiveEnergyDemand,
                                                 ElectricCarUse.NoElectricCar,
                                                 hh.Name,
                                                 null,
                                                 null,
                                                 null,
                                                 null,
                                                 HouseholdDataSpecifictionType.ByPersons);

            hd.IsCarProfileCalculated           = true;
            hd.HouseholdDataPersonSpecification = new HouseholdDataPersonSpecification(new List <PersonData>());
            if (hh.Occupants.Count == 0)
            {
                throw new FlaException("No occupants in the household " + hh.Name);
            }

            foreach (var occupant in hh.Occupants)
            {
                hd.HouseholdDataPersonSpecification.Persons.Add(new PersonData(occupant.Age, (Gender)occupant.Gender));
            }

            House house = _dbDto.Houses.First(x => x.Guid == hh.HouseGuid);

            if (Services.RunningConfig.LpgPrepareMode == LpgPrepareMode.PrepareWithFullLpgLoad)
            {
                Profile lpgProfile = null;
                try {
                    lpgProfile = _lpgloader.LoadLPGProfile(parameters,
                                                           ha.Trafokreis,
                                                           LoadtypetoSearchFor,
                                                           _saveableEntry,
                                                           hh.HouseholdKey,
                                                           out _,
                                                           house.ComplexName,
                                                           Services.RunningConfig);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                    parameters.HouseComponentResultObject.LPGErrors = "trying to load lpg profile failed: " + ex.Message;
                    Error("trying to load lpg profile: " + ex.Message);
                }

                if (lpgProfile != null)
                {
                    hd.IsHouseholdProfileCalculated = true;
                }
                else
                {
                    hd.IsHouseholdProfileCalculated = false;
                }
            }
            else if (Services.RunningConfig.LpgPrepareMode == LpgPrepareMode.PrepareWithOnlyNamecheck)
            {
                if (_saveableEntry.CheckForName(hh.HouseholdKey, Services.Logger))
                {
                    hd.IsHouseholdProfileCalculated = true;
                }
                else
                {
                    hd.IsHouseholdProfileCalculated = false;
                }
            }
            else
            {
                throw new FlaException("Unknown lpg prepare mode");
            }

            houseJob.House.Households.Add(hd);
            return(true);
        }