protected override void RunActualProcess() { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice); dbHouse.RecreateTable <Household>(); //load data var potentialHouseholds = dbHouse.Fetch <PotentialHousehold>(); var houses = dbHouse.Fetch <House>(); var validIsns = houses.SelectMany(x => x.Hausanschluss.Select(y => y.Isn)).ToHashSet(); Debug("Total valid isns: " + validIsns.Count); potentialHouseholds.Sort((x, y) => y.YearlyElectricityUse.CompareTo(x.YearlyElectricityUse)); var count = 0; if (potentialHouseholds.Count < HouseholdAccordingToStadtverwaltung) { throw new Exception("Not enough potential households found: potential:" + potentialHouseholds.Count + " needed minimum: " + HouseholdAccordingToStadtverwaltung); } dbHouse.BeginTransaction(); const int randomlyChosenHa = 0; const int reassignedHAs = 0; int chosenHouseholds = 0; foreach (var potentialHousehold in potentialHouseholds) { if (count < HouseholdAccordingToStadtverwaltung) { //make household var hh = new Household(potentialHousehold); chosenHouseholds++; dbHouse.Save(hh); } else { var pbi = new PotentialBuildingInfrastructure(potentialHousehold.HouseGuid, potentialHousehold.BusinessPartnerName, potentialHousehold.YearlyElectricityUse, 0, potentialHousehold.LocalnetEntries, new List <Localnet>(), potentialHousehold.Standort, Guid.NewGuid().ToString()); dbHouse.Save(pbi); } count++; } if (chosenHouseholds != HouseholdAccordingToStadtverwaltung) { throw new FlaException("Wrong number of households"); } 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); dbHouse.CompleteTransaction(); }
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); }
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); }
protected override void RunActualProcess() { SqlConnection.RecreateTable <Household>(Stage.Houses, Constants.PresentSlice); const int householdAccordingToStadtverwaltung = 8081; var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; //load data var potentialHouseholds = dbHouse.Fetch <PotentialHousehold>(); var houses = dbHouse.Fetch <House>(); var hausanschlusses = dbHouse.Fetch <Hausanschluss>(); var validIsns = houses.SelectMany(x => x.Hausanschluss.Select(y => y.Isn)).ToHashSet(); Info("Total valid isns: " + validIsns.Count); potentialHouseholds.Sort((x, y) => y.YearlyElectricityUse.CompareTo(x.YearlyElectricityUse)); var count = 0; if (potentialHouseholds.Count < householdAccordingToStadtverwaltung) { throw new Exception("Not enough potential households found: potential:" + potentialHouseholds.Count + " needed minimum: " + householdAccordingToStadtverwaltung); } List <int> invalidIsns = new List <int>(); dbHouse.BeginTransaction(); int randomlyChosenHa = 0; int reassignedHAs = 0; foreach (var potentialHousehold in potentialHouseholds) { if (count < householdAccordingToStadtverwaltung) { //make household var hh = new Household(potentialHousehold); int validisn = 0; foreach (int hhIsn in hh.OriginalISNs) { if (!validIsns.Contains(hhIsn)) { invalidIsns.Add(hhIsn); } else { validisn = hhIsn; } } var house = houses.Single(x => x.HouseGuid == hh.HouseGuid); if (validisn == 0) { hh.FinalIsn = house.Hausanschluss[0].Isn; } else { hh.FinalIsn = validisn; } var ha = hausanschlusses.Where(x => x.HouseGuid == hh.HouseGuid && x.Isn == hh.FinalIsn).ToList(); if (ha.Count == 0) { //throw new FlaException("Kein Hausanschluss gefunden."); reassignedHAs++; hh.HausAnschlussGuid = house.Hausanschluss[0].HausanschlussGuid; } if (ha.Count == 1) { hh.HausAnschlussGuid = ha[0].HausanschlussGuid; } if (ha.Count > 1) { randomlyChosenHa++; hh.HausAnschlussGuid = ha[Services.Rnd.Next(ha.Count)].HausanschlussGuid; //throw new FlaException("zu viele Hausanschlüsse gefunden.: " + ha.Count); } dbHouse.Save(hh); } else { var pbi = new PotentialBuildingInfrastructure { HouseGuid = potentialHousehold.HouseGuid, Geschäftspartner = potentialHousehold.BusinessPartnerName, LowVoltageTotalElectricityDemand = potentialHousehold.YearlyElectricityUse }; dbHouse.Save(pbi); } count++; } 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(); }
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(); }
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); }