Skip to content

Commit

Permalink
traffic-a22-forecast: add validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Oct 3, 2023
1 parent 05d154f commit 8c1e589
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public static class ForecastData {
public static class TrafficDataLine {
@JsonProperty("PrevisioniTraffico")
public List<TrafficData> data;

// if every day of whole month has value = 0; forecast is not valid
public boolean isValid() {
for (TrafficData trafficData : data)
if (trafficData.isValid())s
return true;
return false;
}
}

@ToString
Expand All @@ -72,6 +80,14 @@ public static class TrafficData {
@JsonProperty("Sud")
@JsonIgnoreProperties("Tipo")
public Map<String, TrafficValues> south;

public boolean isValid() {
for (TrafficValues values : south.values())
if ((values.value0to6.type + values.value6to12.type + values.value12to18.type
+ values.value18to24.type) == 0)
return false;
return true;
}
}

@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public class ForecastMap extends HashMap<String, Map<Long, TrafficValues>> {

public void add(ForecastDto dto) {
for (TrafficDataLine line : dto.data.trafficDataLines) {
for (TrafficData data : line.data) {
putValues(data.south, data.date, "Sud");
putValues(data.north, data.date, "Nord");
}
if (line.isValid())
for (TrafficData data : line.data) {
putValues(data.south, data.date, "Sud");
putValues(data.north, data.date, "Nord");
}
}
}

Expand Down

0 comments on commit 8c1e589

Please sign in to comment.