private void HouseCountsPerTrafokreis([NotNull][ItemNotNull] List <CSVFile> files, [NotNull] ScenarioSliceParameters parameters) { string suffix = files[0].GenerationOrLoad.ToString(); var column = 0; var names = new List <string>(); var countSeries = new List <BarSeriesEntry>(); foreach (var pair in files) { countSeries.Add(BarSeriesEntry.MakeBarSeriesEntry("", pair.Lines.Count, column++)); names.Add(pair.TsName); } var filename1 = MakeAndRegisterFullFilename("TrafokreisHouseCount" + suffix + ".png", parameters); Services.PlotMaker.MakeBarChart(filename1, "TrafokreisHouseCount", countSeries, names); var electricitySeries = new List <BarSeriesEntry>(); column = 0; const double factor = 1_000_000; foreach (var pair in files) { electricitySeries.Add(BarSeriesEntry.MakeBarSeriesEntry("", pair.CalculateTotalEnergy() / factor, column++)); } var filename2 = MakeAndRegisterFullFilename("TrafokreisHouseElectricity" + suffix + ".png", parameters); Services.PlotMaker.MakeBarChart(filename2, "Energie [GWh]", electricitySeries, names); }
private void MakeOneAnalysis([NotNull] List <double> areas, int bucketSize, [NotNull] string baseName, [NotNull] string sectionDescription, [NotNull] ScenarioSliceParameters slice) { { var maxArea = areas.Max(); var histogram = new Histogram(); for (var i = 0; i < bucketSize * 10; i += bucketSize) { histogram.AddBucket(new Bucket(i, i + bucketSize)); } if (maxArea > bucketSize * 10) { histogram.AddBucket(new Bucket(bucketSize * 10, maxArea)); } histogram.AddData(areas); string histogramfilename = MakeAndRegisterFullFilename(baseName + "_Histogram.png", Name, sectionDescription, slice); var bs = BarSeriesEntry.MakeBarSeriesEntry(histogram, out var colNames); var bss = new List <BarSeriesEntry> { bs }; Services.PlotMaker.MakeBarChart(histogramfilename, "Anzahl von Haushalten mit Fläche in diesem Bereich", bss, colNames); } { string dstFileName2 = MakeAndRegisterFullFilename(baseName + "_SortedAreas.png", Name, sectionDescription, slice); var lse = new LineSeriesEntry("Sorted"); var sorted = areas.ToList(); sorted.Sort(); for (var i = 0; i < sorted.Count; i++) { lse.Values.Add(new Point(i, sorted[i])); } var lss = new List <LineSeriesEntry> { lse }; Services.PlotMaker.MakeLineChart(dstFileName2, "", lss, new List <PlotMaker.AnnotationEntry>()); } { string dstFileName2 = MakeAndRegisterFullFilename(baseName + "_Kumulativ.png", Name, sectionDescription, slice); var lse = new LineSeriesEntry("Kumulativ"); var sorted = areas.ToList(); sorted.Sort(); double tempSum = 0; for (var i = 0; i < sorted.Count; i++) { tempSum += sorted[i]; lse.Values.Add(new Point(i, tempSum)); } var lss = new List <LineSeriesEntry> { lse }; Services.PlotMaker.MakeLineChart(dstFileName2, "", lss, new List <PlotMaker.AnnotationEntry>()); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouses = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var dbRaw = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var houses = dbHouses.Fetch <House>(); var pvPotentials = dbHouses.Fetch <PVPotential>(); var heatingsystems = dbHouses.Fetch <HeatingSystemEntry>(); List <SonnenDach> sonnendach = dbRaw.Fetch <SonnenDach>(); HashSet <string> houseGuidsForSystemsWithPV = new HashSet <string>(); Dictionary <string, double> pvPotentialByHouseGuid = new Dictionary <string, double>(); foreach (var house in houses) { pvPotentialByHouseGuid.Add(house.Guid, 0); } foreach (var pvpot in pvPotentials) { if (!houseGuidsForSystemsWithPV.Contains(pvpot.HouseGuid) && pvpot.SonnendachStromErtrag > 0) { houseGuidsForSystemsWithPV.Add(pvpot.HouseGuid); } pvPotentialByHouseGuid[pvpot.HouseGuid] += pvpot.SonnendachStromErtrag; } PVPotentialSankey(); MakePhotovoltaicDemandComparison(); MakePvSystemSankey(); MakePhotovoltaicSystemMap(); MakePvPowerSankey(); MakeHousePhotovotaikPoowerAufHousesMitLocalnet(); MakeHousePhotovotaikAufHouses(); MakeHousePhotovotaikAufHousesMitLocalnet(); void PVPotentialSankey() { var ssa = new SingleSankeyArrow("PVPotentialSankey", 1000, MyStage, SequenceNumber, Name, slice, Services); const double fac = 1_000_000; double sonnendachPotential = sonnendach.Sum(x => x.stromertrag); ssa.AddEntry(new SankeyEntry("PVPotential", sonnendachPotential / fac, 5000, Orientation.Straight)); var housesPotential = houses.Sum(x => pvPotentialByHouseGuid[x.Guid]); var diff = sonnendachPotential - housesPotential; ssa.AddEntry(new SankeyEntry("Auf Häusern", housesPotential * -1 / fac, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Sonstiges", diff / fac * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeHousePhotovotaikAufHousesMitLocalnet() { var ssa = new SingleSankeyArrow("HouseSankeyFürPvZuordnungMitLocalnet", 1000, MyStage, SequenceNumber, nameof(PVPotentialSankey), slice, Services); ssa.AddEntry(new SankeyEntry("Complexes", houses.Count, 5000, Orientation.Straight)); var housesMitGebäude = houses.Where(x => houseGuidsForSystemsWithPV.Contains(x.Guid) && x.GebäudeObjectIDs.Count > 0).ToList(); var countHousesMitGebäude = housesMitGebäude.Count; var housesTotal = houses.Count; ssa.AddEntry(new SankeyEntry("Gebäude mit Objektids und PV", countHousesMitGebäude * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Gebäude ohne Objektids und/oder ohne PV", (housesTotal - countHousesMitGebäude) * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeHousePhotovotaikAufHouses() { var ssa = new SingleSankeyArrow("HouseSankeyFürPvZuordnung", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Complexes", houses.Count, 5000, Orientation.Straight)); var housesMitGebäude = houses.Where(x => houseGuidsForSystemsWithPV.Contains(x.Guid)).ToList(); var countHousesMitGebäude = housesMitGebäude.Count; var housesTotal = houses.Count; ssa.AddEntry(new SankeyEntry("Gebäude mit PV", countHousesMitGebäude * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Gebäude ohne PV", (housesTotal - countHousesMitGebäude) * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakePhotovoltaicSystemMap() { RGB GetColor(House h) { if (pvPotentials.Any(x => x.HouseGuid == h.Guid)) { return(Constants.Green); } return(Constants.Blue); } var mapColors = houses.Select(x => x.GetMapColorForHouse(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("PotentialPVSystems.png", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Hat PV Potential", Constants.Green), new MapLegendEntry("Hat kein PV", Constants.Blue), new MapLegendEntry("Hat kein Daten", Constants.Red) }; Services.PlotMaker.MakeOsmMap(Name, filename, mapColors, new List <WgsPoint>(), legendEntries, new List <LineEntry>()); SaveToPublicationDirectory(filename, slice, "4"); } void MakePvSystemSankey() { var ssa = new SingleSankeyArrow("HousePVPotentialSystems", 1500, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight)); var houseguidsWithPV = pvPotentials.Select(x => x.HouseGuid).Distinct().ToList(); ssa.AddEntry(new SankeyEntry("PVSystems", houseguidsWithPV.Count * -1, 2000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Kein PV", (houses.Count - houseguidsWithPV.Count) * -1, 2000, Orientation.Straight)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakePvPowerSankey() { var sonnendachRaw = dbRaw.Fetch <SonnenDach>(); double rawSum = sonnendachRaw.Sum(x => x.stromertrag); const double fac = 1_000_000; var ssa = new SingleSankeyArrow("HousePVPowerSystems", 1500, MyStage, SequenceNumber, Name, slice, Services); var installed = pvPotentials.Sum(x => x.SonnendachStromErtrag); ssa.AddEntry(new SankeyEntry("Gesamt", rawSum / fac, 5000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("PV Systems", installed * -1 / fac, 2000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Kein PV", (rawSum - installed) * -1 / fac, 2000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeHousePhotovotaikPoowerAufHousesMitLocalnet() { var ssa = new SingleSankeyArrow("HouseSankeyFürPvPowerZuordnung", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Complexes", houses.Count, 5000, Orientation.Straight)); var housesMitGebäude = houses.Where(x => houseGuidsForSystemsWithPV.Contains(x.Guid) && x.GebäudeObjectIDs.Count > 0).ToList(); var countHousesMitGebäude = housesMitGebäude.Count; var housesTotal = houses.Count; ssa.AddEntry(new SankeyEntry("Gebäude mit Objektids und PV", countHousesMitGebäude * -1, 5000, Orientation.Up)); ssa.AddEntry( new SankeyEntry("Gebäude ohne Objektids und ohne PV", (housesTotal - countHousesMitGebäude) * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); RGB GetColor(House h) { if (h.GebäudeObjectIDs.Count > 0 && houseGuidsForSystemsWithPV.Contains(h.Guid)) { return(new RGB(255, 0, 0)); } if (h.GebäudeObjectIDs.Count > 0) { return(new RGB(0, 0, 255)); } return(new RGB(0, 255, 0)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("MapPVWithLocalnet.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Localnet und Solar", 255, 0, 0), new MapLegendEntry("Localnet Daten verfügbar", 0, 0, 255), new MapLegendEntry("Rest", 0, 255, 0) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakePhotovoltaicDemandComparison() { var differenceInPower = new List <double>(); foreach (var heatingSystemEntry in heatingsystems) { if (heatingSystemEntry.OriginalHeatingSystemType == HeatingSystemType.GasheatingLocalnet) { continue; } var pvpotentialentries = pvPotentials.Where(x => x.HouseGuid == heatingSystemEntry.HouseGuid).ToList(); var energysum = pvpotentialentries.Sum(x => x.SonnendachBedarfHeizung + x.SonnendachBedarfWarmwasser); var h = houses.Single(x => x.Guid == heatingSystemEntry.HouseGuid); if (energysum > 0 && heatingSystemEntry.EffectiveEnergyDemand > 0 && h.EnergieBezugsFläche > 0) { var diff = (energysum - heatingSystemEntry.EffectiveEnergyDemand) / h.EnergieBezugsFläche; if (diff > 500) { diff = 500; } if (diff < -500) { diff = -500; } differenceInPower.Add(diff); } } differenceInPower.Sort(); var barSeries = new List <BarSeriesEntry>(); var bs = BarSeriesEntry.MakeBarSeriesEntry("differences"); bs.Values.AddRange(differenceInPower); barSeries.Add(bs); var filename = MakeAndRegisterFullFilename("ComparisonSonnendachVsReal.svg", slice); var labes = new List <string>(); Services.PlotMaker.MakeBarChart(filename, "ComparisonSonnendachVsReal", barSeries, labes, ExportType.SVG); } }
protected override void RunChartMaking() { var dbComplex = SqlConnection.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice).Database; var dbComplexEnergie = SqlConnection.GetDatabaseConnection(Stage.ComplexEnergyData, Constants.PresentSlice).Database; var complexes = dbComplex.Fetch <BuildingComplex>(); var dbRaw = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database; var ebbe = dbRaw.Fetch <EnergiebedarfsdatenBern>(); //var complexes = dbComplex.Fetch<BuildingComplex>(); var complexBuildingData = dbComplexEnergie.Fetch <ComplexBuildingData>(); MakeComplexAreaSankey(Constants.PresentSlice); //var sonnendach = dbRaw.Fetch<SonnenDach>(); MakeBuildingSizeComplex(Constants.PresentSlice); SizeHistogram(); MovedCharts(); void MakeBuildingSizeComplex(ScenarioSliceParameters slice) { var ssa = new SingleSankeyArrow("BuildingSizeComplex", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice); ssa.AddEntry(new SankeyEntry("Complexes", complexes.Count, 2000, Orientation.Straight)); var complexWithOneBuilding = complexes.Count(x => x.EGids.Count == 1); var complexWithTwoBuilding = complexes.Count(x => x.EGids.Count == 2); var complexWithThreeBuilding = complexes.Count(x => x.EGids.Count == 3); var complexWithManyBuilding = complexes.Count(x => x.EGids.Count > 3); ssa.AddEntry(new SankeyEntry("Komplexe mit 1 Gebäude", complexWithOneBuilding * -1, 1000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Komplexe mit 2 Gebäuden", complexWithTwoBuilding * -1, 2000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Komplexe mit 3 Gebäuden", complexWithThreeBuilding * -1, 3000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Komplexe mit mehr als 3 Gebäuden", complexWithManyBuilding * -1, 3000, Orientation.Up)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeComplexAreaSankey(ScenarioSliceParameters slice) { var ssa = new SingleSankeyArrow("ComplexSankeyTotalArea", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice); var ebbeEnergieBezugsfläche = ebbe.Select(x => x.upd_ebf).Sum() / 1000; var complexBuildingDataArea = complexBuildingData.Select(x => x.TotalEnergieBezugsfläche).Sum() / 1000; var diff = ebbeEnergieBezugsfläche - complexBuildingDataArea; ssa.AddEntry(new SankeyEntry("Ebbe EBF", ebbeEnergieBezugsfläche, 5000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Complex EBF ", complexBuildingDataArea * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Fehlend", diff * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void SizeHistogram() { var counts = new Dictionary <int, int>(); foreach (var complex in complexes) { if (!counts.ContainsKey(complex.EGids.Count)) { counts.Add(complex.EGids.Count, 0); } counts[complex.EGids.Count]++; } var filename = MakeAndRegisterFullFilename("EgidPerComplexHistogram.png", Name, "", Constants.PresentSlice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); var column = 0; foreach (var pair in counts) { names.Add(pair.Value.ToString()); var count = pair.Value; barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(pair.Key.ToString(), count, column)); column++; } Services.PlotMaker.MakeBarChart(filename, "", barSeries, names); } //read database var dbComplexEnergy = SqlConnection.GetDatabaseConnection(Stage.ComplexEnergyData, Constants.PresentSlice).Database; var monthlyElectricityUsePerStandorts = dbComplexEnergy.Fetch <MonthlyElectricityUsePerStandort>(); var localnetData = dbRaw.Fetch <Localnet>(); var coords = 0; foreach (var complex in complexes) { coords += complex.Coords.Count; } Log(MessageType.Info, "UsedCoords = " + coords); var arrows = new List <SingleSankeyArrow>(); arrows.AddRange(MakeElectricityArrow(complexes, localnetData, monthlyElectricityUsePerStandorts, MyStage)); arrows.AddRange(MakeGasArrow(complexes, localnetData, monthlyElectricityUsePerStandorts)); arrows.AddRange(MakeFernwärmeArrow(complexes, localnetData, monthlyElectricityUsePerStandorts)); Directory.SetCurrentDirectory(Constants.BasePath); foreach (var arrow in arrows) { Services.PlotMaker.MakeSankeyChart(arrow); } }
protected override void RunChartMaking() { var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; var houses = dbHouse.Fetch <House>(); var energyUses = dbHouse.Fetch <HouseSummedLocalnetEnergyUse>(); var households = dbHouse.Fetch <Household>(); MakeTrafoKreisMapForNonTrafoKreisHouses(Constants.PresentSlice); MakeTrafoKreisMap(Constants.PresentSlice); MakeTrafoKreisMapForElectricityUsers(Constants.PresentSlice); MakeBarChartEnergyPertrafokreis(Constants.PresentSlice); MakeBarChartHouseholdsPertrafokreis(Constants.PresentSlice); MakeBarChartHousesPerTrafokreis(Constants.PresentSlice); MakeSankeyEnergyChartPertrafokreis(Constants.PresentSlice); void MakeSankeyEnergyChartPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); //List<string> categoryLabels = new List<string>(); var energyPerTk = new Dictionary <string, double>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); double sumElectricity = 0; foreach (var tkHouse in tkHouses) { var eu = energyUses.Single(x => x.HouseGuid == tkHouse.HouseGuid); sumElectricity += eu.ElectricityUse; } // categoryLabels.Add(tk); var tkSp = tk ?? ""; if (energyPerTk.ContainsKey(tkSp)) { energyPerTk[tkSp] += sumElectricity; } else { energyPerTk.Add(tkSp, sumElectricity); } } var energysum = energyPerTk.Values.Sum() / 1000000; var energySumAssigned = energyPerTk.Where(x => !string.IsNullOrWhiteSpace(x.Key)).Select(x => x.Value).Sum() / 1000000; var diff = energysum - energySumAssigned; var ssa = new SingleSankeyArrow("EnergyInAssignedTks", 500, MyStage, SequenceNumber, Name, Services.Logger, slice); ssa.AddEntry(new SankeyEntry("Strom Gesamt", energysum, 200, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("An Trafokreisen", energySumAssigned * -1, 200, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Nicht an Trafokreisen", diff * -1, 200, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeBarChartHousesPerTrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, tkHouses.Count, i); barseries.Add(bse); } var filename = MakeAndRegisterFullFilename("HousesProTrafokreis.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "", barseries, categoryLabels); } void MakeBarChartHouseholdsPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); var tkhouseholdCount = 0; foreach (var tkHouse in tkHouses) { var householdsCount = households.Where(x => x.HouseGuid == tkHouse.HouseGuid).Count(); tkhouseholdCount += householdsCount; } categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, tkhouseholdCount, i); barseries.Add(bse); } var filename = MakeAndRegisterFullFilename("HouseholdsProTrafokreis.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "", barseries, categoryLabels); } void MakeBarChartEnergyPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var filenameCsv = MakeAndRegisterFullFilename("StromProTrafokreis.csv", Name, "", slice); using (var sw = new StreamWriter(filenameCsv)) { var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); double sumElectricity = 0; foreach (var tkHouse in tkHouses) { var eu = energyUses.Single(x => x.HouseGuid == tkHouse.HouseGuid); sumElectricity += eu.ElectricityUse; } categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, sumElectricity, i); barseries.Add(bse); sw.WriteLine(tk + ";" + sumElectricity); } var filename = MakeAndRegisterFullFilename("StromProTrafokreis.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "", barseries, categoryLabels); sw.Close(); } } void MakeTrafoKreisMap(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var cg = new ColorGenerator(); RGB GetColor(House h) { var idx = trafokreise.IndexOf(h.TrafoKreis); return(cg.GetRGB(idx)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("Trafokreise.svg", Name, "", slice); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage); } void MakeTrafoKreisMapForElectricityUsers(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var cg = new ColorGenerator(); RGB GetColor(House h) { if (h.GebäudeObjectIDs.Count == 0) { return(new RGB(240, 240, 240)); } var idx = trafokreise.IndexOf(h.TrafoKreis); return(cg.GetRGB(idx)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("TrafokreiseEbbeLightgrey.svg", Name, "", slice); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage); } void MakeTrafoKreisMapForNonTrafoKreisHouses(ScenarioSliceParameters slice) { RGBWithSize GetColor(House h) { var eu = energyUses.Single(x => x.HouseGuid == h.HouseGuid); var energy = eu.ElectricityUse / 1_000_000; if (energy < 10) { energy = 10; } if (string.IsNullOrWhiteSpace(h.TrafoKreis)) { return(new RGBWithSize(255, 0, 0, (int)energy)); } return(new RGBWithSize(0, 0, 0, 10)); } var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("HousesWithoutTrafoKreisEnergyUse.svg", Name, "", slice); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage); } }
protected override void RunChartMaking() { var slice = Constants.PresentSlice; var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; var houses = dbHouse.Fetch <House>(); var occupants = dbHouse.Fetch <Occupant>(); var outgoingCommuters = dbHouse.Fetch <OutgoingCommuterEntry>(); var carDistances = dbHouse.Fetch <CarDistanceEntry>(); MakeCarDistanceHistogram(); MakeCommuterSankey(); MakeCommuterMap(); MakeCommuterDistanceHistogram(); MakeCommuterDistanceHistogramNonBurgdorf(); void MakeCommuterSankey() { var ssa = new SingleSankeyArrow("OutgoingCommuters", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice); ssa.AddEntry(new SankeyEntry("Einwohner", occupants.Count, 5000, Orientation.Straight)); var workersOutside = outgoingCommuters.Count(x => x.DistanceInKm > 0); var workersBurgdorf = outgoingCommuters.Count(x => Math.Abs(x.DistanceInKm) < 0.000001); var unemployed = occupants.Count - workersOutside - workersBurgdorf; ssa.AddEntry(new SankeyEntry("Ohne Anstellung", unemployed * -1, 2000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Pendler aus Burgdorf", workersOutside * -1, 2000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Arbeiter in Burgdorf", workersBurgdorf * -1, 2000, Orientation.Up)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeCarDistanceHistogram() { var commuterDistances = carDistances.Select(x => x.TotalDistance).ToList(); var hg = new Histogram(commuterDistances, 15); var bse = new List <BarSeriesEntry>(); var barSeries = BarSeriesEntry.MakeBarSeriesEntry(hg, out var colNames, "F1"); bse.Add(barSeries); var filename = MakeAndRegisterFullFilename("CarDistanceHistogram.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "Anzahl Autos mit dieser Entfernung", bse, colNames); } void MakeCommuterDistanceHistogram() { var commuterDistances = outgoingCommuters.Select(x => x.DistanceInKm).ToList(); var hg = new Histogram(commuterDistances, 15); var bse = new List <BarSeriesEntry>(); var barSeries = BarSeriesEntry.MakeBarSeriesEntry(hg, out var colNames, "F1"); bse.Add(barSeries); var filename = MakeAndRegisterFullFilename("OutgoingCommutersDistanceHistogram.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "Anzahl Pendler mit dieser Entfernung", bse, colNames); } void MakeCommuterDistanceHistogramNonBurgdorf() { var commuterDistances = outgoingCommuters.Where(x => x.DistanceInKm > 0).Select(x => x.DistanceInKm).ToList(); var hg = new Histogram(commuterDistances, 15); var bse = new List <BarSeriesEntry>(); var barSeries = BarSeriesEntry.MakeBarSeriesEntry(hg, out var colNames, "F1"); bse.Add(barSeries); var filename = MakeAndRegisterFullFilename("OutgoingCommutersDistanceHistogramNoBurgdorf.png", Name, "", slice); Services.PlotMaker.MakeBarChart(filename, "Anzahl Pendler mit dieser Entfernung", bse, colNames); } void MakeCommuterMap() { RGBWithSize GetColor(House h) { var outgoing = outgoingCommuters.Count(x => x.HouseGuid == h.HouseGuid); if (outgoing > 0) { return(new RGBWithSize(Constants.Red, outgoing + 10)); } return(new RGBWithSize(Constants.Black, 10)); } var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("OutgoingCommutersMap.svg", Name, "", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Arbeiter", Constants.Red), new MapLegendEntry("Keine Pendler", Constants.Black) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters parameters, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, parameters); var houses = dbHouse.Fetch <House>(); var households = dbHouse.Fetch <Household>(); var parkingSpaces = dbHouse.Fetch <ParkingSpace>(); MakeCarAmountSankey(); CarCountHistogram(); MakeCarMap(); void MakeCarAmountSankey() { var ssa = new SingleSankeyArrow("HouseholdsWithParkingSpace", 1000, MyStage, SequenceNumber, Name, parameters, Services); ssa.AddEntry(new SankeyEntry("Households", households.Count, 5000, Orientation.Straight)); var autos = parkingSpaces.Count; ssa.AddEntry(new SankeyEntry("Mit Parkieren", autos * -1, 5000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Ohne Parkieren", (households.Count - autos) * -1, 5000, Orientation.Straight)); Services.PlotMaker.MakeSankeyChart(ssa); } void CarCountHistogram() { var carCountsPerHouse = new List <int>(); foreach (var house in houses) { var carsInHouse = parkingSpaces.Where(x => x.HouseGuid == house.Guid).ToList(); carCountsPerHouse.Add(carsInHouse.Count); } var maxSize = carCountsPerHouse.Max(); var filename = MakeAndRegisterFullFilename("ParkingPerHouseHistogram.png", parameters); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); for (var i = 0; i < maxSize + 1; i++) { names.Add(i.ToString()); var j = i; var count = carCountsPerHouse.Count(x => x == j); barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(i + " Autos", count, i)); } Services.PlotMaker.MakeBarChart(filename, "", barSeries, names); } void MakeCarMap() { var mapPoints = new List <MapPoint>(); RGBWithSize GetMapPoint(House h) { var carsInHouse = parkingSpaces.Count(x => x.HouseGuid == h.Guid); return(new RGBWithSize(Constants.Red, carsInHouse + 10)); } foreach (var house in houses) { mapPoints.Add(house.GetMapPointWithSize(GetMapPoint)); } var filename = MakeAndRegisterFullFilename("AutosProHaus.svg", parameters); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } }
protected override void RunChartMaking() { var slice = Constants.PresentSlice; var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database; var houses = dbHouse.Fetch <House>(); var dhwHeaterEntries = dbHouse.Fetch <DHWHeaterEntry>(); MakeDhwHeatingSystemSankey(); HeatingSystemCountHistogram(); MakeHeatingSystemMap(); void MakeDhwHeatingSystemSankey() { var ssa = new SingleSankeyArrow("HouseDhwHeatingSystems", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice); ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight)); var counts = new Dictionary <DhwHeatingSystem, int>(); foreach (var entry in dhwHeaterEntries) { if (!counts.ContainsKey(entry.DhwHeatingSystemType)) { counts.Add(entry.DhwHeatingSystemType, 0); } counts[entry.DhwHeatingSystemType]++; } var i = 1; foreach (var pair in counts) { ssa.AddEntry(new SankeyEntry(pair.Key.ToString(), pair.Value * -1, 2000 * i, Orientation.Up)); i++; } Services.PlotMaker.MakeSankeyChart(ssa); } void HeatingSystemCountHistogram() { var counts = new Dictionary <DhwHeatingSystem, int>(); foreach (var entry in dhwHeaterEntries) { if (!counts.ContainsKey(entry.DhwHeatingSystemType)) { counts.Add(entry.DhwHeatingSystemType, 0); } counts[entry.DhwHeatingSystemType]++; } var filename = MakeAndRegisterFullFilename("DhwHeatingSystemHistogram.png", Name, "", slice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); var column = 0; foreach (var pair in counts) { names.Add(pair.Value.ToString()); var count = pair.Value; barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(pair.Key.ToString(), count, column)); column++; } Services.PlotMaker.MakeBarChart(filename, "", barSeries, names); } void MakeHeatingSystemMap() { var rgbs = new Dictionary <DhwHeatingSystem, RGB>(); var hs = dhwHeaterEntries.Select(x => x.DhwHeatingSystemType).Distinct().ToList(); var cg = new ColorGenerator(); var idx = 0; foreach (var type in hs) { rgbs.Add(type, cg.GetRGB(idx++)); } RGB GetColor(House h) { var hse = dhwHeaterEntries.Single(x => x.HouseGuid == h.HouseGuid); return(rgbs[hse.DhwHeatingSystemType]); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("DhwHeatingSystemMap.svg", Name, "", slice); var legendEntries = new List <MapLegendEntry>(); foreach (var pair in rgbs) { legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value)); } Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var houses = dbHouse.Fetch <House>(); var households = dbHouse.Fetch <Household>(); var cars = dbHouse.Fetch <Car>(); if (cars.Count == 0) { throw new FlaException("No cars found"); } MakeCarAmountSankey(); CarCountHistogram(); MakeCarMap(); void MakeCarAmountSankey() { var ssa = new SingleSankeyArrow("HouseholdsWithCar", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Households", households.Count, 5000, Orientation.Straight)); var autos = cars.Count; ssa.AddEntry(new SankeyEntry("Mit Auto", autos * -1, 5000, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Ohne Auto", (households.Count - autos) * -1, 5000, Orientation.Straight)); Services.PlotMaker.MakeSankeyChart(ssa); } void CarCountHistogram() { var carCountsPerHouse = new List <int>(); foreach (var house in houses) { var carsInHouse = cars.Where(x => x.HouseGuid == house.Guid).ToList(); carCountsPerHouse.Add(carsInHouse.Count); } var maxSize = carCountsPerHouse.Max(); var filename = MakeAndRegisterFullFilename("CarsPerHouseHistogram.png", slice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); for (var i = 0; i < maxSize + 1; i++) { names.Add(i.ToString()); var j = i; var count = carCountsPerHouse.Count(x => x == j); barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(i + " Autos", count, i)); } Services.PlotMaker.MakeBarChart(filename, "", barSeries, names); } void MakeCarMap() { var mapPoints = new List <MapPoint>(); foreach (var house in houses) { if (house.WgsGwrCoords.Count == 0) { continue; } var carsInHouse = cars.Count(x => x.HouseGuid == house.Guid); mapPoints.Add(new MapPoint(house.WgsGwrCoords[0].Lon, house.WgsGwrCoords[0].Lat, carsInHouse, carsInHouse + 10)); } var filename = MakeAndRegisterFullFilename("AutosProHaus.svg", slice); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var houses = dbHouse.Fetch <House>(); var households = dbHouse.Fetch <Household>(); if (households.Count == 0) { throw new FlaException("Not a single household"); } MakeAgeHistogram(); MakePeopleCountMap2(); MakeFamilySizeSankey(); MakePeopleCountMap(); MakeAgeMap(); void MakeAgeHistogram() { List <Occupant> occupants = households.SelectMany(x => x.Occupants).ToList(); double maxAge = occupants.Max(x => x.Age); var histogram = new Histogram(); const int bucketSize = 5; for (var i = 0; i < maxAge; i += bucketSize) { histogram.AddBucket(new Bucket(i, i + bucketSize)); } var ages = occupants.Select(x => (double)x.Age).ToList(); histogram.AddData(ages); var filename = MakeAndRegisterFullFilename("Altersverteilung.png", slice); var bs = BarSeriesEntry.MakeBarSeriesEntry(histogram, out var colNames); var bss = new List <BarSeriesEntry> { bs }; Services.PlotMaker.MakeBarChart(filename, "Anzahl von Personen in diesem Altersbereich", bss, colNames); } void MakeFamilySizeSankey() { var ssa = new SingleSankeyArrow("Households", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Households", houses.Count, 5000, Orientation.Straight)); var counts = households.Select(x => x.Occupants.Count).ToList(); var maxSize = counts.Max(); var filename = MakeAndRegisterFullFilename("HouseholdSizeHistogram.png", slice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); for (var i = 0; i < maxSize + 1; i++) { names.Add(i.ToString()); var j = i; // because of closure var count = counts.Count(x => x == j); barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(i + "Personen", count, i)); } Services.PlotMaker.MakeBarChart(filename, "HouseholdSizeHistogram", barSeries, names); } void MakePeopleCountMap() { RGB GetColor(House h) { var hhs = households.Where(x => x.HouseGuid == h.Guid).ToList(); var peopleCount = hhs.Select(x => x.Occupants.Count).Sum(); if (peopleCount == 0) { return(new RGB(128, 128, 128)); } if (peopleCount == 1) { return(Constants.Green); } if (peopleCount == 2) { return(Constants.Blue); } return(Constants.Red); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("AnzahlPersonenProHaushalt.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Keine Einwohner", new RGB(128, 128, 128)), new MapLegendEntry("Ein Einwohner", Constants.Green), new MapLegendEntry("Zwei Einwohner", Constants.Blue), new MapLegendEntry("Drei+ Einwohner", Constants.Red) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakePeopleCountMap2() { var maxCount = 0; foreach (var house in houses) { var hhs = households.Where(x => x.HouseGuid == house.Guid).ToList(); var sumCount = hhs.Sum(x => x.Occupants.Count); if (maxCount < sumCount) { maxCount = sumCount; } } var colorStep = 250.0 / maxCount; double color = 0; var colorDict = new Dictionary <int, int>(); for (var i = 1; i <= maxCount; i++) { colorDict.Add(i, (int)color); color += colorStep; } RGBWithSize GetColor(House h) { var hhs = households.Where(x => x.HouseGuid == h.Guid).ToList(); var peopleCount = hhs.Select(x => x.Occupants.Count).Sum(); if (peopleCount == 0) { return(new RGBWithSize(128, 128, 128, 10)); } var red = colorDict[peopleCount]; var size = 10; if (peopleCount > size) { size = peopleCount; } return(new RGBWithSize(red, 0, 0, size)); } var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("AnzahlPersonenProHaushaltRelative.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Keine Einwohner", new RGB(128, 128, 128)) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakeAgeMap() { RGB GetColor(House h) { var hhs = households.Where(x => x.HouseGuid == h.Guid).ToList(); var houseoccupants = hhs.SelectMany(x => x.Occupants).ToList(); double averageAge = 0; if (houseoccupants.Count > 0) { averageAge = houseoccupants.Average(x => x.Age); } if (houseoccupants.Count == 0) { return(new RGB(128, 128, 128)); } var agefactor = averageAge / 100; if (agefactor > 1) { agefactor = 1; } return(new RGB((int)(255.0 * agefactor), 0, 0)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("Durchschnittsalter.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Keine Einwohner", new RGB(128, 128, 128)), new MapLegendEntry("0 Jahre Durchschnittsalter", new RGB(0, 0, 0)), new MapLegendEntry("100 Jahre Durchschnittsalter", new RGB(255, 0, 0)) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var houses = dbHouse.Fetch <House>(); var business = dbHouse.Fetch <BusinessEntry>(); if (business.Count == 0) { throw new FlaException("No businesses"); } MakeBusinessSankey(); MakeHouseholdsMap(); MakeBusinessTypeHistogram(); void MakeBusinessTypeHistogram() { var counts = new Dictionary <BusinessType, int>(); foreach (var entry in business) { if (!counts.ContainsKey(entry.BusinessType)) { counts.Add(entry.BusinessType, 0); } counts[entry.BusinessType]++; } var filename = MakeAndRegisterFullFilename("BusinessHistogram.png", slice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); var column = 0; foreach (var pair in counts) { names.Add(pair.Key.ToString()); var count = pair.Value; barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(pair.Key.ToString(), count, column)); column++; } Services.PlotMaker.MakeBarChart(filename, "BusinessHistogram", barSeries, names); } void MakeBusinessSankey() { var ssa = new SingleSankeyArrow("Houses", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Houses total", houses.Count, 5000, Orientation.Straight)); var housesWithZeroBusinesses = 0; var housesWithOneBusiness = 0; var housesWithManyBusiness = 0; foreach (var house in houses) { var businessesForHouse = business.Where(x => x.HouseGuid == house.Guid).ToList(); if (businessesForHouse.Count == 0) { housesWithZeroBusinesses++; } else if (businessesForHouse.Count == 1) { housesWithOneBusiness++; } else { housesWithManyBusiness++; } } ssa.AddEntry(new SankeyEntry("Häuser mit 0 Geschäften", housesWithZeroBusinesses * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Häuser mit 1 Geschäft", housesWithOneBusiness * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Mehrere Geschäfte", housesWithManyBusiness * -1, 5000, Orientation.Up)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeHouseholdsMap() { RGB GetColor(House h) { var s = business.Where(x => x.HouseGuid == h.Guid).ToList(); if (s.Count == 0) { return(new RGB(255, 0, 0)); } var multiplier = 1; if (s.Any(x => x.BusinessType == BusinessType.Industrie)) { multiplier = 2; } if (s.Count == 1) { return(new RGB(0, 0, 125 * multiplier)); } return(new RGB(0, 125 * multiplier, 0)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("MapHouseholdCountsPerHouse.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("No Business", 255, 0, 0), new MapLegendEntry("Genau 1 Business", 0, 0, 255), new MapLegendEntry("Viele Business", 0, 255, 0) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } }
protected override void RunChartMaking() { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice); var houses = dbHouse.Fetch <House>(); var energyUses = dbHouse.Fetch <HouseSummedLocalnetEnergyUse>(); var households = dbHouse.Fetch <Household>(); MakeTrafoKreisMapForNonTrafoKreisHouses(Constants.PresentSlice); MakeTrafoKreisOsmMap(Constants.PresentSlice); MakeTrafoKreisMap(Constants.PresentSlice); MakeTrafoKreisMapForElectricityUsers(Constants.PresentSlice); MakeBarChartEnergyPertrafokreis(Constants.PresentSlice); MakeBarChartHouseholdsPertrafokreis(Constants.PresentSlice); MakeBarChartHousesPerTrafokreis(Constants.PresentSlice); MakeSankeyEnergyChartPertrafokreis(Constants.PresentSlice); void MakeSankeyEnergyChartPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); //List<string> categoryLabels = new List<string>(); var energyPerTk = new Dictionary <string, double>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); double sumElectricity = 0; foreach (var tkHouse in tkHouses) { var eu = energyUses.Single(x => x.HouseGuid == tkHouse.Guid); sumElectricity += eu.ElectricityUse; } // categoryLabels.Add(tk); var tkSp = tk ?? ""; if (energyPerTk.ContainsKey(tkSp)) { energyPerTk[tkSp] += sumElectricity; } else { energyPerTk.Add(tkSp, sumElectricity); } } var energysum = energyPerTk.Values.Sum() / 1000000; var energySumAssigned = energyPerTk.Where(x => !string.IsNullOrWhiteSpace(x.Key)).Select(x => x.Value).Sum() / 1000000; var diff = energysum - energySumAssigned; var ssa = new SingleSankeyArrow("EnergyInAssignedTks", 500, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Strom Gesamt", energysum, 200, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("An Trafokreisen", energySumAssigned * -1, 200, Orientation.Straight)); ssa.AddEntry(new SankeyEntry("Nicht an Trafokreisen", diff * -1, 200, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } void MakeBarChartHousesPerTrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, tkHouses.Count, i); barseries.Add(bse); } var filename = MakeAndRegisterFullFilename("HousesProTrafokreis.png", slice); Services.PlotMaker.MakeBarChart(filename, "HousesProTrafokreis", barseries, categoryLabels); } void MakeBarChartHouseholdsPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); var tkhouseholdCount = 0; foreach (var tkHouse in tkHouses) { var householdsCount = households.Count(x => x.HouseGuid == tkHouse.Guid); tkhouseholdCount += householdsCount; } categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, tkhouseholdCount, i); barseries.Add(bse); } var filename = MakeAndRegisterFullFilename("HouseholdsProTrafokreis.png", slice); Services.PlotMaker.MakeBarChart(filename, "HouseholdsProTrafokreis", barseries, categoryLabels); } void MakeBarChartEnergyPertrafokreis(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); var barseries = new List <BarSeriesEntry>(); var filenameCsv = MakeAndRegisterFullFilename("StromProTrafokreis.csv", slice); using (var sw = new StreamWriter(filenameCsv)) { var categoryLabels = new List <string>(); for (var i = 0; i < trafokreise.Count; i++) { var tk = trafokreise[i]; var tkHouses = houses.Where(x => x.TrafoKreis == tk).ToList(); double sumElectricity = 0; foreach (var tkHouse in tkHouses) { var eu = energyUses.Single(x => x.HouseGuid == tkHouse.Guid); sumElectricity += eu.ElectricityUse; } categoryLabels.Add(tk); var bse = BarSeriesEntry.MakeBarSeriesEntry(tk, sumElectricity, i); barseries.Add(bse); sw.WriteLine(tk + ";" + sumElectricity); } var filename = MakeAndRegisterFullFilename("StromProTrafokreis.png", slice); Services.PlotMaker.MakeBarChart(filename, "StromProTrafokreis", barseries, categoryLabels); sw.Close(); } } void MakeTrafoKreisMap(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); RGB GetColor(House h) { var idx = trafokreise.IndexOf(h.TrafoKreis); return(ColorGenerator.GetRGB(idx)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("Trafokreise.svg", slice); var legendEntries = new List <MapLegendEntry>(); Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakeTrafoKreisOsmMap(ScenarioSliceParameters slice) { var trafokreise = houses.Select(x => x.TrafoKreis).Distinct().ToList(); Dictionary <string, RGB> colorByTrafokreis = new Dictionary <string, RGB>(); int idx = 0; foreach (var tk in trafokreise) { var rgb = ColorGenerator.GetRGB(idx); while (rgb.R == 255 && rgb.G == 255 && rgb.B == 255) { idx++; rgb = ColorGenerator.GetRGB(idx); } colorByTrafokreis.Add(tk, rgb); idx++; } foreach (var rgb in colorByTrafokreis) { Info(rgb.Key + ": " + rgb.Value); } RGB GetColor(House h) => colorByTrafokreis[h.TrafoKreis ?? throw new InvalidOperationException()]; var mapPoints = houses.Select(x => x.GetMapColorForHouse(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("TrafokreiseOsm.png", slice); var legendEntries = new List <MapLegendEntry>(); legendEntries.Add(new MapLegendEntry("Mittelspannung", colorByTrafokreis["MV_customers"])); legendEntries.Add(new MapLegendEntry("Nicht erfasst", new RGB(255, 0, 0))); Services.PlotMaker.MakeOsmMap(Name, filename, mapPoints, new List <WgsPoint>(), legendEntries, new List <LineEntry>()); }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); List <House> houses1 = dbHouse.Fetch <House>(); var heatingsystems1 = dbHouse.Fetch <HeatingSystemEntry>(); Dictionary <string, HeatingSystemEntry> heatingsystemsByGuid = new Dictionary <string, HeatingSystemEntry>(); foreach (var hse in heatingsystems1) { heatingsystemsByGuid.Add(hse.HouseGuid, hse); } MakeHeatingSystemAnalysis(); EnergyIntensityHistogram(); MakeHeatingTypeIntensityMap(); MakeHeatingTypeMap(); MakeHeatingSystemSankey(); HeatingSystemCountHistogram(); MakeHeatingSystemMapError(); MakeHeatingSystemMap(); MakeFernwärmeTypeMap(); if (isPresent) { PresentOnlyVisualisations(heatingsystemsByGuid, slice, houses1, dbHouse); } void MakeHeatingSystemAnalysis() { var filename = MakeAndRegisterFullFilename("analysis.csv", slice); var sw = new StreamWriter(filename); sw.WriteLine("Original Heating system - Anzahl"); foreach (HeatingSystemType hst in Enum.GetValues(typeof(HeatingSystemType))) { var fs1 = heatingsystems1.Where(x => x.OriginalHeatingSystemType == hst).ToList(); sw.WriteLine(hst + ";" + fs1.Count); } sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("Original Heating system - Summe"); foreach (HeatingSystemType hst in Enum.GetValues(typeof(HeatingSystemType))) { var fs1 = heatingsystems1.Where(x => x.OriginalHeatingSystemType == hst).ToList(); sw.WriteLine(hst + ";" + fs1.Sum(x => x.EffectiveEnergyDemand)); } sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("Target Anzahl"); foreach (HeatingSystemType hst in Enum.GetValues(typeof(HeatingSystemType))) { var fs1 = heatingsystems1.Where(x => x.SynthesizedHeatingSystemType == hst).ToList(); sw.WriteLine(hst + ";" + fs1.Count); } sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("Target Summe"); foreach (HeatingSystemType hst in Enum.GetValues(typeof(HeatingSystemType))) { var fs1 = heatingsystems1.Where(x => x.SynthesizedHeatingSystemType == hst).ToList(); sw.WriteLine(hst + ";" + fs1.Sum(x => x.EffectiveEnergyDemand)); } sw.Close(); } void EnergyIntensityHistogram() { var filename = MakeAndRegisterFullFilename("EnergyIntensityHistogram.png", slice); var ages = heatingsystems1.Select(x => x.CalculatedAverageHeatingEnergyDemandDensity).Where(y => y > 0).ToList(); var barSeries = new List <BarSeriesEntry>(); var h = new Histogram(ages, 100); barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(h, out var colnames, "F0")); Services.PlotMaker.MakeBarChart(filename, "EnergyIntensityHistogram", barSeries, colnames); var xlsfilename = MakeAndRegisterFullFilename("EnergyIntensity.xlsx", slice); var heatingSystems = heatingsystems1.Where(y => y.CalculatedAverageHeatingEnergyDemandDensityWithNulls != null).ToList(); var rbDict = new Dictionary <string, RowBuilder>(); foreach (var hs in heatingSystems) { int bucket = (int)(Math.Floor(hs.CalculatedAverageHeatingEnergyDemandDensityWithNulls / 50 ?? 0) * 50); string key = bucket.ToString(); string et = hs.EnergyType.ToString(); RowBuilder rb; if (rbDict.ContainsKey(key)) { rb = rbDict[key]; } else { rb = RowBuilder.Start("Energieträger", key); rbDict.Add(key, rb); } rb.AddToPossiblyExisting(et, 1); } RowCollection rc = new RowCollection("energy", "energy"); foreach (var builder in rbDict) { rc.Add(builder.Value); } RowCollection rc2 = new RowCollection("raw", "raw"); foreach (var heatingSystemEntry in heatingsystems1) { RowBuilder rb = RowBuilder.Start("Träger", heatingSystemEntry.EnergyType) .Add("Effektiv", heatingSystemEntry.EffectiveEnergyDemand) .Add("EBF", heatingSystemEntry.Ebf); rc2.Add(rb); } XlsxDumper.WriteToXlsx(xlsfilename, rc, rc2); } void MakeHeatingSystemSankey() { var ssa1 = new SingleSankeyArrow("HouseHeatingSystems", 1500, MyStage, SequenceNumber, Name, slice, Services); ssa1.AddEntry(new SankeyEntry("Houses", houses1.Count, 5000, Orientation.Straight)); var ssa2 = new SingleSankeyArrow("EnergyBySystems", 1500, MyStage, SequenceNumber, Name, slice, Services); ssa2.AddEntry(new SankeyEntry("Houses", heatingsystems1.Sum(x => x.EffectiveEnergyDemand) / 1000000, 5000, Orientation.Straight)); var counts = new Dictionary <HeatingSystemType, int>(); var energy = new Dictionary <HeatingSystemType, double>(); foreach (var entry in heatingsystems1) { if (!counts.ContainsKey(entry.SynthesizedHeatingSystemType)) { counts.Add(entry.SynthesizedHeatingSystemType, 0); energy.Add(entry.SynthesizedHeatingSystemType, 0); } counts[entry.SynthesizedHeatingSystemType]++; energy[entry.SynthesizedHeatingSystemType] += entry.EffectiveEnergyDemand; } var i = 1; foreach (var pair in counts) { ssa1.AddEntry(new SankeyEntry(pair.Key.ToString(), pair.Value * -1, 2000 * i, Orientation.Up)); i++; } i = 1; foreach (var pair in energy) { ssa2.AddEntry(new SankeyEntry(pair.Key.ToString(), pair.Value * -1 / 1000000, 2000 * i, Orientation.Up)); i++; } Services.PlotMaker.MakeSankeyChart(ssa1); Services.PlotMaker.MakeSankeyChart(ssa2); } void HeatingSystemCountHistogram() { var counts = new Dictionary <HeatingSystemType, int>(); foreach (var entry in heatingsystems1) { if (!counts.ContainsKey(entry.SynthesizedHeatingSystemType)) { counts.Add(entry.SynthesizedHeatingSystemType, 0); } counts[entry.SynthesizedHeatingSystemType]++; } var filename = MakeAndRegisterFullFilename("HeatingSystemHistogram.png", slice); var names = new List <string>(); var barSeries = new List <BarSeriesEntry>(); var column = 0; foreach (var pair in counts) { names.Add(pair.Value.ToString()); var count = pair.Value; barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(pair.Key.ToString(), count, column)); column++; } Services.PlotMaker.MakeBarChart(filename, "HeatingSystemHistogram", barSeries, names); } void MakeHeatingSystemMapError() { RGB GetColor(House h) { var hse = heatingsystemsByGuid[h.Guid]; if (hse.OriginalHeatingSystemType == HeatingSystemType.Fernwärme) { return(Constants.Red); } if (hse.OriginalHeatingSystemType == HeatingSystemType.Gas) { return(Constants.Orange); } if (hse.OriginalHeatingSystemType == HeatingSystemType.FeuerungsstättenGas) { return(Constants.Orange); } return(Constants.Black); } var mapPoints = houses1.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("KantonHeatingSystemErrors.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Kanton Fernwärme", Constants.Red), new MapLegendEntry("Kanton Gas", Constants.Orange) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakeHeatingSystemMap() { var rgbs = new Dictionary <HeatingSystemType, RGB>(); var hs = heatingsystems1.Select(x => x.SynthesizedHeatingSystemType).Distinct().ToList(); var idx = 0; foreach (var type in hs) { rgbs.Add(type, ColorGenerator.GetRGB(idx++)); } RGB GetColor(House h) { var hse = heatingsystemsByGuid[h.Guid]; return(rgbs[hse.SynthesizedHeatingSystemType]); } var mapPoints = houses1.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("HeatingSystemMap.svg", slice); var legendEntries = new List <MapLegendEntry>(); foreach (var pair in rgbs) { legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value)); } Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void MakeHeatingTypeMap() { var maxEnergy = heatingsystems1.Max(x => x.EffectiveEnergyDemand); var colorsByHeatingSystem = new Dictionary <HeatingSystemType, RGB> { { HeatingSystemType.Gas, Constants.Orange }, { HeatingSystemType.Öl, Constants.Black }, { HeatingSystemType.Electricity, Constants.Green }, { HeatingSystemType.Heatpump, Constants.Green }, { HeatingSystemType.Fernwärme, Constants.Blue }, { HeatingSystemType.Other, Constants.Türkis }, { HeatingSystemType.None, Constants.Yellow } }; RGBWithSize GetColorWithSize(House h) { var s = heatingsystemsByGuid[h.Guid]; var energy = Math.Log(s.EffectiveEnergyDemand / maxEnergy * 100) * 50; if (energy < 10) { energy = 10; } if (!colorsByHeatingSystem.ContainsKey(s.SynthesizedHeatingSystemType)) { throw new Exception("undefined color for " + s.SynthesizedHeatingSystemType); } var rgb = colorsByHeatingSystem[s.SynthesizedHeatingSystemType]; return(new RGBWithSize(rgb.R, rgb.G, rgb.B, (int)energy)); } RGB GetColor(House h) { var s = heatingsystemsByGuid[h.Guid]; if (!colorsByHeatingSystem.ContainsKey(s.SynthesizedHeatingSystemType)) { throw new Exception("undefined color for " + s.SynthesizedHeatingSystemType); } var rgb = colorsByHeatingSystem[s.SynthesizedHeatingSystemType]; return(new RGB(rgb.R, rgb.G, rgb.B)); } var mapPoints = houses1.Select(x => x.GetMapPointWithSize(GetColorWithSize)).ToList(); var filename = MakeAndRegisterFullFilename("MapHeatingTypeAndSystemPerHousehold.svg", slice); var legendEntries = new List <MapLegendEntry>(); foreach (var pair in colorsByHeatingSystem) { legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value)); } Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); var filenameOsm = MakeAndRegisterFullFilename("MapHeatingTypeAndSystemPerHouseholdOsm.png", slice); legendEntries.Add(new MapLegendEntry("Nicht Stadtgebiet", Constants.Red)); var mceh = houses1.Select(x => x.GetMapColorForHouse(GetColor)).ToList(); Services.PlotMaker.MakeOsmMap("HeatingTypeMap", filenameOsm, mceh, new List <WgsPoint>(), legendEntries, new List <LineEntry>()); } void MakeFernwärmeTypeMap() { RGBWithLabel GetColor(House h) { var s = heatingsystemsByGuid[h.Guid]; if (s.SynthesizedHeatingSystemType == HeatingSystemType.Fernwärme) { return(new RGBWithLabel(Constants.Green, "")); } return(new RGBWithLabel(Constants.Blue, "")); //h.ComplexName } var legendEntries = new List <MapLegendEntry>(); var filenameOsm = MakeAndRegisterFullFilename("FernwärmeOSM.png", slice); legendEntries.Add(new MapLegendEntry("Nicht Stadtgebiet", Constants.Red)); legendEntries.Add(new MapLegendEntry("Nicht Fernwärme", Constants.Blue)); legendEntries.Add(new MapLegendEntry("Fernwärme", Constants.Green)); var mceh = houses1.Select(x => x.GetMapColorForHouse(GetColor)).ToList(); Services.PlotMaker.MakeOsmMap("HeatingTypeMap", filenameOsm, mceh, new List <WgsPoint>(), legendEntries, new List <LineEntry>()); } void MakeHeatingTypeIntensityMap() { var colorsByHeatingSystem = new Dictionary <HeatingSystemType, RGB> { { HeatingSystemType.Gas, Constants.Orange }, { HeatingSystemType.Öl, Constants.Black }, { HeatingSystemType.Electricity, Constants.Green }, { HeatingSystemType.Heatpump, Constants.Green }, { HeatingSystemType.Fernwärme, Constants.Blue }, { HeatingSystemType.Other, Constants.Türkis }, { HeatingSystemType.None, Constants.Türkis } }; RGBWithSize GetColor(House h) { var s = heatingsystemsByGuid[h.Guid]; var energy = s.CalculatedAverageHeatingEnergyDemandDensity / 10; if (energy < 10) { energy = 10; } if (!colorsByHeatingSystem.ContainsKey(s.SynthesizedHeatingSystemType)) { throw new Exception("undefined color for " + s.SynthesizedHeatingSystemType); } var rgb = colorsByHeatingSystem[s.SynthesizedHeatingSystemType]; return(new RGBWithSize(rgb.R, rgb.G, rgb.B, (int)energy)); } var mapPoints = houses1.Select(x => x.GetMapPointWithSize(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("MapHeatingTypeAndIntensityPerHouse.svg", slice); var legendEntries = new List <MapLegendEntry>(); foreach (var pair in colorsByHeatingSystem) { legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value)); } Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } }
protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent) { var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice); var houses = dbHouse.Fetch <House>(); if (houses.Count == 0) { throw new FlaException("No houses were found in the data"); } if (isPresent) { var dbRaw = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var dbComplex = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice); var complexes = dbComplex.Fetch <BuildingComplex>(); MakeHouseKey(houses, complexes, slice); var gwr = dbRaw.Fetch <GwrData>(); Debug("Loaded gwr data: " + gwr.Count); var allHouseholds = dbHouse.Fetch <PotentialHousehold>(); Info("Loaded haushalte " + allHouseholds.Count); MakeOtherHouseChart(allHouseholds, gwr, complexes, houses, slice); } AgeHistogram(); MakeHouseGebäudeResultsKey(); MakeHouseAgeMap(); void MakeHouseAgeMap() { var minHouseAge = houses.Where(x => x.AverageBuildingAge > 0).Min(x => x.AverageBuildingAge); var maxHouseAge = houses.Max(x => x.AverageBuildingAge); var range = maxHouseAge - minHouseAge; RGB GetColor(House h) { if (h.AverageBuildingAge < 1) { return(new RGB(0, 0, 128)); } var relativeAge = (h.AverageBuildingAge - minHouseAge) / range; var color = (int)(250.0 * relativeAge); return(new RGB(color, 0, 0)); } var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList(); var filename = MakeAndRegisterFullFilename("BuildingAgeMap.svg", slice); var legendEntries = new List <MapLegendEntry> { new MapLegendEntry("Gebäudealter = " + minHouseAge.ToString("F0"), 0, 0, 0), new MapLegendEntry("Gebäudealter = " + maxHouseAge.ToString("F0"), 255, 0, 0) }; Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries); } void AgeHistogram() { var filename = MakeAndRegisterFullFilename("AgeHistogram.png", slice); var ages = houses.Select(x => x.AverageBuildingAge).Where(y => y > 0).ToList(); var barSeries = new List <BarSeriesEntry>(); var h = new Histogram(ages, 100); barSeries.Add(BarSeriesEntry.MakeBarSeriesEntry(h, out var colnames)); Services.PlotMaker.MakeBarChart(filename, "AgeHistogram", barSeries, colnames); } void MakeHouseGebäudeResultsKey() { var ssa = new SingleSankeyArrow("HouseSankeyMitGebäudeObjektIDs", 1000, MyStage, SequenceNumber, Name, slice, Services); ssa.AddEntry(new SankeyEntry("Complexes", houses.Count, 5000, Orientation.Straight)); var housesMitGebäude = houses.Where(x => x.GebäudeObjectIDs.Count > 0).ToList(); var countHousesMitGebäude = housesMitGebäude.Count; var housesTotal = houses.Count; ssa.AddEntry(new SankeyEntry("Gebäude mit Objektids", countHousesMitGebäude * -1, 5000, Orientation.Up)); ssa.AddEntry(new SankeyEntry("Gebäude ohne Objektids", (housesTotal - countHousesMitGebäude) * -1, 5000, Orientation.Down)); Services.PlotMaker.MakeSankeyChart(ssa); } }