use {
UsStateCode
} from './state-codes.jv';
pipeline ElectricVehiclesPipeline {
ElectricVehiclesHttpExtractor
-> ElectricVehiclesTextFileInterpreter
-> ElectricVehiclesCSVInterpreter
-> ElectricVehiclesTableInterpreter
-> ElectricRangeTransformer;
ElectricRangeTransformer
-> ElectricVehiclesSQLiteLoader;
ElectricRangeTransformer
-> ElectricVehiclesPostgresLoader;
block ElectricVehiclesHttpExtractor oftype HttpExtractor {
url: "https://data.wa.gov/api/views/f6w7-q2d2/rows.csv?accessType=DOWNLOAD";
}
block ElectricVehiclesTextFileInterpreter oftype TextFileInterpreter { }
block ElectricVehiclesCSVInterpreter oftype CSVInterpreter { }
valuetype ElectricVehicle {
property vin oftype VehicleIdentificationNumber10;
property county oftype text;
property city oftype text;
property state oftype UsStateCode;
property postal oftype text;
property modelYear oftype integer;
property make oftype text;
property model oftype text;
property evType oftype text;
property cafvEligibility oftype text;
property electricRange oftype integer;
property baseMSRP oftype integer;
property legislativeDistrict oftype text;
property dolID oftype integer;
property location oftype text;
property utility oftype text;
property censusTract oftype text;
}
transform ElectricVehicleParser {
from r oftype Collection<text>;
to ev oftype ElectricVehicle;
ev: {
vin: r cellInColumn "VIN (1-10)",
county: asText (r cellInColumn "County"),
city: asText (r cellInColumn "City"),
state: asText (r cellInColumn "State"),
postal: asText (r cellInColumn "Postal Code"),
modelYear: asInteger (r cellInColumn "Model Year"),
make: asText (r cellInColumn "Make"),
model: asText (r cellInColumn "Model"),
evType: asText (r cellInColumn "Electric Vehicle Type"),
cafvEligibility: asText (r cellInColumn "Clean Alternative Fuel Vehicle (CAFV) Eligibility"),
electricRange: asInteger (r cellInColumn "Electric Range"),
baseMSRP: asInteger (r cellInColumn "Base MSRP"),
legislativeDistrict: asText (r cellInColumn "LegislativeDistrict"),
dolID: asInteger (r cellInColumn "DOL Vehicle ID"),
location: asText (r cellInColumn "Vehicle Location"),
utility: asText (r cellInColumn "Electric Utility"),
censusTract: asText (r cellInColumn "2020 Census Tract"),
};
}
block ElectricVehiclesTableInterpreter oftype TableInterpreter {
header: true;
columns: ElectricVehicle;
parseWith: ElectricVehicleParser;
}
block ElectricRangeTransformer oftype TableTransformer {
inputColumns: [
"electricRange"
];
outputColumn: "electricRange (km)";
uses: MilesToKilometers;
}
transform MilesToKilometers {
from miles oftype decimal;
to kilometers oftype integer;
kilometers: round (miles * 1.609344);
}
block ElectricVehiclesSQLiteLoader oftype SQLiteLoader {
table: "ElectricVehiclePopulationData";
file: "./electric-vehicles.sqlite";
}
block ElectricVehiclesPostgresLoader oftype PostgresLoader {
host: requires DB_HOST;
port: requires DB_PORT;
username: requires DB_USERNAME;
password: requires DB_PASSWORD;
database: requires DB_DATABASE;
table: "ElectricVehiclePopulationData";
}
}
valuetype VehicleIdentificationNumber10 {
property id oftype text;
constraint capitalized: OnlyCapitalLettersAndDigits on id;
constraint exactlyTenCharacters: lengthof id == 10;
}
constraint OnlyCapitalLettersAndDigits on text: value matches /^[A-Z0-9]*$/;