Skip to content

Commit

Permalink
a22-traveltimes #673 add new API fields
Browse files Browse the repository at this point in the history
  • Loading branch information
clezag committed Oct 21, 2024
1 parent ed3326e commit d8529d0
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 106 deletions.
6 changes: 4 additions & 2 deletions data-collectors/traveltimes-a22/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: CC0-1.0

version: "3.4"

services:
app:
image: maven:3-jdk-8-alpine
Expand All @@ -25,4 +23,8 @@ services:
- ~/.m2/:/var/maven/.m2
- ./:/code
working_dir: /code
ulimits:
nofile:
soft: 65536
hard: 65536
tty: true
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public void execute()
// step 3
// get the list of travel times
try {

long scanWindowSeconds = Long.parseLong(a22TraveltimesProperties.getProperty("scanWindowSeconds"));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Expand All @@ -138,69 +137,54 @@ public void execute()
long lastTimeStamp = getLastTimestampOfStationInSeconds(id);

do {
DataMapDto<RecordDtoImpl> ldsDataMapDto = new DataMapDto<>();
DataMapDto<RecordDtoImpl> ldsDescDataMapDto = new DataMapDto<>();
DataMapDto<RecordDtoImpl> ldsValDataMapDto = new DataMapDto<>();
DataMapDto<RecordDtoImpl> tempoDataMapDto = new DataMapDto<>();
DataMapDto<RecordDtoImpl> velocitaDataMapDto = new DataMapDto<>();

DataMapDto<RecordDtoImpl> recs = new DataMapDto<>();

List<HashMap<String, String>> traveltimes = a22Service.getTravelTimes(lastTimeStamp, lastTimeStamp + scanWindowSeconds, id);

LOG.debug("got " + traveltimes.size() + " traveltime data records for " + simpleDateFormat.format(new Date(lastTimeStamp * 1000)) + ", " + simpleDateFormat.format(new Date((lastTimeStamp + scanWindowSeconds) * 1000)) + ", " + id + ":");
if (!traveltimes.isEmpty()) {
LOG.debug("the first travel time is: {}", traveltimes.get(0));
traveltimes.forEach(traveltime -> {

String stationId = traveltime.get("idtratto");
long ts = Long.parseLong(traveltime.get("data")) * 1000;

// ########## LIGHT VEHICLES ##########
// lds
String ldsKey = datatypesProperties.getProperty("a22traveltimes.datatype.lds.key");
String ldsRaw = traveltime.get("lds");
SimpleRecordDto lds = new SimpleRecordDto(Long.parseLong(traveltime.get("data")) * 1000,
ldsRaw,
1);
ldsDataMapDto.addRecord(traveltime.get("idtratto"),
ldsKey,
lds);
SimpleRecordDto ldsDesc = new SimpleRecordDto(Long.parseLong(traveltime.get("data")) * 1000,
datatypesProperties.getProperty("a22traveltimes.datatype.lds.mapping." + ldsRaw + ".desc"),
1);
ldsDescDataMapDto.addRecord(traveltime.get("idtratto"),
ldsKey + "_desc",
ldsDesc);
SimpleRecordDto ldsVal = new SimpleRecordDto(Long.parseLong(traveltime.get("data")) * 1000,
Double.parseDouble(datatypesProperties.getProperty("a22traveltimes.datatype.lds.mapping." + ldsRaw + ".val")),
1);
ldsValDataMapDto.addRecord(traveltime.get("idtratto"),
ldsKey + "_val",
ldsVal);
String ldsLightKey = datatypesProperties.getProperty("a22traveltimes.datatype.lds_leggeri.key");
String ldsLightRaw = traveltime.get("lds");
recs.addRecord(stationId, ldsLightKey, new SimpleRecordDto(ts, ldsLightRaw, 1));
String ldsLightDesc = datatypesProperties.getProperty("a22traveltimes.datatype.lds_leggeri.mapping." + ldsLightRaw + ".desc");
recs.addRecord(stationId, ldsLightKey + "_desc", new SimpleRecordDto(ts, ldsLightDesc, 1));
double ldsLightVal = Double.parseDouble(datatypesProperties.getProperty("a22traveltimes.datatype.lds_leggeri.mapping." + ldsLightRaw + ".val"));
recs.addRecord(stationId, ldsLightKey + "_val",new SimpleRecordDto(ts, ldsLightVal, 1));

// tempo
SimpleRecordDto tempo = new SimpleRecordDto(Long.parseLong(traveltime.get("data")) * 1000L,
Double.parseDouble(traveltime.get("tempo")),
1);
tempoDataMapDto.addRecord(traveltime.get("idtratto"),
datatypesProperties.getProperty("a22traveltimes.datatype.tempo.key"),
tempo);
String tempoLightKey = datatypesProperties.getProperty("a22traveltimes.datatype.tempo_leggeri.key");
recs.addRecord(stationId, tempoLightKey, new SimpleRecordDto(ts, Double.parseDouble(traveltime.get("tempo")), 1));
// velocita
String velocitaLightKey = datatypesProperties.getProperty("a22traveltimes.datatype.velocita_leggeri.key");
recs.addRecord(stationId, velocitaLightKey,new SimpleRecordDto(ts, Double.parseDouble(traveltime.get("velocita")), 1));

// ########## HEAVY VEHICLES ##########
// lds
String ldsHeavyKey = datatypesProperties.getProperty("a22traveltimes.datatype.lds_pesanti.key");
String ldsHeavyRaw = traveltime.get("pesanti_lds");
recs.addRecord(stationId, ldsHeavyKey, new SimpleRecordDto(ts, ldsHeavyRaw, 1));
String ldsHeavyDesc = datatypesProperties.getProperty("a22traveltimes.datatype.lds_pesanti.mapping." + ldsHeavyRaw + ".desc");
recs.addRecord(stationId, ldsHeavyKey + "_desc", new SimpleRecordDto(ts, ldsHeavyDesc, 1));
double ldsHeavyVal = Double.parseDouble(datatypesProperties.getProperty("a22traveltimes.datatype.lds_pesanti.mapping." + ldsHeavyRaw + ".val"));
recs.addRecord(stationId, ldsHeavyKey + "_val",new SimpleRecordDto(ts, ldsHeavyVal, 1));

// tempo
String tempoHeavyKey = datatypesProperties.getProperty("a22traveltimes.datatype.tempo_pesanti.key");
recs.addRecord(stationId, tempoHeavyKey, new SimpleRecordDto(ts, Double.parseDouble(traveltime.get("pesanti_tempo")), 1));
// velocita
SimpleRecordDto velocita = new SimpleRecordDto(Long.parseLong(traveltime.get("data")) * 1000L,
Double.parseDouble(traveltime.get("velocita")),
1);
velocitaDataMapDto.addRecord(traveltime.get("idtratto"),
datatypesProperties.getProperty("a22traveltimes.datatype.velocita.key"),
velocita);
String velocitaHeavyKey = datatypesProperties.getProperty("a22traveltimes.datatype.velocita_pesanti.key");
recs.addRecord(stationId, velocitaHeavyKey,new SimpleRecordDto(ts, Double.parseDouble(traveltime.get("pesanti_velocita")), 1));
});

LOG.debug("pushing all ldsDataMapDto data: " + stationList.size() + " records");
pusher.pushData(ldsDataMapDto);
LOG.debug("pushing all ldsDescDataMapDto data: " + stationList.size() + " records");
pusher.pushData(ldsDescDataMapDto);
LOG.debug("pushing all ldsValDataMapDto data: " + stationList.size() + " records");
pusher.pushData(ldsValDataMapDto);
LOG.debug("pushing all tempoDataMapDto data: " + stationList.size() + " records");
pusher.pushData(tempoDataMapDto);
LOG.debug("pushing all velocitaDataMapDto data: " + stationList.size() + " records");
pusher.pushData(velocitaDataMapDto);
LOG.debug("pushing all data: " + stationList.size() + " records");
pusher.pushData(recs);
}
lastTimeStamp += scanWindowSeconds;
} while (lastTimeStamp < System.currentTimeMillis() / 1000);
Expand Down Expand Up @@ -230,35 +214,30 @@ private Connector setupA22ServiceConnector() throws IOException
{
return new Connector(a22ConnectorURL, a22ConnectorUsr, a22ConnectorPwd);
}

private DataTypeDto mkDt(String id, String postix) {
return new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype."+id+".key") + postix,
datatypesProperties.getProperty("a22traveltimes.datatype."+id+".unit"),
datatypesProperties.getProperty("a22traveltimes.datatype."+id+".description"),
datatypesProperties.getProperty("a22traveltimes.datatype."+id+".rtype"));

}

private void setupDataType()
{
private void setupDataType() {
List<DataTypeDto> dataTypeDtoList = new ArrayList<>();
DataTypeDto lds = new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype.lds.key"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.unit"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.description"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.rtype"));
DataTypeDto ldsDesc = new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype.lds.key") + "_desc",
datatypesProperties.getProperty("a22traveltimes.datatype.lds.unit"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.description"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.rtype"));
DataTypeDto ldsVal = new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype.lds.key") + "_val",
datatypesProperties.getProperty("a22traveltimes.datatype.lds.unit"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.description"),
datatypesProperties.getProperty("a22traveltimes.datatype.lds.rtype"));
DataTypeDto tempo = new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype.tempo.key"),
datatypesProperties.getProperty("a22traveltimes.datatype.tempo.unit"),
datatypesProperties.getProperty("a22traveltimes.datatype.tempo.description"),
datatypesProperties.getProperty("a22traveltimes.datatype.tempo.rtype"));
DataTypeDto velocita = new DataTypeDto(datatypesProperties.getProperty("a22traveltimes.datatype.velocita.key"),
datatypesProperties.getProperty("a22traveltimes.datatype.velocita.unit"),
datatypesProperties.getProperty("a22traveltimes.datatype.velocita.description"),
datatypesProperties.getProperty("a22traveltimes.datatype.velocita.rtype"));
dataTypeDtoList.add(lds);
dataTypeDtoList.add(ldsDesc);
dataTypeDtoList.add(ldsVal);
dataTypeDtoList.add(tempo);
dataTypeDtoList.add(velocita);

dataTypeDtoList.add(mkDt("lds_leggeri", ""));
dataTypeDtoList.add(mkDt("lds_leggeri", "_desc"));
dataTypeDtoList.add(mkDt("lds_leggeri", "_val"));
dataTypeDtoList.add(mkDt("velocita_leggeri", ""));
dataTypeDtoList.add(mkDt("tempo_leggeri", ""));

dataTypeDtoList.add(mkDt("lds_pesanti", ""));
dataTypeDtoList.add(mkDt("lds_pesanti", "_desc"));
dataTypeDtoList.add(mkDt("lds_pesanti", "_val"));
dataTypeDtoList.add(mkDt("velocita_pesanti", ""));
dataTypeDtoList.add(mkDt("tempo_pesanti", ""));

pusher.syncDataTypes(dataTypeDtoList);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
a22traveltimes.datatype.lds.key=lds
a22traveltimes.datatype.lds.unit=
a22traveltimes.datatype.lds.description=Livello di servizio
a22traveltimes.datatype.lds.rtype=Mean
a22traveltimes.datatype.lds.mapping=true
a22traveltimes.datatype.lds.mapping.A.desc=traffico scorrevole
a22traveltimes.datatype.lds.mapping.A.val=1
a22traveltimes.datatype.lds.mapping.B.desc=rallentamenti
a22traveltimes.datatype.lds.mapping.B.val=2
a22traveltimes.datatype.lds.mapping.C.desc=code a tratti
a22traveltimes.datatype.lds.mapping.C.val=3
a22traveltimes.datatype.lds.mapping.D.desc=code
a22traveltimes.datatype.lds.mapping.D.val=4
a22traveltimes.datatype.lds.mapping.E.desc=traffico scorrevole
a22traveltimes.datatype.lds.mapping.E.val=5
a22traveltimes.datatype.lds.mapping.Z.desc=non definito
a22traveltimes.datatype.lds.mapping.Z.val=99
a22traveltimes.datatype.tempo.key=tempo
a22traveltimes.datatype.tempo.unit=[s]
a22traveltimes.datatype.tempo.description=Tempo di percorrenza
a22traveltimes.datatype.tempo.rtype=false
a22traveltimes.datatype.tempo.mapping=Mean
a22traveltimes.datatype.velocita.key=velocita
a22traveltimes.datatype.velocita.unit=[km/h]
a22traveltimes.datatype.velocita.description=Velocità di percorrenza
a22traveltimes.datatype.velocita.rtype=Mean
a22traveltimes.datatype.velocita.mapping=false
a22traveltimes.datatype.lds_leggeri.key=lds_leggeri
a22traveltimes.datatype.lds_leggeri.unit=
a22traveltimes.datatype.lds_leggeri.description=Livello di servizio mezzi leggeri
a22traveltimes.datatype.lds_leggeri.rtype=Mean
a22traveltimes.datatype.lds_leggeri.mapping=true
a22traveltimes.datatype.lds_leggeri.mapping.A.desc=traffico scorrevole
a22traveltimes.datatype.lds_leggeri.mapping.A.val=1
a22traveltimes.datatype.lds_leggeri.mapping.B.desc=rallentamenti
a22traveltimes.datatype.lds_leggeri.mapping.B.val=2
a22traveltimes.datatype.lds_leggeri.mapping.C.desc=code a tratti
a22traveltimes.datatype.lds_leggeri.mapping.C.val=3
a22traveltimes.datatype.lds_leggeri.mapping.D.desc=code
a22traveltimes.datatype.lds_leggeri.mapping.D.val=4
a22traveltimes.datatype.lds_leggeri.mapping.E.desc=traffico scorrevole
a22traveltimes.datatype.lds_leggeri.mapping.E.val=5
a22traveltimes.datatype.lds_leggeri.mapping.Z.desc=non definito
a22traveltimes.datatype.lds_leggeri.mapping.Z.val=99
a22traveltimes.datatype.tempo_leggeri.key=tempo_leggeri
a22traveltimes.datatype.tempo_leggeri.unit=[s]
a22traveltimes.datatype.tempo_leggeri.description=Tempo di percorrenza mezzi leggeri
a22traveltimes.datatype.tempo_leggeri.rtype=false
a22traveltimes.datatype.tempo_leggeri.mapping=Mean
a22traveltimes.datatype.velocita_leggeri.key=velocita_leggeri
a22traveltimes.datatype.velocita_leggeri.unit=[km/h]
a22traveltimes.datatype.velocita_leggeri.description=Velocità di percorrenza mezzi leggeri
a22traveltimes.datatype.velocita_leggeri.rtype=Mean
a22traveltimes.datatype.velocita_leggeri.mapping=false

a22traveltimes.datatype.lds_pesanti.key=lds_pesanti
a22traveltimes.datatype.lds_pesanti.unit=
a22traveltimes.datatype.lds_pesanti.description=Livello di servizio mezzi pesanti
a22traveltimes.datatype.lds_pesanti.rtype=Mean
a22traveltimes.datatype.lds_pesanti.mapping=true
a22traveltimes.datatype.lds_pesanti.mapping.A.desc=traffico scorrevole
a22traveltimes.datatype.lds_pesanti.mapping.A.val=1
a22traveltimes.datatype.lds_pesanti.mapping.B.desc=rallentamenti
a22traveltimes.datatype.lds_pesanti.mapping.B.val=2
a22traveltimes.datatype.lds_pesanti.mapping.C.desc=code a tratti
a22traveltimes.datatype.lds_pesanti.mapping.C.val=3
a22traveltimes.datatype.lds_pesanti.mapping.D.desc=code
a22traveltimes.datatype.lds_pesanti.mapping.D.val=4
a22traveltimes.datatype.lds_pesanti.mapping.E.desc=traffico scorrevole
a22traveltimes.datatype.lds_pesanti.mapping.E.val=5
a22traveltimes.datatype.lds_pesanti.mapping.Z.desc=non definito
a22traveltimes.datatype.lds_pesanti.mapping.Z.val=99
a22traveltimes.datatype.tempo_pesanti.key=tempo_pesanti
a22traveltimes.datatype.tempo_pesanti.unit=[s]
a22traveltimes.datatype.tempo_pesanti.description=Tempo di percorrenza mezzi pesanti
a22traveltimes.datatype.tempo_pesanti.rtype=false
a22traveltimes.datatype.tempo_pesanti.mapping=Mean
a22traveltimes.datatype.velocita_pesanti.key=velocita_pesanti
a22traveltimes.datatype.velocita_pesanti.unit=[km/h]
a22traveltimes.datatype.velocita_pesanti.description=Velocità di percorrenza mezzi pesanti
a22traveltimes.datatype.velocita_pesanti.rtype=Mean
a22traveltimes.datatype.velocita_pesanti.mapping=false

0 comments on commit d8529d0

Please sign in to comment.