Skip to content

Instantly share code, notes, and snippets.

@mminella
Last active August 29, 2015 14:18
Show Gist options
  • Save mminella/cb0f32be1fe61f26210c to your computer and use it in GitHub Desktop.
Save mminella/cb0f32be1fe61f26210c to your computer and use it in GitHub Desktop.
import groovy.json.JsonSlurper
def result = true
def slurper = new JsonSlurper()
def jsonPayload = null;
try {
jsonPayload = slurper.parseText(payload)
} catch (Exception e) {
return false;
}
def fuelLevelInput = jsonPayload.containsKey("fuel_level_input") ? jsonPayload?.fuel_level_input : null
def massAirFlow = jsonPayload.containsKey("maf_airflow") ? jsonPayload?.maf_airflow : null
def rpm = jsonPayload.containsKey("rpm") ? jsonPayload?.rpm : null
def intakeManifoldPressure = jsonPayload.containsKey("intake_manifold_pressure") ? jsonPayload?.intake_manifold_pressure : null
def intakeAirTemp = jsonPayload.containsKey("intake_air_temp") ? jsonPayload?.intake_air_temp : null
def vehicleSpeed = jsonPayload.containsKey("vehicle_speed") ? jsonPayload?.vehicle_speed : null
if((fuelLevelInput == null || fuelLevelInput instanceof String) || (vehicleSpeed == null || vehicleSpeed instanceof String)) {
println "Rejecting " + payload + " because either fuelLevelInput or vehicleSpeed are empty"
result = false
} else {
if((massAirFlow == null || massAirFlow instanceof String)) {
if((rpm == null || rpm instanceof String) || (intakeAirTemp == null || intakeAirTemp instanceof String) || (intakeManifoldPressure == null || intakeMainfoldPressure instanceof String)) {
println "Rejecting " + payload + " because maf related fields are not available"
result = false
}
}
}
return result
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.acmemotors.filter;
import java.io.IOException;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
/**
* @author Michael Minella
*/
public class DataFilterTests {
@Test
public void testEmptyString() throws Exception {
testScript("", false);
}
@Test
public void testEmptyJson() throws Exception {
testScript("{}", false);
}
@Test
public void testNull() throws Exception {
testScript(null, false);
}
@Test
public void testNoFuelLevelInput() throws Exception {
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":\"\",\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", true);
}
@Test
public void testNoVehicleSpeed() throws Exception {
testScript("{\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":\"\",\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", true);
}
@Test
public void testNoMassAirFlowNoRpm() throws Exception {
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":\"\",\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":\"\",\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", true);
}
@Test
public void testNoMassAirFlowNoIntakeAirTemp() throws Exception {
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":\"\"," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":\"\"," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", true);
}
@Test
public void testNoMassAirFlowNoIntakeMainfoldPressure() throws Exception {
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", false);
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," +
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," +
"\"engine_load\":30,\"latitude\":\"32.984979\"," +
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," +
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," +
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," +
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," +
"\"throttle_position\":14,\"barometric_pressure\":95," +
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," +
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," +
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," +
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," +
"\"timestamp\":1408670439897}", true);
}
@Test
public void testDallas() throws Exception {
testScript("{\"vehicle_speed\":0,\"obd_standards\":2,\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8,\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\",\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\",\"catalyst_temp\":446,\"relative_throttle_pos\":1,\"fuel_level_input\":99,\"fuel_system_status\":[2,0],\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\",\"throttle_position\":14,\"barometric_pressure\":95,\"control_module_voltage\":13,\"longitude\":\"-96.709578\",\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60,\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217,\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2,\"timestamp\":1408670439897,\"guid\":\"de7a9806-0e13-48d3-b93f-119d17b6dc6f\"}", true);
}
private void testScript(String payload, boolean result) throws IOException {
Binding binding = new Binding();
binding.setVariable("payload", payload);
GroovyShell shell = new GroovyShell(binding);
Object value =
shell.evaluate(new ClassPathResource("DataFilter.groovy").getFile());
assert value.equals(result);
}
}
@mminella
Copy link
Author

{
    "absolute_throttle_pos_b": 18,
    "acceleration": "0.992",
    "accelerator_throttle_pos_d": 16,
    "accelerator_throttle_pos_e": 8,
    "barometric_pressure": 95,
    "bearing": "319.492374",
    "catalyst_temp": 446,
    "control_module_voltage": 13,
    "coolant_temp": 92,
    "distance_with_mil_on": 0,
    "engine_load": 30,
    "fuel_level_input": 99,
    "fuel_system_status": [
        2,
        0
    ],
    "guid": "de7a9806-0e13-48d3-b93f-119d17b6dc6f",
    "intake_air_temp": 60,
    "intake_manifold_pressure": "",
    "latitude": "32.984979",
    "long_term_fuel": 2,
    "longitude": "-96.709578",
    "maf_airflow": 7,
    "obd_standards": 2,
    "relative_throttle_pos": 1,
    "rpm": 659,
    "short_term_fuel": -1,
    "throttle_position": 14,
    "time_since_engine_start": 217,
    "timestamp": 1408670439897,
    "vehicle_speed": 0,
    "vin": "SCEDT26T0BD007019"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment