diff --git a/src/main/java/org/tub/vsp/bvwp/RunLocalCsvScraping.java b/src/main/java/org/tub/vsp/bvwp/RunLocalCsvScraping.java new file mode 100644 index 0000000..4d9e037 --- /dev/null +++ b/src/main/java/org/tub/vsp/bvwp/RunLocalCsvScraping.java @@ -0,0 +1,36 @@ +package org.tub.vsp.bvwp; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.tub.vsp.bvwp.data.container.analysis.StreetAnalysisDataContainer; +import org.tub.vsp.bvwp.io.StreetCsvWriter; +import org.tub.vsp.bvwp.scraping.StreetScraper; + +import java.util.List; + +public class RunLocalCsvScraping { + private static final Logger logger = LogManager.getLogger(RunLocalCsvScraping.class); + + public static void main(String[] args) { + logger.warn("(vermutl. weitgehend gelöst) Teilweise werden die Hauptprojekte bewertet und nicht die " + + "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 der https://www.bvwp-projekte.de/strasse/A14-G20-ST-BB/A14-G20-ST-BB.html der " + + "Nutzen mit impl und co2Price sogar nach oben?"); + + + StreetScraper scraper = new StreetScraper(); + + logger.info("Starting scraping"); + List allStreetBaseData = scraper.extractAllLocalBaseData("./data/street", "A", ".*" ) + .stream() + .map(StreetAnalysisDataContainer::new) + .toList(); + + logger.info("Writing csv"); + StreetCsvWriter csvWriter = new StreetCsvWriter("output/street_data.csv"); + csvWriter.writeCsv(allStreetBaseData); + } +} 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 816bec4..9b6ada6 100644 --- a/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java +++ b/src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java @@ -242,7 +242,7 @@ public static Double b_co2(Modifications modifications, Amounts amounts, Benefit // co2 Bau { - co2 += benefits.co2_infra; + co2 += benefits.co2_infra / 145. * modifications.co2Price() ; } // co2 Betrieb @@ -265,9 +265,14 @@ public static Double b_co2(Modifications modifications, Amounts amounts, Benefit } { co2 += b_co2_induz / 145. * modifications.co2Price(); + co2 += modifications.mehrFzkm() * amounts.co2_per_pkwkm * b_per_co2 / 145. * modifications.co2Price(); + // mehrFzkm are those which are on top of PRINS. We do same calculation as with the other co2 contribs, except that this one here is currently on one line. } - return -co2; + return co2; + // The result will be negative. We return positive so we can logplot it. yyyyyy really??? -- no longer + + // Note that this really says nothing about old vs new co2 price, or old vs new addl traffic. That all depends on the settings in "modifications". } } 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 a2fb580..31d3a36 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/Headers.java +++ b/src/main/java/org/tub/vsp/bvwp/data/Headers.java @@ -1,33 +1,40 @@ package org.tub.vsp.bvwp.data; public final class Headers{ + public static final String ADDTL_LANE_KM = "additional_lane_km"; + public static final String ADDTL_PKWKM_DIFF = "addtl_pkwkm_diff"; + public static final String ADDTL_PKWKM_NEU = "addtl_pkwkm_neu"; + public static final String ADDTL_PKWKM_ORIG = "addtl_pkwkm_orig"; + public static final String BAUTYP = "bautyp"; + public static final String B_CO_2_EQUIVALENTS_ORIG = "b_co2-equivalents-overall"; + public static final String B_FZKM = "b_fzkm"; + public static final String B_OVERALL = "b_overall"; public static final String B_PER_KM = "b/km"; - public static final String NKV_NO_CHANGE = "nkv"; + public static final String CO2_COST_NEU = "cost_co2_neu"; + public static final String CO2_COST_ORIG = "cost_co2_orig"; + public static final String COST_OVERALL = "cost"; + public static final String CO_2_EQUIVALENTS_EMISSIONS = "co2-equivalents-emissions"; + public static final String EINSTUFUNG = "Einstufung"; + public static final String LENGTH = "length"; + public static final String LINK = "link"; + public static final String NKV_CAPPED = "nkv_old_capped"; public static final String NKV_CO2 = "nkv_co2"; + public static final String NKV_CO2_2000_EN = "BCR_co2_2000"; + public static final String NKV_CO2_680_EN = "BCR_co2_680"; + public static final String NKV_DIFF = "nkvDiff"; public static final String NKV_INDUZ = "nkv_induz"; public static final String NKV_INDUZ_CO2 = "nkv_induzCo2"; - public static final String NKV_NO_CHANGE_EN = "BCR"; - public static final String NKV_CO2_680_EN = "BCR_co2_680"; - public static final String NKV_CO2_2000_EN = "BCR_co2_2000"; - public static final String NKV_INDUZ_EN = "BCR_induz"; + public static final String NKV_INDUZ_CO2_CAPPED = "nkv_induzCo2_capped"; public static final String NKV_INDUZ_CO2_EN = "BCR_induzCo2"; - public static final String PROJECT_NAME = "project name"; - public static final String LINK = "link"; - public static final String PRIORITY = "priority"; - public static final String BAUTYP = "bautyp"; - public static final String LENGTH = "length"; - public static final String PKWKM_ALL = "pkwkm_all"; - public static final String B_FZKM = "b_fzkm"; - public static final String CO_2_EQUIVALENTS_EMISSIONS = "co2-equivalents-emissions"; - public static final String B_CO_2_EQUIVALENTS_ANNUAL = "b_co2-equivalents-annual"; - public static final String B_CO_2_EQUIVALENTS_OVERALL = "b_co2-equivalents-overall"; - public static final String B_OVERALL = "b_overall"; - public static final String COST_OVERALL = "cost"; + public static final String NKV_INDUZ_EN = "BCR_induz"; + public static final String NKV_NO_CHANGE = "nkv"; + public static final String NKV_NO_CHANGE_EN = "BCR"; + public static final String NKV_ORIG = "nkv"; public static final String PKWKM_INDUZ = "pkwkm_induz"; - public static final String PKWKM_ALL_NEU = "pkwkm_all_neu"; - public static final String B_CO2_NEU = "b_co2_neu"; - public static final String ADDITIONAL_LANE_KM = "additional_lane_km"; - public static final String NKV_DIFF = "nkvDiff"; - public static final String VERKEHRSBELASTUNG_2030 = "DTV 2030"; + public static final String PRIORITY = "priority"; + public static final String PRIO_AS_NUMBER = "prioAsNumber"; + public static final String PROJECT_NAME = "project name"; + public static final String VERKEHRSBELASTUNG_PLANFALL = "Verkehrsbelastung Planfall"; +// public static final String B_CO_2_EQUIVALENTS_ANNUAL = "b_co2-equivalents-annual"; private Headers(){} // do not instantiate } 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 6e1e896..9a83dc5 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,7 +77,7 @@ private void addComputations() { .getBautyp()); } - entries.put(Headers.ADDITIONAL_LANE_KM, additionalLaneKm); + entries.put( Headers.ADDTL_LANE_KM, additionalLaneKm ); double mehrFzkmFromElasticity = additionalLaneKm / ComputationKN.LANE_KM_AB * 0.6 * ComputationKN.FZKM_AB; final double INFLATION_Factor2022to2012 = 0.917; // Zinse Wert von 2020 auf BVWP Zeitpunkt 2012 ab. @@ -94,7 +94,7 @@ private void addComputations() { entries.put(Headers.B_PER_KM, streetBaseDataContainer.getCostBenefitAnalysis().getOverallBenefit() .overall() / streetBaseDataContainer.getProjectInformation() .getLength()); - entries.put(Headers.NKV_NO_CHANGE, NkvCalculator.calculateNkv(Modifications.NO_CHANGE, + entries.put(Headers.NKV_ORIG, NkvCalculator.calculateNkv(Modifications.NO_CHANGE, streetBaseDataContainer)); entries.put(Headers.NKV_CO2, NkvCalculator.calculateNkv(Modifications.CO2_PRICE_5FACH, streetBaseDataContainer)); @@ -109,11 +109,11 @@ private void addComputations() { entries.put(Headers.NKV_INDUZ_CO2, NkvCalculator.calculateNkv(Modifications.createInducedAndCo2WithMehrFzkm(additionalFzkm), streetBaseDataContainer)); - entries.put(Headers.PKWKM_ALL_NEU, mehrFzkmFromElasticity); - entries.put(Headers.B_CO2_NEU, - NkvCalculator.calculateB_CO2(Modifications.createInducedAndCo2WithMehrFzkm(additionalFzkm), + entries.put(Headers.ADDTL_PKWKM_NEU, mehrFzkmFromElasticity ); + entries.put( Headers.CO2_COST_ORIG, - NkvCalculator.calculateB_CO2( Modifications.NO_CHANGE, streetBaseDataContainer ) ); + entries.put( Headers.CO2_COST_NEU, - NkvCalculator.calculateB_CO2(Modifications.createInducedAndCo2WithMehrFzkm(additionalFzkm), streetBaseDataContainer)); - entries.put(Headers.VERKEHRSBELASTUNG_2030, streetBaseDataContainer.getProjectInformation() + entries.put(Headers.VERKEHRSBELASTUNG_PLANFALL, streetBaseDataContainer.getProjectInformation() .getVerkehrsbelastung2030()); if (streetBaseDataContainer.getProjectInformation().getProjectNumber().contains("A1-G50-NI")) { diff --git a/src/main/java/org/tub/vsp/bvwp/data/container/base/street/StreetProjectInformationDataContainer.java b/src/main/java/org/tub/vsp/bvwp/data/container/base/street/StreetProjectInformationDataContainer.java index 9190ac3..7a6d8f8 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/container/base/street/StreetProjectInformationDataContainer.java +++ b/src/main/java/org/tub/vsp/bvwp/data/container/base/street/StreetProjectInformationDataContainer.java @@ -85,8 +85,7 @@ public StreetProjectInformationDataContainer setLength(Double length) { public Double getLength() { return length; } - - public StreetProjectInformationDataContainer setVerkehrsbelastung2030(Double verkehrsbelastung2030) { + public StreetProjectInformationDataContainer setVerkehrsbelastungPlanfall( Double verkehrsbelastung2030 ){ this.verkehrsbelastung2030 = verkehrsbelastung2030; return this; } diff --git a/src/main/java/org/tub/vsp/bvwp/data/mapper/ProjectInformationMapper.java b/src/main/java/org/tub/vsp/bvwp/data/mapper/ProjectInformationMapper.java new file mode 100644 index 0000000..44d4b3e --- /dev/null +++ b/src/main/java/org/tub/vsp/bvwp/data/mapper/ProjectInformationMapper.java @@ -0,0 +1,84 @@ +package org.tub.vsp.bvwp.data.mapper; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jsoup.nodes.Document; +import org.tub.vsp.bvwp.JSoupUtils; +import org.tub.vsp.bvwp.data.container.base.street.StreetProjectInformationDataContainer; +import org.tub.vsp.bvwp.data.type.Bautyp; +import org.tub.vsp.bvwp.data.type.Priority; + +import java.text.ParseException; +import java.util.Optional; + +public class ProjectInformationMapper { + private static final Logger logger = LogManager.getLogger(ProjectInformationMapper.class); + + public StreetProjectInformationDataContainer mapDocument( Document document ) { + StreetProjectInformationDataContainer projectInformation = new StreetProjectInformationDataContainer(); + + String projectNumber = extractInformation(document, 0, "Projektnummer"); + String street = extractInformation(document, 0, "Straße"); + String length = extractInformation( document, 0, "Länge" ); + if ( length!= null ) { + length = length.replace( " km", "" ); + } + String bautyp = extractInformation( document, 0, "Bautyp(en), Bauziel(e)" ); + + String verkehrsbelastungPlanfall = extractInformation( document, 0, "im Planfall 2030" ); + if ( verkehrsbelastungPlanfall!=null ) { + verkehrsbelastungPlanfall = verkehrsbelastungPlanfall.replace( " Kfz/24h", "" ); + } else { + // ( other format for Knotenpunkte ) + verkehrsbelastungPlanfall = extractInformation( document, 0, "/ Planfall 2030" ); + verkehrsbelastungPlanfall = verkehrsbelastungPlanfall.replaceAll( "^.* / ", "" ); + verkehrsbelastungPlanfall = verkehrsbelastungPlanfall.replace( " Kfz/24h", "" ); + } + if ( verkehrsbelastungPlanfall==null ) { + verkehrsbelastungPlanfall = "0."; + } + + String priority = extractInformation(document, 1, "Dringlichkeitseinstufung"); + + if ( projectNumber.startsWith( "A008-G010" ) ) { + // NKV ist im Hauptprojekt, aber Einstufungen sind in den Teilprojekten. 3 davon VBE, 1 WBP --> VBE. + + priority = Priority.VBE.name(); + logger.warn( "priority=" + priority ); + } + + if ( priority.equalsIgnoreCase( "siehe Teilprojekte" ) ) { + logger.warn("project=" + projectNumber ) ; + } + + try{ + return projectInformation.setProjectNumber(projectNumber) + .setStreet(street) + .setLength( JSoupUtils.parseDouble( length ) ) + .setBautyp( Bautyp.getFromString( bautyp ) ) + .setPriority( Priority.getFromString(priority ) ) + .setVerkehrsbelastungPlanfall( JSoupUtils.parseDouble( verkehrsbelastungPlanfall ) ) + ; + } catch( ParseException e ){ + throw new RuntimeException( e ); + } + } + + //mapping information from the grunddaten table. There are two tables with the same class, so we need to specify + // the index + public static String extractInformation(Document document, int tableIndex, String key) { + Optional info = document.select("table.table_grunddaten") + .get(tableIndex) + .select("tr") + .stream() + .filter(r -> r.text() + .contains(key)) + .findFirst() + .map(r -> r.child(1) + .text()); + if (info.isEmpty()) { + logger.warn("Could not find information for key {} in table {}", key, tableIndex); + } + return info.orElse(null); + } +} diff --git a/src/main/java/org/tub/vsp/bvwp/data/type/Priority.java b/src/main/java/org/tub/vsp/bvwp/data/type/Priority.java index 78f7325..8868453 100644 --- a/src/main/java/org/tub/vsp/bvwp/data/type/Priority.java +++ b/src/main/java/org/tub/vsp/bvwp/data/type/Priority.java @@ -1,12 +1,18 @@ package org.tub.vsp.bvwp.data.type; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + public enum Priority{ VBE("Vordringlicher Bedarf - Engpassbeseitigung (VB-E)"), VB("Vordringlicher Bedarf (VB)"), WBP("Weiterer Bedarf mit Planungsrecht (WB*)"), WB( "Weiterer Bedarf (WB)"), + @Deprecated // yyyyyy lieber aufklären!! UNDEFINED("undefined"); + private static final Logger log = LogManager.getLogger( Priority.class ); + public final String description; Priority( String description ) { @@ -14,10 +20,15 @@ public enum Priority{ } public static Priority getFromString( String description ) { - for ( Priority v : values()) - if (v.description.equalsIgnoreCase(description)) { + for ( Priority v : values()){ + if( v.description.equalsIgnoreCase( description ) ){ + return v; + } + if ( v.name().equalsIgnoreCase( description ) ) { return v; } + } + log.warn( "description=" + description ); return UNDEFINED; } } diff --git a/src/main/java/org/tub/vsp/bvwp/io/StreetCsvWriter.java b/src/main/java/org/tub/vsp/bvwp/io/StreetCsvWriter.java index 8d05acc..f8a480a 100644 --- a/src/main/java/org/tub/vsp/bvwp/io/StreetCsvWriter.java +++ b/src/main/java/org/tub/vsp/bvwp/io/StreetCsvWriter.java @@ -171,12 +171,12 @@ private static List getCsvRecord(StreetAnalysisDataContainer analysisDat //general info record.add(Headers.PROJECT_NAME, baseDataContainer.getProjectInformation().getProjectNumber()); record.add(Headers.LINK, baseDataContainer.getUrl()); - record.add(Headers.PRIORITY, baseDataContainer.getProjectInformation().getPriority().name()); + record.add( Headers.EINSTUFUNG, baseDataContainer.getProjectInformation().getPriority().name() ); record.add(Headers.BAUTYP, baseDataContainer.getProjectInformation().getBautyp().name()); record.add(Headers.LENGTH, baseDataContainer.getProjectInformation().getLength()); - record.add(Headers.PKWKM_ALL, baseDataContainer.getPhysicalEffect().getVehicleKilometers().overall()); + record.add(Headers.ADDTL_PKWKM_ORIG, baseDataContainer.getPhysicalEffect().getVehicleKilometers().overall()); record.add(Headers.PKWKM_INDUZ, Optional.ofNullable(baseDataContainer.getPhysicalEffect().getVehicleKilometers() .induced()).orElse(0.)); @@ -185,10 +185,10 @@ private static List getCsvRecord(StreetAnalysisDataContainer analysisDat //co2 equivalents record.add(Headers.CO_2_EQUIVALENTS_EMISSIONS, baseDataContainer.getPhysicalEffect().getEmissionsDataContainer() .co2Overall()); - record.add(Headers.B_CO_2_EQUIVALENTS_ANNUAL, baseDataContainer.getCostBenefitAnalysis() - .getCo2EquivalentBenefit() - .annual()); // yyyy not needed - record.add(Headers.B_CO_2_EQUIVALENTS_OVERALL, baseDataContainer.getCostBenefitAnalysis() +// record.add(Headers.B_CO_2_EQUIVALENTS_ANNUAL, baseDataContainer.getCostBenefitAnalysis() +// .getCo2EquivalentBenefit() +// .annual()); // yyyy not needed + record.add(Headers.B_CO_2_EQUIVALENTS_ORIG, baseDataContainer.getCostBenefitAnalysis() .getCo2EquivalentBenefit().overall()); //emissions @@ -257,18 +257,18 @@ private static List getHeaders(List analysi headers.addStringColumn(Headers.PROJECT_NAME); headers.addStringColumn(Headers.LINK); - headers.addStringColumn(Headers.PRIORITY); + headers.addStringColumn( Headers.EINSTUFUNG ); headers.addStringColumn(Headers.BAUTYP); headers.addDoubleColumn(Headers.LENGTH); - headers.addDoubleColumn(Headers.PKWKM_ALL); + headers.addDoubleColumn( Headers.ADDTL_PKWKM_ORIG ); headers.addDoubleColumn(Headers.PKWKM_INDUZ); // headers.addDoubleColumn( Headers.PKWKM_INDUZ_NEU ); // added by automagic headers.addDoubleColumn(Headers.B_FZKM); headers.addDoubleColumn(Headers.CO_2_EQUIVALENTS_EMISSIONS); - headers.addDoubleColumn(Headers.B_CO_2_EQUIVALENTS_ANNUAL); - headers.addDoubleColumn(Headers.B_CO_2_EQUIVALENTS_OVERALL); +// headers.addDoubleColumn( Headers.B_CO_2_EQUIVALENTS_ANNUAL ); + headers.addDoubleColumn( Headers.B_CO_2_EQUIVALENTS_ORIG ); // for (String colName : EMISSION_COLUMNS.values()) { // headers.add(colName + "-emissions"); diff --git a/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotExample.java b/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotExample.java index 1e375b1..45436d4 100644 --- a/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotExample.java +++ b/src/main/java/org/tub/vsp/bvwp/plot/MultiPlotExample.java @@ -49,6 +49,14 @@ class MultiPlotExample { + "
" + System.lineSeparator() + "
" + + System.lineSeparator() + + "
" + + System.lineSeparator() + + "
" + + System.lineSeparator() + + "
" + + System.lineSeparator() + + "
" + System.lineSeparator(); private static final String pageBottom = "" + System.lineSeparator() + ""; 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 26cc228..eb62631 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 @@ -164,8 +164,8 @@ static Figure createFigureNkv(Axis xAxis, int plotWidth, Table table, String xNa } static Figure createFigureCO2(Axis xAxis, int plotWidth, Table table, String xName){ - String yName = Headers.B_CO2_NEU; - String y2Name = Headers.B_CO2_NEU; + String yName = Headers.CO2_COST_NEU; + String y2Name = Headers.CO2_COST_NEU; Axis yAxis = Axis.builder() .title( yName ) 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 b856345..809b3ee 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 @@ -86,7 +86,7 @@ public static void main(String[] args) throws IOException { String xNameKMT; Axis.AxisBuilder xAxisBuilder = Axis.builder(); { - xNameKMT = Headers.B_CO2_NEU; + xNameKMT = Headers.CO2_COST_NEU; xAxisBuilder.type(Type.LINEAR); } // { @@ -140,7 +140,7 @@ public static void main(String[] args) throws IOException { table = table.sortOn(comparator); NumberFormat format = NumberFormat.getCompactNumberInstance(); format.setMaximumFractionDigits(0); - table.numberColumn(Headers.B_CO2_NEU).setPrintFormatter(format, "n/a"); + table.numberColumn(Headers.CO2_COST_NEU).setPrintFormatter(format, "n/a"); //Projekte, die bereits vor Änderung NKV <1 haben Table tableBaseKl1 = table.where(table.numberColumn(Headers.NKV_NO_CHANGE).isLessThan(1.)); @@ -170,10 +170,10 @@ public static void main(String[] args) throws IOException { System.out.println(BvwpUtils.SEPARATOR); System.out.println( table.summarize( - Headers.B_CO2_NEU, sum, mean, stdDev, min, max).by(Headers.PRIORITY)); + Headers.CO2_COST_NEU, sum, mean, stdDev, min, max).by(Headers.PRIORITY)); System.out.println(System.lineSeparator() + "Davon NKV < 1:"); System.out.println( - tableIndCo2kl1.summarize(Headers.B_CO2_NEU, sum, mean, stdDev, min, max) + tableIndCo2kl1.summarize(Headers.CO2_COST_NEU, sum, mean, stdDev, min, max) .by(Headers.PRIORITY)); } diff --git a/src/main/java/org/tub/vsp/bvwp/users/kn/FiguresKN.java b/src/main/java/org/tub/vsp/bvwp/users/kn/FiguresKN.java index 4b03ec2..6131a15 100644 --- a/src/main/java/org/tub/vsp/bvwp/users/kn/FiguresKN.java +++ b/src/main/java/org/tub/vsp/bvwp/users/kn/FiguresKN.java @@ -1,7 +1,10 @@ package org.tub.vsp.bvwp.users.kn; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.tub.vsp.bvwp.computation.ComputationKN; import org.tub.vsp.bvwp.data.Headers; +import org.tub.vsp.bvwp.data.type.Priority; import tech.tablesaw.api.DoubleColumn; import tech.tablesaw.api.Table; import tech.tablesaw.plotly.components.Axis; @@ -12,6 +15,7 @@ import tech.tablesaw.plotly.traces.Trace; class FiguresKN{ + private static final Logger log = LogManager.getLogger( FiguresKN.class ); private static final int plotWidth = 2000; private static final String legendFormat = "%30s"; private final Table table; @@ -23,14 +27,14 @@ class FiguresKN{ { // xName = Headers.B_CO2_NEU; // xName = Headers.COST_OVERALL; - xName = Headers.VERKEHRSBELASTUNG_2030; +// xName = Headers.VERKEHRSBELASTUNG_PLANFALL; } // --------------------------------------------------------------- // --------------------------------------------------------------- // { // xName = Headers.NKV_NO_CHANGE; // xName = Headers.NKV_INDUZ_CO2; -// xName = Headers.NKV_DIFF; + xName = Headers.NKV_DIFF; // xName = Headers.ADDITIONAL_LANE_KM; // xAxisBuilder // .type( Axis.Type.LOG ) @@ -41,28 +45,94 @@ class FiguresKN{ // --------------------------------------------------------------- switch( xName ){ - case Headers.NKV_NO_CHANGE + case Headers.NKV_ORIG // , Headers.VERKEHRSBELASTUNG_2030 -> xAxisBuilder.type( Axis.Type.LOG ); } +// xAxisBuilder.type( Axis.Type.LOG ); - table = table.sortAscendingOn( xName ); - this.xAxis = xAxisBuilder.title( xName ).build(); - DoubleColumn newColumn = DoubleColumn.create( Headers.VERKEHRSBELASTUNG_2030 ); - for( Double value : table.doubleColumn( Headers.VERKEHRSBELASTUNG_2030 ) ){ - newColumn.append( value - 500. + 1000. * Math.random() ); // randomize so that they are not on top of each other in plotly +// table = table.where( table.numberColumn( Headers.NKV_INDUZ_CO2 ).isLessThan( 2.) ); + + // ============================================ + table.addColumns( + table.numberColumn( Headers.NKV_INDUZ_CO2).subtract( table.numberColumn( Headers.NKV_ORIG ) ).setName( Headers.NKV_DIFF ) + ,table.numberColumn( Headers.ADDTL_PKWKM_NEU ).subtract( table.numberColumn( Headers.ADDTL_PKWKM_ORIG ) ).setName( Headers.ADDTL_PKWKM_DIFF ) + ); + // ============================================ + // ============================================ + { + DoubleColumn newColumn = DoubleColumn.create( Headers.NKV_INDUZ_CO2_CAPPED ); + for( Double number : table.doubleColumn( Headers.NKV_INDUZ_CO2 ) ){ + number = Math.min( number, 10. ); + newColumn.append( number ); + } + table.addColumns( newColumn ); + } + // ============================================ + // ============================================ + { + DoubleColumn newColumn = DoubleColumn.create( Headers.NKV_CAPPED ); + for( Double number : table.doubleColumn( Headers.NKV_ORIG ) ){ + number = Math.min( number, 10. ); + newColumn.append( number ); + } + table.addColumns( newColumn ); + } + // ============================================ + // =========================== + { + DoubleColumn newColumn = DoubleColumn.create( Headers.VERKEHRSBELASTUNG_PLANFALL ); + for( Double value : table.doubleColumn( Headers.VERKEHRSBELASTUNG_PLANFALL ) ){ + newColumn.append( value + 2000. * Math.random() ); // randomize so that they are not on top of each other in plotly. Deliberately not centered to that values are > 0. + } + table.removeColumns( Headers.VERKEHRSBELASTUNG_PLANFALL ); + table.addColumns( newColumn ); + } + // =========================== + // =========================== + { + DoubleColumn column = DoubleColumn.create( Headers.PRIO_AS_NUMBER ); + final double factor = 5.; + for( String prio : table.stringColumn( Headers.EINSTUFUNG ) ){ + switch( Priority.valueOf( prio ) ){ + case VBE -> { + column.append( 4. * factor ); + } + case VB -> { + column.append( 3. * factor ); + } + case WBP -> { + column.append( 2. * factor ); + } + case WB -> { + column.append( 1. * factor ); + } + case UNDEFINED -> { + column.append( 2. ); + } + default -> throw new IllegalStateException( "Unexpected value: " + prio ); + } + } + table.addColumns( column ); } - table.removeColumns( Headers.VERKEHRSBELASTUNG_2030 ); - table.addColumns( newColumn ); + // =========================== + + + + table = table.sortAscendingOn( xName ); + this.xAxis = xAxisBuilder.title( xName ).build(); this.table = table; } - Figure createFigureCost( ){ + Figure createFigureCostVsLanekm(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).type( Axis.Type.LOG ).build(); + Figure figure3; String yName = Headers.COST_OVERALL; - String y3Name = Headers.COST_OVERALL; +// String y3Name = Headers.COST_OVERALL; String y2Name = Headers.COST_OVERALL; Axis yAxis = Axis.builder() @@ -70,55 +140,56 @@ Figure createFigureCost( ){ // .range( 1.1*table.numberColumn( y2Name ).min(),4. ) .title( yName ) .build(); - Layout layout = Layout.builder( yName ) + Layout layout = Layout.builder( "construction cost SIMTO lane-km, but quite varied:" ) .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(); +// 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 = getTraceCyan( table, xName, y2Name ); final Trace traceWbp = getTraceMagenta( table, xName, y2Name ); final Trace traceVb = getTraceOrange( table, xName, y2Name ); final Trace traceVbe = getTraceRed( table, xName, y2Name ); - 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(); +// final Trace trace3 = getTrace( xName, y3Name, table, y3Name, "gray" ); // 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 ); + figure3 = new Figure( layout +// , trace, trace3 + , traceWb, traceWbp, traceVb, traceVbe ); return figure3; } - Figure createFigureNkv( ){ + Figure createFigureNkvVsLanekm(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).type( Axis.Type.LOG ).build(); + Figure figure2; - String yName = Headers.NKV_INDUZ_CO2; + String yName = Headers.NKV_DIFF; // String y3Name = Headers.NKV_CO2; - String y2Name = Headers.NKV_INDUZ_CO2; + String y2Name = Headers.NKV_DIFF; 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 ) + Layout layout = Layout.builder( "since (co2_cost SIMTO lane-km) and (cost SIMTO lane-km), the division of the two does not depend on lane-km:" ) .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(); +// 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 traceCyan = getTraceCyan( table, xName, y2Name ); final Trace traceMagenta = getTraceMagenta( table, xName, y2Name ); @@ -142,14 +213,14 @@ Figure createFigureNkv( ){ // , trace // , trace3 , traceCyan,traceMagenta -// , traceOrange, traceRed + , traceOrange, traceRed , trace4 ); return figure2; } Figure createFigurePkwKm( ){ Figure figure; String yName = Headers.PKWKM_INDUZ; - String y2Name = Headers.PKWKM_ALL_NEU; + String y2Name = Headers.ADDTL_PKWKM_NEU; Axis yAxis = Axis.builder() .title( yName ) @@ -178,17 +249,20 @@ Figure createFigurePkwKm( ){ return figure; } public Figure createFigureElasticities(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).type( Axis.Type.LOG ).build(); + String yName = "elasticity_old"; String y2Name = "elasticity_new"; - table.addColumns( table.numberColumn( Headers.PKWKM_ALL ) + table.addColumns( table.numberColumn( Headers.ADDTL_PKWKM_ORIG ) .divide( ComputationKN.FZKM_AB ) .multiply( ComputationKN.LANE_KM_AB ) - .divide( table.numberColumn( Headers.ADDITIONAL_LANE_KM ) ).setName("elasticity_old"), - table.numberColumn( Headers.PKWKM_ALL_NEU ) + .divide( table.numberColumn( Headers.ADDTL_LANE_KM ) ).setName("elasticity_old" ), + table.numberColumn( Headers.ADDTL_PKWKM_NEU ) .divide( ComputationKN.FZKM_AB ) .multiply( ComputationKN.LANE_KM_AB ) - .divide( table.numberColumn( Headers.ADDITIONAL_LANE_KM ) ).setName("elasticity_new" ) + .divide( table.numberColumn( Headers.ADDTL_LANE_KM ) ).setName("elasticity_new" ) ); double xMin = table.numberColumn( xName ).min(); @@ -224,8 +298,8 @@ public Figure createFigureElasticities(){ trace1, trace2 ); } public Figure createFigureFzkm(){ - String y2Name = Headers.PKWKM_ALL; - String yName = Headers.PKWKM_ALL_NEU; + String y2Name = Headers.ADDTL_PKWKM_NEU; + String yName = Headers.ADDTL_PKWKM_ORIG; Axis yAxis = Axis.builder().title( yName ) .type( Axis.Type.LOG ) @@ -257,13 +331,16 @@ public Figure createFigureFzkm(){ ); } - Figure createFigureCO2( ){ - String yName = Headers.B_CO2_NEU; - String y2Name = Headers.B_CO2_NEU; + Figure createFigureCO2VsLanekm(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).build(); - Axis yAxis = Axis.builder().title( yName ).type( Axis.Type.LOG ).build(); + String yName = Headers.CO2_COST_ORIG; + String y2Name = Headers.CO2_COST_NEU; - Layout layout = Layout.builder( "plot" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + Axis yAxis = Axis.builder().title( yName ).build(); + + Layout layout = Layout.builder( "CO2 costs SIMTO addtl lane-km:" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) .name( String.format( legendFormat, yName ) ) @@ -276,16 +353,48 @@ Figure createFigureCO2( ){ final Trace traceVbe = getTraceRed( table, xName, y2Name ); - return new Figure( layout, trace, traceWb, traceWbp, traceVb, traceVbe ); + return new Figure( layout + , trace + , traceWb, traceWbp, traceVb, traceVbe ); } public Figure createFigureDtv(){ - String yName = Headers.VERKEHRSBELASTUNG_2030; - String y2Name = Headers.VERKEHRSBELASTUNG_2030; + String yName = Headers.VERKEHRSBELASTUNG_PLANFALL; + String y2Name = Headers.VERKEHRSBELASTUNG_PLANFALL; 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( String.format( legendFormat, yName ) ) +// .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) +// .build(); + + final Trace traceWb = getTraceCyan( table, xName, y2Name ); + final Trace traceWbp = getTraceMagenta( table, xName, y2Name ); + final Trace traceVb = getTraceOrange( table, xName, y2Name ); + final Trace traceVbe = getTraceRed( table, xName, y2Name ); + + + return new Figure( layout +// , trace + , traceWb + ,traceWbp + , traceVb + , traceVbe + ); + } + public Figure createFigureFzkmNewVsLanekm(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).type( Axis.Type.LOG ).build(); + + String yName = Headers.ADDTL_PKWKM_ORIG; + String y2Name = Headers.ADDTL_PKWKM_NEU; + + Axis yAxis = Axis.builder().title( y2Name ).type( Axis.Type.LOG ).build(); + + Layout layout = Layout.builder( "addtl veh-km PROPTO addtl lane-km:" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) .name( String.format( legendFormat, yName ) ) .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) @@ -296,48 +405,180 @@ public Figure createFigureDtv(){ final Trace traceVb = getTraceOrange( table, xName, y2Name ); final Trace traceVbe = getTraceRed( table, xName, y2Name ); + log.warn( table.where( table.stringColumn( Headers.PROJECT_NAME ).startsWith( "A008" ) ) ); + log.warn("here"); - return new Figure( layout, trace + return new Figure( layout + , trace , traceWb ,traceWbp , traceVb , traceVbe ); } + public Figure createFigureFzkmDiffVsLanekm(){ + String xName = Headers.ADDTL_LANE_KM; + Axis xAxis = Axis.builder().title(xName).build(); + + String y2Name = Headers.ADDTL_PKWKM_DIFF; + + Axis yAxis = Axis.builder().title( y2Name ).build(); + + Layout layout = Layout.builder( "diff of addtl veh-km SIM addtl lane-km:" ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + +// Trace trace = ScatterTrace.builder( table.numberColumn( xName ), table.numberColumn( yName ) ) +// .name( String.format( legendFormat, yName ) ) +// .text( table.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) +// .build(); + + final Trace traceWb = getTraceCyan( table, xName, y2Name ); + final Trace traceWbp = getTraceMagenta( table, xName, y2Name ); + final Trace traceVb = getTraceOrange( table, xName, y2Name ); + final Trace traceVbe = getTraceRed( table, xName, y2Name ); + + return new Figure( layout +// , trace + , traceWb + ,traceWbp + , traceVb + , traceVbe + ); + } + + + public Figure createFigureNkvVsDtv(){ + String xName = Headers.VERKEHRSBELASTUNG_PLANFALL; + Axis xAxis = Axis.builder().title(xName).build(); + + Table table2 = table.sortAscendingOn( xName ); // cannot remember why this is necessary + + String yName = Headers.NKV_INDUZ_CO2_CAPPED; + Axis yAxis = Axis.builder().title( yName ).build(); // cannot use a a logarithmic y axis since it removes nkv < 1 + + String title = "nkv_nb normally low; nkv_knotenpunkt normally high; nkv_ew depends on dtv"; + Layout layout = Layout.builder( title ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + // the nkv=1 line: + double[] xx = new double[]{0., 1.1* table2.numberColumn( xName ).max() }; + double[] yy = new double[]{1., 1.}; + Trace trace4 = ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).build(); + + final Trace traceCyan = getTraceCyan( table2, xName, yName ); + final Trace traceMagenta = getTraceMagenta( table2, xName, yName ); + final Trace traceOrange = getTraceOrange( table2, xName, yName ); + final Trace traceRed = getTraceRed( table2, xName, yName ); + + return new Figure( layout, traceCyan, traceMagenta, traceOrange, traceRed, trace4 ); + } + public Figure createFigureCostVsNkvNew(){ + String xName = Headers.NKV_INDUZ_CO2_CAPPED; + Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) +// .visible( false ) +// .showLine( false ) + .showZeroLine( false ) + .zeroLineWidth( 0 ) + .zeroLineColor( "lightgray" ) + .build(); + + Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary + + String yName = Headers.COST_OVERALL; + Axis yAxis = Axis.builder().title( yName ) +// .showZeroLine( false ) +// .showLine( false ) +// .visible( false ) +// .zeroLineWidth( 100 ) + .type( Axis.Type.LOG ) + .build(); + + String title = "nkv_nb normally low; nkv_knotenpunkt normally high; nkv_ew depends on dtv"; + Layout layout = Layout.builder( title ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + // the nkv=1 line: + double[] xx = new double[]{1., 1.}; + double[] yy = new double[]{0., 1.1* table2.numberColumn( yName ).max() }; + Trace trace4 = ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).build(); + + final Trace traceCyan = getTraceCyan( table2, xName, yName ); + final Trace traceMagenta = getTraceMagenta( table2, xName, yName ); + final Trace traceOrange = getTraceOrange( table2, xName, yName ); + final Trace traceRed = getTraceRed( table2, xName, yName ); + + return new Figure( layout, traceCyan, traceMagenta, traceOrange, traceRed + , trace4 + ); + } + public Figure createFigureCostVsNkvOld(){ + String xName = Headers.NKV_CAPPED; + Axis xAxis = Axis.builder().title(xName).autoRange( Axis.AutoRange.REVERSED ) +// .visible( false ) +// .showLine( false ) + .showZeroLine( false ) + .zeroLineWidth( 0 ) + .zeroLineColor( "lightgray" ) + .build(); + + Table table2 = table.sortDescendingOn( xName ); // cannot remember why this is necessary + + String yName = Headers.COST_OVERALL; + Axis yAxis = Axis.builder().title( yName ) +// .showZeroLine( false ) +// .showLine( false ) +// .visible( false ) +// .zeroLineWidth( 100 ) + .type( Axis.Type.LOG ) + .build(); + + String title = "nkv_nb normally low; nkv_knotenpunkt normally high; nkv_ew depends on dtv"; + Layout layout = Layout.builder( title ).xAxis( xAxis ).yAxis( yAxis ).width( plotWidth ).build(); + + // the nkv=1 line: + double[] xx = new double[]{1., 1.}; + double[] yy = new double[]{0., 1.1* table2.numberColumn( yName ).max() }; + Trace trace4 = ScatterTrace.builder( xx, yy ).mode( ScatterTrace.Mode.LINE ).build(); + + final Trace traceCyan = getTraceCyan( table2, xName, yName ); + final Trace traceMagenta = getTraceMagenta( table2, xName, yName ); + final Trace traceOrange = getTraceOrange( table2, xName, yName ); + final Trace traceRed = getTraceRed( table2, xName, yName ); + + return new Figure( layout, traceCyan, traceMagenta, traceOrange, traceRed + , trace4 + ); + } + // "BubblePlot" handles categorical variables --> could convert BAUTYP into the categories that are of interest. + // There is also ScatterPlot3D + + // one can combine the four methods below by setting the marker color etc. to a Column instead of to a single value. See examples in BubblePlot. + // (however, in the end this does not work that much differently from what follows here except that it loops over the categorical column instead of repeating the code) private static Trace getTraceRed( Table table, String xName, String y2Name ){ Table tableVbe = table.where( table.stringColumn( Headers.BAUTYP ).isIn( "EW8" ) ); + final String nameInLegend = "EW8"; + final String color = "red"; + final Trace traceVbe = getTrace( xName, y2Name, tableVbe, nameInLegend, color ); + return traceVbe; + } + private static Trace getTrace( String xName, String y2Name, Table tableVbe, String nameInLegend, String color ){ Trace traceVbe = ScatterTrace.builder( tableVbe.numberColumn( xName ), tableVbe.numberColumn( y2Name ) ) .text( tableVbe.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, y2Name ) ) - .marker( Marker.builder().color( "red" ).build() ) + .name( String.format( legendFormat, nameInLegend ) ) + .marker( Marker.builder().color( color ).size( tableVbe.doubleColumn( Headers.PRIO_AS_NUMBER ) ).sizeMode( Marker.SizeMode.DIAMETER ).build() ) .build(); return traceVbe; } private static Trace getTraceOrange( Table table, String xName, String y2Name ){ - Table tableVb = table.where( table.stringColumn( Headers.BAUTYP ).isIn( "EW6" ) ); - Trace traceVb = ScatterTrace.builder( tableVb.numberColumn( xName ), tableVb.numberColumn( y2Name ) ) - .text( tableVb.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, y2Name ) ) - .marker( Marker.builder().color( "orange" ).build() ) - .build(); + Table tableVb = table.where( table.stringColumn( Headers.BAUTYP ).isIn( "EW6","EW6_EW8" ) ); + final Trace traceVb = getTrace( xName, y2Name, tableVb, "EW6", "orange" ); return traceVb; } private static Trace getTraceMagenta( Table table, String xName, String y2Name ){ Table tableWb = table.where( table.stringColumn( Headers.BAUTYP ).containsString( "NB" ) ); - Trace traceWb = ScatterTrace.builder( tableWb.numberColumn( xName ), tableWb.numberColumn( y2Name ) ) - .text( tableWb.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, y2Name ) ) - .marker( Marker.builder().color( "magenta" ).build() ) - .build(); + final Trace traceWb = getTrace( xName, y2Name, tableWb, "Neubau", "magenta" ); return traceWb; } private static Trace getTraceCyan( Table table, String xName, String y2Name ){ Table tableWb = table.where( table.stringColumn( Headers.BAUTYP ).containsString( "KNOTENPUNKT" ) ) ; - Trace traceWb = ScatterTrace.builder( tableWb.numberColumn( xName ), tableWb.numberColumn( y2Name ) ) - .text( tableWb.stringColumn( Headers.PROJECT_NAME ).asObjectArray() ) - .name( String.format( legendFormat, y2Name ) ) - .marker( Marker.builder().color( "cyan" ).build() ) - .build(); + final Trace traceWb = getTrace( xName, y2Name, tableWb, "Knotenpunkt", "cyan" ); return traceWb; } } 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 23fc9e3..13c9a8b 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 @@ -9,7 +9,6 @@ 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.DoubleColumn; import tech.tablesaw.api.Row; import tech.tablesaw.api.Table; import tech.tablesaw.plotly.components.Figure; @@ -59,17 +58,6 @@ public static void main(String[] args) throws IOException{ StreetCsvWriter csvWriter = new StreetCsvWriter( "output/street_data.csv" ); Table table = csvWriter.writeCsv( allStreetBaseData ); -// table = table.where( table.numberColumn( Headers.NKV_INDUZ_CO2 ).isLessThan( 2.) ); - - table.addColumns( table.numberColumn( Headers.NKV_NO_CHANGE ).subtract( table.numberColumn( Headers.NKV_INDUZ_CO2 ) ).setName( Headers.NKV_DIFF ) ); - - DoubleColumn newColumn = DoubleColumn.create( Headers.NKV_INDUZ_CO2 ); - for( Double number : table.doubleColumn( Headers.NKV_INDUZ_CO2 ) ){ - number = Math.min( number, 10. ); - newColumn.append( number ); - } - table.removeColumns( Headers.NKV_INDUZ_CO2 ); - table.addColumns( newColumn ); // final Table newTable = table.selectColumns( "nkvDiff", Headers.COST_OVERALL ); @@ -81,22 +69,31 @@ public static void main(String[] args) throws IOException{ FiguresKN figures = new FiguresKN( table ); - Figure figure = figures.createFigurePkwKm(); - Figure figure2 = figures.createFigureNkv(); - Figure figure3 = figures.createFigureCost(); - Figure figure4 = figures.createFigureCO2(); - Figure figure5 = figures.createFigureElasticities(); - Figure figure6 = figures.createFigureFzkm(); + Figure figure = figures.createFigureFzkmNewVsLanekm(); + Figure figure2 = figures.createFigureElasticities(); + Figure figure3 = figures.createFigureFzkmDiffVsLanekm(); + Figure figure4 = figures.createFigureCO2VsLanekm(); + Figure figure5 = figures.createFigureCostVsLanekm(); + Figure figure6 = figures.createFigureNkvVsLanekm(); Figure figure7 = figures.createFigureDtv(); + Figure figure8 = figures.createFigureFzkmNewVsLanekm(); + + Figure figureA = figures.createFigureNkvVsDtv(); + Figure figureB = figures.createFigureCostVsNkvOld(); + Figure figureC = figures.createFigureCostVsNkvNew(); String page = MultiPlotUtils.pageTop + System.lineSeparator() + - figure2.asJavascript( "plot1" ) + System.lineSeparator() + - figure.asJavascript( "plot2" ) + System.lineSeparator() + + figure.asJavascript( "plot1" ) + System.lineSeparator() + + figure2.asJavascript( "plot2" ) + System.lineSeparator() + figure3.asJavascript( "plot3" ) + System.lineSeparator() + figure4.asJavascript( "plot4" ) + System.lineSeparator() + figure5.asJavascript( "plot5" ) + System.lineSeparator() + figure6.asJavascript( "plot6" ) + System.lineSeparator() + figure7.asJavascript( "plot7" ) + System.lineSeparator() + + figure8.asJavascript( "plot8" ) + System.lineSeparator() + + figureA.asJavascript( "plotA" ) + System.lineSeparator() + + figureB.asJavascript( "plotB" ) + System.lineSeparator() + + figureC.asJavascript( "plotC" ) + System.lineSeparator() + MultiPlotUtils.pageBottom; File outputFile = Paths.get("multiplot.html" ).toFile(); @@ -110,31 +107,31 @@ public static void main(String[] args) throws IOException{ // === Comparator comparator = ( o1, o2 ) -> { - Priority p1 = Priority.valueOf( o1.getString( Headers.PRIORITY ) ); - Priority p2 = Priority.valueOf( o2.getString( Headers.PRIORITY ) ); + Priority p1 = Priority.valueOf( o1.getString( Headers.EINSTUFUNG ) ); + Priority p2 = Priority.valueOf( o2.getString( Headers.EINSTUFUNG ) ); return p1.compareTo( p2 ); }; table = table.sortOn( comparator ); NumberFormat format = NumberFormat.getCompactNumberInstance(); format.setMaximumFractionDigits( 0 ); - table.numberColumn( Headers.B_CO2_NEU ).setPrintFormatter( format, "n/a" ); + table.numberColumn( Headers.CO2_COST_NEU ).setPrintFormatter( format, "n/a" ); Table table2 = table.where( table.numberColumn( Headers.NKV_INDUZ_CO2 ).isLessThan( 1. ) ); System.out.println(BvwpUtils.SEPARATOR); - System.out.println( table.summarize( Headers.NKV_NO_CHANGE, count ).by(Headers.PRIORITY).print() ); + System.out.println( table.summarize( Headers.NKV_ORIG, count ).by(Headers.EINSTUFUNG ).print() ); System.out.println( System.lineSeparator() + "Davon müssen folgende nachbewertet werden:"); - System.out.println( table2.summarize( Headers.NKV_NO_CHANGE, count ).by(Headers.PRIORITY)); + System.out.println( table2.summarize( Headers.NKV_ORIG, count ).by(Headers.EINSTUFUNG ) ); System.out.println(BvwpUtils.SEPARATOR); - System.out.println( table.summarize( Headers.COST_OVERALL, sum, mean, stdDev, min, max ).by(Headers.PRIORITY) ); + System.out.println( table.summarize( Headers.COST_OVERALL, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); System.out.println( System.lineSeparator() + "Davon müssen folgende nachbewertet werden:"); - System.out.println( table2.summarize( Headers.COST_OVERALL, sum, mean, stdDev, min, max ).by(Headers.PRIORITY)); + System.out.println( table2.summarize( Headers.COST_OVERALL, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); System.out.println(BvwpUtils.SEPARATOR); - System.out.println( table.summarize( Headers.B_CO2_NEU, sum, mean, stdDev, min, max ).by(Headers.PRIORITY) ); + System.out.println( table.summarize( Headers.CO2_COST_NEU, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); System.out.println( System.lineSeparator() + "Davon müssen folgende nachbewertet werden:"); - System.out.println( table2.summarize( Headers.B_CO2_NEU, sum, mean, stdDev, min, max ).by(Headers.PRIORITY)); + System.out.println( table2.summarize( Headers.CO2_COST_NEU, sum, mean, stdDev, min, max ).by(Headers.EINSTUFUNG ) ); } }