Skip to content

Commit

Permalink
AER-2554 Fix serialization to/from json for cold start stuff (#259)
Browse files Browse the repository at this point in the history
Using 2 different names for the same source class is problematic. Reading is fine, but writing will always use 1 of the names (could maybe do something with another subtype defintion in a class between EmissionSource and ColdStartEmissionSource and then looking at the vehicleBasedCharacteristics value, but that's rather ugly and not even sure if that'd work). Better to use 1 name. Deprecated the existing values while we fix this, and added a new one that should be used instead.
Also using a json annotation to specify a different name for vehicle type: vehicleType is already used for the distinction between standard, specific and custom, so can't use that again.
Also added 2 json round trip cases for cold start.
  • Loading branch information
BertScholten authored Apr 10, 2024
1 parent 7bdfd1d commit 8d85a71
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
@Type(value = SRM1RoadEmissionSource.class, name = EmissionSourceType.Names.SRM1_ROAD),
@Type(value = SRM2RoadEmissionSource.class, name = EmissionSourceType.Names.SRM2_ROAD),
@Type(value = ADMSRoadEmissionSource.class, name = EmissionSourceType.Names.ADMS_ROAD),
@Type(value = ColdStartEmissionSource.class, name = EmissionSourceType.Names.COLD_START),
@Type(value = ColdStartEmissionSource.class, name = EmissionSourceType.Names.COLD_START_OTHER),
@Type(value = ColdStartEmissionSource.class, name = EmissionSourceType.Names.COLD_START_PARKING_GARAGE),
@Type(value = InlandShippingEmissionSource.class, name = EmissionSourceType.Names.SHIPPING_INLAND),
@Type(value = MooringInlandShippingEmissionSource.class, name = EmissionSourceType.Names.SHIPPING_INLAND_DOCKED),
@Type(value = InlandMaritimeShippingEmissionSource.class, name = EmissionSourceType.Names.SHIPPING_MARITIME_INLAND),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ public enum EmissionSourceType {
* Medium combustion plant values.
*/
MEDIUM_COMBUSTION_PLANT(Names.MEDIUM_COMBUSTION_PLANT),
/**
* Cold start emission values.
*/
COLD_START(Names.COLD_START),
/**
* Cold start parking emission values.
*
* @Deprecated Use COLD_START instead.
*/
@Deprecated
COLD_START_PARKING_GARAGE(Names.COLD_START_PARKING_GARAGE),
/**
* Cold start other emission values.
*
* @Deprecated Use COLD_START instead.
*/
@Deprecated
COLD_START_OTHER(Names.COLD_START_OTHER),
/**
* Mobile off road emission values.
Expand Down Expand Up @@ -92,7 +102,16 @@ public static final class Names {
public static final String GENERIC = "GENERIC";
public static final String MEDIUM_COMBUSTION_PLANT = "MEDIUM_COMBUSTION_PLANT";
public static final String OFFROAD_MOBILE = "OFFROAD_MOBILE";
public static final String COLD_START = "COLD_START";
/**
* @Deprecated Use COLD_START instead.
*/
@Deprecated
public static final String COLD_START_PARKING_GARAGE = "COLD_START_PARKING_GARAGE";
/**
* @Deprecated Use COLD_START instead.
*/
@Deprecated
public static final String COLD_START_OTHER = "COLD_START_OTHER";
public static final String PLAN = "PLAN";
public static final String SRM1_ROAD = "SRM1_ROAD";
Expand All @@ -104,7 +123,8 @@ public static final class Names {
public static final String SHIPPING_MARITIME_INLAND = "SHIPPING_MARITIME_INLAND";
public static final String SHIPPING_MARITIME_MARITIME = "SHIPPING_MARITIME_MARITIME";

private Names() {}
private Names() {
}
}

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import nl.overheid.aerius.shared.domain.Substance;

/**
Expand All @@ -41,6 +43,7 @@ public void setVehiclesPerTimeUnit(final double vehiclesPerTimeUnit) {
this.vehiclesPerTimeUnit = vehiclesPerTimeUnit;
}

@JsonProperty("vehicleCode")
public String getVehicleType() {
return vehicleType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ void testConvertGeometries(final String fileName) throws IOException {
"MooringInlandShippingEmissionSource.json",
"InlandMaritimeShippingEmissionSource.json",
"MaritimeMaritimeShippingEmissionSource.json",
"MooringMaritimeShippingEmissionSource.json"
"MooringMaritimeShippingEmissionSource.json",
"ColdStartEmissionSourceParkingGarage.json",
"ColdStartEmissionSourceOther.json"
})
void testConvertEmissionSourceTypes(final String fileName) throws IOException {
final String originalJson = getFileContent(fileName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type" : "Feature",
"id" : "1",
"geometry" : {
"type" : "Point",
"coordinates" : [ 130.12, -123.99 ]
},
"properties" : {
"emissionSourceType" : "COLD_START",
"sectorId" : 3160,
"label" : "Label 3160",
"emissions" : {
"NH3" : 10.0,
"NOX" : 11.0
},
"subSources" : [ {
"vehicleType" : "STANDARD_CS",
"timeUnit" : "DAY",
"valuesPerVehicleTypes" : {
"LIGHT_TRAFFIC" : 101.1,
"HEAVY_FREIGHT" : 54.7
}
}, {
"vehicleType" : "CUSTOM",
"timeUnit" : "YEAR",
"vehiclesPerTimeUnit" : 2000.0,
"description" : "Oude eenden",
"emissionFactors" : {
"NOX" : 1.5,
"NH3" : 0.6
},
"vehicleCode" : "HEAVY_FREIGHT"
}, {
"vehicleType" : "SPECIFIC",
"timeUnit" : "MONTH",
"vehiclesPerTimeUnit" : 300.0,
"vehicleCode" : "BA-B-E3"
} ],
"vehicleBasedCharacteristics" : true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"type" : "Feature",
"id" : "1",
"geometry" : {
"type" : "Point",
"coordinates" : [ 130.12, -123.99 ]
},
"properties" : {
"emissionSourceType" : "COLD_START",
"sectorId" : 3150,
"label" : "Label 3150",
"characteristics" : {
"type" : "OPS",
"heatContent" : 123.45,
"emissionHeight" : 5.0
},
"emissions" : {
"NH3" : 10.0,
"NOX" : 11.0
},
"subSources" : [ {
"vehicleType" : "STANDARD_CS",
"timeUnit" : "DAY",
"valuesPerVehicleTypes" : {
"LIGHT_TRAFFIC" : 101.1,
"HEAVY_FREIGHT" : 54.7
}
}, {
"vehicleType" : "CUSTOM",
"timeUnit" : "YEAR",
"vehiclesPerTimeUnit" : 2000.0,
"description" : "Oude eenden",
"emissionFactors" : {
"NOX" : 1.5,
"NH3" : 0.6
}
}, {
"vehicleType" : "SPECIFIC",
"timeUnit" : "MONTH",
"vehiclesPerTimeUnit" : 300.0,
"vehicleCode" : "BA-B-E3"
} ],
"vehicleBasedCharacteristics" : false
}
}

0 comments on commit 8d85a71

Please sign in to comment.