Unverified Commit c9785027 authored by Martin Raifer's avatar Martin Raifer
Browse files

fix some minor code style issues

parent 8d2becb2
Pipeline #2005 created
......@@ -10,17 +10,14 @@ import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
public class DistinctContributors {
public static void main(String[] args) throws Exception {
// database
OSHDBH2 oshdb = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.mv.db").getFile())
.multithreading(true);
//keytables
OSHDBH2 oshdbKeytables = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.keytables.mv.db").getFile());
// query
SortedMap<OSHDBTimestamp, Integer> result = OSMContributionView.on(oshdb)
.keytables(oshdbKeytables)
......@@ -30,7 +27,6 @@ public class DistinctContributors {
.map(k -> k.getContributorUserId())
.aggregateByTimestamp()
.countUniq();
// output
for (Map.Entry<OSHDBTimestamp, Integer> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......@@ -39,5 +35,4 @@ public class DistinctContributors {
);
}
}
}
......@@ -12,7 +12,6 @@ import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
public class RoadLength {
static final List<String> other = List.of("unclassified", "road", "service", "track", "path",
"pedestrian", "footway", "cycleway", "steps", "platform", "bridleway");
static final List<String> highway_motorway = List.of(
......@@ -30,7 +29,6 @@ public class RoadLength {
OSHDBH2 oshdbKeytables = new OSHDBH2(RoadLength.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", ""));
// query
SortedMap<OSHDBTimestamp, Number> result = OSMEntitySnapshotView.on(oshdb)
.keytables(oshdbKeytables)
......@@ -39,7 +37,6 @@ public class RoadLength {
.filter("type:way and highway in (" + String.join(",", highway_motorway) + ")")
.aggregateByTimestamp()
.sum(snapshot -> Geo.lengthOf(snapshot.getGeometry()) / 1000);
// output
for (Map.Entry<OSHDBTimestamp, Number> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......@@ -48,5 +45,4 @@ public class RoadLength {
);
}
}
}
package org.heigit.ohsome.oshdb.tutorial;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
......@@ -11,7 +10,6 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
import org.heigit.ohsome.oshdb.api.db.OSHDBJdbc;
import org.heigit.ohsome.oshdb.api.mapreducer.OSMContributionView;
import org.heigit.ohsome.oshdb.api.object.OSMContribution;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshdb.util.celliterator.ContributionType;
import org.heigit.ohsome.oshdb.util.function.SerializableBinaryOperator;
import org.heigit.ohsome.oshdb.util.function.SerializableFunction;
......@@ -20,9 +18,7 @@ import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps;
import org.jfree.ui.RefineryUtilities;
public class AdvandcedExample {
public static void main(String[] args) throws Exception {
//Declare Database
OSHDBDatabase oshdb = new OSHDBH2(AdvandcedExample.class.getResource("/test.oshdb.mv.db")
.getFile()
......@@ -30,8 +26,6 @@ public class AdvandcedExample {
OSHDBJdbc keytables = new OSHDBH2(Tutorial.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", ""));
//Define MapReducer
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> reduce = OSMContributionView.on(oshdb)
.keytables(keytables)
......@@ -40,7 +34,6 @@ public class AdvandcedExample {
.map(new Mapper())
.aggregateByTimestamp()
.reduce(new IdentitySupplier(), new Combiner());
//Display Result
TutorialChart chart = new TutorialChart("BigDB Analyses",
"Contribution-Types per timestamp!", reduce);
......@@ -51,31 +44,23 @@ public class AdvandcedExample {
private static class Mapper implements
SerializableFunction<OSMContribution, Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> apply(OSMContribution contribution) {
//get an empty result-map
Map<ContributionType, Integer> result = new IdentitySupplier().get();
//count contribution-types
contribution.getContributionTypes().forEach((ContributionType type) -> {
result.put(type, result.get(type) + 1);
});
contribution.getContributionTypes().forEach((ContributionType type) ->
result.put(type, result.get(type) + 1));
return result;
}
}
private static class IdentitySupplier implements
SerializableSupplier<Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> get() {
//create an empty result-map
Map<ContributionType, Integer> result = new HashMap<>();
//fill with 0 values
Arrays.asList(ContributionType.values())
.forEach(
......@@ -84,31 +69,22 @@ public class AdvandcedExample {
);
return result;
}
}
private static class Combiner implements
SerializableBinaryOperator<Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> apply(
Map<ContributionType, Integer> mapResultA,
Map<ContributionType, Integer> mapResultB) {
//get an empty result-map
Map<ContributionType, Integer> result = new IdentitySupplier().get();
//put all counts of map-result A
result.putAll(mapResultA);
//sum up with all result from map-result B
mapResultB.forEach((ContributionType contribType, Integer integ) -> {
result.merge(contribType, integ, (Integer int1, Integer int2) -> int1 + int2);
});
mapResultB.forEach((ContributionType contribType, Integer integ) ->
result.merge(contribType, integ, Integer::sum));
return result;
}
}
}
package org.heigit.ohsome.oshdb.tutorial;
import java.io.IOException;
import java.sql.SQLException;
import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.api.db.OSHDBDatabase;
import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
......@@ -9,17 +7,13 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBJdbc;
import org.heigit.ohsome.oshdb.api.mapreducer.MapReducer;
import org.heigit.ohsome.oshdb.api.mapreducer.OSMEntitySnapshotView;
import org.heigit.ohsome.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshdb.util.function.SerializableFunction;
import org.heigit.ohsome.oshdb.util.function.SerializablePredicate;
import org.heigit.ohsome.oshdb.util.geometry.Geo;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
public class Tutorial {
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException,
Exception {
public static void main(String[] args) throws Exception {
// -- PREPARATION --
// Start writing the OSHDB query
// declare and open a link to the OSHDB
......@@ -76,21 +70,16 @@ public class Tutorial {
}
private static class Mapper implements SerializableFunction<OSMEntitySnapshot, Double> {
@Override
public Double apply(OSMEntitySnapshot snapshot) {
return Geo.areaOf(snapshot.getGeometry());
}
}
private static class ResultFilter implements SerializablePredicate<Double> {
@Override
public boolean test(Double area) {
return area < 1000.0;
}
}
}
......@@ -15,23 +15,23 @@ import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
public class TutorialChart extends ApplicationFrame {
private SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> dataset;
public TutorialChart(
String applicationTitle,
String chartTitle,
String applicationTitle,
String chartTitle,
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> result) {
super(applicationTitle);
this.dataset = result;
JFreeChart barChart = ChartFactory.createBarChart(
chartTitle,
"Category",
"Score",
createDataset(),
PlotOrientation.VERTICAL,
true, true, false);
chartTitle,
"Category",
"Score",
createDataset(),
PlotOrientation.VERTICAL,
true,
true,
false);
ChartPanel chartPanel = new ChartPanel(barChart);
chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
setContentPane(chartPanel);
......@@ -47,10 +47,7 @@ public class TutorialChart extends ApplicationFrame {
a.addValue(ff.getValue().get(contribType), contribType, ff
.getKey());
});
}
return a;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment