-
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
9 changed files
with
164 additions
and
37 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
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
31 changes: 31 additions & 0 deletions
31
...ersdrukte/src/main/java/nl/bertriksikken/verkeersdrukte/traffic/AggregateMeasurement.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,31 @@ | ||
package nl.bertriksikken.verkeersdrukte.traffic; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* JSON serializable representation of a measurement for one location. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public final class AggregateMeasurement { | ||
@JsonProperty("datetime") | ||
final String dateTime; | ||
@JsonProperty("flow") | ||
final Double flow; // vehicles per hour | ||
@JsonProperty("speed") | ||
final Double speed; // km per hour | ||
|
||
public AggregateMeasurement(String dateTime, double flow, double speed) { | ||
this.dateTime = dateTime; | ||
this.flow = Double.isFinite(flow) ? flow : null; | ||
this.speed = Double.isFinite(speed) ? speed : null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format(Locale.ROOT, "{flow=%.1f,speed=%.1f}", flow, speed); | ||
} | ||
} | ||
|
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
23 changes: 23 additions & 0 deletions
23
verkeersdrukte/src/main/java/nl/bertriksikken/verkeersdrukte/traffic/MeasurementCache.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,23 @@ | ||
package nl.bertriksikken.verkeersdrukte.traffic; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public final class MeasurementCache { | ||
|
||
private final String publishedDateTime; | ||
private Map<String, AggregateMeasurement> measurementMap = new ConcurrentHashMap<>(); | ||
|
||
MeasurementCache(String publishedDateTime) { | ||
this.publishedDateTime = publishedDateTime; | ||
} | ||
|
||
public void put(String location, AggregateMeasurement measurement) { | ||
measurementMap.put(location, measurement); | ||
} | ||
|
||
public AggregateMeasurement get(String location) { | ||
return measurementMap.get(location); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
verkeersdrukte/src/main/java/nl/bertriksikken/verkeersdrukte/traffic/MeasurementResult.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,18 @@ | ||
package nl.bertriksikken.verkeersdrukte.traffic; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public final class MeasurementResult { | ||
|
||
@JsonProperty("location") | ||
public final String location; | ||
|
||
@JsonProperty("measurement") | ||
public final AggregateMeasurement measurement; | ||
|
||
public MeasurementResult(String location, AggregateMeasurement measurement) { | ||
this.location = location; | ||
this.measurement = measurement; | ||
} | ||
|
||
} |
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