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");
        }
예제 #2
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);
        }
        protected override void RunActualProcess()
        {
            SqlConnection.RecreateTable <BusinessEntry>(Stage.Houses, Constants.PresentSlice);
            var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;

            //load data
            var        potentialBusinesses = dbHouse.Fetch <PotentialBusinessEntry>();
            var        hausanschlusses     = dbHouse.Fetch <Hausanschluss>();
            var        houses           = dbHouse.Fetch <House>();
            var        validIsns        = houses.SelectMany(x => x.Hausanschluss.Select(y => y.Isn)).ToHashSet();
            List <int> invalidIsns      = new List <int>();
            int        randomlyChosenHa = 0;
            int        reassignedHAs    = 0;

            dbHouse.BeginTransaction();
            foreach (var pb in potentialBusinesses)
            {
                if (pb.MyCategory == "Immobilien" || pb.MyCategory == "WEG")
                {
                    if (pb.HighVoltageYearlyElectricityUse > 0)
                    {
                        throw new FlaException("Building infrastructure with MS?");
                    }
                    var pbi = new PotentialBuildingInfrastructure {
                        HouseGuid        = pb.HouseGuid,
                        Geschäftspartner = pb.BusinessName,
                        LowVoltageTotalElectricityDemand  = pb.LowVoltageYearlyElectricityUse,
                        HighVoltageTotalElectricityDemand = pb.HighVoltageYearlyElectricityUse
                    };
                    dbHouse.Save(pbi);
                }
                else
                {
                    BusinessType bt          = GetTypeFromDescription(pb.MyCategory);
                    var          be          = new BusinessEntry(pb, bt);
                    var          hasIndustry = false;
                    if (pb.LowVoltageLocalnetEntries.Any(x => x.Rechnungsart == "Industrie") || pb.HighVoltageLocalnetEntries.Any(x => x.Rechnungsart == "Industrie"))
                    {
                        hasIndustry = true;
                    }

                    if (hasIndustry)
                    {
                        be.BusinessType = BusinessType.Industrie;
                    }
                    else
                    {
                        be.BusinessType = GetTypeFromDescription(pb.MyCategory);
                    }
                    //isn kontrolle
                    int validisn = 0;
                    foreach (int hhIsn in be.OriginalISNs)
                    {
                        if (!validIsns.Contains(hhIsn))
                        {
                            invalidIsns.Add(hhIsn);
                        }
                        else
                        {
                            validisn = hhIsn;
                        }
                    }

                    var house = houses.Single(x => x.HouseGuid == be.HouseGuid);
                    if (validisn == 0)
                    {
                        be.FinalIsn = house.Hausanschluss[0].Isn;
                    }
                    else
                    {
                        be.FinalIsn = validisn;
                    }

                    var ha = hausanschlusses.Where(x => x.HouseGuid == be.HouseGuid && x.Isn == be.FinalIsn).ToList();
                    if (ha.Count == 0)
                    {
                        //throw new FlaException("Kein Hausanschluss gefunden.");
                        reassignedHAs++;
                        be.HausAnschlussGuid = house.Hausanschluss[0].HausanschlussGuid;
                    }

                    if (ha.Count == 1)
                    {
                        be.HausAnschlussGuid = ha[0].HausanschlussGuid;
                    }

                    if (ha.Count > 1)
                    {
                        randomlyChosenHa++;
                        be.HausAnschlussGuid = ha[Services.Rnd.Next(ha.Count)].HausanschlussGuid;
                        //throw new FlaException("zu viele Hausanschlüsse gefunden.: " + ha.Count);
                    }
                    dbHouse.Save(be);
                }
            }
            Info("Invalid Isns: " + invalidIsns.Distinct().Count());
            Info("Zufällig ausgewählte Hausanschlüsse bei Häusern mit mehr als einem HA: " + randomlyChosenHa);
            Info("Wohnungen mit neuem Hausanschluss wegen nicht gefundener ISN: " + reassignedHAs);
            dbHouse.CompleteTransaction();
        }
        private Profile GetCorrectProfile(BusinessType beBusinessType, double targetEnergy, [NotNull] BusinessEntry be)
        {
            var overrideEntry = _repository.GetEntry(be.ComplexName, be.BusinessName, be.Standort);

            if (overrideEntry != null)
            {
                _usedProfileOverrides.Add(overrideEntry);
                if (overrideEntry.ProfileName.ToLower() == "flat")
                {
                    return(Profile.MakeConstantProfile(targetEnergy, "Flat", Profile.ProfileResolution.QuarterHour));
                }

                return(_slpProvider.Run(overrideEntry.ProfileName, targetEnergy));
            }

            switch (beBusinessType)
            {
            case BusinessType.Büro:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Shop:
                return(_slpProvider.Run("G4", targetEnergy));

            case BusinessType.Werkstatt:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Seniorenheim:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Restaurant:
                return(_slpProvider.Run("G2", targetEnergy));

            case BusinessType.Bäckerei:
                return(_slpProvider.Run("G5", targetEnergy));

            case BusinessType.Industrie:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Sonstiges:
                return(_slpProvider.Run("G0", targetEnergy));

            case BusinessType.Praxis:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Kirche:
                return(_slpProvider.Run("G6", targetEnergy));

            case BusinessType.Schule:
                return(_slpProvider.Run("G1", targetEnergy));

            case BusinessType.Tankstelle:
                return(_slpProvider.Run("G4", targetEnergy));

            case BusinessType.Wasserversorgung:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Brauerei:
                return(Profile.MakeConstantProfile(targetEnergy, "Flat", Profile.ProfileResolution.QuarterHour));

            case BusinessType.Hotel:
                return(_slpProvider.Run("G0", targetEnergy));

            case BusinessType.Museum:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Hallenbad:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Eissport:
                return(_slpProvider.Run("G3", targetEnergy));

            case BusinessType.Mobilfunk:
                return(Profile.MakeConstantProfile(targetEnergy, "Flat", Profile.ProfileResolution.QuarterHour));

            case BusinessType.Unknown:
                throw new ArgumentOutOfRangeException(nameof(beBusinessType), beBusinessType, null);

            default:
                throw new ArgumentOutOfRangeException(nameof(beBusinessType), beBusinessType, null);
            }
        }
        protected override void RunActualProcess()
        {
            var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice);

            dbHouse.RecreateTable <BusinessEntry>();
            //load data
            var                  potentialBusinesses = dbHouse.Fetch <PotentialBusinessEntry>();
            var                  hausanschlusses     = dbHouse.Fetch <Hausanschluss>();
            var                  houses           = dbHouse.Fetch <House>();
            var                  validIsns        = houses.SelectMany(x => x.Hausanschluss.Select(y => y.Isn)).ToHashSet();
            List <int>           invalidIsns      = new List <int>();
            const int            randomlyChosenHa = 0;
            const int            reassignedHAs    = 0;
            List <BusinessEntry> businesses       = new List <BusinessEntry>();

            dbHouse.BeginTransaction();
            foreach (var pb in potentialBusinesses)
            {
                if ((pb.MyCategory == "Immobilien" || pb.MyCategory == "WEG") &&
                    pb.Standort != "Einschlagweg 59, Geschoss unbekannt, 3400 Burgdorf" &&
                    pb.Standort != "Fabrikweg 6, Geschoss unbekannt, 3400 Burgdorf")
                {
                    if (pb.HighVoltageYearlyElectricityUse > 0)
                    {
                        throw new FlaException("Building infrastructure with MS?");
                    }

                    var pbi = new PotentialBuildingInfrastructure(pb.HouseGuid,
                                                                  pb.BusinessName,
                                                                  pb.LowVoltageYearlyElectricityUse,
                                                                  pb.HighVoltageYearlyElectricityUse,
                                                                  pb.LowVoltageLocalnetEntries,
                                                                  pb.HighVoltageLocalnetEntries,
                                                                  pb.Standort, Guid.NewGuid().ToString());
                    dbHouse.Save(pbi);
                }
                else
                {
                    BusinessType bt = GetTypeFromDescription(pb.MyCategory);
                    var          be = new BusinessEntry(pb, bt);
                    be.HouseComponentType = HouseComponentType.BusinessNoLastgangLowVoltage;
                    //var hasIndustry = false;

                    /*if (pb.LowVoltageLocalnetEntries.Any(x => x.Rechnungsart == "Industrie") ||
                     *  pb.HighVoltageLocalnetEntries.Any(x => x.Rechnungsart == "Industrie")) {
                     *  hasIndustry = true;
                     * }*/

/*                    if (hasIndustry) {
 *                      be.BusinessType = BusinessType.Industrie;
 *                  }
 *                  else {
 *                      ;
 *                  }*/

                    //isn kontrolle
                    int validisn = 0;
                    foreach (int hhIsn in be.OriginalISNs)
                    {
                        if (!validIsns.Contains(hhIsn))
                        {
                            invalidIsns.Add(hhIsn);
                        }
                        else
                        {
                            validisn = hhIsn;
                        }
                    }

                    var house = houses.Single(x => x.Guid == be.HouseGuid);
                    if (validisn == 0)
                    {
                        be.FinalIsn = house.Hausanschluss[0].Isn;
                    }
                    else
                    {
                        be.FinalIsn = validisn;
                    }


                    var ha = hausanschlusses.Single(x => x.Guid == pb.HausAnschlussGuid);
                    if (ha == null)
                    {
                        throw new FlaException("ha was null");
                    }

                    /*     hausanschlusses.Where(x => x.HouseGuid == be.HouseGuid && x.Isn == be.FinalIsn).ToList();
                     * if (ha.Count == 0)
                     * {
                     *     //throw new FlaException("Kein Hausanschluss gefunden.");
                     *     reassignedHAs++;
                     *     be.HausAnschlussGuid = house.Hausanschluss[0].HausanschlussGuid;
                     * }
                     *
                     * if (ha.Count == 1)
                     * {
                     *     be.HausAnschlussGuid = ha[0].HausanschlussGuid;
                     * }
                     *
                     * if (ha.Count > 1)
                     * {
                     *     randomlyChosenHa++;
                     *     be.HausAnschlussGuid = ha[Services.Rnd.Next(ha.Count)].HausanschlussGuid;
                     *     //throw new FlaException("zu viele Hausanschlüsse gefunden.: " + ha.Count);
                     * }*/
                    be.HausAnschlussGuid = pb.HausAnschlussGuid;
                    businesses.Add(be);
                }
            }
            dbHouse.CompleteTransaction();
            AssignRlmProfiles(businesses, houses);
            foreach (var businessEntry in businesses)
            {
                if (businessEntry.LocalnetHighVoltageYearlyTotalElectricityUse > 0)
                {
                    if (businessEntry.HouseComponentType == HouseComponentType.BusinessNoLastgangLowVoltage)
                    {
                        businessEntry.HouseComponentType = HouseComponentType.BusinessNoLastgangHighVoltage;
                    }
                    else if (businessEntry.HouseComponentType == HouseComponentType.BusinessWithLastgangLowVoltage)
                    {
                        businessEntry.HouseComponentType = HouseComponentType.BusinessWithLastgangHighVoltage;
                    }
                }
            }

            Debug("Invalid Isns: " + invalidIsns.Distinct().Count());
            Debug("Zufällig ausgewählte Hausanschlüsse bei Häusern mit mehr als einem HA: " + randomlyChosenHa);
            Debug("Wohnungen mit neuem Hausanschluss wegen nicht gefundener ISN: " + reassignedHAs);
            int normalBusinesses = businesses.Count(x => x.HouseComponentType == HouseComponentType.BusinessNoLastgangLowVoltage);
            int rlmBusinesses    = businesses.Count(x => x.HouseComponentType == HouseComponentType.BusinessWithLastgangLowVoltage);

            Debug("Businesses without rlm:" + normalBusinesses + " with: " + rlmBusinesses);
            dbHouse.BeginTransaction();
            foreach (BusinessEntry entry in businesses)
            {
                dbHouse.Save(entry);
            }

            dbHouse.CompleteTransaction();
            RowCollection rc = new RowCollection("Businesses", "");

            foreach (var entry in businesses)
            {
                RowBuilder rb = RowBuilder.Start("Name", entry.BusinessName);
                rb.Add("Verbrauchstyp", entry.EnergyType);
                rb.Add("Verbrauch", entry.EffectiveEnergyDemand);
                rb.Add("Businesstype", entry.BusinessType.ToString());
                rc.Add(rb);
            }

            var fn = MakeAndRegisterFullFilename("Businesses.xlsx", Constants.PresentSlice);

            XlsxDumper.WriteToXlsx(fn, rc);
        }