private PotentialHousehold MakePotentialHouseholds([NotNull] House h, [NotNull] StandortAnalysis sa, [NotNull][ItemNotNull] List <Hausanschluss> hausanschlusses) { var houseGuid = h.Guid; var householdGuid = Guid.NewGuid().ToString(); double yearlyElectricityUse = sa.LowVoltageTotalElectricity; var tarif = sa.ElectricityTarif; var numberOfLocalnetEntries = sa.LowVoltageElectricityEntries.Count; var businessPartnerName = sa.BusinessPartnerName; var householdKey = Household.MakeHouseholdKey(h.ComplexName, sa.Standort, sa.BusinessPartnerName); var ha = h.GetHausanschlussByIsn(sa.OriginalISNs, sa.Standort, hausanschlusses, Services.Logger); var hh = new PotentialHousehold(houseGuid, householdGuid, yearlyElectricityUse, tarif, numberOfLocalnetEntries, businessPartnerName, householdKey, ha?.Guid ?? throw new FlaException("no hausanschluss"), sa.Standort); hh.LocalnetEntries = sa.LowVoltageElectricityEntries; if (sa.HighVoltageTotalElectricity > 0) { throw new Exception("Wohnhaus mit MS"); } return(hh); }
private static PotentialHousehold MakePotentialHouseholds([NotNull] House h, [NotNull] StandortAnalysis sa, [NotNull][ItemNotNull] List <Hausanschluss> hausanschlusses) { var houseGuid = h.HouseGuid; var householdGuid = Guid.NewGuid().ToString(); double yearlyElectricityUse = sa.LowVoltageTotalElectricity; var tarif = sa.ElectricityTarif; var numberOfLocalnetEntries = sa.LowVoltageElectricityEntries.Count; var businessPartnerName = sa.BusinessPartnerName; var householdKey = Household.MakeHouseholdKey(h.ComplexName, sa.Standort, sa.BusinessPartnerName); string hausanschlussGuid = hausanschlusses.Single(x => x.Isn == sa.IsnID).HausanschlussGuid; var hh = new PotentialHousehold(houseGuid, householdGuid, yearlyElectricityUse, tarif, numberOfLocalnetEntries, businessPartnerName, householdKey, hausanschlussGuid); hh.Standorte.Add(sa.Standort); hh.LocalnetEntries = sa.LowVoltageElectricityEntries; if (sa.HighVoltageTotalElectricity > 0) { throw new Exception("Haus mit MS"); } return(hh); }
private PotentialBusinessEntry MakeBusinessEntry([NotNull] StandortAnalysis sa, [NotNull] House h, [NotNull][ItemNotNull] List <Hausanschluss> hausanschlusses) { var houseGuid = h.Guid; var businessGuid = Guid.NewGuid().ToString(); var businessName = sa.BusinessPartnerName; var complexName = h.ComplexName; var lowVoltageYearlyElectricityUse = sa.LowVoltageTotalElectricity; var highVoltageYearlyElectricityUse = sa.HighVoltageTotalElectricity; var lowVoltageYearlyElectricityUseDaytime = sa.LowVoltageElectricityUseDaytime; var lowVoltageYearlyElectricityUseNighttime = sa.LowVoltageElectricityUseNighttime; string hausanschlussGuid = h.GetHausanschlussByIsn(sa.OriginalISNs, sa.Standort, hausanschlusses, Services.Logger)?.Guid ?? throw new FlaException("no hausanschluss"); var be = new PotentialBusinessEntry(houseGuid, businessGuid, businessName, complexName, lowVoltageYearlyElectricityUse, highVoltageYearlyElectricityUse, lowVoltageYearlyElectricityUseDaytime, lowVoltageYearlyElectricityUseNighttime, sa.GasUse, sa.FernWärme, sa.SummerBaseGasUse, -1, sa.LocalNetEntries.Count, sa.ElectricityTarif, sa.BusinessCategory, hausanschlussGuid); be.Standort = sa.Standort; be.LowVoltageLocalnetEntries = sa.LowVoltageElectricityEntries; be.HighVoltageLocalnetEntries = sa.HighVoltageElectricityEntries; be.NumberOfLocalnetEntries = sa.LowVoltageElectricityEntries.Count + sa.HighVoltageElectricityEntries.Count; be.Tarif = sa.ElectricityTarif; return(be); }
private static PotentialBusinessEntry MakeBusinessEntry([NotNull] StandortAnalysis sa, [NotNull] House h, [NotNull][ItemNotNull] List <Hausanschluss> hausanschlusses) { var houseGuid = h.HouseGuid; var businessGuid = Guid.NewGuid().ToString(); var businessName = sa.BusinessPartnerName; var complexName = h.ComplexName; var lowVoltageYearlyElectricityUse = sa.LowVoltageTotalElectricity; var highVoltageYearlyElectricityUse = sa.HighVoltageTotalElectricity; var lowVoltageYearlyElectricityUseDaytime = sa.LowVoltageElectricityUseDaytime; var lowVoltageYearlyElectricityUseNighttime = sa.LowVoltageElectricityUseNighttime; string hausanschlussGuid = hausanschlusses.Single(x => x.Isn == sa.IsnID).HausanschlussGuid; var be = new PotentialBusinessEntry(houseGuid, businessGuid, businessName, complexName, lowVoltageYearlyElectricityUse, highVoltageYearlyElectricityUse, lowVoltageYearlyElectricityUseDaytime, lowVoltageYearlyElectricityUseNighttime, sa.GasUse, sa.FernWärme, sa.SummerLowVoltageBaseElectricity, sa.SummerBaseGasUse, false, -1, sa.LocalNetEntries.Count, sa.ElectricityTarif, sa.BusinessCategory, hausanschlussGuid); be.Standorte.Add(sa.Standort); be.LowVoltageLocalnetEntries = sa.LowVoltageElectricityEntries; be.NumberOfLocalnetEntries = sa.LowVoltageElectricityEntries.Count + sa.HighVoltageElectricityEntries.Count; be.Tarif = sa.ElectricityTarif; return(be); }
private KleinWasserkraft MakeWasserkraftEntry([NotNull] StandortAnalysis sa, [NotNull][ItemNotNull] List <WasserkraftwerkImport> wasserimport, [NotNull] House house) { WasserkraftwerkImport wk = wasserimport.Single(x => x.Standort == sa.Standort); _assignedWkws.Add(wk); if (sa.OriginalISNs.Count != 1) { throw new FlaException("More than 1 isn"); } int finalisn = sa.OriginalISNs[0]; var hausanschluss = house.Hausanschluss.FirstOrDefault(x => x.Standort == wk.Standort); if (hausanschluss == null) { hausanschluss = house.Hausanschluss[0]; } KleinWasserkraft kwk = new KleinWasserkraft(wk.ComplexName, sa.LowVoltageTotalElectricity, sa.HighVoltageTotalElectricity, sa.OriginalISNs, finalisn, house.Guid, hausanschluss.Guid, Guid.NewGuid().ToString(), wk.Standort, sa.BusinessPartnerName, wk.Bezeichnung, wk.Anlagennummer, wk.Status, wk.LastProfil); return(kwk); }
private static PotentialBuildingInfrastructure MakePotentialBuildingInfrastructureEntry([NotNull] House h, [NotNull] StandortAnalysis sa) { var bi = new PotentialBuildingInfrastructure { HouseGuid = h.HouseGuid, Geschäftspartner = sa.BusinessPartnerName, LowVoltageTotalElectricityDemand = sa.LowVoltageTotalElectricity, HighVoltageTotalElectricityDemand = sa.HighVoltageTotalElectricity }; return(bi); }
protected override void RunActualProcess() { //tables SqlConnection.RecreateTable <PotentialHousehold>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <PotentialBusinessEntry>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <PotentialHeatingSystemEntry>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <SuspiciousBusinessEntry>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <PotentialBuildingInfrastructure>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <StreetLightingEntry>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <HouseSummedLocalnetEnergyUse>(Stage.Houses, Constants.PresentSlice); SqlConnection.RecreateTable <PotentialCookingSystemEntry>(Stage.Houses, Constants.PresentSlice); //databases var dbComplex = SqlConnection.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice).Database; var dbRaw = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database; var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; //load data var buildingcomplexes = dbComplex.Fetch <BuildingComplex>(); var businesses = dbRaw.Fetch <BusinessName>(); var houses = dbHouse.Fetch <House>(); var localnet = dbRaw.Fetch <Localnet>(); var hausanschlusses = dbHouse.Fetch <Hausanschluss>(); //initialize dictionaries var complexesByID = new Dictionary <string, BuildingComplex>(); foreach (var complex in buildingcomplexes) { complexesByID.Add(complex.ComplexGuid, complex); } var localnetByStandort = new Dictionary <string, List <Localnet> >(); foreach (var localnet1 in localnet) { if (!localnetByStandort.ContainsKey(localnet1.Objektstandort ?? throw new InvalidOperationException())) { localnetByStandort.Add(localnet1.Objektstandort, new List <Localnet>()); } localnetByStandort[localnet1.Objektstandort].Add(localnet1); } var alreadyRegisteredPotentialBusinesses = new List <string>(); dbHouse.BeginTransaction(); foreach (var h in houses) { var complex = complexesByID[h.ComplexGuid]; //standort analysis für jeden standort initialisieren var standorte = complex.ObjektStandorte; var standortAnalysises = new List <StandortAnalysis>(); foreach (var standort in standorte) { var locanetforStandort = localnetByStandort[standort]; if (locanetforStandort.Count == 0) { throw new Exception("No entries for standort " + standort); } var geschäftspartnerNames = locanetforStandort.Select(x => x.VertragspartnerAdresse).Distinct().ToList(); foreach (var gs in geschäftspartnerNames) { List <Localnet> localnetForGs = locanetforStandort.Where(x => x.VertragspartnerAdresse == gs).ToList(); var sa = new StandortAnalysis(localnetForGs, Services.MyLogger, standort, gs, dbHouse, businesses, alreadyRegisteredPotentialBusinesses); standortAnalysises.Add(sa); } } var hsl = new HouseSummedLocalnetEnergyUse { HouseGuid = h.HouseGuid }; foreach (var sa in standortAnalysises) { //try to figure out for each standort what it is. //find all localnet entries if ((sa.LowVoltageTotalElectricity + sa.HighVoltageTotalElectricity) > 0) { hsl.ElectricityUse += sa.LowVoltageTotalElectricity + sa.HighVoltageTotalElectricity; hsl.ElectricityUseDayHigh += sa.HighVoltageElectricityUseDaytime; hsl.ElectricityUseDayLow += sa.LowVoltageElectricityUseDaytime; hsl.ElectricityUseNightHigh += sa.HighVoltageElectricityUseNighttime; hsl.ElectricityUseNightLow += sa.LowVoltageElectricityUseNighttime; double sum = hsl.ElectricityUseDayHigh + hsl.ElectricityUseDayLow + hsl.ElectricityUseNightHigh + hsl.ElectricityUseNightLow; if (Math.Abs(hsl.ElectricityUse - sum) > 0.00001) { throw new FlaException("invalid addition"); } if (sa.Rechnungsart == "Oeffentliche Beleuchtung") { var sle = new StreetLightingEntry { HouseGuid = h.HouseGuid, YearlyElectricityUse = sa.LowVoltageTotalElectricity + sa.HighVoltageTotalElectricity, LightingGuid = Guid.NewGuid().ToString() }; dbHouse.Save(sle); } else if (sa.BusinessCategory == "Immobilien") { var bi = MakePotentialBuildingInfrastructureEntry(h, sa); dbHouse.Save(bi); } else if (sa.IsBusiness()) { var be = MakeBusinessEntry(sa, h, hausanschlusses); dbHouse.Save(be); } else if (sa.Rechnungsart == "Haushalt (P 42/45/48/51)" || sa.Rechnungsart == "Haushalt (P 43/46/49/52)" || sa.Rechnungsart == "Haushalt (P 41/44/47/50)") { var hh = MakePotentialHouseholds(h, sa, hausanschlusses); dbHouse.Save(hh); } else { throw new Exception("Unknown rechnungsart: " + sa.Rechnungsart); } } if (sa.GasUse > 0) { if (sa.GasUse > 1000) { var hse = new PotentialHeatingSystemEntry(h.HouseGuid, Guid.NewGuid().ToString(), sa.IsnID) { YearlyGasDemand = sa.GasUse, HeatingSystemType = HeatingSystemType.GasheatingLocalnet }; dbHouse.Save(hse); } else { var hse = new PotentialCookingSystemEntry(h.HouseGuid, Guid.NewGuid().ToString(), sa.Standort) { YearlyGasDemand = sa.GasUse, HeatingSystemType = HeatingSystemType.GasheatingLocalnet }; dbHouse.Save(hse); } hsl.GasUse += sa.GasUse; } if (sa.FernWärme > 0) { var hse = new PotentialHeatingSystemEntry(h.HouseGuid, Guid.NewGuid().ToString(), sa.IsnID) { YearlyFernwärmeDemand = sa.FernWärme, HeatingSystemType = HeatingSystemType.FernwärmeLocalnet }; dbHouse.Save(hse); hsl.WärmeUse += sa.FernWärme; } } dbHouse.Save(hsl); } dbHouse.CompleteTransaction(); }
private static PotentialBuildingInfrastructure MakePotentialBuildingInfrastructureEntry([NotNull] House h, [NotNull] StandortAnalysis sa) { var bi = new PotentialBuildingInfrastructure(h.Guid, sa.BusinessPartnerName, sa.LowVoltageTotalElectricity, sa.HighVoltageTotalElectricity, sa.LowVoltageElectricityEntries, sa.HighVoltageElectricityEntries, sa.Standort, Guid.NewGuid().ToString()); return(bi); }