-
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.
- Loading branch information
Showing
8 changed files
with
403 additions
and
34 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
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
126 changes: 126 additions & 0 deletions
126
...in/java/org/tub/vsp/bvwp/data/container/base/street/StreetEnvironmentalDataContainer.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,126 @@ | ||
package org.tub.vsp.bvwp.data.container.base.street; | ||
|
||
import org.tub.vsp.bvwp.data.type.EnvironmentalCriteria; | ||
|
||
import java.util.Objects; | ||
|
||
public class StreetEnvironmentalDataContainer { | ||
private EnvironmentalCriteria naturschutzVorrangflaechen21; | ||
private EnvironmentalCriteria natura2000Gebiete22; | ||
private EnvironmentalCriteria unzerschnitteneKernraeume23; | ||
private EnvironmentalCriteria unzerschnitteneGrossraeume24; | ||
private EnvironmentalCriteria flaechenInanspruchnahme25; | ||
private EnvironmentalCriteria ueberschwemmungsgebiete26; | ||
private EnvironmentalCriteria wasserschutzgebiete27; | ||
private EnvironmentalCriteria verkehrsarmeRaeume28; | ||
private EnvironmentalCriteria kulturLandschaftsschutz29; | ||
|
||
public EnvironmentalCriteria getNaturschutzVorrangflaechen21() { | ||
return naturschutzVorrangflaechen21; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setNaturschutzVorrangflaechen21(EnvironmentalCriteria naturschutzVorrangflaechen21) { | ||
this.naturschutzVorrangflaechen21 = naturschutzVorrangflaechen21; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getNatura2000Gebiete22() { | ||
return natura2000Gebiete22; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setNatura2000Gebiete22(EnvironmentalCriteria natura2000Gebiete22) { | ||
this.natura2000Gebiete22 = natura2000Gebiete22; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getUnzerschnitteneKernraeume23() { | ||
return unzerschnitteneKernraeume23; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setUnzerschnitteneKernraeume23(EnvironmentalCriteria unzerschnitteneKernraeume23) { | ||
this.unzerschnitteneKernraeume23 = unzerschnitteneKernraeume23; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getUnzerschnitteneGrossraeume24() { | ||
return unzerschnitteneGrossraeume24; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setUnzerschnitteneGrossraeume24(EnvironmentalCriteria unzerschnitteneGrossraeume24) { | ||
this.unzerschnitteneGrossraeume24 = unzerschnitteneGrossraeume24; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getFlaechenInanspruchnahme25() { | ||
return flaechenInanspruchnahme25; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setFlaechenInanspruchnahme25(EnvironmentalCriteria flaechenInanspruchnahme25) { | ||
this.flaechenInanspruchnahme25 = flaechenInanspruchnahme25; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getUeberschwemmungsgebiete26() { | ||
return ueberschwemmungsgebiete26; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setUeberschwemmungsgebiete26(EnvironmentalCriteria ueberschwemmungsgebiete26) { | ||
this.ueberschwemmungsgebiete26 = ueberschwemmungsgebiete26; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getWasserschutzgebiete27() { | ||
return wasserschutzgebiete27; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setWasserschutzgebiete27(EnvironmentalCriteria wasserschutzgebiete27) { | ||
this.wasserschutzgebiete27 = wasserschutzgebiete27; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getVerkehrsarmeRaeume28() { | ||
return verkehrsarmeRaeume28; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setVerkehrsarmeRaeume28(EnvironmentalCriteria verkehrsarmeRaeume28) { | ||
this.verkehrsarmeRaeume28 = verkehrsarmeRaeume28; | ||
return this; | ||
} | ||
|
||
public EnvironmentalCriteria getKulturLandschaftsschutz29() { | ||
return kulturLandschaftsschutz29; | ||
} | ||
|
||
public StreetEnvironmentalDataContainer setKulturLandschaftsschutz29(EnvironmentalCriteria kulturLandschaftsschutz29) { | ||
this.kulturLandschaftsschutz29 = kulturLandschaftsschutz29; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
StreetEnvironmentalDataContainer that = (StreetEnvironmentalDataContainer) o; | ||
return Objects.equals(naturschutzVorrangflaechen21, that.naturschutzVorrangflaechen21) && Objects.equals(natura2000Gebiete22, | ||
that.natura2000Gebiete22) && Objects.equals(unzerschnitteneKernraeume23, that.unzerschnitteneKernraeume23) && Objects.equals(unzerschnitteneGrossraeume24, that.unzerschnitteneGrossraeume24) && Objects.equals(flaechenInanspruchnahme25, that.flaechenInanspruchnahme25) && Objects.equals(ueberschwemmungsgebiete26, that.ueberschwemmungsgebiete26) && Objects.equals(wasserschutzgebiete27, that.wasserschutzgebiete27) && Objects.equals(verkehrsarmeRaeume28, that.verkehrsarmeRaeume28) && Objects.equals(kulturLandschaftsschutz29, that.kulturLandschaftsschutz29); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hashCode(naturschutzVorrangflaechen21); | ||
result = 31 * result + Objects.hashCode(natura2000Gebiete22); | ||
result = 31 * result + Objects.hashCode(unzerschnitteneKernraeume23); | ||
result = 31 * result + Objects.hashCode(unzerschnitteneGrossraeume24); | ||
result = 31 * result + Objects.hashCode(flaechenInanspruchnahme25); | ||
result = 31 * result + Objects.hashCode(ueberschwemmungsgebiete26); | ||
result = 31 * result + Objects.hashCode(wasserschutzgebiete27); | ||
result = 31 * result + Objects.hashCode(verkehrsarmeRaeume28); | ||
result = 31 * result + Objects.hashCode(kulturLandschaftsschutz29); | ||
return result; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...org/tub/vsp/bvwp/data/mapper/environmentalCriteria/StreetEnvironmentalCriteriaMapper.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,69 @@ | ||
package org.tub.vsp.bvwp.data.mapper.environmentalCriteria; | ||
|
||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.tub.vsp.bvwp.JSoupUtils; | ||
import org.tub.vsp.bvwp.data.container.base.street.StreetEnvironmentalDataContainer; | ||
import org.tub.vsp.bvwp.data.type.EnvironmentalCriteria; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class StreetEnvironmentalCriteriaMapper { | ||
public static StreetEnvironmentalDataContainer mapDocument(Document document) { | ||
StreetEnvironmentalDataContainer result = new StreetEnvironmentalDataContainer(); | ||
|
||
Element envTable = JSoupUtils.getTableByCssKeyAndPredicate(document, "table.table_webprins", | ||
StreetEnvironmentalCriteriaMapper::isEnvironmentalCriteriaTable) | ||
.orElseThrow(); | ||
|
||
result.setNaturschutzVorrangflaechen21(extractFlatEnvironmentalCriteria(envTable, "2.1")) | ||
.setNatura2000Gebiete22(extractWithSubEnvironmentalCriteria(envTable, "2.2", 2)) | ||
.setUnzerschnitteneKernraeume23(extractFlatEnvironmentalCriteria(envTable, "2.3")) | ||
.setUnzerschnitteneGrossraeume24(extractWithSubEnvironmentalCriteria(envTable, "2.4", 4)) | ||
.setFlaechenInanspruchnahme25(extractFlatEnvironmentalCriteria(envTable, "2.5")) | ||
.setUeberschwemmungsgebiete26(extractFlatEnvironmentalCriteria(envTable, "2.6")) | ||
.setWasserschutzgebiete27(extractFlatEnvironmentalCriteria(envTable, "2.7")) | ||
.setVerkehrsarmeRaeume28(extractFlatEnvironmentalCriteria(envTable, "2.8")) | ||
.setKulturLandschaftsschutz29(extractFlatEnvironmentalCriteria(envTable, "2.9")); | ||
|
||
return result; | ||
} | ||
|
||
private static EnvironmentalCriteria extractFlatEnvironmentalCriteria(Element table, String number) { | ||
Element row = JSoupUtils.firstRowWithKeyInCol(table, number, 0).orElseThrow(); | ||
|
||
Double absolut = JSoupUtils.parseDoubleOrElseThrow(row.select("td").get(2).text()); | ||
Double betroffen = JSoupUtils.parseDoubleOrElseThrow(row.select("td").get(4).text()); | ||
EnvironmentalCriteria.Description description = new EnvironmentalCriteria.Description(absolut, betroffen); | ||
|
||
EnvironmentalCriteria.UmweltBewertung bewertung = handleBewertung(row.select("td").get(6).text()); | ||
return new EnvironmentalCriteria(List.of(description), bewertung); | ||
} | ||
|
||
private static EnvironmentalCriteria extractWithSubEnvironmentalCriteria(Element table, String number, int rows) { | ||
int headRowIndex = JSoupUtils.getFirstRowIndexWithTextInCol(table, number, 0).orElseThrow(); | ||
EnvironmentalCriteria.UmweltBewertung umweltBewertung = handleBewertung(JSoupUtils.getTextFromRowAndCol(table, headRowIndex, 6)); | ||
|
||
List<EnvironmentalCriteria.Description> descriptions = new ArrayList<>(); | ||
for (int i = 1; i <= rows; i++) { | ||
Double absolut = JSoupUtils.parseDoubleOrElseThrow(JSoupUtils.getTextFromRowAndCol(table, headRowIndex + i, 2)); | ||
Double betroffen = JSoupUtils.parseDoubleOrElseThrow(JSoupUtils.getTextFromRowAndCol(table, headRowIndex + i, 4)); | ||
EnvironmentalCriteria.Description description = new EnvironmentalCriteria.Description(absolut, betroffen); | ||
descriptions.add(description); | ||
} | ||
|
||
return new EnvironmentalCriteria(descriptions, umweltBewertung); | ||
} | ||
|
||
private static EnvironmentalCriteria.UmweltBewertung handleBewertung(String bewertung) { | ||
if (bewertung.equals("-")) { | ||
return null; | ||
} | ||
return EnvironmentalCriteria.UmweltBewertung.valueOf(bewertung.toUpperCase()); | ||
} | ||
|
||
private static boolean isEnvironmentalCriteriaTable(Element element) { | ||
return element.select("th").stream().map(Element::text).limit(4).toList().equals(List.of("Nr.", "Kriterium", "Beschreibung", "Bewertung")); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/tub/vsp/bvwp/data/type/EnvironmentalCriteria.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,12 @@ | ||
package org.tub.vsp.bvwp.data.type; | ||
|
||
import java.util.List; | ||
|
||
public record EnvironmentalCriteria(List<Description> description, UmweltBewertung bewertung) { | ||
public record Description(double absolute, double betroffenheit) { | ||
} | ||
|
||
public enum UmweltBewertung { | ||
HOCH, MITTEL, GERING; | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...tub/vsp/bvwp/data/mapper/environmentalCriteria/StreetEnvironmentalCriteriaMapperTest.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,50 @@ | ||
package org.tub.vsp.bvwp.data.mapper.environmentalCriteria; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.tub.vsp.bvwp.data.LocalFileAccessor; | ||
import org.tub.vsp.bvwp.data.container.base.street.StreetEnvironmentalDataContainer; | ||
import org.tub.vsp.bvwp.data.type.EnvironmentalCriteria; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
class StreetEnvironmentalCriteriaMapperTest { | ||
@Test | ||
void test_a20() throws IOException { | ||
StreetEnvironmentalDataContainer result = StreetEnvironmentalCriteriaMapper.mapDocument(LocalFileAccessor.getLocalDocument("a20.html")); | ||
|
||
Assertions.assertEquals(result.getNaturschutzVorrangflaechen21().bewertung(), EnvironmentalCriteria.UmweltBewertung.MITTEL); | ||
Assertions.assertEquals(result.getNaturschutzVorrangflaechen21().description(), List.of(new EnvironmentalCriteria.Description(1.6, 0.01))); | ||
|
||
Assertions.assertEquals(result.getNatura2000Gebiete22().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getNatura2000Gebiete22().description(), List.of(new EnvironmentalCriteria.Description(4., 0.0), | ||
new EnvironmentalCriteria.Description(0., 0.0))); | ||
|
||
Assertions.assertEquals(result.getUnzerschnitteneKernraeume23().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getUnzerschnitteneKernraeume23().description(), List.of(new EnvironmentalCriteria.Description(15.9, 0.1))); | ||
|
||
Assertions.assertEquals(result.getUnzerschnitteneGrossraeume24().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getUnzerschnitteneGrossraeume24().description(), List.of(new EnvironmentalCriteria.Description(5.9, 0.04), | ||
new EnvironmentalCriteria.Description(14.0, 0.09), | ||
new EnvironmentalCriteria.Description(0.0, 0.0), | ||
new EnvironmentalCriteria.Description(0.0, 0.0))); | ||
|
||
Assertions.assertNull(result.getFlaechenInanspruchnahme25().bewertung()); | ||
Assertions.assertEquals(result.getFlaechenInanspruchnahme25().description(), List.of(new EnvironmentalCriteria.Description(870.9, 0.0))); | ||
|
||
Assertions.assertEquals(result.getUeberschwemmungsgebiete26().bewertung(), EnvironmentalCriteria.UmweltBewertung.GERING); | ||
Assertions.assertEquals(result.getUeberschwemmungsgebiete26().description(), List.of(new EnvironmentalCriteria.Description(0.0, 0.0))); | ||
|
||
Assertions.assertEquals(result.getWasserschutzgebiete27().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getWasserschutzgebiete27().description(), List.of(new EnvironmentalCriteria.Description(0.5, 0.0))); | ||
|
||
Assertions.assertEquals(result.getVerkehrsarmeRaeume28().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getVerkehrsarmeRaeume28().description(), List.of(new EnvironmentalCriteria.Description(18941.4, 0.0))); | ||
|
||
Assertions.assertEquals(result.getKulturLandschaftsschutz29().bewertung(), EnvironmentalCriteria.UmweltBewertung.HOCH); | ||
Assertions.assertEquals(result.getKulturLandschaftsschutz29().description(), List.of(new EnvironmentalCriteria.Description(76.7, 0.49))); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.