From 64047b1ea1b272eb108a8b71b9c4cf7d1243645a Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 5 Jul 2024 14:28:42 +0200 Subject: [PATCH] changes --- .../vsp/bvwp/computation/ComputationKN.java | 26 +- .../vsp/bvwp/computation/NkvCalculator.java | 12 +- .../java/org/tub/vsp/bvwp/data/Headers.java | 39 +- .../analysis/RailAnalysisDataContainer.java | 2 +- .../analysis/StreetAnalysisDataContainer.java | 49 ++- .../org/tub/vsp/bvwp/plot/MultiPlotUtils.java | 40 ++- .../tub/vsp/bvwp/scraping/StreetScraper.java | 5 + .../org/tub/vsp/bvwp/users/kn/Figures1KN.java | 105 +++++- .../tub/vsp/bvwp/users/kn/Figures1RailKN.java | 14 +- .../org/tub/vsp/bvwp/users/kn/Figures2KN.java | 336 ++++++++++++------ .../bvwp/users/kn/RunLocalCsvScrapingKN.java | 134 +++++-- .../bvwp/users/kn/RunLocalRailScrapingKN.java | 5 +- 12 files changed, 534 insertions(+), 233 deletions(-) diff --git a/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java b/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java index 6d73cc3..8028bcd 100644 --- a/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java +++ b/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java @@ -203,37 +203,37 @@ static double nkvOhneKR_induz(Modifications modifications, Amounts amounts, Bene b_all -= b_co2_induz; // ### then rescale the remaining benefit with the corresponding modification: - - b_all *= modifications.nonCo2BenefitsFactor(); - + { + double b_tmp = b_all; + b_all *= modifications.nonCo2BenefitsFactor(); + prn( "b w nonCo2 factor:", b_all, b_tmp ); + } // ### then add the CO2 components with the new values: // co2 Bau { -// double b_tmp = b_all; + double b_tmp = b_all; b_all += modifications.co2Price() / 145. * benefits.co2_infra; -// prn("b_co2_infra", b_all, b_tmp); + prn("b after co2 infra:", b_all, b_tmp); } // co2 Betrieb - -// double bb_tmp = b_all; { -// double b_tmp = b_all; + double b_tmp = b_all; b_all += b_co2_reroute / 145. * modifications.co2Price(); -// prn("co2 after reRoute", b_all, b_tmp); + prn("b after co2 reroute:", b_all, b_tmp); } { -// double b_tmp = b_all; + double b_tmp = b_all; b_all += b_co2_verl / 145. * modifications.co2Price(); -// prn("co2 after verl", b_all, b_tmp); + prn("b after co2 verl:", b_all, b_tmp); } { -// double b_tmp = b_all; + double b_tmp = b_all; b_all += b_co2_induz / 145. * modifications.co2Price(); b_all += modifications.mehrFzkm() * amounts.co2_per_pkwkm * b_per_co2 * modifications.co2Price() / 145; -// prn("co2 after induz", b_all, b_tmp); + prn("b after co2 induz", b_all, b_tmp); } // prn("b_co2_betrieb", b_all, bb_tmp); diff --git a/src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java b/src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java index 8c24a4d..f0f55fb 100644 --- a/src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java +++ b/src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java @@ -24,8 +24,8 @@ public NkvCalculator( StreetBaseDataContainer streetBaseDataContainer ) { public Double calculateNkv( Modifications modifications ) { return calculateNkv( modifications, this.streetBaseDataContainer ); } - public Double calculateCost_CO2( Modifications modifications ) { - return calculateCost_CO2( modifications, this.streetBaseDataContainer ); + public Double calculateCo2_t( Modifications modifications ) { + return calculateCo2_t( modifications, this.streetBaseDataContainer ); } // old static methods beyond: @@ -95,7 +95,7 @@ private static Optional benefitsFromStreetBaseData(StreetBaseDataConta } @Deprecated // use instance approach - public static Double calculateCost_CO2( Modifications modifications, StreetBaseDataContainer streetBaseDataContainer ) { + public static Double calculateCo2_t( Modifications modifications, StreetBaseDataContainer streetBaseDataContainer ) { log.warn("modifications=" + modifications); Optional a = amountsFromStreetBaseData(streetBaseDataContainer); Optional b = benefitsFromStreetBaseData(streetBaseDataContainer); @@ -103,10 +103,10 @@ public static Double calculateCost_CO2( Modifications modifications, StreetBaseD if (a.isEmpty() || b.isEmpty()) { throw new RuntimeException( "co2 costs cannot be computed" ); } - final double co2Costs = -b_co2( modifications, a.get(), b.get() ); + final double result = -b_co2( modifications, a.get(), b.get() ) / 145.; - log.warn( TEXT_RED + "project=" + streetBaseDataContainer.getProjectInformation().getProjectNumber() + "; co2Costs=" + co2Costs + TEXT_BLACK ); + log.warn( TEXT_RED + "project=" + streetBaseDataContainer.getProjectInformation().getProjectNumber() + "; result=" + result + TEXT_BLACK ); - return co2Costs; + return result; } } diff --git a/src/main/java/org/tub/vsp/bvwp/data/Headers.java b/src/main/java/org/tub/vsp/bvwp/data/Headers.java index 4aca629..3f154a6 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/Headers.java +++ b/src/main/java/org/tub/vsp/bvwp/data/Headers.java @@ -12,6 +12,7 @@ public final class Headers{ /** * = {@link #ADDTL_PKWKM_EL03} - {@link #ADDTL_PKWKM_ORIG} */ + public static final String ADDTL_PKWKM = "zusätzliche Pkw-km"; public static final String ADDTL_PKWKM_EL03_DIFF = "addtl_pkwkm_el03_diff"; /** * Der "induzierte" (Mehr-)Verkehr laut PRINS. @@ -21,12 +22,13 @@ public final class Headers{ * Mehrverkehr auf Pkw, den das Projekt erzeugt, laut unserer eigenen Abschätzung. Wird immer mal mit anderen Elastizitäten gerechnet, so * dass sich die Werte immer mal ändern. */ - public static final String ADDTL_PKWKM_EL03 = "addtl_pkwkm_el03"; + public static final String ADDTL_PKWKM_EL03 = ADDTL_PKWKM + " aus Elastizität 0,3"; /** * Mehrverkehr auf Pkw, den das Projekt erzeugt, laut PRINS. */ - public static final String ADDTL_PKWKM_ORIG = "addtl_pkwkm_orig"; - public static final String ADDTL_PKWKM_FROM_TTIME = "addtl_pkwkm_from_ttime"; + public static final String ADDTL_PKWKM_ORIG = ADDTL_PKWKM + " aus PRINS"; + public static final String ADDTL_PKWKM_FROM_TTIME = ADDTL_PKWKM + " aus Reisezeitgewinnen"; + public static final String ADDTL_PKWKM_FROM_TTIME_DIFF = "addtl_pkwkm_from_ttime_diff"; /** * So etwas wie "Neubau", "Knotenpunkt(projekt)", Erweiterung auf 6 oder 8 Spuren. @@ -65,7 +67,7 @@ public final class Headers{ /** * Investitionskosten nach Berechnung der TUD */ - public static final String INVCOST_TUD = "investmentCost_tud"; + public static final String INVCOST_TUD = "Investitionskosten neu"; /** * Umrechnung von Emissionen (welchen??) in CO2-Äquivalente. */ @@ -87,7 +89,7 @@ public final class Headers{ /** * min( 5 , {@link #NKV_ORIG} ) */ - public static final String NKV_ORIG_CAPPED5 = "NKV_orig_capped5"; + public static final String NKV_ORIG = "NKV aus PRINS"; /** * NKV bei erhöhtem CO2-Preis (welchem?). */ @@ -103,8 +105,8 @@ public final class Headers{ */ public static final String NKV_EL03 = "NKV_el03"; public static final String NKV_EL03_CAPPED5 = NKV_EL03 + "_capped5"; - public static final String NKV_CARBON700 = "NKV_carbon700"; - public static final String NKV_CARBON700_CAPPED5 = NKV_CARBON700 + "_capped5"; + public static final String NKV_CARBON700ptpr0 = "NKV mit erhöhten CO2-Kosten"; + public static final String NKV_CARBON700_CAPPED5 = NKV_CARBON700ptpr0 + "_capped5"; /** * Neues NKV mit höherem Mehrverkehr, CO2-Preis 215, sowie höheren Investitionskosten. */ @@ -114,26 +116,28 @@ public final class Headers{ * min( 5, {@link #NKV_EL03_CARBON215_INVCOSTTUD}) */ public static final String NKV_EL03_CARBON215_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON215_INVCOSTTUD + "_capped5"; - public static final String NKV_EL03_CARBON700tpr0 = "NKV_el03_carbon700tpr0"; - public static final String NKV_EL03_CARBON700_CAPPED5 = NKV_EL03_CARBON700tpr0 + "_capped5"; - public static final String NKV_EL03_CARBON700tpr0_INVCOSTTUD = "NKV_el03_carbon700tpr0_invcostTud"; - public static final String NKV_EL03_CARBON700_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON700tpr0_INVCOSTTUD + "_capped5"; + public static final String NKV_EL03_CARBON700ptpr0 = "NKV_el03_carbon700tpr0"; + public static final String NKV_EL03_CARBON700_CAPPED5 = NKV_EL03_CARBON700ptpr0 + "_capped5"; + public static final String NKV_EL03_CARBON700ptpr0_INVCOSTTUD = "NKV_el03_carbon700tpr0_invcostTud"; + public static final String NKV_EL03_CARBON700_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON700ptpr0_INVCOSTTUD + "_capped5"; public static final String NKV_INDUZ_CO2_EN = "BCR_induzCo2"; public static final String NKV_INDUZ_EN = "BCR_induz"; public static final String NKV_NO_CHANGE_EN = "BCR"; /** * Originales NKV. */ - public static final String NKV_ORIG = "NKV_orig"; /** * Dies ist da, damit "bubble size" als Funktion der Einstufung geplottet werden kann. */ public static final String EINSTUFUNG_AS_NUMBER = "einstufungAsNumber"; public static final String PROJECT_NAME = "project _name"; public static final String VERKEHRSBELASTUNG_PLANFALL = "DTV_Planfall"; + public static final String NKV_INVCOSTTUD = "NKV mit erhöhten Baukosten"; + public static final String NKV_ELTTIME = "NKV mit erhöhtem Straßenmehrverkehr"; public static final String NKV_ELTTIME_CARBON215_INVCOSTTUD = "NKV_elTtime_carbon215_invcostTud"; - public static final String NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD = "NKV_elTtime_carbon700tpr0_invcostTud"; + public static final String NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD = "NKV mit erhöhtem Straßenmehrverkehr/Baukosten/CO2-Preis"; public static final String NKV_ELTTIME_CARBON2000_INVCOSTTUD = "NKV_elTtime_carbon2000_invcostTud"; + public static final String CO2_ELTTIME = "CO2[mt] bei erhöhem Straßenmehrverkehr"; public static String capped5Of( String str ) { int cap=5; @@ -147,13 +151,18 @@ public static void addCap5( Table table, String key ) { int cap=5; addCap( cap, table, key ); } - public static void addCap( int cap, Table table, String key ){ - DoubleColumn newColumn = DoubleColumn.create( Headers.cappedOf( cap, key ) ); + public static String addCap( int cap, Table table, String key ){ + final String newColumnName = Headers.cappedOf( cap, key ); + if ( table. containsColumn( newColumnName ) ){ + return newColumnName; + } + DoubleColumn newColumn = DoubleColumn.create( newColumnName ); for( Double number : table.doubleColumn( key ) ){ number = Math.min( number, cap - Math.random() * 0.1 + 0.05 ); newColumn.append( number ); } table.addColumns( newColumn ); + return newColumnName; } private Headers(){} // do not instantiate diff --git a/src/main/java/org/tub/vsp/bvwp/data/container/analysis/RailAnalysisDataContainer.java b/src/main/java/org/tub/vsp/bvwp/data/container/analysis/RailAnalysisDataContainer.java index ded9e61..10c49db 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/container/analysis/RailAnalysisDataContainer.java +++ b/src/main/java/org/tub/vsp/bvwp/data/container/analysis/RailAnalysisDataContainer.java @@ -60,7 +60,7 @@ private void addComputations() { entries.put(Headers.NKV_ORIG, NkvCalculatorRail.calculateNkv( NO_CHANGE, baseDataContainer ) ); entries.put(Headers.NKV_CO2, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer)); entries.put(Headers.NKV_CO2_700_EN, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer)); - entries.put(Headers.NKV_CARBON700, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer)); + entries.put(Headers.NKV_CARBON700ptpr0, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer ) ); entries.put(Headers.NKV_CO2_2000_EN, NkvCalculatorRail.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1 ), baseDataContainer ) ); // entries.put(Headers.NKV_EL03, NkvCalculatorRail.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), baseDataContainer ) ); // entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ), baseDataContainer ) ); diff --git a/src/main/java/org/tub/vsp/bvwp/data/container/analysis/StreetAnalysisDataContainer.java b/src/main/java/org/tub/vsp/bvwp/data/container/analysis/StreetAnalysisDataContainer.java index e062503..e1157d1 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/container/analysis/StreetAnalysisDataContainer.java +++ b/src/main/java/org/tub/vsp/bvwp/data/container/analysis/StreetAnalysisDataContainer.java @@ -77,36 +77,53 @@ private void addComputations() { // streetBaseDataContainer.getProjectInformation().getLength() ); entries.put(Headers.B_PER_KM, streetBaseData.getCostBenefitAnalysis().getOverallBenefit().overall() / streetBaseData.getProjectInformation().getLength() ); - entries.put(Headers.NKV_ORIG, NkvCalculator.calculateNkv( NO_CHANGE, streetBaseData ) ); - entries.put(Headers.NKV_CO2, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) ); - entries.put(Headers.NKV_CO2_700_EN, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) ); - entries.put(Headers.NKV_CARBON700, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) ); - entries.put(Headers.NKV_CO2_2000_EN, NkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1. ), streetBaseData ) ); - entries.put(Headers.NKV_EL03, NkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), streetBaseData ) ); - entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ), streetBaseData ) ); - entries.put(Headers.NKV_EL03_CARBON700tpr0_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1.75 ), streetBaseData ) ); - entries.put(Headers.NKV_EL03_CARBON700tpr0, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, 1., 1.75 ), streetBaseData ) ); -// entries.put(Headers.NKV_EL03_CO2_INVCOST50, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor ), streetBaseData ) ); +// if ( !streetBaseData.getProjectInformation().getProjectNumber().contains( "A20" ) ) { +// return; +// } + final double fact = 1.; + // ptpr0 = stpr 1%. Diskontierung 1% statt 1.7% über Jahre 0 bis 42 bedeutet 1.14 x so viel Nutzen. Vgl. prins.mw. Könnte man ordentlicher machen. + // dennoch 1 gewählt, weil wir nach neuester Überlegung co2 um diesen Faktor nach oben schieben müssen. Machen wir jetzt aber auch nicht, wg. Elektromobilität. + + NkvCalculator nkvCalculator = new NkvCalculator( streetBaseData ); + + entries.put(Headers.NKV_ORIG, nkvCalculator.calculateNkv( NO_CHANGE ) ); + entries.put(Headers.NKV_CO2, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) ); + entries.put(Headers.NKV_CO2_700_EN, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) ); + entries.put(Headers.NKV_CARBON700ptpr0, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) ); + entries.put(Headers.NKV_CO2_2000_EN, nkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1. ) ) ); + entries.put(Headers.NKV_EL03, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ) ) ); + entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ) ) ); + entries.put(Headers.NKV_EL03_CARBON700ptpr0_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor, fact ) ) ); + entries.put(Headers.NKV_EL03_CARBON700ptpr0, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, 1., fact ) ) ); +// entries.put(Headers.NKV_EL03_CO2_INVCOST50, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor ), streetBaseData ) ); +// entries.put(Headers.ADDTL_PKWKM_EL03, addtlFzkmFromElasticity03 ); - entries.put(Headers.CO2_COST_ORIG, Math.max( 1., NkvCalculator.calculateCost_CO2( NO_CHANGE, streetBaseData ) ) ); - entries.put(Headers.CO2_COST_EL03, Math.max( 1., NkvCalculator.calculateCost_CO2( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), streetBaseData ) ) ); - // ("max(1,...)" so that they become visible on logplot. find other solution! +// entries.put(Headers.CO2_COST_ORIG, Math.max( 1., nkvCalculator.calculateCost_CO2( NO_CHANGE, streetBaseData ) ) ); + entries.put(Headers.CO2_COST_EL03, Math.max( 1., nkvCalculator.calculateCo2_t( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ) ) ) ); +// ("max(1,...)" so that they become visible on logplot. find other solution! entries.put(Headers.INVCOST_TUD, this.constructionCostTud ); double AVERAGE_SPEED_OF_ADDITIONAL_TRAVEL = 50; // km/h double addtlFzkmFromTtime = - streetBaseData.getPhysicalEffect().getVehicleHours().overall() * AVERAGE_SPEED_OF_ADDITIONAL_TRAVEL; entries.put( Headers.ADDTL_PKWKM_FROM_TTIME, addtlFzkmFromTtime ); - entries.put( Headers.NKV_ELTTIME_CARBON215_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmFromTtime, constructionCostFactor, 1. ), streetBaseData ) ); - entries.put( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), streetBaseData ) ); + entries.put( Headers.NKV_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, 0., constructionCostFactor, 1. ) ) ); + entries.put( Headers.NKV_ELTTIME, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmFromTtime, 1, 1. ) ) ); + entries.put( Headers.NKV_ELTTIME_CARBON215_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmFromTtime, constructionCostFactor, 1. ) ) ); + entries.put( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmFromTtime, constructionCostFactor, 1. ) ) ); + + // for the 1.15 see "barwert.mw". kai, jun'24 + entries.put(Headers.CO2_ELTTIME, nkvCalculator.calculateCo2_t( new Modifications( co2PriceBVWP, addtlFzkmFromTtime, 1, 1. ) ) ); - entries.put( Headers.NKV_ELTTIME_CARBON2000_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), streetBaseData ) ); + entries.put( Headers.NKV_ELTTIME_CARBON2000_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, addtlFzkmFromTtime, constructionCostFactor, fact ) ) ); if ( streetBaseData.getProjectInformation().getProjectNumber().contains("A1-G50-NI" )) { this.remarks.add("Eher geringer Benefit pro km ... erzeugt dann ueber die El pro km relativ viel Verkehr " + "der per co2 stark negativ bewertet wird."); } +// logger.info("exit"); +// System.exit(-1); } diff --git a/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotUtils.java b/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotUtils.java index f84d281..9609c80 100644 --- a/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotUtils.java +++ b/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotUtils.java @@ -6,30 +6,34 @@ */ public class MultiPlotUtils { public static String pageTop(){ - String result = - "" - + System.lineSeparator() - + "" - + System.lineSeparator() - + " Multi-plot test" - + System.lineSeparator() - + " " - + System.lineSeparator() - + "" - + System.lineSeparator() - + "" - + System.lineSeparator() - + "

Part A

" + System.lineSeparator(); + StringBuilder result = + new StringBuilder( "" + + System.lineSeparator() + + "" + + System.lineSeparator() + + " Multi-plot test" + + System.lineSeparator() + + " " + + System.lineSeparator() + + "" + + System.lineSeparator() + + "" + + System.lineSeparator() + + "

Part A

" + System.lineSeparator() ); for( int ii = 0 ; ii < 99 ; ii++ ){ - result += "
" + System.lineSeparator(); + result.append( "
" ).append( System.lineSeparator() ); } - result += "

Part B

" + System.lineSeparator(); + result.append( "

2. Zwischenbericht

" ).append( System.lineSeparator() ); + for( int ii = 1001 ; ii < 1100 ; ii++ ){ + result.append( "
" ).append( System.lineSeparator() ); + } + result.append( "

Part B

" ).append( System.lineSeparator() ); for( int ii = 0 ; ii < 26 ; ii++ ){ final char c = (char) (ii + 65); // generate A, B, ... to be backwards compatible with what we had so far. kai, mar'24 - result += "
" + System.lineSeparator(); + result.append( "
" ).append( System.lineSeparator() ); } - return result; + return result.toString(); } public static final String pageBottom = "" + System.lineSeparator() + ""; diff --git a/src/main/java/org/tub/vsp/bvwp/scraping/StreetScraper.java b/src/main/java/org/tub/vsp/bvwp/scraping/StreetScraper.java index 60524eb..080cbaa 100644 --- a/src/main/java/org/tub/vsp/bvwp/scraping/StreetScraper.java +++ b/src/main/java/org/tub/vsp/bvwp/scraping/StreetScraper.java @@ -53,6 +53,11 @@ public List extractAllLocalBaseData(String path, String .filter(file -> !file.getName().matches("A20-G10-SH.html")) // gibt es nochmal mit A20-G10-SH-NI. Muss man beide zusammenzählen? kai, feb'24 // .filter(file -> !file.getName().matches("A57-G10-NW.html")) // sehr hohes DTV für 4 Spuren. ?? kai, mar'24 // .filter(file -> !file.getName().matches("A81-G50-BW.html")) // sehr hohes DTV für 4 Spuren. ?? kai, mar'24 + .filter(file -> !file.getName().matches("A61-G10-RP-T2-RP.html")) // benefits and costs for T1 and T2 are same; there are no revised investment costs from TUD for T2 + .filter(file -> !file.getName().matches("A3-G30-HE-T05-HE.html")) // benefits and costs for T04 and T05 are same; there are no revised investment costs from TUD for T05 + .filter(file -> !file.getName().matches("A3-G30-HE-T08-HE.html")) // benefits and costs for T06 and T06 are same; there are no revised investment costs from TUD for T08 + .filter(file -> !file.getName().matches("A40-G30-NW-T4-NW.html")) // dto + .filter(file -> !file.getName().matches("A003-G061-BY.html")) // dto .filter(file -> !file.getName().matches( regexToExclude )) .map(this::extractLocalBaseData) .filter(Optional::isPresent) diff --git a/src/main/java/org/tub/vsp/bvwp/users/kn/Figures1KN.java b/src/main/java/org/tub/vsp/bvwp/users/kn/Figures1KN.java index 663ffe9..a0d35b4 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kn/Figures1KN.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kn/Figures1KN.java @@ -11,10 +11,7 @@ import tech.tablesaw.columns.Column; import tech.tablesaw.io.csv.CsvWriteOptions; import tech.tablesaw.io.csv.CsvWriter; -import tech.tablesaw.plotly.components.Axis; -import tech.tablesaw.plotly.components.Figure; -import tech.tablesaw.plotly.components.Layout; -import tech.tablesaw.plotly.components.Marker; +import tech.tablesaw.plotly.components.*; import tech.tablesaw.plotly.traces.ScatterTrace; import tech.tablesaw.plotly.traces.Trace; @@ -37,6 +34,9 @@ class Figures1KN{ final double nkvCappedMax; final double nkvMin; private static boolean init = true ; + Margin defaultMargin; + + static final Font defaultFont = Font.builder().size( 20 ).family( Font.Family.VERDANA ).build(); Figures1KN( Table table, String xName ){ this.xName = xName; Axis.AxisBuilder xAxisBuilder = Axis.builder(); @@ -88,16 +88,17 @@ class Figures1KN{ // =========================== // =========================== Headers.addCap5( table, NKV_EL03_CARBON215_INVCOSTTUD ); - Headers.addCap5( table, NKV_EL03_CARBON700tpr0_INVCOSTTUD ); + Headers.addCap5( table, NKV_EL03_CARBON700ptpr0_INVCOSTTUD ); Headers.addCap5( table, NKV_ELTTIME_CARBON215_INVCOSTTUD ); Headers.addCap5( table, NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ); Headers.addCap5( table, NKV_ORIG ); Headers.addCap5( table, NKV_EL03 ); - Headers.addCap5( table, NKV_EL03_CARBON700tpr0 ); - Headers.addCap5( table, NKV_CARBON700 ); + Headers.addCap5( table, NKV_EL03_CARBON700ptpr0 ); + Headers.addCap5( table, NKV_CARBON700ptpr0 ); Headers.addCap5( table, NKV_ELTTIME_CARBON2000_INVCOSTTUD ); Headers.addCap( 10, table, NKV_EL03_CARBON215_INVCOSTTUD ); + Headers.addCap( 10, table, NKV_ELTTIME_CARBON215_INVCOSTTUD ); // =========================== // =========================== { @@ -114,7 +115,7 @@ class Figures1KN{ { DoubleColumn column = DoubleColumn.create( EINSTUFUNG_AS_NUMBER ); final double factor = 8.; - final double offset = 2.; + final double offset = 6.; for( String prio : table.stringColumn( EINSTUFUNG ) ){ switch( Einstufung.valueOf( prio ) ){ case VBE -> { @@ -163,9 +164,17 @@ class Figures1KN{ this.table = table; + final String NKV_ORIG_CAPPED5 = Headers.addCap( 5, table, NKV_ORIG ); nkvCappedMax = table.doubleColumn( NKV_ORIG_CAPPED5 ).max() + 0.2 ; - nkvMin = table.doubleColumn( NKV_EL03_CARBON215_INVCOSTTUD_CAPPED5 ).min(); + nkvMin = table.doubleColumn( NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ).min(); + this.defaultMargin = Margin.builder() +// .autoExpand( true ) + .padding( 0 ) + .top( 25 ) // even smaller number swallows the title + .bottom( 100 ) + .build(); + ; } @@ -332,7 +341,7 @@ Figure nkv_carbon700(){ // ======================================================================================== // ======================================================================================== Figure nkv_el03_carbon700(){ - String yName = NKV_EL03_CARBON700tpr0; + String yName = NKV_EL03_CARBON700ptpr0; String y2Name = NKV_EL03_CARBON700_CAPPED5; Axis yAxis = Axis.builder() @@ -681,4 +690,80 @@ static Trace getTraceCyan( Table table, String xName, String y2Name ){ final Trace traceWb = getTrace( xName, y2Name, tableWb, "Knotenpunkt", "cyan" ); return traceWb; } + static List getTracesByColor( Table table, String xName, String y2Name ){ + List list = new ArrayList<>(); + list.add( getTraceRed( table, xName, y2Name ) ); + list.add( getTraceMagenta( table, xName, y2Name ) ); + list.add( getTraceCyan( table, xName, y2Name ) ); + list.add( getTraceOrange( table, xName, y2Name ) ); + return list; + } + static ScatterTrace diagonalLine( Table table, String xName, String y2Name ){ + double xMin = table.numberColumn( xName ).min(); + double yMin = table.numberColumn( y2Name ).min(); + double overallMin = Math.min( xMin, yMin); + + { + var column = table.doubleColumn( xName ); + for ( int ii=0; ii traces = new ArrayList<>(); { @@ -54,31 +54,18 @@ public Figure nkvVsDtv(){ table2.addColumns( table2.doubleColumn( xName ).power( 2 ).setName( "power2" ) ); - { -// Table tableVb = table2 -// .where( table -> table.stringColumn( BAUTYP ).isIn( "EW6", "EW6_EW8" ) ) -// .where( table -> table.doubleColumn( xName ).isGreaterThanOrEqualTo( 60000. ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A57-G10-NW" ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A81-G50-BW" ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A40-G70-NW-T3" ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A1-G30-NW" ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A61-G60-NW" ) ) -// .dropWhere( table -> table.stringColumn( PROJECT_NAME ).containsString( "A66-G10-HE-T1" ) ) -// .sortAscendingOn( xName ); -// LinearModel regression = OLS.fit( Formula.lhs( NKV_EL03_CARBON215_INVCOST50 ), -// tableVb.selectColumns( xName, NKV_EL03_CARBON215_INVCOST50 -//// , "power2" -// ).smile().toDataFrame() ); -// log.info( regression ); -// var column = DoubleColumn.create( "regression" ); -// for( double fittedValue : regression.fittedValues() ){ -// column.append( fittedValue ); -// } -// rTrace = ScatterTrace.builder( tableVb.doubleColumn( xName ), column ).mode( ScatterTrace.Mode.LINE ).build(); - double[] xx = new double[]{ 60_000., 100_000. }; - double[] yy = new double[]{0., 10.}; - traces.add( ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).name( "line to guide the eye" ).build() ); + switch ( whichNKV ) { + case NKV_ORIG -> { + traces.add( ScatterTrace.builder( new double[]{60_000., 100_000.}, new double[]{0., 10.} ).mode( ScatterTrace.Mode.LINE ).name( "line to guide the eye" ).build() ); + traces.add( ScatterTrace.builder( new double[]{ 100_000., 140_000. }, new double[]{0., 10.} ).mode( ScatterTrace.Mode.LINE ).name( "line to guide they eye" ).build() ); + } + case NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD -> { + traces.add( ScatterTrace.builder( new double[]{70_000., 110_000.}, new double[]{0., 10.} ).mode( ScatterTrace.Mode.LINE ).name( "line to guide the eye" ).build() ); + traces.add( ScatterTrace.builder( new double[]{ 110_000., 150_000. }, new double[]{0., 10.} ).mode( ScatterTrace.Mode.LINE ).name( "line to guide they eye" ).build() ); + } + default -> throw new IllegalStateException( "Unexpected value: " + whichNKV ); } + { // Table tableEW8 = table.where( table.stringColumn( BAUTYP ).containsString( "EW8" ) ); // LinearModel regression = OLS.fit( Formula.lhs( NKV_EL03_CARBON215_INVCOST50 ), @@ -89,9 +76,6 @@ public Figure nkvVsDtv(){ // column.append( fittedValue ); // } // traces.add( ScatterTrace.builder( tableEW8.doubleColumn( xName ), column ).mode( ScatterTrace.Mode.LINE ).build() ); - double[] xx = new double[]{ 100_000., 140_000. }; - double[] yy = new double[]{0., 10.}; - traces.add( ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).name( "line to guide they eye" ).build() ); } return new Figure( layout , traces.toArray(new Trace[]{}) ); } @@ -115,14 +99,14 @@ public Figure invcost50_vs_NkvEl03Cprice700InvcostTud(){ Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary - Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().title(xName).titleFont( defaultFont ).autoRange( Axis.AutoRange.REVERSED ) .showZeroLine( false ) .zeroLineWidth( 0 ) .zeroLineColor( "lightgray" ) .range( nkvCappedMax, nkvMin ) .build(); - Axis yAxis = Axis.builder().title( yName ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); Layout layout = Layout.builder( "" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); @@ -143,7 +127,7 @@ public Figure cumcost50_vs_nkvEl03Cprice700InvcostTud(){ String xName = NKV_EL03_CARBON700_INVCOSTTUD_CAPPED5; - Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().title(xName).titleFont( defaultFont ).autoRange( Axis.AutoRange.REVERSED ) .showZeroLine( false ) .zeroLineWidth( 0 ) .zeroLineColor( "lightgray" ) @@ -167,7 +151,7 @@ public Figure cumcost50_vs_nkvEl03Cprice700InvcostTud(){ String yName = "cumulative_cost"; Axis yAxis = Axis.builder().title( yName ) - .build(); + .titleFont( defaultFont ).build(); // String title = "WB meistens NKV<1; Knotenpunkt alle NKV>1; bei Erweiterung (EW) haengt NKV von der Verkehrsmenge ab; bei Neubau (NB) meist hohes NKV wenn Lueckenschluss, sonst niedrig bis < 1"; String title = ""; @@ -184,9 +168,9 @@ public Figure cumcost50_vs_nkvEl03Cprice700InvcostTud(){ // ======================================================================================== public Figure costOrigVsCumulativeCostOrig(){ - String xName = NKV_ORIG_CAPPED5; + String xName = Headers.addCap( 5, table, NKV_ORIG ); - Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().title(xName).titleFont( defaultFont ).autoRange( Axis.AutoRange.REVERSED ) .showZeroLine( false ) .zeroLineWidth( 0 ) .zeroLineColor( "lightgray" ) @@ -206,7 +190,7 @@ public Figure costOrigVsCumulativeCostOrig(){ new CsvWriter().write( table2, CsvWriteOptions.builder( new File( "cumCostsOrig.tsv" ) ).separator( '\t' ).usePrintFormatters( true ).build() ); - Axis yAxis = Axis.builder().title( "Kumulierte Investitionskosten (orig) [Mio]" ).build(); + Axis yAxis = Axis.builder().titleFont( defaultFont ).title( "Kumulierte Investitionskosten (orig) [Mio]" ).build(); Layout layout = Layout.builder( "" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); @@ -220,9 +204,9 @@ public Figure costOrigVsCumulativeCostOrig(){ // ======================================================================================== // ======================================================================================== public Figure cost_VS_nkvOrig(){ - String xName = NKV_ORIG_CAPPED5; + String xName = Headers.addCap( 5, table, NKV_ORIG ); - Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().titleFont( defaultFont ).title(xName).autoRange( Axis.AutoRange.REVERSED ) // .visible( false ) // .showLine( false ) .showZeroLine( false ) @@ -234,7 +218,7 @@ public Figure cost_VS_nkvOrig(){ Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary String yName = INVCOST_ORIG; - Axis yAxis = Axis.builder().title( yName ) + Axis yAxis = Axis.builder().titleFont( defaultFont ).title( yName ) // .showZeroLine( false ) // .showLine( false ) // .visible( false ) @@ -264,7 +248,7 @@ public Figure cost_VS_nkvOrig(){ Figure carbon_vs_nkvEl03Cprice215Invcost50Capped5(){ String xName = NKV_EL03_CARBON215_INVCOSTTUD_CAPPED5; - Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().title(xName).titleFont( defaultFont ).autoRange( Axis.AutoRange.REVERSED ) .showZeroLine( false ) .zeroLineWidth( 0 ) .zeroLineColor( "lightgray" ) @@ -275,7 +259,7 @@ Figure carbon_vs_nkvEl03Cprice215Invcost50Capped5(){ String yName = CO2_COST_ORIG; String y2Name = CO2_COST_EL03; - Axis yAxis = Axis.builder().title( yName ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); String title = ""; if ( ADDTL_LANE_KM.equals( xName ) ) { @@ -297,39 +281,55 @@ Figure carbon_vs_nkvEl03Cprice215Invcost50Capped5(){ } // ======================================================================================== // ======================================================================================== - public List
nkvElttimeCarbon215( int cap ) { + public List
getFigures( int cap, String xNameOrig ){ List
figures = new ArrayList<>(); - String xName = Headers.cappedOf( cap, NKV_ELTTIME_CARBON215_INVCOSTTUD ); - figures.add( investmentCostTud( cap, xName ) ); - figures.add( cumulativeInvestmentCostTud( cap, xName ) ); - figures.add( cumBenefitVsCumCost(NKV_EL03_CARBON215_INVCOSTTUD ) ); + String xName = Headers.cappedOf( cap, xNameOrig ); + figures.add( investmentCostTud( cap, xNameOrig ) ); + figures.add( carbon( cap, xNameOrig ) ); +// figures.add( cumulativeInvestmentCostTud( cap, xName ) ); + figures.add( cumBenefitVsCumCost( xNameOrig ) ); + figures.add( cumBenefitVsCumCarbon( xNameOrig )); return figures; } // ======================================================================================== // ======================================================================================== - public Figure invcosttud_vs_nkvElttimeCarbon700Invcosttud( int cap ){ - String xName = Headers.cappedOf( cap, NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ); - return investmentCostTud( cap, xName ); + public Figure nkvNew_vs_nkvOrig( int cap, String yName ){ + String xName = NKV_ORIG; + String x2Name = Headers.addCap( cap, table, NKV_ORIG ); + Axis.AxisBuilder xAxisBuilder = Axis.builder(); +// xAxisBuilder.range( 0, 50 ); + + Table table2 = table.sortDescendingOn( x2Name ); // cannot remember why this is necessary + + String y2Name = Headers.addCap( cap, table2, yName ); + + Axis yAxis = Axis.builder().titleFont( defaultFont ).title( yName ) +// .range(-5,50) + .build(); + + Layout layout = Layout.builder( "" ).margin( defaultMargin ).xAxis( xAxisBuilder.title( xName ).titleFont( defaultFont ).build() ).yAxis( yAxis ).width( plotWidth ).build(); + + List traces = new ArrayList<>( getTracesByColor( table2, x2Name, y2Name ) ); + traces.add( diagonalLine2( table2, x2Name, y2Name ) ); + traces.add( horizontalNkvOneLine( table2, x2Name ) ); + return new Figure( layout, traces.toArray( new Trace[]{} ) ); } // ======================================================================================== // ======================================================================================== - public Figure carbon_vs_inv(){ + public Figure carbon_vs_invcostTud(){ String xName = INVCOST_TUD; Axis.AxisBuilder xAxisBuilder = Axis.builder(); Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary - String yName = CO2_COST_EL03; - Axis yAxis = Axis.builder().title( yName ).build(); + String yName = CO2_ELTTIME; + Axis yAxis = Axis.builder().titleFont( defaultFont ).title( yName ).build(); - Layout layout = Layout.builder( "" ).xAxis( xAxisBuilder.title( xName ).build() ).yAxis( yAxis ).width( plotWidth ).build(); + Layout layout = Layout.builder( "CO2-Kosten vs Investitionskosten" ).margin( defaultMargin ).xAxis( xAxisBuilder.titleFont( defaultFont ).title( xName ).build() ).yAxis( yAxis ).width( plotWidth ).build(); - List traces = new ArrayList<>(); - traces.add( getTraceCyan( table2, xName, yName ) ); - traces.add( getTraceMagenta( table2, xName, yName ) ); - traces.add( getTraceOrange( table2, xName, yName ) ); - traces.add( getTraceRed( table2, xName, yName ) ); + List traces = new ArrayList<>( getTracesByColor( table2, xName, yName )); +// traces.add( ScatterTrace.builder( new double[]{0., 4000.}, new double[]{0., 1900.} ).mode( ScatterTrace.Mode.LINE ).name( "line to guide the eye" ).build() ); return new Figure( layout, traces.toArray( new Trace[]{} ) ); } @@ -337,7 +337,7 @@ public Figure carbon_vs_inv(){ // ======================================================================================== public Figure nco2v_vs_vs_nkvElttimeCarbon700Invcosttud( int cap ){ String xName = Headers.cappedOf( cap, NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ); - Axis.AxisBuilder xAxisBuilder = Axis.builder(); + Axis.AxisBuilder xAxisBuilder = Axis.builder().titleFont( defaultFont ); if ( cap ==Integer.MAX_VALUE ) { xName = NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD; @@ -363,7 +363,7 @@ public Figure nco2v_vs_vs_nkvElttimeCarbon700Invcosttud( int cap ){ String yName = N_CO2_V; - Axis yAxis = Axis.builder().title( yName ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); Layout layout = Layout.builder( "" ).xAxis( xAxisBuilder.title( xName ).build() ).yAxis( yAxis ).width( plotWidth ).build(); @@ -388,11 +388,11 @@ public Figure invcosttud_vs_nkvElttimeCarbon2000Invcosttud(){ String xName = Headers.capped5Of( NKV_ELTTIME_CARBON2000_INVCOSTTUD ); String y2Name = INVCOST_TUD; - Axis xAxis = Axis.builder().title( xName ).autoRange( Axis.AutoRange.REVERSED ) + Axis xAxis = Axis.builder().title( xName ).titleFont( defaultFont ).autoRange( Axis.AutoRange.REVERSED ) // .range( nkvCappedMax, nkvMin ) .build(); - Axis yAxis = Axis.builder().title( y2Name ).build(); + Axis yAxis = Axis.builder().title( y2Name ).titleFont( defaultFont ).build(); Layout layout = Layout.builder("").xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); @@ -422,19 +422,17 @@ Figure invcost_tud_vs_orig(){ // String y3Name = Headers.COST_OVERALL; String y2Name = INVCOST_TUD; - String plotTitle = ""; - Axis xAxis = Axis.builder() .title( xName ) - .type( Axis.Type.LOG) - .build(); +// .type( Axis.Type.LOG) + .titleFont( defaultFont ).build(); Axis yAxis = Axis.builder() - .type( Axis.Type.LOG ) +// .type( Axis.Type.LOG ) // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) .title( yName ) - .build(); - Layout layout = Layout.builder( plotTitle ) + .titleFont( defaultFont ).build(); + Layout layout = Layout.builder( "Investitionskosten neu vs Investitionskosten lt. PRINS" ) .xAxis( xAxis ) .yAxis( yAxis ) .width( plotWidth ) @@ -465,22 +463,83 @@ Figure invcost_tud_vs_orig(){ public Figure fzkmFromTtime_vs_fzkmOrig(){ String xName = ADDTL_PKWKM_ORIG; - String y2Name = ADDTL_PKWKM_FROM_TTIME; String yName = ADDTL_PKWKM_FROM_TTIME; + String y2Name = yName; - Axis xAxis = Axis.builder().title( xName ).build(); + Axis xAxis = Axis.builder().title( xName ).titleFont( defaultFont ).build(); - Axis yAxis = Axis.builder().title( y2Name ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); Layout layout = Layout.builder().xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); List traces = new ArrayList<>(); + traces.addAll( getTracesByColor( table, xName, y2Name ) ); + traces.add( diagonalLine2( table, xName, y2Name ) ); + return new Figure( layout, traces.toArray(new Trace[]{} ) ); + } + public Figure fzkmEl03_vs_fzkmOrig(){ + String xName = ADDTL_PKWKM_ORIG; - traces.add( getTraceCyan( table, xName, y2Name ) ); - traces.add( getTraceMagenta( table, xName, y2Name ) ); - traces.add( getTraceOrange( table, xName, y2Name ) ); - traces.add( getTraceRed( table, xName, y2Name ) ); + String yName = ADDTL_PKWKM_EL03; + String y2Name = yName; + + Axis xAxis = Axis.builder().title( xName ).titleFont( defaultFont ).build(); + + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); + + Layout layout = Layout.builder().xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + List traces = new ArrayList<>(); + traces.addAll( getTracesByColor( table, xName, y2Name ) ); + traces.add( diagonalLine2( table, xName, y2Name ) ); + return new Figure( layout, traces.toArray(new Trace[]{} ) ); + } + public Figure fzkmFromTtimeDelta_vs_fzkmOrig(){ + String x2Name = ADDTL_PKWKM_ORIG; + + String yName = ADDTL_PKWKM_FROM_TTIME_DIFF; + String y2Name = ADDTL_PKWKM_FROM_TTIME_DIFF; + + Table table2 = Table.create( table.column( PROJECT_NAME ) + , table.stringColumn( BAUTYP ) + , table.column( EINSTUFUNG_AS_NUMBER ) + , table.doubleColumn( x2Name ) + , table.doubleColumn( ADDTL_PKWKM_FROM_TTIME ) + , table.doubleColumn( ADDTL_PKWKM_FROM_TTIME ).subtract( table.doubleColumn( x2Name ) ).setName( y2Name ) + ); + Axis xAxis = Axis.builder().title( x2Name ).titleFont( defaultFont ).build(); + + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); + + Layout layout = Layout.builder().xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + List traces = new ArrayList<>(); + traces.addAll( getTracesByColor( table2, x2Name, y2Name ) ); + return new Figure( layout, traces.toArray(new Trace[]{} ) ); + } + public Figure fzkmFromEl03Delta_vs_fzkmOrig(){ + String xName = ADDTL_PKWKM_ORIG; + + String yName = ADDTL_PKWKM_EL03_DIFF; + String y2Name = yName; + + Table table2 = Table.create( table.column( PROJECT_NAME ) + , table.stringColumn( BAUTYP ) + , table.column( EINSTUFUNG_AS_NUMBER ) + , table.doubleColumn( xName ) + , table.doubleColumn( ADDTL_PKWKM_EL03 ) + , table.doubleColumn( ADDTL_PKWKM_EL03 ).subtract( table.doubleColumn( xName ) ).setName( y2Name ) + ); + + Axis xAxis = Axis.builder().title( xName ).titleFont( defaultFont ).build(); + + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); + + Layout layout = Layout.builder().xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + List traces = new ArrayList<>(); + traces.addAll( getTracesByColor( table2, xName, y2Name ) ); return new Figure( layout, traces.toArray(new Trace[]{} ) ); } public Figure fzkmFromTtimeSum_vs_fzkmOrig(){ @@ -492,29 +551,20 @@ public Figure fzkmFromTtimeSum_vs_fzkmOrig(){ String y2Name = ADDTL_PKWKM_FROM_TTIME_PLUS_ORIG; - Axis xAxis = Axis.builder().title( xName ).build(); + Axis xAxis = Axis.builder().title( xName ).titleFont( defaultFont ).build(); - Axis yAxis = Axis.builder().title( y2Name ).build(); + Axis yAxis = Axis.builder().title( y2Name ).titleFont( defaultFont ).build(); Layout layout = Layout.builder().xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); List traces = new ArrayList<>(); - - traces.add( getTraceCyan( table, xName, y2Name ) ); - traces.add( getTraceMagenta( table, xName, y2Name ) ); - traces.add( getTraceOrange( table, xName, y2Name ) ); - traces.add( getTraceRed( table, xName, y2Name ) ); - + traces.addAll( getTracesByColor( table, xName, y2Name ) ); return new Figure( layout, traces.toArray(new Trace[]{} ) ); } - private static ScatterTrace vertialNkvOneLine( Table table, String y2Name ){ - return ScatterTrace.builder( new double[]{1., 1.}, new double[]{0., 1.1 * table.numberColumn( y2Name ).max()} ).mode( ScatterTrace.Mode.LINE ).name( "NKV=1" ).build(); - } private Figure investmentCostTud( int cap, String xName ){ Axis.AxisBuilder xAxisBuilder = Axis.builder(); if ( cap ==Integer.MAX_VALUE ) { - xName = NKV_EL03_CARBON215_INVCOSTTUD; xAxisBuilder.autoRange( Axis.AutoRange.REVERSED ); } else { xAxisBuilder.range( nkvCappedMax, nkvMin ); @@ -523,28 +573,37 @@ private Figure investmentCostTud( int cap, String xName ){ Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary String yName = INVCOST_TUD; - Axis yAxis = Axis.builder().title( yName ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); - Layout layout = Layout.builder( "" ).xAxis( xAxisBuilder.title( xName ).build() ).yAxis( yAxis ).width( plotWidth ).build(); + Layout layout = Layout.builder( "" ).margin( defaultMargin ).xAxis( xAxisBuilder.title( xName ).titleFont( defaultFont ).build() ).yAxis( yAxis ).width( plotWidth ).build(); - List traces = new ArrayList<>(); + List traces = new ArrayList<>( getTracesByColor( table2, xName, yName )); + traces.add( vertialNkvOneLine( table2, yName ) ); + return new Figure( layout, traces.toArray( new Trace[]{} ) ); + } + private Figure carbon( int cap, String xName ){ + Axis.AxisBuilder xAxisBuilder = Axis.builder(); - // the nkv=1 line: - double[] xx = new double[]{1., 1.}; - double[] yy = new double[]{0., 1.1* table2.numberColumn( yName ).max() }; - traces.add( ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).name("NKV=1").build() ); + if ( cap ==Integer.MAX_VALUE ) { + xAxisBuilder.autoRange( Axis.AutoRange.REVERSED ); + } else { + xAxisBuilder.range( nkvCappedMax, nkvMin ); + } - traces.add( getTraceCyan( table2, xName, yName ) ); - traces.add( getTraceMagenta( table2, xName, yName ) ); - traces.add( getTraceOrange( table2, xName, yName ) ); - traces.add( getTraceRed( table2, xName, yName ) ); + Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary + + String yName = CO2_ELTTIME; + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); + + Layout layout = Layout.builder( "" ).margin( defaultMargin ).xAxis( xAxisBuilder.title( xName ).titleFont( defaultFont ).build() ).yAxis( yAxis ).width( plotWidth ).build(); + List traces = new ArrayList<>( getTracesByColor( table2, xName, yName )); + traces.add( vertialNkvOneLine( table2, yName ) ); return new Figure( layout, traces.toArray( new Trace[]{} ) ); } private Figure cumulativeInvestmentCostTud( int cap, String xName ){ Axis.AxisBuilder xAxisBuilder = Axis.builder(); if ( cap ==Integer.MAX_VALUE ) { - xName = NKV_EL03_CARBON215_INVCOSTTUD; xAxisBuilder.autoRange( Axis.AutoRange.REVERSED ); } else { xAxisBuilder.range( nkvCappedMax, nkvMin ); @@ -557,9 +616,9 @@ private Figure cumulativeInvestmentCostTud( int cap, String xName ){ // new CsvWriter().write( table2, CsvWriteOptions.builder( new File( "cumCosts.tsv" ) ).separator( '\t' ).usePrintFormatters( true ).build() ); - Axis xAxis = xAxisBuilder.title( xName ).build(); - Axis yAxis = Axis.builder().title( yName ).build(); - Layout layout = Layout.builder( "" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + Axis xAxis = xAxisBuilder.title( xName ).titleFont( defaultFont ).build(); + Axis yAxis = Axis.builder().title( yName ).titleFont( defaultFont ).build(); + Layout layout = Layout.builder( "Kumulierte Investitionskosten:" ).margin( defaultMargin ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); List traces = new ArrayList<>(); @@ -570,11 +629,64 @@ private Figure cumulativeInvestmentCostTud( int cap, String xName ){ return new Figure( layout, traces.toArray( new Trace[]{} ) ); } + private Figure cumBenefitVsCumCarbon( String nkvToUseOrig ){ + String nkvToUse = Headers.cappedOf( 30, nkvToUseOrig ); + Headers.addCap( 30, table, nkvToUseOrig ); + + Axis.AxisBuilder xAxisBuilder = Axis.builder().titleFont( defaultFont ); + + final String BENEFIT = "benefit"; + + // add benefits row: + Table tableTmp = Table.create( table.stringColumn( PROJECT_NAME ), table.doubleColumn( nkvToUse ), table.doubleColumn( CO2_ELTTIME ) ); + tableTmp.addColumns( table.doubleColumn( nkvToUse ).multiply( table.doubleColumn( INVCOST_TUD ) ).setName( BENEFIT ) ); + + tableTmp = tableTmp.sortDescendingOn( nkvToUse ); // necessary to get cumulations right + + System.out.println( tableTmp.print() ); + + // add cumulative benefits row: + String yName = "cumulative_" + BENEFIT; + { + DoubleColumn cumulativeCost = DoubleColumn.create( yName ); + double sum = 0.; + for( Double cost : tableTmp.doubleColumn( BENEFIT ) ){ + sum += cost; + cumulativeCost.append( sum ); + } + tableTmp.addColumns( cumulativeCost ); + + } + // add cumulative costs row: + String xName = "cumulative_" + CO2_ELTTIME; + { + DoubleColumn cumulativeCost = DoubleColumn.create( xName ); + double sum = 0.; + for( Double cost : tableTmp.doubleColumn( CO2_ELTTIME ) ){ + sum += cost; + cumulativeCost.append( sum ); + } + tableTmp.addColumns( cumulativeCost ); + } + +// new CsvWriter().write( table2, CsvWriteOptions.builder( new File( "cumCosts.tsv" ) ).separator( '\t' ).usePrintFormatters( true ).build() ); + + Axis xAxis = xAxisBuilder.title( xName ).build(); + Axis yAxis = Axis.builder().titleFont( defaultFont ).title( yName ).build(); + Layout layout = Layout.builder( "Kumulierte Nutzen vs kumulierter CO2-Ausstoss:" ).margin( defaultMargin ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + List traces = new ArrayList<>(); + + var nameInLegend = "cumulative cost"; + traces.add( ScatterTrace.builder( tableTmp.doubleColumn( xName ), tableTmp.doubleColumn(yName) ).mode( ScatterTrace.Mode.LINE ).showLegend( true ).name( String.format( legendFormat, nameInLegend ) ).build() ); + + return new Figure( layout, traces.toArray( new Trace[]{} ) ); + } private Figure cumBenefitVsCumCost( String nkvToUseOrig ){ String nkvToUse = Headers.cappedOf( 30, nkvToUseOrig ); Headers.addCap( 30, table, nkvToUseOrig ); - Axis.AxisBuilder xAxisBuilder = Axis.builder(); + Axis.AxisBuilder xAxisBuilder = Axis.builder().titleFont( defaultFont ); final String BENEFIT = "benefit"; @@ -614,7 +726,7 @@ private Figure cumBenefitVsCumCost( String nkvToUseOrig ){ Axis xAxis = xAxisBuilder.title( xName ).build(); Axis yAxis = Axis.builder().title( yName ).build(); - Layout layout = Layout.builder( "" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + Layout layout = Layout.builder( "Kumulierter Nutzen vs kumulierte Investitionskosten:" ).margin(defaultMargin).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); List traces = new ArrayList<>(); diff --git a/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalCsvScrapingKN.java b/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalCsvScrapingKN.java index fbe0b55..9b18126 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalCsvScrapingKN.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalCsvScrapingKN.java @@ -5,11 +5,9 @@ import org.tub.vsp.bvwp.BvwpUtils; import org.tub.vsp.bvwp.data.Headers; import org.tub.vsp.bvwp.data.container.analysis.StreetAnalysisDataContainer; -import org.tub.vsp.bvwp.data.type.Einstufung; import org.tub.vsp.bvwp.io.StreetCsvWriter; import org.tub.vsp.bvwp.plot.MultiPlotUtils; import org.tub.vsp.bvwp.scraping.StreetScraper; -import tech.tablesaw.api.Row; import tech.tablesaw.api.Table; import tech.tablesaw.plotly.components.Figure; import tech.tablesaw.plotly.display.Browser; @@ -18,10 +16,12 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Paths; -import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; -import static org.tub.vsp.bvwp.data.Headers.NKV_ORIG_CAPPED5; +import static org.tub.vsp.bvwp.data.Headers.*; public class RunLocalCsvScrapingKN{ private static final Logger logger = LogManager.getLogger( RunLocalCsvScrapingKN.class ); @@ -64,10 +64,12 @@ public static void main(String[] args) throws IOException{ Table table = csvWriter.writeCsv( allStreetBaseData ); // === + final String NKV_ORIG_CAPPED5 = Headers.addCap( 5, table, NKV_ORIG); Figures1KN figures1 = new Figures1KN( table, NKV_ORIG_CAPPED5 ); Figures2KN figures2 = new Figures2KN( table ); List
plots1 = new ArrayList<>(); + List
plotsZb = new ArrayList<>(); List
plots2 = new ArrayList<>(); // plots1.add( figures1.invCostTud() ); @@ -87,64 +89,126 @@ public static void main(String[] args) throws IOException{ // plots1.add( figures1.nkv_el03_diff() ); // plots1.add( figures1.dtv() ); // plots1.add( figures1.fzkmNew() ); -// + + + // Induzierter Strassenmehrverkehr: + plotsZb.add( figures2.fzkmEl03_vs_fzkmOrig() ); +// plotsZb.add( figures2.fzkmFromEl03Delta_vs_fzkmOrig() ); + plotsZb.add( figures2.fzkmFromTtime_vs_fzkmOrig() ); +// plotsZb.add( figures2.fzkmFromTtimeDelta_vs_fzkmOrig() ); + + + // Abhängigkeit von Verkehrsnachfrage: + plotsZb.add( figures2.nkvNeu_vs_dtv( NKV_ORIG) ); +// plotsZb.add( figures2.nkvNeu_vs_dtv( NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ) ); + + + // Veränderung NKV durch ... + + // ... Investitionskosten: + plotsZb.add( figures2.nkvNew_vs_nkvOrig( 10, NKV_INVCOSTTUD ) ); + + // ... induzierten Verkehr: + plotsZb.add( figures2.nkvNew_vs_nkvOrig( 10, NKV_ELTTIME ) ); + + // ... erhöhten CO2-Kosten: + plotsZb.add( figures2.nkvNew_vs_nkvOrig( 10, NKV_CARBON700ptpr0 ) ); + + // ... alle drei: + plotsZb.add( figures2.nkvNew_vs_nkvOrig( 10, NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ) ); + + // andere Darstellung "alle drei": + plotsZb.addAll( figures2.getFigures( 10, NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ) ); + + // Änlichkeit zwischen carbon cost und Investitionskosten: + plotsZb.add( figures2.carbon_vs_invcostTud() ); + + // ### nicht verwendet: + + // changes in investment cost: plots2.add( figures2.invcost_tud_vs_orig() ); - plots2.add( figures2.nkvVsDtv() ); -// plots2.add( figures2.cost_VS_nkvOrig() ); -// plots2.add( figures2.costOrigVsCumulativeCostOrig() ); - plots2.addAll( figures2.nkvElttimeCarbon215(5 ) ); - plots2.add( figures2.invcosttud_vs_nkvEl03Cprice215Invcosttud( 5) ); - plots2.add( figures2.cumulativeCostTud_vs_nkvEl03Cprice215InvcostTud(5 ) ); - plots2.add( figures2.cumulativeCostTud_vs_nkvEl03Cprice215InvcostTud(Integer.MAX_VALUE ) ); - plots2.add( figures2.invcosttud_vs_nkvEl03Cprice215Invcosttud( Integer.MAX_VALUE) ); - plots2.add( figures2.invcosttud_vs_nkvElttimeCarbon700Invcosttud(5) ); -// plots2.add( figures2.invcost50_vs_NkvEl03Cprice700InvcostTud() ); -// plots2.add( figures2.cumcost50_vs_nkvEl03Cprice700InvcostTud() ); - plots2.add( figures2.invcosttud_vs_nkvElttimeCarbon2000Invcosttud() ); - plots2.add( figures2.carbon_vs_nkvEl03Cprice215Invcost50Capped5() ); +// plots2.add( figures2.cost_VS_nkvOrig() ); + +// plots2.add( figures2.costOrigVsCumulativeCostOrig() ); + - plots2.add( figures2.nco2v_vs_vs_nkvElttimeCarbon700Invcosttud(5 ) ); +// plots2.addAll( figures2.getFigures( 5, NKV_ORIG ) ); +// plots2.addAll( figures2.getFigures( 5, NKV_ELTTIME_CARBON215_INVCOSTTUD ) ); - plots2.add( figures2.carbon_vs_inv() ); +// plots2.add( figures2.invcosttud_vs_nkvEl03Cprice215Invcosttud( 5) ); +// plots2.add( figures2.cumulativeCostTud_vs_nkvEl03Cprice215InvcostTud(5 ) ); +// plots2.add( figures2.cumulativeCostTud_vs_nkvEl03Cprice215InvcostTud(Integer.MAX_VALUE ) ); +// plots2.add( figures2.invcosttud_vs_nkvEl03Cprice215Invcosttud( Integer.MAX_VALUE) ); +// +// plots2.add( figures2.invcosttud_vs_nkvElttimeCarbon700Invcosttud(5) ); +//// plots2.add( figures2.invcost50_vs_NkvEl03Cprice700InvcostTud() ); +//// plots2.add( figures2.cumcost50_vs_nkvEl03Cprice700InvcostTud() ); +// plots2.add( figures2.invcosttud_vs_nkvElttimeCarbon2000Invcosttud() ); +// +// plots2.add( figures2.carbon_vs_nkvEl03Cprice215Invcost50Capped5() ); +// +// plots2.add( figures2.nco2v_vs_vs_nkvElttimeCarbon700Invcosttud(5 ) ); // === - String page = MultiPlotUtils.pageTop() + System.lineSeparator(); + StringBuilder page = new StringBuilder( MultiPlotUtils.pageTop() + System.lineSeparator() ); for( int ii=0; ii comparator = ( o1, o2 ) -> { - Einstufung p1 = Einstufung.valueOf( o1.getString( Headers.EINSTUFUNG ) ); - Einstufung p2 = Einstufung.valueOf( o2.getString( Headers.EINSTUFUNG ) ); - return p1.compareTo( p2 ); - }; - table = table.sortOn( comparator ); - NumberFormat format = NumberFormat.getCompactNumberInstance(); - format.setMaximumFractionDigits( 0 ); - table.numberColumn( Headers.CO2_COST_EL03 ).setPrintFormatter( format, "n/a" ); + Table table2 = table.where( table.stringColumn( Headers.PROJECT_NAME ).containsString( "A61-" ) ); + + Table table3 = Table.create( table2.stringColumn( PROJECT_NAME ) + ,table2.numberColumn( Headers.B_OVERALL ) + , table2.numberColumn( Headers.INVCOST_ORIG ) + , table2.numberColumn( Headers.INVCOST_TUD ) + , table2.numberColumn( Headers.NKV_ORIG ) +// , table2.numberColumn( Headers.NKV_EL03_CARBON215_INVCOSTTUD ) + , table2.numberColumn( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD ) + ); + + System.out.println( table3 ); + +// newTable.write().csv( "a20.csv" ); + + + +// Comparator comparator = ( o1, o2 ) -> { +// Einstufung p1 = Einstufung.valueOf( o1.getString( Headers.EINSTUFUNG ) ); +// Einstufung p2 = Einstufung.valueOf( o2.getString( Headers.EINSTUFUNG ) ); +// return p1.compareTo( p2 ); +// }; +// table = table.sortOn( comparator ); +// NumberFormat format = NumberFormat.getCompactNumberInstance(); +// format.setMaximumFractionDigits( 0 ); +// table.numberColumn( Headers.CO2_COST_EL03 ).setPrintFormatter( format, "n/a" ); // Table table2 = table.where( table.numberColumn( Headers.NKV_EL03_CARBON215_INVCOSTTUD ).isLessThan( 1. ) ); // diff --git a/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalRailScrapingKN.java b/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalRailScrapingKN.java index 05c5d35..d6e1487 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalRailScrapingKN.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kn/RunLocalRailScrapingKN.java @@ -2,6 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.tub.vsp.bvwp.data.Headers; import org.tub.vsp.bvwp.data.container.analysis.RailAnalysisDataContainer; import org.tub.vsp.bvwp.io.RailTableCreator; import org.tub.vsp.bvwp.plot.MultiPlotUtils; @@ -17,8 +18,6 @@ import java.util.ArrayList; import java.util.List; -import static org.tub.vsp.bvwp.data.Headers.NKV_ORIG_CAPPED5; - public class RunLocalRailScrapingKN{ private static final Logger logger = LogManager.getLogger( RunLocalRailScrapingKN.class ); @@ -36,7 +35,7 @@ public static void main(String[] args) throws IOException { // === - Figures1RailKN figures1 = new Figures1RailKN( table, NKV_ORIG_CAPPED5 ); + Figures1RailKN figures1 = new Figures1RailKN( table, Headers.addCap( 5, table, Headers.NKV_ORIG ) ); // Figures2KN figures2 = new Figures2KN( table ); List
plots1 = new ArrayList<>();