Exemple #1
0
 public AirConditioningEntry([JetBrains.Annotations.NotNull] string houseGuid,
                             [JetBrains.Annotations.NotNull] string acGuid,
                             double yearlyElectricityUse,
                             double cop,
                             AirConditioningType airConditioningType,
                             [JetBrains.Annotations.NotNull] string hausAnschlussGuid,
                             [JetBrains.Annotations.NotNull] string name,
                             [JetBrains.Annotations.NotNull] string standort)
 {
     HouseGuid             = houseGuid;
     Guid                  = acGuid;
     COP                   = cop;
     EffectiveEnergyDemand = yearlyElectricityUse;
     AirConditioningType   = airConditioningType;
     HausAnschlussGuid     = hausAnschlussGuid;
     Name                  = name;
     Standort              = standort;
     EnergyType            = EnergyType.Electricity;
 }
        protected override void RunActualProcess([NotNull] ScenarioSliceParameters slice)
        {
            var dbSrcHouses = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice.PreviousSliceNotNull);
            var dbDstHouses = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice);

            dbDstHouses.RecreateTable <AirConditioningEntry>();
            var srcAirconditioningEntries = dbSrcHouses.Fetch <AirConditioningEntry>();
            var srcHouses       = dbSrcHouses.Fetch <House>();
            var airConGuids     = srcAirconditioningEntries.Select(x => x.HouseGuid).ToList();
            var hausanschlusess = dbSrcHouses.Fetch <Hausanschluss>();
            var businesses      = dbDstHouses.Fetch <BusinessEntry>();
            var housesWithoutAirconditioning1 = srcHouses.Where(x => !airConGuids.Contains(x.Guid)).ToList();

            if (housesWithoutAirconditioning1.Count == 0)
            {
                throw new FlaException("no houses left without airconditioning");
            }

            foreach (var conditioningEntry in srcAirconditioningEntries)
            {
                conditioningEntry.HausAnschlussGuid.Should().NotBeNullOrWhiteSpace();
                var ha = hausanschlusess.First(x => x.Guid == conditioningEntry.HausAnschlussGuid);
                if (ha.ObjectID.ToLower().Contains("kleinanschluss"))
                {
                    throw new FlaException("No ac at kleinanschluss");
                }
            }

            // ReSharper disable once ArrangeLocalFunctionBody
            double CalculateYearlyAirConditioningEnergyConsumption(House h) =>
            h.EnergieBezugsFläche * slice.AirConditioningEnergyIntensityInKWhPerSquareMeter;

            double totalEbf = srcHouses.Sum(x => x.EnergieBezugsFläche);
            double totalTargetAirConditioning =
                totalEbf * slice.PercentageOfAreaWithAirConditioning * slice.AirConditioningEnergyIntensityInKWhPerSquareMeter;
            double currentAirConditioning = srcAirconditioningEntries.Sum(x => x.EffectiveEnergyDemand);
            double newlyInstealledEnergyForAirconditioning = totalTargetAirConditioning - currentAirConditioning;

            if (newlyInstealledEnergyForAirconditioning < 0)
            {
                throw new FlaException("Negative air conditioning target. Currently installed in " + slice + " are " +
                                       currentAirConditioning / (totalEbf * slice.AirConditioningEnergyIntensityInKWhPerSquareMeter));
            }

            bool failOnOver = slice.DstYear != 2050;
            WeightedRandomAllocator <House> allocator = new WeightedRandomAllocator <House>(Services.Rnd, Services.Logger);
            var housesForAirConditioning = allocator.PickObjectUntilLimit(housesWithoutAirconditioning1,
                                                                          x => x.EnergieBezugsFläche,
                                                                          CalculateYearlyAirConditioningEnergyConsumption,
                                                                          newlyInstealledEnergyForAirconditioning,
                                                                          failOnOver);
            var dstAirConditioningEntries = new List <AirConditioningEntry>();

            foreach (var house in housesForAirConditioning)
            {
                var businessesInHouse   = businesses.Where(x => x.HouseGuid == house.Guid).ToList();
                AirConditioningType act = AirConditioningType.Commercial;
                if (businessesInHouse.Count == 0)
                {
                    act = AirConditioningType.Residential;
                }

                foreach (var entry in businessesInHouse)
                {
                    if (entry.BusinessType == BusinessType.Industrie)
                    {
                        act = AirConditioningType.Industrial;
                    }
                }

                Hausanschluss ha = house.GetHausanschlussByIsn(new List <int>(), null, hausanschlusess, MyLogger, false);
                if (ha != null && ha.ObjectID.ToLower().Contains("kleinanschluss"))
                {
                    ha = null;
                }

                if (ha != null)
                {
                    var ace = new AirConditioningEntry(house.Guid,
                                                       Guid.NewGuid().ToString(),
                                                       CalculateYearlyAirConditioningEnergyConsumption(house),
                                                       1,
                                                       act,
                                                       ha.Guid,
                                                       house.ComplexName + " - Air Conditioning",
                                                       "");
                    dstAirConditioningEntries.Add(ace);
                }
            }

            foreach (var airconditioningEntry in srcAirconditioningEntries)
            {
                airconditioningEntry.ID = 0;
                dstAirConditioningEntries.Add(airconditioningEntry);
            }

            //final checks
            foreach (var dstAirConditioningEntry in dstAirConditioningEntries)
            {
                dstAirConditioningEntry.HausAnschlussGuid.Should().NotBeNullOrWhiteSpace();
                var ha = hausanschlusess.First(x => x.Guid == dstAirConditioningEntry.HausAnschlussGuid);
                if (ha.ObjectID.ToLower().Contains("kleinanschluss"))
                {
                    throw new FlaException("No ac at kleinanschluss");
                }
            }

            dbDstHouses.BeginTransaction();
            foreach (var airConditioningEntry in dstAirConditioningEntries)
            {
                dbDstHouses.Save(airConditioningEntry);
            }

            dbDstHouses.CompleteTransaction();
        }