예제 #1
0
        protected override void RunChartMaking()
        {
            var slice         = Constants.PresentSlice;
            var dbSrcProfiles = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var bkws          = dbSrcProfiles.Fetch <BkwProfile>();
            var bkw           = bkws[0];
            var rlms          = dbSrcProfiles.Fetch <RlmProfile>();
            var emptyArr      = new double[rlms[0].Profile.Values.Count];
            var allRlmsVals   = new List <double>();

            allRlmsVals.AddRange(emptyArr);
            var allLocalElectricityVals = new List <double>();

            allLocalElectricityVals.AddRange(emptyArr);
            var allLocalElectricity = new Profile("Locally Generated", allLocalElectricityVals.AsReadOnly(), EnergyOrPower.Power);
            var allRlms             = new Profile("All RLMs", allRlmsVals.AsReadOnly(), EnergyOrPower.Power);

            foreach (var rlm in rlms)
            {
                Profile profile = new Profile(rlm.Name, rlm.Profile.Values, rlm.Profile.EnergyOrPower);
                var     onlyPos = profile.GetOnlyPositive(rlm.Name);

                if (onlyPos.Values.Sum() > 1)
                {
                    allRlms = allRlms.Add(onlyPos, "all Rlms");
                }
                else
                {
                    var onlyNeg = profile.GetOnlyNegative(rlm.Name);
                    allLocalElectricity = allLocalElectricity.Add(onlyNeg, "Locally Generated");
                }
            }

            var bkwProfile = new Profile(bkw.Profile);

            allLocalElectricity = allLocalElectricity.MultiplyWith(-1, "Locally Generated");
            var          residual             = bkwProfile.Minus(allRlms, "Residual");
            const double fac                  = 1_000_000;
            var          rlmTotal             = allRlms.EnergySum() / fac;
            var          bkwTotal             = bkwProfile.EnergySum() / fac;
            var          localGenerationTotal = allLocalElectricity.EnergySum() / fac;
            var          cityTotal            = localGenerationTotal + bkwTotal;
            var          residualTotal        = residual.EnergySum() / fac + localGenerationTotal;
            var          arrows               = new List <SingleSankeyArrow>();
            var          ssa1                 = new SingleSankeyArrow("Erzeugung", 500, MyStage, SequenceNumber, Name, slice, Services);

            ssa1.AddEntry(new SankeyEntry("Lokale Erzeugung", localGenerationTotal, 200, Orientation.Up));
            ssa1.AddEntry(new SankeyEntry("BKW", bkwTotal, 200, Orientation.Straight));
            ssa1.AddEntry(new SankeyEntry("Burgdorf Strom [GWh]", cityTotal * -1, 200, Orientation.Straight));
            arrows.Add(ssa1);
            var ssa2 = new SingleSankeyArrow("Verbrauch", 500, MyStage, SequenceNumber, Name, slice, Services);

            ssa2.AddEntry(new SankeyEntry("", cityTotal, 200, Orientation.Straight));
            ssa2.AddEntry(new SankeyEntry("Residual", residualTotal * -1, 200, Orientation.Up));
            ssa2.AddEntry(new SankeyEntry("RLM", rlmTotal * -1, 200, Orientation.Straight));
            arrows.Add(ssa2);

            Services.PlotMaker.MakeSankeyChart(arrows);
            MakeBarCharts(allRlms, residual, allLocalElectricity);
        }
        protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice, bool isPresent)
        {
            var dbHouse   = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice);
            var houses    = dbHouse.Fetch <House>();
            var pvSystems = dbHouse.Fetch <PvSystemEntry>();

            MakePvSystemSankey();
            MakePVMap();
            MakePvSystemComparison();

            void MakePvSystemSankey()
            {
                var ssa = new SingleSankeyArrow("HousePVSystems", 1500, MyStage, SequenceNumber, Name, slice, Services);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var count = pvSystems.Count;

                ssa.AddEntry(new SankeyEntry("PVSystems", count * -1, 2000, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Kein PV", (houses.Count - count) * -1, 2000, Orientation.Straight));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakePvSystemComparison()
            {
                var          ssa = new SingleSankeyArrow("RealPVSystemsVsPotential", 50, MyStage, SequenceNumber, Name, slice, Services);
                var          houseGuidsWithPV   = pvSystems.Select(x => x.HouseGuid).ToList();
                var          potentials         = dbHouse.Fetch <PVPotential>();
                var          relevantPotentials = potentials.Where(x => houseGuidsWithPV.Contains(x.HouseGuid)).ToList();
                const double fac             = 1_000_000;
                var          potentialEnergy = relevantPotentials.Sum(x => x.SonnendachStromErtrag) / fac;
                var          installedEnergy = pvSystems.Sum(x => x.EffectiveEnergyDemand) / fac;

                ssa.AddEntry(new SankeyEntry("Sonnendach Potential auf Häusern mit PV", potentialEnergy, 20, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Installed", installedEnergy * -1, 20, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Verschwendetes Potential", (potentialEnergy - installedEnergy) * -1, 20, Orientation.Down));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakePVMap()
            {
                RGB GetColor(House h)
                {
                    if (pvSystems.Any(x => x.HouseGuid == h.Guid))
                    {
                        return(Constants.Red);
                    }

                    return(Constants.Black);
                }

                var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList();

                var filename      = MakeAndRegisterFullFilename("PVSystems.svg", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("PV", Constants.Red)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
            }
        }
예제 #3
0
        private SingleSankeyArrow MakeArr1([ItemNotNull][NotNull] List <BuildingComplex> complexes)
        {
            var slice = Constants.PresentSlice;
            //write python
            var arr1    = new SingleSankeyArrow("komplexe", 1000, MyStage, SequenceNumber, Name, slice, Services);
            var sources = complexes.Select(x => x.SourceOfThisEntry).Distinct().ToList();
            var length  = 2000;

            foreach (var entry in sources)
            {
                var count = complexes.Count(x => x.SourceOfThisEntry == entry);
                if (count > 3000)
                {
                    arr1.AddEntry(new SankeyEntry(entry.ToString(), count, length, Orientation.Straight));
                }
                else
                {
                    arr1.AddEntry(new SankeyEntry(entry.ToString(), count, length, Orientation.Up));
                }

                length += 2000;
            }

            arr1.AddEntry(new SankeyEntry("Komplexe", complexes.Count * -1, 1000, Orientation.Straight));
            return(arr1);
        }
        protected override void RunChartMaking()
        {
            var slice                = Constants.PresentSlice;
            var dbHouse              = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;
            var houses               = dbHouse.Fetch <House>();
            var airconditioing       = dbHouse.Fetch <AirconditioningEntry>();
            var airConditioningGuids = airconditioing.Select(x => x.HouseGuid).Distinct().ToList();

            MakeAirConditioningSankeySankey();
            MakeAirConditioningMap();

            void MakeAirConditioningSankeySankey()
            {
                var ssa = new SingleSankeyArrow("AirConditioingHouses", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var housesWithLight = airConditioningGuids.Count;

                ssa.AddEntry(new SankeyEntry("Klimatisierung", housesWithLight * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Sonstige Häuser", (houses.Count - housesWithLight) * -1, 2000, Orientation.Up));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeAirConditioningMap()
            {
                RGBWithSize GetColor(House h)
                {
                    var ace = airconditioing.FirstOrDefault(x => x.HouseGuid == h.HouseGuid);

                    if (ace == null)
                    {
                        return(new RGBWithSize(Constants.Black, 10));
                    }

                    if (ace.AirConditioningType == AirConditioningType.Commercial)
                    {
                        return(new RGBWithSize(Constants.Red, 20));
                    }

                    if (ace.AirConditioningType == AirConditioningType.Industrial)
                    {
                        return(new RGBWithSize(Constants.Blue, 20));
                    }

                    throw new Exception("Unbekannte Klimatisierung");
                }

                var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor, House.CoordsToUse.Localnet)).ToList();

                var filename      = MakeAndRegisterFullFilename("Klimatisierung.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("Klimatisierung (GHD)", Constants.Red),
                    new MapLegendEntry("Klimatisierung (Industrie)", Constants.Blue),
                    new MapLegendEntry("Keine Klimatisierung", Constants.Black)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }
        }
        private void MakeHouseKey([NotNull][ItemNotNull] List <House> houses, [NotNull][ItemNotNull] List <BuildingComplex> complexes, [NotNull] ScenarioSliceParameters slice)
        {
            var ssa = new SingleSankeyArrow("HouseSankey", 1000, MyStage,
                                            SequenceNumber, Name, slice, Services);

            ssa.AddEntry(new SankeyEntry("Complexes", complexes.Count, 5000, Orientation.Straight));
            ssa.AddEntry(new SankeyEntry("Houses", houses.Count * -1, 5000, Orientation.Straight));
            ssa.AddEntry(new SankeyEntry("Ignored", (complexes.Count - houses.Count) * -1, 5000, Orientation.Straight));
            Services.PlotMaker.MakeSankeyChart(ssa);
        }
예제 #6
0
        protected override void RunChartMaking()
        {
            var slice   = Constants.PresentSlice;
            var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice);
            var houses  = dbHouse.Fetch <House>();
            //var businesses = dbHouse.Fetch<BusinessEntry>();
            var incoming = dbHouse.Fetch <IncomingCommuterEntry>();

            MakeCommuterSankey();
            MakeCommuterMap();

            void MakeCommuterSankey()
            {
                var ssa = new SingleSankeyArrow("IncomingComuters", 1500, MyStage,
                                                SequenceNumber, Name, slice, Services);

                ssa.AddEntry(new SankeyEntry("Arbeiter", incoming.Count, 5000, Orientation.Straight));
                var workersFromOutside  = incoming.Count(x => x.DistanceInKm > 0);
                var workersFromBurgdorf = incoming.Count(x => Math.Abs(x.DistanceInKm) < 0.000001);

                ssa.AddEntry(new SankeyEntry("Pendler nach Burgdorf", workersFromOutside * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Arbeiter in Burgdorf", workersFromBurgdorf * -1, 2000, Orientation.Up));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeCommuterMap()
            {
                RGBWithSize GetColor(House h)
                {
                    var incomingCount = incoming.Count(x => x.HouseGuid == h.Guid);

                    if (incomingCount > 0)
                    {
                        return(new RGBWithSize(Constants.Red, incomingCount + 10));
                    }

                    return(new RGBWithSize(Constants.Black, 10));
                }

                var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor)).ToList();

                var filename      = MakeAndRegisterFullFilename("Employees.svg", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("Betrieb mit Angestellten", Constants.Red),
                    new MapLegendEntry("Keine Angestellten", Constants.Black)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
            }
        }
        protected override void RunChartMaking()
        {
            var dbComplex = SqlConnection.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice).Database;
            var complexes = dbComplex.Fetch <BuildingComplex>();

            MakeLocalnetCoordSankey(Constants.PresentSlice);

            void MakeLocalnetCoordSankey(ScenarioSliceParameters slice)
            {
                var ssa = new SingleSankeyArrow("ComplexesWithLocalnetCoords", 1000,
                                                MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Complexes", complexes.Count, 5000, Orientation.Straight));
                var complexesWithBoth         = complexes.Count(x => x.LocalnetCoords.Count > 0 && x.Coords.Count > 0);
                var complexesWithOnlyLocalnet = complexes.Count(x => x.LocalnetCoords.Count > 0 && x.Coords.Count == 0);
                var complexesWithOnlyGWR      = complexes.Count(x => x.LocalnetCoords.Count == 0 && x.Coords.Count > 0);
                var complexesWithNone         = complexes.Count(x => x.LocalnetCoords.Count == 0 && x.Coords.Count == 0);

                ssa.AddEntry(new SankeyEntry("GWR & Localnet", complexesWithBoth * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("GWR ", complexesWithOnlyGWR * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Localnet Daten Verfügbar", complexesWithOnlyLocalnet * -1, 2000, Orientation.Down));
                ssa.AddEntry(new SankeyEntry("none  ", complexesWithNone * -1, 2000, Orientation.Down));
                Services.PlotMaker.MakeSankeyChart(ssa);

                /*
                 * RGB GetColor(House h)
                 * {
                 *  if (h.GebäudeObjectIDs.Count > 0 && h.TotalSolarEnergyPotential > 0)
                 *  {
                 *      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 = complexes.Select(x => x.GetMapPoint(GetColor)).ToList();
                 * var filename = MakeAndRegisterFullFilename("MapPVWithLocalnet.svg", Name, "");
                 * List<MapLegendEntry> legendEntries = new List<MapLegendEntry>();
                 * legendEntries.Add(new MapLegendEntry("Localnet und Solar", 255, 0, 0));
                 * legendEntries.Add(new MapLegendEntry("Localnet", 0, 0, 255));
                 * legendEntries.Add(new MapLegendEntry("Rest", 0, 255, 0));
                 * Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
                 */
            }
        }
예제 #8
0
        protected override void RunChartMaking()
        {
            var slice           = Constants.PresentSlice;
            var dbHouse         = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;
            var houses          = dbHouse.Fetch <House>();
            var lights          = dbHouse.Fetch <StreetLightingEntry>();
            var lightHouseGuids = lights.Select(x => x.HouseGuid).Distinct().ToList();

            MakeLightSankey();
            MakeCommuterMap();

            void MakeLightSankey()
            {
                var ssa = new SingleSankeyArrow("LightingHouses", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var housesWithLight = lightHouseGuids.Count;

                ssa.AddEntry(new SankeyEntry("Strassenbeleuchtungen", housesWithLight * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Sonstige Häuser", (houses.Count - housesWithLight) * -1, 2000, Orientation.Up));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeCommuterMap()
            {
                RGBWithSize GetColor(House h)
                {
                    if (lightHouseGuids.Contains(h.HouseGuid))
                    {
                        return(new RGBWithSize(Constants.Red, 20));
                    }

                    return(new RGBWithSize(Constants.Black, 10));
                }

                var mapPoints = houses.Select(x => x.GetMapPointWithSize(GetColor, House.CoordsToUse.Localnet)).ToList();

                var filename      = MakeAndRegisterFullFilename("Strassenbeleuchtung.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("Strassenbeleuchtung", Constants.Red),
                    new MapLegendEntry("Sonstiges", Constants.Black)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }
        }
예제 #9
0
        private void MakeTotalsSankey1([NotNull][ItemNotNull] List <CSVFile> csvs, [NotNull] ScenarioSliceParameters parameters)
        {
            string suffix          = csvs[0].GenerationOrLoad.ToString();
            var    ssa             = new SingleSankeyArrow("EnergyUseTotalVsRealizedInCSV" + suffix, 1000, MyStage, SequenceNumber, Name, parameters, Services);
            var    dbComplexEnergy = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.ComplexEnergyData, Constants.PresentSlice);
            var    monthlyElectricityUsePerStandorts =
                dbComplexEnergy.Fetch <double>("select YearlyElectricityUseNetz from " + nameof(MonthlyElectricityUsePerStandort));
            const int fac      = 1_000_000;
            var       totalSum = monthlyElectricityUsePerStandorts.Sum() / fac;

            var sumAssigned = csvs.Sum(x => x.CalculateTotalEnergy()) / fac;
            var sumMissing  = totalSum - sumAssigned;

            ssa.AddEntry(new SankeyEntry("Total Electricity", totalSum, 500, Orientation.Straight));
            ssa.AddEntry(new SankeyEntry("Fehlend", sumMissing * -1, 500, Orientation.Straight));
            ssa.AddEntry(new SankeyEntry("In Lastprofilen", sumAssigned * -1, 500, Orientation.Up));
            Services.PlotMaker.MakeSankeyChart(ssa);
        }
        protected override void RunChartMaking(ScenarioSliceParameters slice)
        {
            var dbDstHouses            = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice);
            var airConditioningEntries = dbDstHouses.Fetch <AirConditioningEntry>();
            var houses = dbDstHouses.Fetch <House>();

            MakeAcSystemEnergySankey();
            MakeAcSystemCountSankey();

            void MakeAcSystemEnergySankey()
            {
                var ssa1 = new SingleSankeyArrow("HouseAirConditioningEnergy", 60, MyStage, SequenceNumber, Name, slice, Services);

                double potentialForAirConditioning =
                    houses.Sum(x => x.EnergieBezugsFläche * slice.AirConditioningEnergyIntensityInKWhPerSquareMeter) / Constants.GWhFactor;
                double actualAirConditioningEnergy = airConditioningEntries.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor;

                ssa1.AddEntry(new SankeyEntry("Houses", potentialForAirConditioning, 60, Orientation.Straight));

                ssa1.AddEntry(new SankeyEntry("Houses without Airconditioning",
                                              (potentialForAirConditioning - actualAirConditioningEnergy) * -1,
                                              60,
                                              Orientation.Up));
                ssa1.AddEntry(new SankeyEntry("Houses with Airconditioning", actualAirConditioningEnergy * -1, 60, Orientation.Down));

                Services.PlotMaker.MakeSankeyChart(ssa1);
            }

            void MakeAcSystemCountSankey()
            {
                var ssa1 = new SingleSankeyArrow("HouseAirConditioningCount", 1500, MyStage, SequenceNumber, Name, slice, Services);

                ssa1.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var airConditioningHouseGuids   = airConditioningEntries.Select(x => x.HouseGuid).Distinct().ToList();
                var housesWithoutAirconditioing = houses.Where(x => !airConditioningHouseGuids.Contains(x.Guid)).Distinct().ToList();

                ssa1.AddEntry(new SankeyEntry("Houses without Airconditioning", housesWithoutAirconditioing.Count * -1, 5000, Orientation.Up));
                ssa1.AddEntry(new SankeyEntry("Houses with Airconditioning", airConditioningHouseGuids.Count * -1, 5000, Orientation.Down));

                Services.PlotMaker.MakeSankeyChart(ssa1);
            }
        }
예제 #11
0
        protected override void RunChartMaking()
        {
            var slice = Constants.PresentSlice;
            //var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice);
            var ap               = new AnalysisRepository(Services.RunningConfig);
            var dbHouse          = ap.GetSlice(Constants.PresentSlice);
            var houses           = dbHouse.Fetch <House>();
            var houseTypeEntries = dbHouse.Fetch <HouseTypeEntry>();

            MakeHouseTypeEntries();
            MakeHouseTypeMap();
            MakeEnergyUseXls();
            void MakeEnergyUseXls()
            {
                var        households   = dbHouse.Fetch <Household>();
                var        businesses   = dbHouse.Fetch <BusinessEntry>();
                var        infra        = dbHouse.Fetch <BuildingInfrastructure>();
                var        light        = dbHouse.Fetch <StreetLightingEntry>();
                var        dhw          = dbHouse.Fetch <DHWHeaterEntry>();
                var        rc           = new RowCollection("energy", "energy");
                RowBuilder rb           = RowBuilder.Start("Haushalte", households.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor);
                var        bigcustomers = businesses.Where(x => x.EffectiveEnergyDemand > 20000);
                var        small        = businesses.Where(x => x.EffectiveEnergyDemand <= 20000);

                rb.Add("Geschäftskunden > 20 MWh", bigcustomers.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor);
                rb.Add("Geschäftskunden < 20 MWh", small.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor);
                rb.Add("Gebäudeinfrastruktur", infra.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor);
                rb.Add("Strassenbeleuchtung", light.Sum(x => x.YearlyElectricityUse) / Constants.GWhFactor);
                rb.Add("Elektroboiler", dhw.Sum(x => x.EffectiveEnergyDemand) / Constants.GWhFactor);

                rc.Add(rb);
                var fn = MakeAndRegisterFullFilename("EnergyTreeMap.xlsx", Constants.PresentSlice);

                XlsxDumper.WriteToXlsx(fn, rc);
                SaveToPublicationDirectory(fn, Constants.PresentSlice, "4.2");
            }

            void MakeHouseTypeEntries()
            {
                var ssa = new SingleSankeyArrow("HouseTypeEntries", 1500, MyStage,
                                                SequenceNumber, Name, slice, Services);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var countsPerType = new Dictionary <HouseType, int>();

                foreach (var entry in houseTypeEntries)
                {
                    if (!countsPerType.ContainsKey(entry.HouseType))
                    {
                        countsPerType.Add(entry.HouseType, 0);
                    }

                    countsPerType[entry.HouseType]++;
                }

                foreach (var pair in countsPerType)
                {
                    ssa.AddEntry(new SankeyEntry(pair.Key.ToString(), pair.Value * -1, 2000, Orientation.Up));
                }

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeHouseTypeMap()
            {
                var rgbs = new Dictionary <HouseType, RGB>();
                var hs   = houseTypeEntries.Select(x => x.HouseType).Distinct().ToList();
                var idx  = 0;

                foreach (var type in hs)
                {
                    var rgb = ColorGenerator.GetRGB(idx++);
                    if (rgb.R == 255 && rgb.B == 255 && rgb.G == 255)
                    {
                        rgb = new RGB(200, 200, 200);
                    }

                    if (rgb.R == 255 && rgb.B == 0 && rgb.G == 0)
                    {
                        rgb = Constants.Orange;
                    }

                    rgbs.Add(type, rgb);
                }

                RGB GetColor(House h)
                {
                    var hse = houseTypeEntries.Single(x => x.HouseGuid == h.Guid);

                    return(rgbs[hse.HouseType]);
                }

                var mapPoints = houses.Select(x => x.GetMapColorForHouse(GetColor)).ToList();

                var filename      = MakeAndRegisterFullFilename("HouseTypeMap.png", slice);
                var legendEntries = new List <MapLegendEntry>();

                foreach (var pair in rgbs)
                {
                    legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value));
                }

                Services.PlotMaker.MakeOsmMap(Name, filename, mapPoints, new List <WgsPoint>(), legendEntries, new List <LineEntry>());
            }
        }
예제 #12
0
        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);
            }
        }
예제 #13
0
        protected override void MakeVisualization([NotNull] ScenarioSliceParameters slice,
                                                  bool isPresent)
        {
            var dbRaw   = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var dbHouse = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Houses, slice);
            var gwrData = dbRaw.Fetch <GwrData>();
            var houses  = dbHouse.Fetch <House>();

            if (houses.Count == 0)
            {
                throw new FlaException("No houses found");
            }
            var households = dbHouse.Fetch <Household>();

            MakeHouseholdsDistributionChart();
            MakeHouseholdsMap();
            HouseholdAppartmentSankey();
            MakeHouseholdsGWRMapComparison();

            void MakeHouseholdsDistributionChart()
            {
                var ssa = new SingleSankeyArrow("Houses", 1000, MyStage,
                                                SequenceNumber, Name, slice, Services);

                ssa.AddEntry(new SankeyEntry("Houses total", houses.Count, 5000, Orientation.Straight));
                var housesWithZeroHouseholds = 0;
                var housesWithOneHousehold   = 0;
                var housesWithManyHouseholds = 0;

                foreach (var house in houses)
                {
                    var houeholdsForHouse = households.Where(x => x.HouseGuid == house.Guid).ToList();
                    if (houeholdsForHouse.Count == 0)
                    {
                        housesWithZeroHouseholds++;
                    }
                    else if (houeholdsForHouse.Count == 1)
                    {
                        housesWithOneHousehold++;
                    }
                    else
                    {
                        housesWithManyHouseholds++;
                    }
                }

                ssa.AddEntry(new SankeyEntry("Häuser mit 0 Haushalten", housesWithZeroHouseholds * -1, 5000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Häuser mit 1 Haushalt", housesWithOneHousehold * -1, 5000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("MFH", housesWithManyHouseholds * -1, 5000, Orientation.Up));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeHouseholdsMap()
            {
                RGB GetColor(House h)
                {
                    var s = households.Where(x => x.HouseGuid == h.Guid).ToList();

                    if (s.Count == 0)
                    {
                        return(new RGB(255, 0, 0));
                    }

                    if (s.Count == 1)
                    {
                        return(new RGB(0, 0, 255));
                    }

                    return(new RGB(0, 255, 0));
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapHouseholdCountsPerHouse.svg", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("No Household", 255, 0, 0),
                    new MapLegendEntry("Genau 1 Haushalt", 0, 0, 255),
                    new MapLegendEntry("Viele Haushalte", 0, 255, 0)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
            }

            void HouseholdAppartmentSankey()
            {
                var householdCount     = households.Count;
                var gwrAppartmentCount = gwrData.Sum(x => x.AnzahlWohnungen_GANZWHG ?? 0);
                var diff = gwrAppartmentCount - householdCount;
                var ssa  = new SingleSankeyArrow("GWRApartmentsVsHouseholds", 5000, MyStage, SequenceNumber,
                                                 Name, slice, Services);

                ssa.AddEntry(new SankeyEntry("GWR", gwrAppartmentCount, 1500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Haushalte", householdCount * -1, 1500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Rest", diff * -1, 500, Orientation.Up));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeHouseholdsGWRMapComparison()
            {
                RGB GetColor(House h)
                {
                    var householdCount     = households.Count(x => x.HouseGuid == h.Guid);
                    var gwrAppartmentList  = gwrData.Where(x => h.EGIDs.Contains(x.EidgGebaeudeidentifikator_EGID ?? 0)).ToList();
                    var gwrAppartmentCount = gwrAppartmentList.Sum(x => x.AnzahlWohnungen_GANZWHG);
                    var diff = householdCount - gwrAppartmentCount;

                    if (diff == 0)
                    {
                        return(new RGB(64, 64, 64));
                    }

                    if (diff > 1)
                    {
                        return(new RGB(0, 0, 255));
                    }

                    return(new RGB(255, 0, 0));
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapHouseholdCountVsGwrHouseholds.svg", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("Same count", 64, 64, 64),
                    new MapLegendEntry("Mehr GWR", 0, 0, 255),
                    new MapLegendEntry("Mehr Haushalte", 255, 0, 0)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
            }
        }
예제 #14
0
        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);
            }
        }
예제 #15
0
        protected override void RunChartMaking()
        {
            var dbHouse = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;
            //var dbRaw = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database;
            var houses = dbHouse.Fetch <House>();
            var potentialHouseholds = dbHouse.Fetch <PotentialHousehold>();
            var potentialBusinesses = dbHouse.Fetch <PotentialBusinessEntry>();

            MakePotentialHouseholdsMap(Constants.PresentSlice);
            MakePotentialBusinessMap();
            EnergySankey(Constants.PresentSlice);
            EnergySankeyTrafokreis(Constants.PresentSlice);

            void MakePotentialHouseholdsMap(ScenarioSliceParameters slice)
            {
                var ssa = new SingleSankeyArrow("Potential Households", 1000,
                                                MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Potential Households total", potentialHouseholds.Count, 5000, Orientation.Straight));
                var potentialHouseholdsEnergySmaller1000 = potentialHouseholds.Count(x => x.YearlyElectricityUse < 1000);
                var potentialHouseholdsEnergySmaller2000 = potentialHouseholds.Count(x => x.YearlyElectricityUse < 2000 && x.YearlyElectricityUse >= 1000);
                var potentialHouseholdsEnergySmaller5000 = potentialHouseholds.Count(x => x.YearlyElectricityUse < 5000 && x.YearlyElectricityUse >= 2000);
                var potentialHouseholdsEnergyGreater5000 = potentialHouseholds.Count(x => x.YearlyElectricityUse > 5000);

                ssa.AddEntry(new SankeyEntry("Haushalte mit Energie < 1000", potentialHouseholdsEnergySmaller1000 * -1, 5000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Haushalte mit Energie < 2000", potentialHouseholdsEnergySmaller2000 * -1, 5000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Haushalte mit Energie < 5000", potentialHouseholdsEnergySmaller5000 * -1, 5000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Haushalte mit Energie > 5000", potentialHouseholdsEnergyGreater5000 * -1, 5000, Orientation.Down));


                Services.PlotMaker.MakeSankeyChart(ssa);

                RGB GetColor(House h)
                {
                    var s = potentialHouseholds.Where(x => x.HouseGuid == h.HouseGuid).ToString();

                    if (s.Length == 0)
                    {
                        return(new RGB(255, 0, 0));
                    }

                    if (h.GebäudeObjectIDs.Count == 1)
                    {
                        return(new RGB(0, 0, 255));
                    }

                    return(new RGB(0, 255, 0));
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapHouseholdCountsPerHouse.svg", Name, "", Constants.PresentSlice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("No Household", 255, 0, 0),
                    new MapLegendEntry("Genau 1 Haushalt", 0, 0, 255),
                    new MapLegendEntry("Viele Haushalte", 0, 255, 0)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }

            void MakePotentialBusinessMap()
            {
                RGB GetColor(House h)
                {
                    var s = potentialBusinesses.Where(x => x.HouseGuid == h.HouseGuid).ToList();

                    if (s.Count == 0)
                    {
                        return(new RGB(255, 0, 0));
                    }

                    if (s.Count == 1)
                    {
                        return(new RGB(0, 0, 255));
                    }

                    return(new RGB(0, 255, 0));
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapBusinessCountsPerHouse.svg", Name, "", Constants.PresentSlice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("No business", 255, 0, 0),
                    new MapLegendEntry("Genau 1 business", 0, 0, 255),
                    new MapLegendEntry("Viele geschäfte", 0, 255, 0)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }

            void EnergySankey(ScenarioSliceParameters slice)
            {
                var          hhs      = dbHouse.Fetch <PotentialHousehold>();
                var          business = dbHouse.Fetch <PotentialBusinessEntry>();
                var          buildingInfrastructures = dbHouse.Fetch <PotentialBuildingInfrastructure>();
                var          streetlights            = dbHouse.Fetch <StreetLightingEntry>();
                const double fac        = 1_000_000;
                var          hhsum      = hhs.Sum(x => x.YearlyElectricityUse) / fac;
                var          businessum = business.Sum(x => x.LowVoltageYearlyElectricityUse + x.HighVoltageYearlyElectricityUse) / fac;
                var          infrasum   = buildingInfrastructures.Sum(x => x.LowVoltageTotalElectricityDemand + x.HighVoltageTotalElectricityDemand) / fac;
                var          streetsum  = streetlights.Sum(x => x.YearlyElectricityUse) / fac;
                var          sum        = hhsum + businessum + infrasum + streetsum;
                var          ssa        = new SingleSankeyArrow("AufgeteilterStromverbrauch", 1000,
                                                                MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Gesamt", sum, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Haushalte", hhsum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Business", businessum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Buildings", infrasum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Beleuchtung", streetsum * -1, 500, Orientation.Up));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void EnergySankeyTrafokreis(ScenarioSliceParameters slice)
            {
                var          hhs      = dbHouse.Fetch <PotentialHousehold>();
                var          business = dbHouse.Fetch <PotentialBusinessEntry>();
                var          buildingInfrastructures = dbHouse.Fetch <PotentialBuildingInfrastructure>();
                var          streetlights            = dbHouse.Fetch <StreetLightingEntry>();
                const double fac        = 1_000_000;
                var          houseguids = houses.Where(x => !string.IsNullOrWhiteSpace(x.TrafoKreis)).Select(x => x.HouseGuid).ToList();
                var          hhsum      = hhs.Where(x => houseguids.Contains(x.HouseGuid)).Sum(x => x.YearlyElectricityUse) / fac;
                var          businessum = business.Where(x => houseguids.Contains(x.HouseGuid)).Sum(x => x.LowVoltageYearlyElectricityUse + x.HighVoltageYearlyElectricityUse) / fac;
                var          infrasum   = buildingInfrastructures.Where(x => houseguids.Contains(x.HouseGuid)).Sum(x => x.LowVoltageTotalElectricityDemand + x.HighVoltageTotalElectricityDemand) / fac;
                var          streetsum  = streetlights.Where(x => houseguids.Contains(x.HouseGuid)).Sum(x => x.YearlyElectricityUse) / fac;
                var          sum        = hhsum + businessum + infrasum + streetsum;
                var          ssa        = new SingleSankeyArrow("AufgeteilterStromverbrauchMitTrafokreis", 1000, MyStage,
                                                                SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Gesamt", sum, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Haushalte", hhsum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Business", businessum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Buildings", infrasum * -1, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Beleuchtung", streetsum * -1, 500, Orientation.Up));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }
        }
예제 #16
0
        private SingleSankeyArrow MakeArr2([ItemNotNull][NotNull] List <BuildingComplex> complexes)
        {
            var slice     = Constants.PresentSlice;
            var outcounts = new Dictionary <string, int>();
            var arr2      = new SingleSankeyArrow("Komplexe", 1000, MyStage, SequenceNumber, Name, slice, Services);

            arr2.AddEntry(new SankeyEntry("Komplexe", complexes.Count, 1000, Orientation.Straight));
            foreach (Variants variant1 in Enum.GetValues(typeof(Variants)))
            {
                // addresses
                string fullDesc;
                List <BuildingComplex> l1Complexes;
                if (variant1 == Variants.None)
                {
                    l1Complexes = complexes.Where(x => x.Adresses.Count == 0).ToList();
                    fullDesc    = "keine Adressen,\\n";
                }
                else
                {
                    l1Complexes = complexes.Where(x => x.Adresses.Count > 0).ToList();
                    fullDesc    = "mindestens eine Addresse,\\n";
                }

                foreach (Variants variant2 in Enum.GetValues(typeof(Variants)))
                {
                    //geocoords
                    List <BuildingComplex> l2Complexes;
                    var l2Desc = fullDesc;
                    if (variant2 == Variants.None)
                    {
                        l2Complexes = l1Complexes.Where(x => x.Coords.Count == 0).ToList();
                        l2Desc     += "keine Koord.,\\n";
                    }
                    else
                    {
                        l2Complexes = l1Complexes.Where(x => x.Coords.Count > 0).ToList();
                        l2Desc     += "mindestens eine Koord.,\\n";
                    }

                    foreach (Variants variant3 in Enum.GetValues(typeof(Variants)))
                    {
                        //localnetGebäudeIDs
                        List <BuildingComplex> l3Complexes;
                        var l3Desc = l2Desc;
                        if (variant3 == Variants.None)
                        {
                            l3Complexes = l2Complexes.Where(x => x.GebäudeObjectIDs.Count == 0).ToList();
                            l3Desc     += "keine LocalnetID";
                            outcounts.Add(l3Desc, l3Complexes.Count);
                        }
                        else
                        {
                            l3Complexes = l2Complexes.Where(x => x.GebäudeObjectIDs.Count > 0).ToList();
                            l3Desc     += "mindestens eine LocalnetID";
                            outcounts.Add(l3Desc, l3Complexes.Count);
                        }
                    }
                }
            }

            var pathLength = 1000;

            foreach (var pair in outcounts)
            {
                if (pair.Value > 0)
                {
                    if (pair.Value > 3000)
                    {
                        arr2.AddEntry(new SankeyEntry(pair.Key, pair.Value * -1, 3000, Orientation.Straight));
                    }
                    else
                    {
                        pathLength += 4000;
                        arr2.AddEntry(new SankeyEntry(pair.Key, pair.Value * -1, pathLength, Orientation.Up));
                    }
                }
            }

            return(arr2);
        }
        protected override void RunChartMaking()
        {
            var slice               = Constants.PresentSlice;
            var dbHouse             = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;
            var dbRaw               = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database;
            var localnetEntries     = dbRaw.Fetch <Localnet>();
            var houses              = dbHouse.Fetch <House>();
            var househeatingentries = dbHouse.Fetch <HouseHeating>();

            MakeOilEnergySankey();
            MakeHeatingSystemSankey();
            MakeHeatingsystemMapLocalnet();
            MakeGasEnergySankey();
            MakeWärmeEnergySankey();
            MakeHeatingsystemMapEBBE();
            MakeEtagenHeizungenLocalnet();
            MakeEbbeLocalnetComparisonSankey();
            MakeHeatingIntensityMap();

            void MakeHeatingSystemSankey()
            {
                var ssa = new SingleSankeyArrow("Houses", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Houses total", houses.Count, 5000, Orientation.Straight));
                var housesWithZeroLocalnetHeatingSystems = 0;
                var housesWithOneLocalnetHeatingSystems  = 0;
                var housesWithManyLocalnetHeatingSystems = 0;

                foreach (var house in houses)
                {
                    var houseHeatings = househeatingentries.Single(x => x.HouseGuid == house.HouseGuid);
                    if (houseHeatings.LocalnetHeatingSystemEntryCount == 0)
                    {
                        housesWithZeroLocalnetHeatingSystems++;
                    }
                    else if (houseHeatings.LocalnetHeatingSystemEntryCount == 1)
                    {
                        housesWithOneLocalnetHeatingSystems++;
                    }
                    else
                    {
                        housesWithManyLocalnetHeatingSystems++;
                    }
                }

                ssa.AddEntry(new SankeyEntry("Häuser mit 0 Localnet heizungen", housesWithZeroLocalnetHeatingSystems * -1, 5000, Orientation.Down));
                ssa.AddEntry(new SankeyEntry("Häuser mit 1 Localnet Heizungen", housesWithOneLocalnetHeatingSystems * -1, 5000, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Häuser mit mehreren Localnet Heizungen", housesWithManyLocalnetHeatingSystems * -1, 5000, Orientation.Up));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeEbbeLocalnetComparisonSankey()
            {
                var    ssa = new SingleSankeyArrow("MakeEbbeLocalnetComparisonSankey", 500, MyStage, SequenceNumber, Name, Services.Logger, slice);
                double ebbeHeizungsBedarf      = 0;
                double localnetHeizungsBedarf  = 0;
                double mergedHeizungsBedarf    = 0;
                double localnetFernWärmeBedarf = 0;
                double localnetGasBedarf       = 0;
                double mergedHeizungsBedarfOnlyLocalnetHouses = 0;
                double ebbeFernwärme = 0;

                foreach (var houseHeating in househeatingentries)
                {
                    ebbeHeizungsBedarf      += houseHeating.KantonTotalEnergyDemand;
                    localnetHeizungsBedarf  += houseHeating.LocalnetCombinedEnergyDemand;
                    mergedHeizungsBedarf    += houseHeating.MergedHeatingDemand;
                    localnetGasBedarf       += houseHeating.LocalnetGasEnergyUse;
                    localnetFernWärmeBedarf += houseHeating.LocalnetFernwärmeEnergyUse;
                    if (houseHeating.KantonHeatingMethods.Contains(HeatingSystemType.Fernwärme))
                    {
                        ebbeFernwärme += houseHeating.KantonTotalEnergyDemand;
                    }

                    var house = houses.Single(x => x.HouseGuid == houseHeating.HouseGuid);
                    if (house.GebäudeObjectIDs.Count > 0)
                    {
                        mergedHeizungsBedarfOnlyLocalnetHouses += houseHeating.MergedHeatingDemand;
                    }
                }

                var filenameCsv = MakeAndRegisterFullFilename("HeizungsVergleich.csv", Name, "", slice);

                using (var sw = new StreamWriter(filenameCsv)) {
                    sw.WriteLine("Ebbe Heizungsbedarf gesamt; " + ebbeHeizungsBedarf);
                    sw.WriteLine("Localnet Gas Bedarf;" + localnetGasBedarf);
                    sw.WriteLine("Localnet Fernwärme Bedarf;" + localnetFernWärmeBedarf);
                    sw.WriteLine("Localnet Combined Bedarf;" + localnetHeizungsBedarf);
                    sw.WriteLine("Merged Bedarf;" + mergedHeizungsBedarf);
                    sw.WriteLine("Merged Bedarf nur für Häuser mit Localnet Stromanschluss;" + mergedHeizungsBedarfOnlyLocalnetHouses);
                    sw.WriteLine("Ebbe Schätzung Fernwärme;" + ebbeFernwärme);
                }

                const double factor = 1_000_000;
                var          diff   = ebbeHeizungsBedarf - localnetHeizungsBedarf;

                ssa.AddEntry(new SankeyEntry("EbbeEnergieBedarf", ebbeHeizungsBedarf / factor, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Merged Heizungsenergiebedarf", localnetHeizungsBedarf * -1 / factor, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Differenz", diff * -1 / factor, 500, Orientation.Up));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeOilEnergySankey()
            {
                var    ebbes = dbRaw.Fetch <EnergiebedarfsdatenBern>();
                double sumEbbeEnergyölHeizung = ebbes.Where(x => x.upd_genhz == 7201).Sum(x => x.calc_ehz);
                double sumEbbeEnergyölWw      = ebbes.Where(x => x.upd_genww == 7201).Sum(x => x.calc_eww);
                var    sumOilUsed             = househeatingentries.Where(x => x.KantonHeatingMethods.Contains(HeatingSystemType.Öl)).Select(x => x.KantonTotalEnergyDemand).Sum();
                //double sumOilFeuerung = househeatingentries.Where(x => x.KantonHeatingMethods.Contains(HeatingSystemType.FeuerungsstättenOil)).Select(x => x.KantonTotalEnergyDemand).Sum();
                var    feuerung = dbRaw.Fetch <FeuerungsStaette>();
                double sumFeuerungsstätteHaus = 0;
                var    oelcount = 0;

                foreach (var staette in feuerung)
                {
                    if (staette.Brennstoff == "Oel")
                    {
                        var ebbeEntry = ebbes.Where(x => x.egid == staette.EGID).ToList();
                        foreach (var bern in ebbeEntry)
                        {
                            sumFeuerungsstätteHaus += bern.calc_ehzww;
                        }

                        oelcount++;
                    }
                }

                Log(MessageType.Info, "Total Öl Gebäude aus feuerungsstätten: " + oelcount);
                const double factor = 1_000_000;
                var          ssa    = new SingleSankeyArrow("Öl", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Öl Heizung", sumEbbeEnergyölHeizung / factor, 500, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Öl WW", sumEbbeEnergyölWw / factor, 500, Orientation.Down));
                var diff = sumEbbeEnergyölHeizung + sumEbbeEnergyölWw - sumOilUsed - sumFeuerungsstätteHaus;

                ssa.AddEntry(new SankeyEntry("BFH Ebbe Öl", sumOilUsed * -1 / factor, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Beco Öl", sumFeuerungsstätteHaus * -1 / factor, 500, Orientation.Straight));
                ssa.AddEntry(new SankeyEntry("Differenz aus der Komplex-Bildung", diff / factor * -1, 500, Orientation.Straight));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeGasEnergySankey()
            {
                var verbrauchsList = localnetEntries.Where(x => x.Verrechnungstyp == "Erdgasverbrauch").ToList();
                var totalSum       = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor             = 1_000_000;
                var          sumAllocatedGasUse = househeatingentries.Sum(x => x.LocalnetGasEnergyUse);
                var          ssa = new SingleSankeyArrow("Erdgas", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Rohdaten Total", totalSum / factor, 5000, Orientation.Straight));

                ssa.AddEntry(new SankeyEntry("Heizungen zugewiesen", sumAllocatedGasUse * -1 / factor, 5000, Orientation.Down));
                ssa.AddEntry(new SankeyEntry("Keinen Heizungen zugewiesen", (totalSum - sumAllocatedGasUse) * -1 / factor, 5000, Orientation.Straight));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeWärmeEnergySankey()
            {
                var verbrauchsList = localnetEntries.Where(x => x.Verrechnungstyp == "Arbeitspreis").ToList();
                var totalSum       = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor             = 1_000_000;
                var          sumAllocatedGasUse = househeatingentries.Sum(x => x.LocalnetFernwärmeEnergyUse);
                var          ssa = new SingleSankeyArrow("Fernwärme", 1000, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Rohdaten Total", totalSum / factor, 5000, Orientation.Straight));

                ssa.AddEntry(new SankeyEntry("Heizungen zugewiesen", sumAllocatedGasUse * -1 / factor, 5000, Orientation.Down));
                ssa.AddEntry(new SankeyEntry("Keinen Heizungen zugewiesen", (totalSum - sumAllocatedGasUse) * -1 / factor, 5000, Orientation.Straight));

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            void MakeHeatingsystemMapLocalnet()
            {
                RGB GetColor(House h)
                {
                    var s = househeatingentries.Single(x => x.HouseGuid == h.HouseGuid);

                    if (s.LocalnetGasEnergyUse > 0)
                    {
                        return(Constants.Green);
                    }

                    return(Constants.Black);
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapLocalnetGasHeizungen.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("No Localnet heating", Constants.Black),
                    new MapLegendEntry("Localnet heating", Constants.Green)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }

            void MakeEtagenHeizungenLocalnet()
            {
                RGB GetColor(House h)
                {
                    var s = househeatingentries.Single(x => x.HouseGuid == h.HouseGuid);

                    if (s.LocalnetHeatingSystemEntryCount == 0)
                    {
                        return(Constants.Black);
                    }

                    if (s.LocalnetHeatingSystemEntryCount == 1)
                    {
                        return(Constants.Blue);
                    }

                    return(Constants.Red);
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapLocalnetHeatingSystemCountsPerHouse.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("No Localnet heating", Constants.Black),
                    new MapLegendEntry("Genau 1 Localnet Heizsystem", Constants.Blue),
                    new MapLegendEntry("Viele Localnet Heizsysteme", Constants.Red)
                };

                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }

            // ReSharper disable once InconsistentNaming
            void MakeHeatingsystemMapEBBE()
            {
                RGB GetColor(House h)
                {
                    var s = househeatingentries.Single(x => x.HouseGuid == h.HouseGuid);

                    if (s.KantonHeatingMethods.Contains(HeatingSystemType.Gas))
                    {
                        return(Constants.Green);
                    }

                    return(Constants.Black);
                }

                var mapPoints     = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapHeatingSystemTypeEbbePerHouse.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("EBBE Gas", Constants.Green),
                    new MapLegendEntry("Sonstiges", Constants.Black)
                };

                //legendEntries.Add(new MapLegendEntry("EBBE Strom", 0, 0, 255));
                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }

            // ReSharper disable once InconsistentNaming
            void MakeHeatingIntensityMap()
            {
                var maxEnergyDensity = househeatingentries.Max(x => x.MergedHeatingEnergyDensity);
                var maxEnergy        = househeatingentries.Max(x => x.MergedHeatingDemand);

                RGBWithSize GetColor(House h)
                {
                    var s      = househeatingentries.Single(x => x.HouseGuid == h.HouseGuid);
                    var color  = 250 * s.MergedHeatingEnergyDensity / maxEnergyDensity;
                    var energy = Math.Log(s.MergedHeatingDemand / maxEnergy * 100) * 50;

                    if (energy < 10)
                    {
                        energy = 10;
                    }

                    return(new RGBWithSize((int)color, 0, 0, (int)energy));
                }

                var mapPoints     = houses.Select(x => x.GetMapPointWithSize(GetColor)).ToList();
                var filename      = MakeAndRegisterFullFilename("MapHeatingIntensityPerHouse.svg", Name, "", slice);
                var legendEntries = new List <MapLegendEntry> {
                    new MapLegendEntry("Energiedichte: 0", Constants.Black),
                    new MapLegendEntry("Energiedichte: " + maxEnergyDensity, Constants.Red)
                };

                //legendEntries.Add(new MapLegendEntry("Sonstiges", Constants.Black));
                Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries, MyStage);
            }
        }
예제 #18
0
        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 potentialHeatingSystems = dbHouse.Fetch <PotentialHeatingSystemEntry>();

            MakeCookingSankey();

            //HeatingSystemCountHistogram();
            //MakeHeatingSystemMapError();
            //MakeHeatingSystemMap();
            void MakeCookingSankey()
            {
                var ssa = new SingleSankeyArrow("PotentialCookingSystems", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var count = 0;

                foreach (var entry in potentialHeatingSystems)
                {
                    if (entry.YearlyGasDemand < 1000)
                    {
                        count++;
                    }
                }

                ssa.AddEntry(new SankeyEntry("Kochgas", count * -1, 2000, Orientation.Up));
                ssa.AddEntry(new SankeyEntry("Elektrisches Kochen", (houses.Count - count) * -1, 2000, Orientation.Straight));
                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            /*
             * void MakeHeatingSystemMapError()
             * {
             *  RGB GetColor(House h)
             *  {
             *      HeatingSystemEntry hse = heatingsystems.Single(x => x.HouseGuid == h.HouseGuid);
             *      if (hse.HeatingSystemType == HeatingSystemType.Fernwärme)
             *      {
             *          return Constants.Red;
             *      }
             *      if (hse.HeatingSystemType == HeatingSystemType.Gasheating)
             *      {
             *          return Constants.Orange;
             *      }
             *      if (hse.HeatingSystemType == HeatingSystemType.FeuerungsstättenGas)
             *      {
             *          return Constants.Orange;
             *      }
             *      return Constants.Black;
             *  }
             *
             *  var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
             *
             *  var filename = MakeAndRegisterFullFilename("KantonHeatingSystemErrors.svg", Name, "");
             *  List<MapLegendEntry> legendEntries = new List<MapLegendEntry>();
             *  legendEntries.Add(new MapLegendEntry("Kanton Fernwärme", Constants.Red));
             *  legendEntries.Add(new MapLegendEntry("Kanton Gas", Constants.Orange));
             *  Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
             * }
             * void MakeHeatingSystemMap()
             * {
             *  Dictionary<HeatingSystemType, RGB> rgbs = new Dictionary<HeatingSystemType, RGB>();
             *  var hs = heatingsystems.Select(x => x.HeatingSystemType).Distinct().ToList();
             *  ColorGenerator cg = new ColorGenerator();
             *  int idx = 0;
             *  foreach (HeatingSystemType type in hs)
             *  {
             *      rgbs.Add(type, cg.GetRGB(idx++));
             *  }
             *  RGB GetColor(House h)
             *  {
             *      HeatingSystemEntry hse = heatingsystems.Single(x => x.HouseGuid == h.HouseGuid);
             *      return rgbs[hse.HeatingSystemType];
             *  }
             *  var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
             *
             *  var filename = MakeAndRegisterFullFilename("HeatingSystemMap.svg", Name, "");
             *  List<MapLegendEntry> 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);
             * }*/
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
        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>());
            }
        private List <SingleSankeyArrow> MakeFernwärmeArrow([ItemNotNull][NotNull] List <BuildingComplex> complexes, [ItemNotNull][NotNull] List <Localnet> rawEntries,
                                                            [ItemNotNull][NotNull] List <MonthlyElectricityUsePerStandort> monthlyElectricityUsePerStandorts)
        {
            var          slice              = Constants.PresentSlice;
            const string section            = "Erdgas";
            const string sectionDescription = "Analyse der Erdgasverbräuche";
            //write python
            var arrows = new List <SingleSankeyArrow>();

            {
                var arr1 = new SingleSankeyArrow("Fernwärme_NachStandorten", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var verbrauchsList = rawEntries.Where(x => x.Verrechnungstyp == "Arbeitspreis").ToList();
                var totalSum       = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total aus Rohdaten", totalSum / factor, 1000, Orientation.Up));
                var monthlyElectricityUseNetz = monthlyElectricityUsePerStandorts.Sum(x => x.YearlyFernwaermeUse);
                arr1.AddEntry(new SankeyEntry("Arbeitspreis in Monthly", monthlyElectricityUseNetz / factor * -1, 1000, Orientation.Down));
                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Fernwärme_Verbrauch_Nach_Identified_Complexed_Standort", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var          totalSum = monthlyElectricityUsePerStandorts.Select(x => x.YearlyFernwaermeUse).Sum();
                const double factor   = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total", totalSum / factor, 1000, Orientation.Up));
                var cleandStandortIDs          = complexes.SelectMany(x => x.CleanedStandorte).ToList();
                var identifiedComplexStandorts = monthlyElectricityUsePerStandorts.Where(x => cleandStandortIDs.Contains(x.CleanedStandort));

                var identifiedmonthlygas = identifiedComplexStandorts.Sum(x => x.YearlyFernwaermeUse);
                arr1.AddEntry(new SankeyEntry("MonthlyElectricityUseNetz", identifiedmonthlygas / factor * -1, 1000, Orientation.Down));
                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Fernwärme_Verbrauch_Nach_BuildingWithGeoCoords", 500, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var          totalSum = monthlyElectricityUsePerStandorts.Select(x => x.YearlyFernwaermeUse).Sum();
                const double factor   = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Fernwärmeverbrauch gesamt", totalSum / factor, 500, Orientation.Straight));
                var cleandStandortIDs                   = complexes.Where(x => x.Coords.Count > 0).SelectMany(x => x.CleanedStandorte).ToList();
                var identifiedComplexStandorts          = monthlyElectricityUsePerStandorts.Where(x => cleandStandortIDs.Contains(x.CleanedStandort));
                var identifiedmonthlyElectricityUseNetz = identifiedComplexStandorts.Sum(x => x.YearlyFernwaermeUse);
                arr1.AddEntry(new SankeyEntry("Fernwärmeverbrauch in\\n Gebäuden mit Geokoordinaten", identifiedmonthlyElectricityUseNetz / factor * -1, 200, Orientation.Straight));

                var notidentified = monthlyElectricityUsePerStandorts.Where(x => !cleandStandortIDs.Contains(x.CleanedStandort));
                var notidentifiedmonthlyElectricityUseNetz = notidentified.Sum(x => x.YearlyFernwaermeUse);
                arr1.AddEntry(new SankeyEntry("Fernwärmeverbrauch in nicht\\n zuordenbaren Gebäuden", notidentifiedmonthlyElectricityUseNetz / factor * -1, 200, Orientation.Up));

                arrows.Add(arr1);
            }
            return(arrows);
        }
        // ReSharper disable once FunctionComplexityOverflow
        private List <SingleSankeyArrow> MakeElectricityArrow([ItemNotNull][NotNull] List <BuildingComplex> complexes, [ItemNotNull][NotNull] List <Localnet> rawEntries,
                                                              [ItemNotNull][NotNull] List <MonthlyElectricityUsePerStandort> monthlyElectricityUsePerStandorts,
                                                              Stage mystage)
        {
            const string section            = "Stromverbräuche";
            const string sectionDescription = "Analyse der Stromverbräuche";
            var          slice = Constants.PresentSlice;
            //write python
            var arrows = new List <SingleSankeyArrow>();

            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Anzahl_nach_Verrechnungstyp", 20000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, mystage);
                rfe.Save();
                var verbrauchsList = rawEntries.Where(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)" || x.Verrechnungstyp == "Netz Tagesstrom (HT)").ToList();
                arr1.AddEntry(new SankeyEntry("Total", verbrauchsList.Count, 100, Orientation.Up));
                var count2 = rawEntries.Count(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)");
                arr1.AddEntry(new SankeyEntry("Nachtstrom", count2 * -1, 100, Orientation.Up));
                var countTag = rawEntries.Count(x => x.Verrechnungstyp == "Netz Tagesstrom (HT)");
                arr1.AddEntry(new SankeyEntry("Tagstrom", countTag * -1, 100, Orientation.Up));
                arrows.Add(arr1);
            }
            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Verbrauch_nach_Verrechnungstyp", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, mystage);
                rfe.Save();
                var verbrauchsList = rawEntries.Where(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)" || x.Verrechnungstyp == "Netz Tagesstrom (HT)").ToList();

                var totalSum = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total", totalSum / factor, 1000, Orientation.Up));
                var sumNight = rawEntries.Where(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)").Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                arr1.AddEntry(new SankeyEntry("Nachtstrom", sumNight / factor * -1, 1000, Orientation.Down));
                var sumDay = rawEntries.Where(x => x.Verrechnungstyp == "Netz Tagesstrom (HT)").Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                arr1.AddEntry(new SankeyEntry("Tagstrom", sumDay / factor * -1, 1000, Orientation.Up));
                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Verbrauch_Nach_Standort", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "",
                                               Constants.PresentSlice, MyStage);
                rfe.Save();
                var verbrauchsList = rawEntries.Where(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)" || x.Verrechnungstyp == "Netz Tagesstrom (HT)").ToList();
                var totalSum       = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total", totalSum / factor, 1000, Orientation.Up));
                var monthlyElectricityUseNetz = monthlyElectricityUsePerStandorts.Sum(x => x.YearlyElectricityUseNetz);
                arr1.AddEntry(new SankeyEntry("MonthlyElectricityUseNetz", monthlyElectricityUseNetz / factor * -1, 1000, Orientation.Down));
                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Verbrauch_Nach_Rechnungsart", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var verbrauchsList = rawEntries.Where(x => x.Verrechnungstyp == "Netz Nachtstrom (NT)" || x.Verrechnungstyp == "Netz Tagesstrom (HT)").ToList();
                var totalSum       = verbrauchsList.Select(x => {
                    if (x.BasisVerbrauch == null)
                    {
                        throw new Exception("Basisverbrauch was null");
                    }

                    return(x.BasisVerbrauch.Value);
                }).Sum();
                const double factor = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total", totalSum / factor, 1000, Orientation.Up));
                var rechungsarten = verbrauchsList.Select(x => x.Rechnungsart).Distinct().ToList();
                var pathlength    = 500;
                foreach (var rechnungsart in rechungsarten)
                {
                    var rechnungsartSum = verbrauchsList.Where(x => x.Rechnungsart == rechnungsart).Select(x => {
                        if (x.BasisVerbrauch == null)
                        {
                            throw new Exception("Basisverbrauch was null");
                        }

                        return(x.BasisVerbrauch.Value);
                    }).Sum();
                    arr1.AddEntry(new SankeyEntry(rechnungsart, rechnungsartSum / factor * -1, pathlength, Orientation.Down));
                    pathlength += 500;
                }

                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Verbrauch_Nach_Identified_Complexed_Standort", 2000, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var          totalSum = monthlyElectricityUsePerStandorts.Select(x => x.YearlyElectricityUseNetz).Sum();
                const double factor   = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Total", totalSum / factor, 1000, Orientation.Up));
                var cleandStandortIDs          = complexes.SelectMany(x => x.CleanedStandorte).ToList();
                var identifiedComplexStandorts = monthlyElectricityUsePerStandorts.Where(x => cleandStandortIDs.Contains(x.CleanedStandort));

                var identifiedmonthlyElectricityUseNetz = identifiedComplexStandorts.Sum(x => x.YearlyElectricityUseNetz);
                arr1.AddEntry(new SankeyEntry("MonthlyElectricityUseNetz", identifiedmonthlyElectricityUseNetz / factor * -1, 1000, Orientation.Down));
                arrows.Add(arr1);
            }

            {
                var arr1 = new SingleSankeyArrow("Stromkunden_Verbrauch_Nach_BuildingWithGeoCoords", 500, MyStage, SequenceNumber, Name, Services.Logger, slice);
                var rfe  = new ResultFileEntry(section, sectionDescription, arr1.FullPngFileName(), arr1.ArrowName, "", Constants.PresentSlice, MyStage);
                rfe.Save();
                var          totalSum = monthlyElectricityUsePerStandorts.Select(x => x.YearlyElectricityUseNetz).Sum();
                const double factor   = 1_000_000;
                arr1.AddEntry(new SankeyEntry("Stromverbrauch gesamt", totalSum / factor, 500, Orientation.Straight));
                var cleandStandortIDs                   = complexes.Where(x => x.Coords.Count > 0).SelectMany(x => x.CleanedStandorte).ToList();
                var identifiedComplexStandorts          = monthlyElectricityUsePerStandorts.Where(x => cleandStandortIDs.Contains(x.CleanedStandort));
                var identifiedmonthlyElectricityUseNetz = identifiedComplexStandorts.Sum(x => x.YearlyElectricityUseNetz);
                arr1.AddEntry(new SankeyEntry("Stromverbrauch in\\n Gebäuden mit Geokoordinaten", identifiedmonthlyElectricityUseNetz / factor * -1, 200, Orientation.Straight));

                var notidentified = monthlyElectricityUsePerStandorts.Where(x => !cleandStandortIDs.Contains(x.CleanedStandort));
                var notidentifiedmonthlyElectricityUseNetz = notidentified.Sum(x => x.YearlyElectricityUseNetz);
                arr1.AddEntry(new SankeyEntry("Stromverbrauch in nicht\\n zuordenbaren Gebäuden", notidentifiedmonthlyElectricityUseNetz / factor * -1, 200, Orientation.Up));

                arrows.Add(arr1);
            }
            return(arrows);
        }
예제 #24
0
        protected override void RunChartMaking()
        {
            var slice            = Constants.PresentSlice;
            var dbHouse          = SqlConnection.GetDatabaseConnection(Stage.Houses, Constants.PresentSlice).Database;
            var houses           = dbHouse.Fetch <House>();
            var houseTypeEntries = dbHouse.Fetch <HouseTypeEntry>();

            MakeHouseTypeEntries();
            //HeatingSystemCountHistogram();
            //MakeHeatingSystemMapError();
            //MakeHeatingSystemMap();
            MakeHouseTypeMap();

            void MakeHouseTypeEntries()
            {
                var ssa = new SingleSankeyArrow("HouseTypeEntries", 1500, MyStage, SequenceNumber, Name, Services.Logger, slice);

                ssa.AddEntry(new SankeyEntry("Houses", houses.Count, 5000, Orientation.Straight));
                var countsPerType = new Dictionary <HouseTypeEnum, int>();

                foreach (var entry in houseTypeEntries)
                {
                    if (!countsPerType.ContainsKey(entry.HouseType))
                    {
                        countsPerType.Add(entry.HouseType, 0);
                    }

                    countsPerType[entry.HouseType]++;
                }

                foreach (var pair in countsPerType)
                {
                    ssa.AddEntry(new SankeyEntry(pair.Key.ToString(), pair.Value * -1, 2000, Orientation.Up));
                }

                Services.PlotMaker.MakeSankeyChart(ssa);
            }

            /*
             * void MakeHeatingSystemMapError()
             * {
             *  RGB GetColor(House h)
             *  {
             *      HeatingSystemEntry hse = heatingsystems.Single(x => x.HouseGuid == h.HouseGuid);
             *      if (hse.HeatingSystemType == HeatingSystemType.Fernwärme)
             *      {
             *          return Constants.Red;
             *      }
             *      if (hse.HeatingSystemType == HeatingSystemType.Gasheating)
             *      {
             *          return Constants.Orange;
             *      }
             *      if (hse.HeatingSystemType == HeatingSystemType.FeuerungsstättenGas)
             *      {
             *          return Constants.Orange;
             *      }
             *      return Constants.Black;
             *  }
             *
             *  var mapPoints = houses.Select(x => x.GetMapPoint(GetColor)).ToList();
             *
             *  var filename = MakeAndRegisterFullFilename("KantonHeatingSystemErrors.svg", Name, "");
             *  List<MapLegendEntry> legendEntries = new List<MapLegendEntry>();
             *  legendEntries.Add(new MapLegendEntry("Kanton Fernwärme", Constants.Red));
             *  legendEntries.Add(new MapLegendEntry("Kanton Gas", Constants.Orange));
             *  Services.PlotMaker.MakeMapDrawer(filename, Name, mapPoints, legendEntries);
             * }*/
            void MakeHouseTypeMap()
            {
                var rgbs = new Dictionary <HouseTypeEnum, RGB>();
                var hs   = houseTypeEntries.Select(x => x.HouseType).Distinct().ToList();
                var cg   = new ColorGenerator();
                var idx  = 0;

                foreach (var type in hs)
                {
                    var rgb = cg.GetRGB(idx++);
                    if (rgb.R == 255 && rgb.B == 255 && rgb.G == 255)
                    {
                        rgb = new RGB(200, 200, 200);
                    }

                    if (rgb.R == 255 && rgb.B == 0 && rgb.G == 0)
                    {
                        rgb = Constants.Orange;
                    }

                    rgbs.Add(type, rgb);
                }

                RGB GetColor(House h)
                {
                    var hse = houseTypeEntries.Single(x => x.HouseGuid == h.HouseGuid);

                    return(rgbs[hse.HouseType]);
                }

                var mapPoints = houses.Select(x => x.GetMapColorForHouse(GetColor)).ToList();

                var filename      = MakeAndRegisterFullFilename("HouseTypeMap.png", Name, "", slice);
                var legendEntries = new List <MapLegendEntry>();

                foreach (var pair in rgbs)
                {
                    legendEntries.Add(new MapLegendEntry(pair.Key.ToString(), pair.Value));
                }

                Services.PlotMaker.MakeOsmMap(Name, filename, mapPoints, new List <WgsPoint>(), legendEntries, new List <LineEntry>());
            }
        }
예제 #25
0
        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 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);
            }
        }
예제 #28
0
        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 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);
            }
        }
예제 #30
0
        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);
            }
        }