-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from matsim-vsp/kaibranch2
Kaibranch2
- Loading branch information
Showing
13 changed files
with
533 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StreetAnalysisDataContainer> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/org/tub/vsp/bvwp/data/mapper/ProjectInformationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
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 ) { | ||
this.description = description; | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.