From 565cecffd91dd4f46d38b959e8bafd590c7097ef Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Mon, 17 Jun 2024 21:37:27 +0200 Subject: [PATCH 1/3] Grafik mit 2 Traces --- .../tub/vsp/bvwp/users/kmt/FiguresKMT.java | 92 ++++++++++++++++++- .../users/kmt/RunLocalCsvScrapingKMT.java | 9 +- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java b/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java index 5c545eb..7cc6f04 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java @@ -232,9 +232,10 @@ static Figure createFigureNkvChange(int plotWidth, Table table, String xName, St double[] xy1 = new double[]{1., 1.}; Trace diagonale = ScatterTrace.builder( xx, yy ) - .name(xName + " = " + yName) - .mode( Mode.LINE ) - .build(); + .name(xName + " = " + yName) + .mode( Mode.LINE ) + .marker( Marker.builder().color( "gray" ).build() ) + .build(); Trace horizontalCbr1 = ScatterTrace.builder( xx, xy1 ) .name(yName + " = 1") @@ -252,6 +253,91 @@ static Figure createFigureNkvChange(int plotWidth, Table table, String xName, St return new Figure( layout, cbrOverCbrTrace, diagonale, horizontalCbr1, verticalCbr1 ); } + /** + * Für NKV vergleich-Plot mit 2 Y-Achsen. + * @param plotWidth + * @param table + * @param xName + * @param yName + * @param yName2 + * @return + */ + static Figure createFigureNkvChange(int plotWidth, Table table, String xName, String yName, String yName2) { + +// String xName = Headers.NKV_NO_CHANGE; +// String yName = Headers.NKV_CO2; + double maxX = 20.; + double maxY = 20.; + + Axis xAxis = Axis.builder() + .type( Type.LINEAR ) + .title( xName ) + .range(0. ,maxX) +// .autoRange( Axis.AutoRange.REVERSED ); + .build(); + + table = table.sortDescendingOn( xName ); + + Axis yAxis = Axis.builder() + .type( Type.LINEAR ) + .range(Double.min(0., 1.1*table.numberColumn(yName).min()) ,maxY) +// .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title( yName ) + .build(); + + Axis yAxis2 = Axis.builder() + .type( Type.LINEAR ) + .range(Double.min(0., 1.1*table.numberColumn(yName2).min()) ,maxY) +// .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title( yName2 ) + .build(); + + Layout layout = Layout.builder( yName + " and " +yName2 + " over " +xName ) + .xAxis( xAxis ) + .yAxis( yAxis ) + .yAxis2( yAxis2 ) + .width( plotWidth ) + .build(); + + Trace cbrOverCbrTrace1 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) + .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) + .name( yName ) + .marker( Marker.builder().color( "blue" ).build() ) + .build(); + + Trace cbrOverCbrTrace2 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName2 ) ) + .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) + .name( yName2 ) + .marker( Marker.builder().color( "red" ).build() ) + .build(); + +// double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; +// double[] yy = new double[]{0., 1.1* table.numberColumn( xName ).max()}; + double[] xx = new double[]{0., maxX }; + double[] yy = new double[]{0., maxY}; + double[] xy1 = new double[]{1., 1.}; + + Trace diagonale = ScatterTrace.builder( xx, yy ) + .name(xName + " = " + yName) + .mode( Mode.LINE ) + .marker(Marker.builder().color("orange").build()) + .build(); + + Trace horizontalCbr1 = ScatterTrace.builder( xx, xy1 ) + .name(yName + " = 1") + .mode( Mode.LINE ) + .marker( Marker.builder().color( "gray" ).build() ) + .build(); + + Trace verticalCbr1 = ScatterTrace.builder( xy1, yy ) + .name(xName + " = 1") + .mode( Mode.LINE ) + .marker( Marker.builder().color( "gray" ).build() ) + .build(); + + + return new Figure( layout, cbrOverCbrTrace1, cbrOverCbrTrace2, diagonale, horizontalCbr1, verticalCbr1 ); + } /** Idee um eine Trennung zu erzeugen... Noch nicht optimal * @param title diff --git a/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java b/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java index 3dd8b99..ca39cef 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java @@ -275,8 +275,11 @@ private static void kmtPlots_Co2values(Axis xAxis, int plotWidth, Table table, S Figure figureNkvChange_Co2_2000_InvCost150 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST150_EN); Figure figureNkvChange_Co2_2000_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST200_EN); + Figure figureNkvChange_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOST150_EN, Headers.NKV_INVCOST200_EN); + Figure figureNkvChange_Co2_700_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOST150_EN, Headers.NKV_CO2_700_INVCOST200_EN); + Figure figureNkvChange_Co2_2000_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST150_EN, Headers.NKV_CO2_2000_INVCOST200_EN); - String page = MultiPlotUtils.pageTop() + System.lineSeparator() + + String page = MultiPlotUtils.pageTop() + System.lineSeparator() + figureNkvChangeCo2_700.asJavascript("plot1") + System.lineSeparator() + figureNkvChangeInduz_2000.asJavascript("plot2") + System.lineSeparator() + @@ -292,6 +295,10 @@ private static void kmtPlots_Co2values(Axis xAxis, int plotWidth, Table table, S figureNkvChange_Co2_2000_InvCost150.asJavascript("plot10") + System.lineSeparator() + figureNkvChange_Co2_2000_InvCost200.asJavascript("plot11") + System.lineSeparator() + + //Plot, der beide Inv Kostenveränderungen für alle Projekte enthält + figureNkvChange_InvCost150_200.asJavascript("plotA") + System.lineSeparator() + + figureNkvChange_Co2_700_InvCost150_200.asJavascript("plotB") + System.lineSeparator() + + figureNkvChange_Co2_2000_InvCost150_200.asJavascript("plotC") + System.lineSeparator() + MultiPlotUtils.pageBottom; File outputFile = Paths.get("EWGT_CO2-Values.html").toFile(); From efc6ddcb6383a59a54f24830e2c169cf96495805 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 20 Jun 2024 11:53:36 +0200 Subject: [PATCH 2/3] reformatting --- .../tub/vsp/bvwp/users/kmt/FiguresKMT.java | 679 +++++++++--------- 1 file changed, 348 insertions(+), 331 deletions(-) diff --git a/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java b/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java index 7cc6f04..92db5b8 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kmt/FiguresKMT.java @@ -15,343 +15,360 @@ class FiguresKMT { - private static final String legendFormat = "%30s"; - - //Do not instanciate - FiguresKMT(){} - - private static Trace getPriorityTrace( Table table, Einstufung priority, String xName, String yName, - String color){ - Table tableVbe = BvwpUtils.extractPriorityTable(table, priority.name()); - return ScatterTrace.builder( tableVbe.numberColumn( xName ), tableVbe.numberColumn( yName ) ) - .text( tableVbe.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, yName + "_" + priority.name()) ) - .marker( Marker.builder().color( color).build() ) - .build(); - } - - //######################### - - static Figure createFigureCostByPriority(int plotWidth, Table table, String xName ){ - Figure figure3; - String yName = Headers.INVCOST_ORIG; - String y3Name = Headers.INVCOST_ORIG; - String y2Name = Headers.INVCOST_ORIG; - - double maxX = table.numberColumn( xName ).max(); - Axis xAxis = Axis.builder() - .type( Type.LINEAR ) - .title( xName ) - .range(0. ,maxX) -// .autoRange( Axis.AutoRange.REVERSED ); - .build(); - - Axis yAxis = Axis.builder() - .type( Type.LOG ) - // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) - .title( yName ) - .build(); - Layout layout = Layout.builder( yName ) - .xAxis( xAxis ) - .yAxis( yAxis ) - .width( plotWidth ) - .build(); - Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, yName ) ) - .build(); - - final Trace traceWb = getPriorityTrace(table, Einstufung.WB, xName, y2Name, "cyan" ); - final Trace traceWbp = getPriorityTrace(table, Einstufung.WBP, xName, y2Name, "yellow" ); - final Trace traceVb = getPriorityTrace(table, Einstufung.VB, xName, y2Name, "orange" ); - final Trace traceVbe = getPriorityTrace( table, Einstufung.VBE , xName, y2Name, "red" ); - - Trace trace3 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( y3Name ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, y3Name ) ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - // double[] xx = new double[]{1., 200.}; - // Trace trace1 = ScatterTrace.builder( xx, xx ) - // .mode( ScatterTrace.Mode.LINE ) - // .build(); - - figure3 = new Figure( layout, trace, trace3, traceWb, traceWbp, traceVb, traceVbe ); - return figure3; - } - static Figure createFigureNkvByPriority( Axis xAxis, int plotWidth, Table table, String xName){ - Figure figure2; - String yName = Headers.NKV_ORIG; -// String y3Name = Headers.NKV_CO2_680_EN; - String y2Name = Headers.NKV_EL03_CARBON215_INVCOSTTUD; - - Axis yAxis = Axis.builder() -// .type( Axis.Type.LOG ) // wirft NKV < 0 raus! - // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) - .title( yName ) - .build(); - Layout layout = Layout.builder( yName ) - .xAxis( xAxis ) - .yAxis( yAxis ) - .width( plotWidth ) - .build(); - Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, String.format( "%30s" , yName ) ) ) - .build(); - - final Trace traceWb = getPriorityTrace(table, Einstufung.WB, xName, y2Name, "cyan" ); - final Trace traceWbp = getPriorityTrace(table, Einstufung.WBP, xName, y2Name, "yellow" ); - final Trace traceVb = getPriorityTrace(table, Einstufung.VB, xName, y2Name, "orange" ); - final Trace traceVbe = getPriorityTrace( table, Einstufung.VBE , xName, y2Name, "red" ); - - -// Trace trace3 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( y3Name ) ) -// .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) -// .name( String.format( legendFormat, y3Name ) ) -// .marker( Marker.builder().color( "gray" ).build() ) -// .build(); - - double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; - double[] yy = new double[]{1., 1.}; - Trace trace4 = ScatterTrace.builder( xx, yy ) - .mode( ScatterTrace.Mode.LINE ) - .build(); - - figure2 = new Figure( layout, trace -// , trace3 - , traceWb,traceWbp, traceVb, traceVbe, trace4 ); - return figure2; - } - - static Figure createFigureNkv(Axis xAxis, int plotWidth, Table table, String xName){ - Figure figure2; - String yName = Headers.NKV_ORIG; - String y3Name = Headers.NKV_CO2_700_EN; -// String y2Name = Headers.NKV_INDUZ_CO2; - - Axis yAxis = Axis.builder() - .type( Type.LINEAR ) - .range( Double.min( - 1.1*table.numberColumn(y3Name).min(), 1.1*table.numberColumn( yName ).min()), - 20. ) - .title( yName ) - .build(); - Layout layout = Layout.builder( yName ) - .xAxis( xAxis ) - .yAxis( yAxis ) - .width( plotWidth ) - .build(); - Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( yName ) - .build(); - - Trace trace3 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( y3Name ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( y3Name ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; - double[] yy = new double[]{1., 1.}; - Trace trace4 = ScatterTrace.builder( xx, yy ) - .mode( Mode.LINE ) - .marker(Marker.builder().color( "red" ).build()) - .build(); - - figure2 = new Figure( layout, trace, trace3, trace4 ); - return figure2; + private static final String legendFormat = "%30s"; + + // Do not instanciate + FiguresKMT() {} + + private static Trace getPriorityTrace( + Table table, Einstufung priority, String xName, String yName, String color) { + Table tableVbe = BvwpUtils.extractPriorityTable(table, priority.name()); + return ScatterTrace.builder(tableVbe.numberColumn(xName), tableVbe.numberColumn(yName)) + .text(tableVbe.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(String.format(legendFormat, yName + "_" + priority.name())) + .marker(Marker.builder().color(color).build()) + .build(); } - static Figure createFigureCO2(Axis xAxis, int plotWidth, Table table, String xName){ - String yName = Headers.CO2_COST_EL03; - String y2Name = Headers.CO2_COST_EL03; - - Axis yAxis = Axis.builder() - .title( yName ) -// .type( Axis.Type.LOG ) - .build(); - Layout layout = Layout.builder( "plot" ).xAxis( xAxis ).yAxis( yAxis ) - .width( plotWidth ) - .build(); - - Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .name( yName ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .build(); - Trace trace2 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( y2Name ) ) - .name( y2Name ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .marker( Marker.builder().color( "red" ).build() ) - .build(); - - return new Figure( layout, trace, trace2 ); + // ######################### + + static Figure createFigureCostByPriority(int plotWidth, Table table, String xName) { + Figure figure3; + String yName = Headers.INVCOST_ORIG; + String y3Name = Headers.INVCOST_ORIG; + String y2Name = Headers.INVCOST_ORIG; + + double maxX = table.numberColumn(xName).max(); + Axis xAxis = + Axis.builder() + .type(Type.LINEAR) + .title(xName) + .range(0., maxX) + // .autoRange( Axis.AutoRange.REVERSED ); + .build(); + + Axis yAxis = + Axis.builder() + .type(Type.LOG) + // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title(yName) + .build(); + Layout layout = Layout.builder(yName).xAxis(xAxis).yAxis(yAxis).width(plotWidth).build(); + Trace trace = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(String.format(legendFormat, yName)) + .build(); + + final Trace traceWb = getPriorityTrace(table, Einstufung.WB, xName, y2Name, "cyan"); + final Trace traceWbp = getPriorityTrace(table, Einstufung.WBP, xName, y2Name, "yellow"); + final Trace traceVb = getPriorityTrace(table, Einstufung.VB, xName, y2Name, "orange"); + final Trace traceVbe = getPriorityTrace(table, Einstufung.VBE, xName, y2Name, "red"); + + Trace trace3 = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(y3Name)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(String.format(legendFormat, y3Name)) + .marker(Marker.builder().color("gray").build()) + .build(); + + // double[] xx = new double[]{1., 200.}; + // Trace trace1 = ScatterTrace.builder( xx, xx ) + // .mode( ScatterTrace.Mode.LINE ) + // .build(); + + figure3 = new Figure(layout, trace, trace3, traceWb, traceWbp, traceVb, traceVbe); + return figure3; + } + + static Figure createFigureNkvByPriority(Axis xAxis, int plotWidth, Table table, String xName) { + Figure figure2; + String yName = Headers.NKV_ORIG; + // String y3Name = Headers.NKV_CO2_680_EN; + String y2Name = Headers.NKV_EL03_CARBON215_INVCOSTTUD; + + Axis yAxis = + Axis.builder() + // .type( Axis.Type.LOG ) // wirft NKV < 0 raus! + // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title(yName) + .build(); + Layout layout = Layout.builder(yName).xAxis(xAxis).yAxis(yAxis).width(plotWidth).build(); + Trace trace = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(String.format(legendFormat, String.format("%30s", yName))) + .build(); + + final Trace traceWb = getPriorityTrace(table, Einstufung.WB, xName, y2Name, "cyan"); + final Trace traceWbp = getPriorityTrace(table, Einstufung.WBP, xName, y2Name, "yellow"); + final Trace traceVb = getPriorityTrace(table, Einstufung.VB, xName, y2Name, "orange"); + final Trace traceVbe = getPriorityTrace(table, Einstufung.VBE, xName, y2Name, "red"); + + // Trace trace3 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( y3Name + // ) ) + // .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) + // .name( String.format( legendFormat, y3Name ) ) + // .marker( Marker.builder().color( "gray" ).build() ) + // .build(); + + double[] xx = new double[] {0., 1.1 * table.numberColumn(xName).max()}; + double[] yy = new double[] {1., 1.}; + Trace trace4 = ScatterTrace.builder(xx, yy).mode(ScatterTrace.Mode.LINE).build(); + + figure2 = + new Figure( + layout, trace + // , trace3 + , traceWb, traceWbp, traceVb, traceVbe, trace4); + return figure2; + } + + static Figure createFigureNkv(Axis xAxis, int plotWidth, Table table, String xName) { + Figure figure2; + String yName = Headers.NKV_ORIG; + String y3Name = Headers.NKV_CO2_700_EN; + // String y2Name = Headers.NKV_INDUZ_CO2; + + Axis yAxis = + Axis.builder() + .type(Type.LINEAR) + .range( + Double.min( + 1.1 * table.numberColumn(y3Name).min(), 1.1 * table.numberColumn(yName).min()), + 20.) + .title(yName) + .build(); + Layout layout = Layout.builder(yName).xAxis(xAxis).yAxis(yAxis).width(plotWidth).build(); + Trace trace = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(yName) + .build(); + + Trace trace3 = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(y3Name)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(y3Name) + .marker(Marker.builder().color("gray").build()) + .build(); + + double[] xx = new double[] {0., 1.1 * table.numberColumn(xName).max()}; + double[] yy = new double[] {1., 1.}; + Trace trace4 = + ScatterTrace.builder(xx, yy) + .mode(Mode.LINE) + .marker(Marker.builder().color("red").build()) + .build(); + + figure2 = new Figure(layout, trace, trace3, trace4); + return figure2; + } + + static Figure createFigureCO2(Axis xAxis, int plotWidth, Table table, String xName) { + String yName = Headers.CO2_COST_EL03; + String y2Name = Headers.CO2_COST_EL03; + + Axis yAxis = + Axis.builder() + .title(yName) + // .type( Axis.Type.LOG ) + .build(); + Layout layout = Layout.builder("plot").xAxis(xAxis).yAxis(yAxis).width(plotWidth).build(); + + Trace trace = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .name(yName) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .build(); + Trace trace2 = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(y2Name)) + .name(y2Name) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .marker(Marker.builder().color("red").build()) + .build(); + + return new Figure(layout, trace, trace2); } static Figure createFigureNkvChange(int plotWidth, Table table, String xName, String yName) { -// String xName = Headers.NKV_NO_CHANGE; -// String yName = Headers.NKV_CO2; - double maxX = 20.; - double maxY = 20.; - - Axis xAxis = Axis.builder() - .type( Type.LINEAR ) - .title( xName ) - .range(0. ,maxX) -// .autoRange( Axis.AutoRange.REVERSED ); - .build(); - - table = table.sortDescendingOn( xName ); - - Axis yAxis = Axis.builder() - .type( Type.LINEAR ) - .range(Double.min(0., 1.1*table.numberColumn(yName).min()) ,maxY) -// .range( 1.1*table.numberColumn( y2Name ).min(),4. ) - .title( yName ) - .build(); - - Layout layout = Layout.builder( yName + " over " +xName ) - .xAxis( xAxis ) - .yAxis( yAxis ) - .width( plotWidth ) - .build(); - - Trace cbrOverCbrTrace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( yName ) - .marker( Marker.builder().color( "blue" ).build() ) - .build(); - -// double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; -// double[] yy = new double[]{0., 1.1* table.numberColumn( xName ).max()}; - double[] xx = new double[]{0., maxX }; - double[] yy = new double[]{0., maxY}; - double[] xy1 = new double[]{1., 1.}; - - Trace diagonale = ScatterTrace.builder( xx, yy ) - .name(xName + " = " + yName) - .mode( Mode.LINE ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - Trace horizontalCbr1 = ScatterTrace.builder( xx, xy1 ) - .name(yName + " = 1") - .mode( Mode.LINE ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - Trace verticalCbr1 = ScatterTrace.builder( xy1, yy ) - .name(xName + " = 1") - .mode( Mode.LINE ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - - return new Figure( layout, cbrOverCbrTrace, diagonale, horizontalCbr1, verticalCbr1 ); + // String xName = Headers.NKV_NO_CHANGE; + // String yName = Headers.NKV_CO2; + double maxX = 20.; + double maxY = 20.; + + Axis xAxis = + Axis.builder() + .type(Type.LINEAR) + .title(xName) + .range(0., maxX) + // .autoRange( Axis.AutoRange.REVERSED ); + .build(); + + table = table.sortDescendingOn(xName); + + Axis yAxis = + Axis.builder() + .type(Type.LINEAR) + .range(Double.min(0., 1.1 * table.numberColumn(yName).min()), maxY) + // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title(yName) + .build(); + + Layout layout = + Layout.builder(yName + " over " + xName).xAxis(xAxis).yAxis(yAxis).width(plotWidth).build(); + + Trace cbrOverCbrTrace = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(yName) + .marker(Marker.builder().color("blue").build()) + .build(); + + // double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; + // double[] yy = new double[]{0., 1.1* table.numberColumn( xName ).max()}; + double[] xx = new double[] {0., maxX}; + double[] yy = new double[] {0., maxY}; + double[] xy1 = new double[] {1., 1.}; + + Trace diagonale = + ScatterTrace.builder(xx, yy) + .name(xName + " = " + yName) + .mode(Mode.LINE) + .marker(Marker.builder().color("gray").build()) + .build(); + + Trace horizontalCbr1 = + ScatterTrace.builder(xx, xy1) + .name(yName + " = 1") + .mode(Mode.LINE) + .marker(Marker.builder().color("gray").build()) + .build(); + + Trace verticalCbr1 = + ScatterTrace.builder(xy1, yy) + .name(xName + " = 1") + .mode(Mode.LINE) + .marker(Marker.builder().color("gray").build()) + .build(); + + return new Figure(layout, cbrOverCbrTrace, diagonale, horizontalCbr1, verticalCbr1); + } + + /** + * Für NKV vergleich-Plot mit 2 Y-Achsen. + * + * @param plotWidth + * @param table + * @param xName + * @param yName + * @param yName2 + * @return + */ + static Figure createFigureNkvChange( + int plotWidth, Table table, String xName, String yName, String yName2) { + + // String xName = Headers.NKV_NO_CHANGE; + // String yName = Headers.NKV_CO2; + double maxX = 20.; + double maxY = 20.; + + Axis xAxis = + Axis.builder() + .type(Type.LINEAR) + .title(xName) + .range(0., maxX) + // .autoRange( Axis.AutoRange.REVERSED ); + .build(); + + table = table.sortDescendingOn(xName); + + Axis yAxis = + Axis.builder() + .type(Type.LINEAR) + .range(Double.min(0., 1.1 * table.numberColumn(yName).min()), maxY) + // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title(yName) + .build(); + + Axis yAxis2 = + Axis.builder() + .type(Type.LINEAR) + .range(Double.min(0., 1.1 * table.numberColumn(yName2).min()), maxY) + // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) + .title(yName2) + .build(); + + Layout layout = + Layout.builder(yName + " and " + yName2 + " over " + xName) + .xAxis(xAxis) + .yAxis(yAxis) + .yAxis2(yAxis2) + .width(plotWidth) + .build(); + + Trace cbrOverCbrTrace1 = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(yName) + .marker(Marker.builder().color("blue").build()) + .build(); + + Trace cbrOverCbrTrace2 = + ScatterTrace.builder(table.numberColumn(xName), table.numberColumn(yName2)) + .text(table.stringColumn(Headers.PROJECT_NAME).asObjectArray()) + .name(yName2) + .marker(Marker.builder().color("red").build()) + .build(); + + // double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; + // double[] yy = new double[]{0., 1.1* table.numberColumn( xName ).max()}; + double[] xx = new double[] {0., maxX}; + double[] yy = new double[] {0., maxY}; + double[] xy1 = new double[] {1., 1.}; + + Trace diagonale = + ScatterTrace.builder(xx, yy) + .name(xName + " = " + yName) + .mode(Mode.LINE) + .marker(Marker.builder().color("orange").build()) + .build(); + + Trace horizontalCbr1 = + ScatterTrace.builder(xx, xy1) + .name(yName + " = 1") + .mode(Mode.LINE) + .marker(Marker.builder().color("gray").build()) + .build(); + + Trace verticalCbr1 = + ScatterTrace.builder(xy1, yy) + .name(xName + " = 1") + .mode(Mode.LINE) + .marker(Marker.builder().color("gray").build()) + .build(); + + return new Figure( + layout, cbrOverCbrTrace1, cbrOverCbrTrace2, diagonale, horizontalCbr1, verticalCbr1); } - /** - * Für NKV vergleich-Plot mit 2 Y-Achsen. - * @param plotWidth - * @param table - * @param xName - * @param yName - * @param yName2 - * @return - */ - static Figure createFigureNkvChange(int plotWidth, Table table, String xName, String yName, String yName2) { - -// String xName = Headers.NKV_NO_CHANGE; -// String yName = Headers.NKV_CO2; - double maxX = 20.; - double maxY = 20.; - - Axis xAxis = Axis.builder() - .type( Type.LINEAR ) - .title( xName ) - .range(0. ,maxX) -// .autoRange( Axis.AutoRange.REVERSED ); - .build(); - - table = table.sortDescendingOn( xName ); - - Axis yAxis = Axis.builder() - .type( Type.LINEAR ) - .range(Double.min(0., 1.1*table.numberColumn(yName).min()) ,maxY) -// .range( 1.1*table.numberColumn( y2Name ).min(),4. ) - .title( yName ) - .build(); - - Axis yAxis2 = Axis.builder() - .type( Type.LINEAR ) - .range(Double.min(0., 1.1*table.numberColumn(yName2).min()) ,maxY) -// .range( 1.1*table.numberColumn( y2Name ).min(),4. ) - .title( yName2 ) - .build(); - - Layout layout = Layout.builder( yName + " and " +yName2 + " over " +xName ) - .xAxis( xAxis ) - .yAxis( yAxis ) - .yAxis2( yAxis2 ) - .width( plotWidth ) - .build(); - - Trace cbrOverCbrTrace1 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( yName ) - .marker( Marker.builder().color( "blue" ).build() ) - .build(); - - Trace cbrOverCbrTrace2 = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName2 ) ) - .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( yName2 ) - .marker( Marker.builder().color( "red" ).build() ) - .build(); - -// double[] xx = new double[]{0., 1.1* table.numberColumn( xName ).max() }; -// double[] yy = new double[]{0., 1.1* table.numberColumn( xName ).max()}; - double[] xx = new double[]{0., maxX }; - double[] yy = new double[]{0., maxY}; - double[] xy1 = new double[]{1., 1.}; - - Trace diagonale = ScatterTrace.builder( xx, yy ) - .name(xName + " = " + yName) - .mode( Mode.LINE ) - .marker(Marker.builder().color("orange").build()) - .build(); - - Trace horizontalCbr1 = ScatterTrace.builder( xx, xy1 ) - .name(yName + " = 1") - .mode( Mode.LINE ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - Trace verticalCbr1 = ScatterTrace.builder( xy1, yy ) - .name(xName + " = 1") - .mode( Mode.LINE ) - .marker( Marker.builder().color( "gray" ).build() ) - .build(); - - - return new Figure( layout, cbrOverCbrTrace1, cbrOverCbrTrace2, diagonale, horizontalCbr1, verticalCbr1 ); - } - - /** Idee um eine Trennung zu erzeugen... Noch nicht optimal - * @param title - * @return - */ - static Figure createTextFigure(String title){ - - Layout layout = Layout.builder( title ) - .yAxis(Axis.builder().visible(false).build()) - .xAxis(Axis.builder().visible(false).build()) - .width( 1) - .height(1) - .build(); - - return new Figure(layout); - } + /** + * Idee um eine Trennung zu erzeugen... Noch nicht optimal + * + * @param title + * @return + */ + static Figure createTextFigure(String title) { + + Layout layout = + Layout.builder(title) + .yAxis(Axis.builder().visible(false).build()) + .xAxis(Axis.builder().visible(false).build()) + .width(1) + .height(1) + .build(); + + return new Figure(layout); + } } From fa6d6ce0b65494c93e39c73f614c046b3e395a19 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 20 Jun 2024 11:58:26 +0200 Subject: [PATCH 3/3] reformatting --- .../users/kmt/RunLocalCsvScrapingKMT.java | 507 ++++++++++-------- 1 file changed, 280 insertions(+), 227 deletions(-) diff --git a/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java b/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java index ca39cef..1b8e5b5 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kmt/RunLocalCsvScrapingKMT.java @@ -31,230 +31,252 @@ import static tech.tablesaw.aggregate.AggregateFunctions.*; public class RunLocalCsvScrapingKMT { - private static final Logger logger = LogManager.getLogger(RunLocalCsvScrapingKMT.class ); - - public static void main(String[] args) throws IOException{ - Locale.setDefault( Locale.US ); - - logger.warn( - "(vermutl. weitgehend gelöst) Teilweise werden die Hauptprojekte bewertet und nicht" + - "Teilprojekte (A20); teilweise werden die Teilprojekte " + - "bewertet aber nicht das Hauptprojekt (A2). " - + "Müssen aufpassen, dass nichts unter den Tisch fällt."); - logger.warn( - "Bei https://www.bvwp-projekte.de/strasse/A559-G10-NW/A559-G10-NW.html " - + "hat evtl. die Veränderung " - + "Betriebsleistung PV falsches VZ. Nutzen (positiv) dann wieder richtig."); - logger.warn( - "Wieso geht bei https://www.bvwp-projekte.de/strasse/A14-G20-ST-BB/A14-G20-ST-BB.html" - + " der Nutzen mit impl und co2Price sogar nach oben?"); - logger.warn("==========="); - - String positivListe = BvwpUtils.getPositivListe(); - - StreetScraper scraper = new StreetScraper(); - - logger.info( "Starting scraping" ); - - String filePath = "../shared-svn/"; - Map constructionCostsByProject = BvwpUtils.getConstructionCostsFromTudFile(filePath ); - - final String regexToExclude = "(A...B.*)|(A....B.*)"; // Bundesstrassen, die von Autobahnen ausgehen. - - // yyyy man könnte (sollte?) den table in den StreetAnalysisDataContainer mit hinein geben, und die Werte gleich dort eintragen. kai, feb'24 - - List allStreetBaseData = scraper - .extractAllLocalBaseData("./data/street/all", "A", ".*", "") - .stream() - .map(streetBaseDataContainer -> new StreetAnalysisDataContainer(streetBaseDataContainer, -// 0. - constructionCostsByProject.get(streetBaseDataContainer.getProjectInformation().getProjectNumber()) - )) + private static final Logger logger = LogManager.getLogger(RunLocalCsvScrapingKMT.class); + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + + logger.warn( + "(vermutl. weitgehend gelöst) Teilweise werden die Hauptprojekte bewertet und nicht" + + "Teilprojekte (A20); teilweise werden die Teilprojekte " + + "bewertet aber nicht das Hauptprojekt (A2). " + + "Müssen aufpassen, dass nichts unter den Tisch fällt."); + logger.warn( + "Bei https://www.bvwp-projekte.de/strasse/A559-G10-NW/A559-G10-NW.html " + + "hat evtl. die Veränderung " + + "Betriebsleistung PV falsches VZ. Nutzen (positiv) dann wieder richtig."); + logger.warn( + "Wieso geht bei https://www.bvwp-projekte.de/strasse/A14-G20-ST-BB/A14-G20-ST-BB.html" + + " der Nutzen mit impl und co2Price sogar nach oben?"); + logger.warn("==========="); + + String positivListe = BvwpUtils.getPositivListe(); + + StreetScraper scraper = new StreetScraper(); + + logger.info("Starting scraping"); + + String filePath = "../shared-svn/"; + Map constructionCostsByProject = BvwpUtils.getConstructionCostsFromTudFile(filePath); + + final String regexToExclude = + "(A...B.*)|(A....B.*)"; // Bundesstrassen, die von Autobahnen ausgehen. + + // yyyy man könnte (sollte?) den table in den StreetAnalysisDataContainer mit hinein geben, und + // die Werte gleich dort eintragen. kai, feb'24 + + List allStreetBaseData = + scraper.extractAllLocalBaseData("./data/street/all", "A", ".*", "").stream() + .map( streetBaseDataContainer -> + new StreetAnalysisDataContainer( + streetBaseDataContainer, + // 0. + constructionCostsByProject.get(streetBaseDataContainer.getProjectInformation().getProjectNumber()))) .toList(); - logger.info("Writing csv"); - StreetCsvWriter csvWriter = new StreetCsvWriter("output/street_data.csv"); - Table table = csvWriter.writeCsv(allStreetBaseData); - - - table.addColumns(table.numberColumn(Headers.NKV_ORIG ) - .subtract(table.numberColumn(Headers.NKV_EL03_CARBON215_INVCOSTTUD ) ).setName( - Headers.NKV_EL03_DIFF ) ); - - { //Plotting and table preparation - String xNameKMT; - Axis.AxisBuilder xAxisBuilder = Axis.builder(); - { - xNameKMT = Headers.CO2_COST_EL03; - xAxisBuilder.type(Type.LINEAR); - } - - table = table.sortDescendingOn(xNameKMT); - Axis xAxis = xAxisBuilder.title(xNameKMT).build(); - final int plotWidth = 1400; - - kmtPlots_old(xAxis, plotWidth, table, xNameKMT); - kmtPlots_Co2values(xAxis, plotWidth, table, xNameKMT); - } - - calculationsAndTableWriting(table); + logger.info("Writing csv"); + StreetCsvWriter csvWriter = new StreetCsvWriter("output/street_data.csv"); + Table table = csvWriter.writeCsv(allStreetBaseData); + + table.addColumns( + table + .numberColumn(Headers.NKV_ORIG) + .subtract(table.numberColumn(Headers.NKV_EL03_CARBON215_INVCOSTTUD)) + .setName(Headers.NKV_EL03_DIFF) + ); + + { // Plotting and table preparation + String xNameKMT; + Axis.AxisBuilder xAxisBuilder = Axis.builder(); + { + xNameKMT = Headers.CO2_COST_EL03; + xAxisBuilder.type(Type.LINEAR); + } + + table = table.sortDescendingOn(xNameKMT); + Axis xAxis = xAxisBuilder.title(xNameKMT).build(); + final int plotWidth = 1400; + + kmtPlots_old(xAxis, plotWidth, table, xNameKMT); + kmtPlots_Co2values(xAxis, plotWidth, table, xNameKMT); } + calculationsAndTableWriting(table); + } + private static void calculationsAndTableWriting(Table table) { // === Some calculations - Comparator comparator = (o1, o2) -> { - Einstufung p1 = Einstufung.valueOf(o1.getString(Headers.EINSTUFUNG ) ); - Einstufung p2 = Einstufung.valueOf(o2.getString(Headers.EINSTUFUNG ) ); - return p1.compareTo(p2); - }; + Comparator comparator = + (o1, o2) -> { + Einstufung p1 = Einstufung.valueOf(o1.getString(Headers.EINSTUFUNG)); + Einstufung p2 = Einstufung.valueOf(o2.getString(Headers.EINSTUFUNG)); + return p1.compareTo(p2); + }; final Table tbl = table.sortOn(comparator); NumberFormat format = NumberFormat.getCompactNumberInstance(); format.setMaximumFractionDigits(0); - tbl.numberColumn(Headers.CO2_COST_EL03 ).setPrintFormatter(format, "n/a" ); - - //Projekte, die bereits vor Änderung NKV <1 haben - Table tableBaseKl1 = tbl.where(tbl.numberColumn(Headers.NKV_ORIG ).isLessThan(1. ) ); - Table tableIndCo2kl1 = tbl.where(tbl.numberColumn(Headers.NKV_EL03_CARBON215_INVCOSTTUD ).isLessThan(1. ) ); - - { //-- von KN - System.out.println(BvwpUtils.SEPARATOR); - System.out.println("NKV Original auf Gesamttabelle"); - System.out.println(tbl.summarize(Headers.NKV_ORIG, count, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); - System.out.println(tbl.summarize(Headers.NKV_ORIG, count, mean, stdDev, min, max ).apply()); - System.out.println(System.lineSeparator() + "Davon NKV < 1: nach Modifikation."); - System.out.println(tableIndCo2kl1.summarize(Headers.NKV_EL03_CARBON215_INVCOSTTUD, count, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); - System.out.println(tableIndCo2kl1.summarize(Headers.NKV_EL03_CARBON215_INVCOSTTUD, count, mean, stdDev, min, max ).apply() ); - - System.out.println(BvwpUtils.SEPARATOR); - System.out.println(tbl.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); - System.out.println(tbl.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max ).apply()); - System.out.println(System.lineSeparator() + "Davon NKV < 1:"); - System.out.println(tableIndCo2kl1.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); - System.out.println(tableIndCo2kl1.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max ).apply()); - System.out.println(BvwpUtils.SEPARATOR); - System.out.println( - tbl.summarize( - Headers.CO2_COST_EL03, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); - System.out.println(System.lineSeparator() + "Davon NKV < 1:"); - System.out.println( - tableIndCo2kl1.summarize(Headers.CO2_COST_EL03, sum, mean, stdDev, min, max ) - .by(Headers.EINSTUFUNG ) ); + tbl.numberColumn(Headers.CO2_COST_EL03).setPrintFormatter(format, "n/a"); + + // Projekte, die bereits vor Änderung NKV <1 haben + Table tableBaseKl1 = tbl.where(tbl.numberColumn(Headers.NKV_ORIG).isLessThan(1.)); + Table tableIndCo2kl1 = + tbl.where(tbl.numberColumn(Headers.NKV_EL03_CARBON215_INVCOSTTUD).isLessThan(1.)); + + { // -- von KN + System.out.println(BvwpUtils.SEPARATOR); + System.out.println("NKV Original auf Gesamttabelle"); + System.out.println(tbl.summarize(Headers.NKV_ORIG, count, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); + System.out.println(tbl.summarize(Headers.NKV_ORIG, count, mean, stdDev, min, max).apply()); + System.out.println(System.lineSeparator() + "Davon NKV < 1: nach Modifikation."); + System.out.println(tableIndCo2kl1.summarize(Headers.NKV_EL03_CARBON215_INVCOSTTUD, count, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); + System.out.println(tableIndCo2kl1.summarize(Headers.NKV_EL03_CARBON215_INVCOSTTUD, count, mean, stdDev, min, max).apply()); + System.out.println(BvwpUtils.SEPARATOR); + System.out.println(tbl.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); + System.out.println(tbl.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max).apply()); + System.out.println(System.lineSeparator() + "Davon NKV < 1:"); + System.out.println(tableIndCo2kl1.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); + System.out.println(tableIndCo2kl1.summarize(Headers.INVCOST_ORIG, sum, mean, stdDev, min, max).apply()); + System.out.println(BvwpUtils.SEPARATOR); + System.out.println(tbl.summarize(Headers.CO2_COST_EL03, sum, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); + System.out.println(System.lineSeparator() + "Davon NKV < 1:"); + System.out.println(tableIndCo2kl1.summarize(Headers.CO2_COST_EL03, sum, mean, stdDev, min, max).by(Headers.EINSTUFUNG)); } { - //KMT - System.out.println(BvwpUtils.SEPARATOR); - System.out.println("### KMT ###"); - System.out.println(BvwpUtils.SEPARATOR); - - List headersKMT = new LinkedList<>(); - headersKMT.add(Headers.NKV_ORIG); - headersKMT.add(Headers.NKV_CO2_700_EN); - headersKMT.add(Headers.NKV_CO2_2000_EN); - headersKMT.add(Headers.NKV_INVCOSTTUD_EN); - headersKMT.add(Headers.NKV_INVCOST150_EN); - headersKMT.add(Headers.NKV_INVCOST200_EN); - headersKMT.add(Headers.NKV_CO2_700_INVCOSTTUD_EN); - headersKMT.add(Headers.NKV_CO2_700_INVCOST150_EN); - headersKMT.add(Headers.NKV_CO2_700_INVCOST200_EN); - headersKMT.add(Headers.NKV_CO2_2000_INVCOSTTUD_EN); - headersKMT.add(Headers.NKV_CO2_2000_INVCOST150_EN); - headersKMT.add(Headers.NKV_CO2_2000_INVCOST200_EN); - - //General Todos for all three analysis: - //Todo: Zeile hinzufügen zu eingsparten Projektanzahl. --> alles in einer Tabelle zusammenfassen?? - //Todo: ! Zeile einfügen, welceh die relative Abweichung zum Base-Case anzeigt... (x% Projekte / Costen sind "raus") - - //Todo: Eigentlich müsste man aus dem folgenden eine Funktion machen können, mit wenigen übergabe-Infos. Weil inhaltlich ist es 3x das gleiche. - { //Projektanzahl - Table nkvBelow1_count = Table.create("Nu of Projects with BCR < 1 "); - nkvBelow1_count.addColumns(DoubleColumn.create("# of all Projects" - , new double[]{tbl.rowCount() - } - )); - - //Erstelle eine Spalte für jeden "Fall" - for (String s : headersKMT) { - Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); - nkvBelow1_count.addColumns(DoubleColumn.create(s, new double[]{tblBelow1.rowCount()})); - } - System.out.println(nkvBelow1_count.print()); - - var options = CsvWriteOptions.builder("output/NKV_below_1_projects.csv").separator(';').build(); - new CsvWriter().write(nkvBelow1_count, options); + // KMT + System.out.println(BvwpUtils.SEPARATOR); + System.out.println("### KMT ###"); + System.out.println(BvwpUtils.SEPARATOR); + + List headersKMT = new LinkedList<>(); + headersKMT.add(Headers.NKV_ORIG); + headersKMT.add(Headers.NKV_CO2_700_EN); + headersKMT.add(Headers.NKV_CO2_2000_EN); + headersKMT.add(Headers.NKV_INVCOSTTUD_EN); + headersKMT.add(Headers.NKV_INVCOST150_EN); + headersKMT.add(Headers.NKV_INVCOST200_EN); + headersKMT.add(Headers.NKV_CO2_700_INVCOSTTUD_EN); + headersKMT.add(Headers.NKV_CO2_700_INVCOST150_EN); + headersKMT.add(Headers.NKV_CO2_700_INVCOST200_EN); + headersKMT.add(Headers.NKV_CO2_2000_INVCOSTTUD_EN); + headersKMT.add(Headers.NKV_CO2_2000_INVCOST150_EN); + headersKMT.add(Headers.NKV_CO2_2000_INVCOST200_EN); + + // General Todos for all three analysis: + // Todo: Zeile hinzufügen zu eingsparten Projektanzahl. --> alles in einer Tabelle + // zusammenfassen?? + // Todo: ! Zeile einfügen, welceh die relative Abweichung zum Base-Case anzeigt... (x% + // Projekte / Costen sind "raus") + + // Todo: Eigentlich müsste man aus dem folgenden eine Funktion machen können, mit wenigen + // übergabe-Infos. Weil inhaltlich ist es 3x das gleiche. + { // Projektanzahl + Table nkvBelow1_count = Table.create("Nu of Projects with BCR < 1 "); + nkvBelow1_count.addColumns(DoubleColumn.create("# of all Projects", new double[] {tbl.rowCount()})); + + // Erstelle eine Spalte für jeden "Fall" + for (String s : headersKMT) { + Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); + nkvBelow1_count.addColumns(DoubleColumn.create(s, new double[] {tblBelow1.rowCount()})); } - - System.out.println(BvwpUtils.SEPARATOR); - - { // Gesparte Investitionskosten - Barwert der Kosten in Mio EUR - Table nkvBelow1_costs = Table.create("Projects with BCR < 1 -- safed Investment Costs - Barwert (Mio EUR)"); - nkvBelow1_costs.addColumns(DoubleColumn.create("Investment costs of all projects (Mio EUR)" - , (double) tbl.summarize(Headers.INVCOST_ORIG, sum).apply().get(0,0)) - ); - - //Erstelle eine Spalte für jeden "Fall" - for (String s : headersKMT) { - Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); - nkvBelow1_costs.addColumns(DoubleColumn.create(s, new double[]{(double) tblBelow1.summarize(Headers.INVCOST_ORIG, sum).apply().get(0,0)})); - } - System.out.println(nkvBelow1_costs.print()); - - var options = CsvWriteOptions.builder("output/NKV_below_1_costsSafed.csv").separator(';').build(); - new CsvWriter().write(nkvBelow1_costs, options); + System.out.println(nkvBelow1_count.print()); + + var options = + CsvWriteOptions.builder("output/NKV_below_1_projects.csv").separator(';').build(); + new CsvWriter().write(nkvBelow1_count, options); + } + + System.out.println(BvwpUtils.SEPARATOR); + + { // Gesparte Investitionskosten - Barwert der Kosten in Mio EUR + Table nkvBelow1_costs = + Table.create("Projects with BCR < 1 -- safed Investment Costs - Barwert (Mio EUR)"); + nkvBelow1_costs.addColumns( + DoubleColumn.create( + "Investment costs of all projects (Mio EUR)", + (double) tbl.summarize(Headers.INVCOST_ORIG, sum).apply().get(0, 0))); + + // Erstelle eine Spalte für jeden "Fall" + for (String s : headersKMT) { + Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); + nkvBelow1_costs.addColumns( + DoubleColumn.create(s, (double) tblBelow1.summarize(Headers.INVCOST_ORIG, sum).apply().get(0, 0))); } - - System.out.println(BvwpUtils.SEPARATOR); - - { // Gesparte CO2 - Emissionen: Aus Verkehr und Lebenszyklusemissionen (t/a) - Table nkvBelow1_co2safed = Table.create("Projects with BCR < 1 -- safed CO2 emissions -- direct and lifecycle of infrastructure (t/a"); - nkvBelow1_co2safed.addColumns(DoubleColumn.create("CO2 Emissions of all projects (t/a)" - , (double) tbl.summarize(Headers.CO_2_EQUIVALENTS_EMISSIONS, sum).apply().get(0,0)) - ); - - //Erstelle eine Spalte für jeden "Fall" - for (String s : headersKMT) { - Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); - nkvBelow1_co2safed.addColumns(DoubleColumn.create(s, (double) tblBelow1.summarize(Headers.CO_2_EQUIVALENTS_EMISSIONS, sum).apply().get(0,0))); - } - System.out.println(nkvBelow1_co2safed.print()); - - var options = CsvWriteOptions.builder("output/NKV_below_1_co2Safed.csv").separator(';').build(); - new CsvWriter().write(nkvBelow1_co2safed, options); + System.out.println(nkvBelow1_costs.print()); + + var options = CsvWriteOptions.builder("output/NKV_below_1_costsSafed.csv").separator(';').build(); + new CsvWriter().write(nkvBelow1_costs, options); + } + + System.out.println(BvwpUtils.SEPARATOR); + + { // Gesparte CO2 - Emissionen: Aus Verkehr und Lebenszyklusemissionen (t/a) + Table nkvBelow1_co2safed = Table.create( + "Projects with BCR < 1 -- safed CO2 emissions -- direct and lifecycle of infrastructure (t/a"); + nkvBelow1_co2safed.addColumns(DoubleColumn.create( + "CO2 Emissions of all projects (t/a)", + (double) tbl.summarize(Headers.CO_2_EQUIVALENTS_EMISSIONS, sum).apply().get(0, 0))); + + // Erstelle eine Spalte für jeden "Fall" + for (String s : headersKMT) { + Table tblBelow1 = tbl.where(tbl.numberColumn(s).isLessThan(1.)); + nkvBelow1_co2safed.addColumns(DoubleColumn.create( + s, + (double) tblBelow1 + .summarize(Headers.CO_2_EQUIVALENTS_EMISSIONS, sum) + .apply() + .get(0, 0))); } + System.out.println(nkvBelow1_co2safed.print()); + var options = + CsvWriteOptions.builder("output/NKV_below_1_co2Safed.csv").separator(';').build(); + new CsvWriter().write(nkvBelow1_co2safed, options); + } } } private static void kmtPlots_old(Axis xAxis, int plotWidth, Table table, String xNameKMT) throws IOException { Figure figureNkv = FiguresKMT.createFigureNkv(xAxis, plotWidth, table, xNameKMT); - Figure figureCostByPriority = FiguresKMT.createFigureCostByPriority(plotWidth, table, Headers.INVCOST_ORIG ); - Figure figureNkvByPriority = FiguresKMT.createFigureNkvByPriority(xAxis, plotWidth, table, Headers.INVCOST_ORIG ); + Figure figureCostByPriority = FiguresKMT.createFigureCostByPriority(plotWidth, table, Headers.INVCOST_ORIG); + Figure figureNkvByPriority = FiguresKMT.createFigureNkvByPriority(xAxis, plotWidth, table, Headers.INVCOST_ORIG); Figure figureCO2Benefit = FiguresKMT.createFigureCO2(xAxis, plotWidth, table, xNameKMT); - Figure figureNkvChangeCo2_680 = FiguresKMT.createFigureNkvChange(plotWidth, table, - Headers.NKV_ORIG, Headers.NKV_CO2_700_EN ); - Figure figureNkvChangeInduz_2000 = FiguresKMT.createFigureNkvChange(plotWidth, table, - Headers.NKV_ORIG, Headers.NKV_CO2_2000_EN ); -// Figure figureNkvChangeInduzCo2 = Figures.createFigureNkvChange(plotWidth, table, -// Headers.NKV_NO_CHANGE, Headers.NKV_INDUZ_CO2); - - String pageKMT = MultiPlotUtils.pageTop() + System.lineSeparator() + - figureNkv.asJavascript("plot1") + System.lineSeparator() + -// FiguresKMT.createTextFigure("Neuer Abschnitt").asJavascript("plot2") + System.lineSeparator() + //Test um mal eine Trennung zu erzeugen... vlt doch anders machen - figureCostByPriority.asJavascript("plot2") + System.lineSeparator() + - figureNkvByPriority.asJavascript("plot3")+System.lineSeparator() + - figureCO2Benefit.asJavascript("plot4") + System.lineSeparator() + - figureNkvChangeCo2_680.asJavascript("plot5") + System.lineSeparator() + - figureNkvChangeInduz_2000.asJavascript("plot6") + System.lineSeparator() + -// figureNkvChangeInduzCo2.asJavascript("plot7") + System.lineSeparator() + - MultiPlotUtils.pageBottom; + Figure figureNkvChangeCo2_680 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_EN); + Figure figureNkvChangeInduz_2000 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_EN); + // Figure figureNkvChangeInduzCo2 = Figures.createFigureNkvChange(plotWidth, table, + // Headers.NKV_NO_CHANGE, Headers.NKV_INDUZ_CO2); + + String pageKMT = + MultiPlotUtils.pageTop() + + System.lineSeparator() + + figureNkv.asJavascript("plot1") + + System.lineSeparator() + + + // FiguresKMT.createTextFigure("Neuer Abschnitt").asJavascript("plot2") + + // System.lineSeparator() + //Test um mal eine Trennung zu erzeugen... vlt doch anders + // machen + figureCostByPriority.asJavascript("plot2") + + System.lineSeparator() + + figureNkvByPriority.asJavascript("plot3") + + System.lineSeparator() + + figureCO2Benefit.asJavascript("plot4") + + System.lineSeparator() + + figureNkvChangeCo2_680.asJavascript("plot5") + + System.lineSeparator() + + figureNkvChangeInduz_2000.asJavascript("plot6") + + System.lineSeparator() + + + // figureNkvChangeInduzCo2.asJavascript("plot7") + System.lineSeparator() + // + + MultiPlotUtils.pageBottom; File outputFileKMT = Paths.get("multiplotKMT.html").toFile(); try (FileWriter fileWriter = new FileWriter(outputFileKMT)) { - fileWriter.write(pageKMT); + fileWriter.write(pageKMT); } new Browser().browse(outputFileKMT); @@ -262,44 +284,76 @@ private static void kmtPlots_old(Axis xAxis, int plotWidth, Table table, String private static void kmtPlots_Co2values(Axis xAxis, int plotWidth, Table table, String xNameKMT) throws IOException { - Figure figureNkvChangeCo2_700 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_EN ); - Figure figureNkvChangeInduz_2000 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_EN ); + Figure figureNkvChangeCo2_700 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_EN); + Figure figureNkvChangeInduz_2000 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_EN); - Figure figureNkvChange_InvCostTud = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOSTTUD_EN ); + Figure figureNkvChange_InvCostTud = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOSTTUD_EN); Figure figureNkvChange_InvCost150 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOST150_EN); - Figure figureNkvChange_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOST200_EN ); + Figure figureNkvChange_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOST200_EN); Figure figureNkvChange_Co2_700_InvCostTud = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOSTTUD_EN); Figure figureNkvChange_Co2_700_InvCost150 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOST150_EN); - Figure figureNkvChange_Co2_700_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOST200_EN ); - Figure figureNkvChange_Co2_2000_InvCostTud = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOSTTUD_EN ); + Figure figureNkvChange_Co2_700_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOST200_EN); + Figure figureNkvChange_Co2_2000_InvCostTud = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOSTTUD_EN); Figure figureNkvChange_Co2_2000_InvCost150 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST150_EN); Figure figureNkvChange_Co2_2000_InvCost200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST200_EN); - Figure figureNkvChange_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_INVCOST150_EN, Headers.NKV_INVCOST200_EN); - Figure figureNkvChange_Co2_700_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_700_INVCOST150_EN, Headers.NKV_CO2_700_INVCOST200_EN); - Figure figureNkvChange_Co2_2000_InvCost150_200 = FiguresKMT.createFigureNkvChange(plotWidth, table, Headers.NKV_ORIG, Headers.NKV_CO2_2000_INVCOST150_EN, Headers.NKV_CO2_2000_INVCOST200_EN); - - String page = MultiPlotUtils.pageTop() + System.lineSeparator() + - figureNkvChangeCo2_700.asJavascript("plot1") + System.lineSeparator() + - figureNkvChangeInduz_2000.asJavascript("plot2") + System.lineSeparator() + - - figureNkvChange_InvCostTud .asJavascript("plot3") + System.lineSeparator() + - figureNkvChange_InvCost150.asJavascript("plot4") + System.lineSeparator() + - figureNkvChange_InvCost200.asJavascript("plot5") + System.lineSeparator() + - - figureNkvChange_Co2_700_InvCostTud.asJavascript("plot6") + System.lineSeparator() + - figureNkvChange_Co2_700_InvCost150.asJavascript("plot7") + System.lineSeparator() + - figureNkvChange_Co2_700_InvCost200.asJavascript("plot8") + System.lineSeparator() + - - figureNkvChange_Co2_2000_InvCostTud.asJavascript("plot9") + System.lineSeparator() + - figureNkvChange_Co2_2000_InvCost150.asJavascript("plot10") + System.lineSeparator() + - figureNkvChange_Co2_2000_InvCost200.asJavascript("plot11") + System.lineSeparator() + - - //Plot, der beide Inv Kostenveränderungen für alle Projekte enthält - figureNkvChange_InvCost150_200.asJavascript("plotA") + System.lineSeparator() + - figureNkvChange_Co2_700_InvCost150_200.asJavascript("plotB") + System.lineSeparator() + - figureNkvChange_Co2_2000_InvCost150_200.asJavascript("plotC") + System.lineSeparator() + - MultiPlotUtils.pageBottom; + Figure figureNkvChange_InvCost150_200 = + FiguresKMT.createFigureNkvChange( + plotWidth, + table, + Headers.NKV_ORIG, + Headers.NKV_INVCOST150_EN, + Headers.NKV_INVCOST200_EN); + Figure figureNkvChange_Co2_700_InvCost150_200 = + FiguresKMT.createFigureNkvChange( + plotWidth, + table, + Headers.NKV_ORIG, + Headers.NKV_CO2_700_INVCOST150_EN, + Headers.NKV_CO2_700_INVCOST200_EN); + Figure figureNkvChange_Co2_2000_InvCost150_200 = + FiguresKMT.createFigureNkvChange( + plotWidth, + table, + Headers.NKV_ORIG, + Headers.NKV_CO2_2000_INVCOST150_EN, + Headers.NKV_CO2_2000_INVCOST200_EN); + + String page = + MultiPlotUtils.pageTop() + + System.lineSeparator() + + figureNkvChangeCo2_700.asJavascript("plot1") + + System.lineSeparator() + + figureNkvChangeInduz_2000.asJavascript("plot2") + + System.lineSeparator() + + figureNkvChange_InvCostTud.asJavascript("plot3") + + System.lineSeparator() + + figureNkvChange_InvCost150.asJavascript("plot4") + + System.lineSeparator() + + figureNkvChange_InvCost200.asJavascript("plot5") + + System.lineSeparator() + + figureNkvChange_Co2_700_InvCostTud.asJavascript("plot6") + + System.lineSeparator() + + figureNkvChange_Co2_700_InvCost150.asJavascript("plot7") + + System.lineSeparator() + + figureNkvChange_Co2_700_InvCost200.asJavascript("plot8") + + System.lineSeparator() + + figureNkvChange_Co2_2000_InvCostTud.asJavascript("plot9") + + System.lineSeparator() + + figureNkvChange_Co2_2000_InvCost150.asJavascript("plot10") + + System.lineSeparator() + + figureNkvChange_Co2_2000_InvCost200.asJavascript("plot11") + + System.lineSeparator() + + + + // Plot, der beide Inv Kostenveränderungen für alle Projekte enthält + figureNkvChange_InvCost150_200.asJavascript("plotA") + + System.lineSeparator() + + figureNkvChange_Co2_700_InvCost150_200.asJavascript("plotB") + + System.lineSeparator() + + figureNkvChange_Co2_2000_InvCost150_200.asJavascript("plotC") + + System.lineSeparator() + + MultiPlotUtils.pageBottom; File outputFile = Paths.get("EWGT_CO2-Values.html").toFile(); @@ -309,5 +363,4 @@ private static void kmtPlots_Co2values(Axis xAxis, int plotWidth, Table table, S new Browser().browse(outputFile); } - }