protected override Prosumer ProvidePrivateProfile([NotNull] ProviderParameterDto ppdto) { DHWHeaterEntry dhw = (DHWHeaterEntry)ppdto.HouseComponent; if (dhw.HouseComponentType != HouseComponentType.Dhw) { throw new FlaException("Wrong type"); } ppdto.HouseComponentResultObject.DhwSystemType = dhw.DhwHeatingSystemType.ToString(); if (dhw.DhwHeatingSystemType != DhwHeatingSystem.Electricity && dhw.DhwHeatingSystemType != DhwHeatingSystem.Heatpump) { ppdto.HouseComponentResultObject.HeatingSystemMessage = "Not electric heating"; return(null); } Hausanschluss ha = _dbDto.Hausanschlusse.Single(x => x.Guid == dhw.HausAnschlussGuid); var pa = new Prosumer(dhw.HouseGuid, dhw.Name, dhw.HouseComponentType, dhw.SourceGuid, dhw.FinalIsn, dhw.HausAnschlussGuid, ha.ObjectID, GenerationOrLoad.Load, ha.Trafokreis, Name, "DHW Profile Generator"); //todo: randomize this with buckets and/or simulate a central control int startTime = 2 * 4 + Services.Rnd.Next(12); int stopTime = startTime + 3 * 4 + Services.Rnd.Next(12); //double targetRuntimePerDay = 3*4 + Services.Rnd.NextDouble() * 4; double trigger = 1 - 0.05 * Services.Rnd.NextDouble(); DhwCalculationParameters dhwCalculationParameters = new DhwCalculationParameters(startTime, stopTime, trigger); var dhwResult = _dhw.Run(dhwCalculationParameters, dhw.EffectiveEnergyDemand, Services.Rnd); pa.Profile = dhwResult.GetEnergyDemandProfile(); return(pa); }
protected override void RunActualProcess() { SqlConnection.RecreateTable <DHWHeaterEntry>(Stage.Houses, Constants.PresentSlice); var dbHouses = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; var houses = dbHouses.Fetch <House>(); var houseHeatings = dbHouses.Fetch <HouseHeating>(); if (houseHeatings.All(x => x.KantonDhwMethods.Count == 0)) { throw new Exception("not a single dhw heating method was set"); } if (houseHeatings.All(x => x.KantonHeatingMethods.Count == 0)) { throw new Exception("not a single space heating method was set"); } dbHouses.BeginTransaction(); foreach (var house in houses) { var hausanschluss = house.Hausanschluss[0]; var dhwHeaterEntry = new DHWHeaterEntry(house.HouseGuid, Guid.NewGuid().ToString(), hausanschluss.HausanschlussGuid, house.ComplexName); var houseHeating = houseHeatings.Single(x => x.HouseGuid == house.HouseGuid); var heatingMethod = HeatingSystemType.Unbekannt; if (houseHeating.KantonDhwMethods.Count > 0) { heatingMethod = houseHeating.KantonDhwMethods[0]; } if (Constants.ScrambledEquals(houseHeating.KantonHeatingMethods, houseHeating.KantonDhwMethods)) { dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.IntegratedInHeating; } else { switch (heatingMethod) { case HeatingSystemType.Electricity: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; // electricity at night break; case HeatingSystemType.SolarThermal: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Sonne; break; case HeatingSystemType.Gas: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Gasheating; break; case HeatingSystemType.Heatpump: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Heatpump; break; case HeatingSystemType.Fernwärme: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.DistrictHeating; break; case HeatingSystemType.Other: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Other; break; case HeatingSystemType.None: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Unknown; break; case HeatingSystemType.Öl: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.OilHeating; break; case HeatingSystemType.Holz: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Wood; break; case HeatingSystemType.Unbekannt: break; case HeatingSystemType.GasheatingLocalnet: break; case HeatingSystemType.FernwärmeLocalnet: break; case HeatingSystemType.FeuerungsstättenOil: break; case HeatingSystemType.FeuerungsstättenGas: break; case HeatingSystemType.Kohle: break; default: throw new Exception("Unknown heating method: " + heatingMethod); } } dbHouses.Save(dhwHeaterEntry); } dbHouses.CompleteTransaction(); }
protected override void RunActualProcess() { var dbHouses = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice); dbHouses.RecreateTable <DHWHeaterEntry>(); var houses = dbHouses.Fetch <House>(); var households = dbHouses.Fetch <Household>(); var houseHeatings = dbHouses.Fetch <HouseHeating>(); var hausanschlusses = dbHouses.Fetch <Hausanschluss>(); if (houseHeatings.All(x => x.KantonDhwMethods.Count == 0)) { throw new Exception("not a single dhw heating method was set"); } if (houseHeatings.All(x => x.KantonHeatingMethods.Count == 0)) { throw new Exception("not a single space heating method was set"); } RowCollection rc = new RowCollection("Sheet1", "Sheet1"); dbHouses.BeginTransaction(); foreach (var house in houses) { var householdInHouse = households.Where(x => x.HouseGuid == house.Guid).ToList(); var occupantsInHouse = householdInHouse.SelectMany(x => x.Occupants).ToList(); var dhwHeaterEntry = new DHWHeaterEntry(house.Guid, Guid.NewGuid().ToString(), "DHW@" + house.ComplexName); var houseHeating = houseHeatings.Single(x => x.HouseGuid == house.Guid); var heatingMethod = HeatingSystemType.Unbekannt; if (houseHeating.KantonDhwMethods.Count > 0) { heatingMethod = houseHeating.GetDominantDhwHeatingMethod(); } var peopleInHouse = occupantsInHouse.Count; RowBuilder rb = RowBuilder.Start("House", house.ComplexName); rc.Add(rb); rb.Add("Households", households.Count); rb.Add("Persons", occupantsInHouse.Count); rb.Add("Ebbe DHW Estimate", houseHeating.KantonWarmwasserEnergyDemand); switch (heatingMethod) { case HeatingSystemType.Electricity: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; // electricity at night break; case HeatingSystemType.SolarThermal: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; break; case HeatingSystemType.Gas: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Gasheating; break; case HeatingSystemType.Heatpump: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; break; case HeatingSystemType.Fernwärme: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.DistrictHeating; break; case HeatingSystemType.Other: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; break; case HeatingSystemType.None: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.None; break; case HeatingSystemType.Öl: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.OilHeating; break; case HeatingSystemType.Holz: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; break; case HeatingSystemType.Unbekannt: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; break; case HeatingSystemType.GasheatingLocalnet: dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Gasheating; break; case HeatingSystemType.FernwärmeLocalnet: throw new Exception("Unknown heating method: " + heatingMethod); case HeatingSystemType.FeuerungsstättenOil: throw new Exception("Unknown heating method: " + heatingMethod); case HeatingSystemType.FeuerungsstättenGas: throw new Exception("Unknown heating method: " + heatingMethod); case HeatingSystemType.Kohle: throw new Exception("Unknown heating method: " + heatingMethod); default: throw new Exception("Unknown heating method: " + heatingMethod); } rb.Add("Heating Method", dhwHeaterEntry.DhwHeatingSystemType); double totalEnergy = 0; double dhwEnergy = 0; Hausanschluss hausanschluss; string hausanschlussGuid = null; string standort = null; foreach (var hh in householdInHouse) { double personEnergy = hh.EffectiveEnergyDemand / hh.Occupants.Count; if (personEnergy > 1800) { dhwHeaterEntry.DhwHeatingSystemType = DhwHeatingSystem.Electricity; } } foreach (var hh in householdInHouse) { double hhdhwEnergy = 0; double personEnergy = hh.EffectiveEnergyDemand / hh.Occupants.Count; if (dhwHeaterEntry.DhwHeatingSystemType == DhwHeatingSystem.Electricity) { hhdhwEnergy = CalculateDHWEnergy(personEnergy) * hh.Occupants.Count; } var rbhh = RowBuilder.Start("household", hh.Name); rbhh.Add("Persons", hh.Occupants.Count); rbhh.Add("Energy Per Person in Household [kWh]", hhdhwEnergy); rbhh.Add("Household DHW heating method", dhwHeaterEntry.DhwHeatingSystemType); rbhh.Add("Household Energy", hh.EffectiveEnergyDemand); rc.Add(rbhh); if (Math.Abs(hh.EffectiveEnergyDemand - hh.LocalnetLowVoltageYearlyTotalElectricityUse) > 0.1) { if (Math.Abs(hh.EffectiveEnergyDemand - (hh.LocalnetLowVoltageYearlyTotalElectricityUse + dhwEnergy)) > 0.1) { throw new FlaException("Energy use does not fit"); } } hh.SetEnergyReduction("DHW", hhdhwEnergy); if (hh.EffectiveEnergyDemand < 0) { throw new FlaException("Effective Energy demand was null"); } totalEnergy += hh.EffectiveEnergyDemand; hausanschlussGuid = hh.HausAnschlussGuid; standort = hh.Standort; dbHouses.Save(hh); dhwEnergy += hhdhwEnergy; } if (hausanschlussGuid != null) { hausanschluss = hausanschlusses.Single(x => x.Guid == hausanschlussGuid); } else { hausanschluss = house.GetHausanschlussByIsn(new List <int>(), null, hausanschlusses, MyLogger) ?? throw new FlaException("no hausanschluss"); } dhwHeaterEntry.Standort = standort; dhwHeaterEntry.HausAnschlussGuid = hausanschluss.Guid; dhwHeaterEntry.EffectiveEnergyDemand = dhwEnergy; if (totalEnergy < 0) { throw new FlaException("Negative total energy"); } rb.Add("Total Energy Originally [kWh]", totalEnergy); rb.Add("Total Energy DHW [kWh]", dhwEnergy); rb.Add("DHW Power [kWh]", dhwEnergy / 365 / 2); rb.Add("Total Energy After Dhw [kWh]", totalEnergy - dhwEnergy); rb.Add("Energy Per Person [kWh]", totalEnergy / peopleInHouse); dbHouses.Save(dhwHeaterEntry); } dbHouses.CompleteTransaction(); var hhdump = MakeAndRegisterFullFilename("Households.xlsx", Constants.PresentSlice); XlsxDumper.WriteToXlsx(hhdump, rc); }