-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a14478
commit 0f78abd
Showing
10 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
__pycache__ | ||
|
||
data/* | ||
!.placeholder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import json | ||
|
||
from .Vehicle import VehicleData | ||
|
||
# Create an echarge-configurator compatible list | ||
class EchargeConfiguratorList: | ||
def __init__(self): | ||
self.output = {} | ||
|
||
# -- Create lists -- | ||
|
||
def add_make(self,make): | ||
if make not in self.output: | ||
self.output[make] = {} | ||
|
||
def add_model(self,make,model): | ||
if make not in self.output[make]: | ||
self.output[make][model] = {} | ||
|
||
def add_year(self,make,model,year): | ||
if year not in self.output[make][model]: | ||
self.output[make][model][year] = {} | ||
|
||
# ---- | ||
|
||
def add(self,make,model,year): | ||
self.add_make(make) | ||
self.add_model(make,model) | ||
self.add_year(make,model,year) | ||
|
||
return self.output[make][model][year] | ||
|
||
# Save built output to file | ||
def write(self,dest): | ||
with open(dest,"w") as f: | ||
json.dump(self.output,f) | ||
return True | ||
|
||
# Process data from vehicles_stored.json and cables.json | ||
class Build(EchargeConfiguratorList): | ||
def __init__(self,vehicles,cables): | ||
super(Build,self).__init__() | ||
self.input = vehicles | ||
self.cables = cables | ||
|
||
self.worker(cables) | ||
|
||
def add_details(self,vehicle): | ||
data = { | ||
"ob_charger": { | ||
"plug": vehicle.data["Charge_Plug"], | ||
"power": str(vehicle.data["Charge_Standard_Power"]), | ||
"phase": str(vehicle.data["Charge_Standard_Phase"]), | ||
"charge_time": str(vehicle.data["Charge_Standard_ChargeTime"]) | ||
} | ||
} | ||
|
||
return data | ||
|
||
def add_cables(self,vehicle): | ||
data = vehicle.compatibility(self.cables) | ||
return data | ||
|
||
def worker(self,cables): | ||
for i in self.input: | ||
vehicle = VehicleData(self.input[i]) | ||
if(not vehicle.valid): | ||
continue | ||
|
||
output = self.add(vehicle.data["Vehicle_Make"],vehicle.data["Vehicle_Model"],vehicle.data["Availability_Date_From"][3:]) | ||
|
||
# Append vehicle data | ||
output["details"] = self.add_details(vehicle) | ||
output["cables"] = self.add_cables(vehicle) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
# Import a JSON file | ||
def load_JSON(f): | ||
# Attempt to load JSON into memory | ||
def load(self,f): | ||
if not Path(f).is_file(): | ||
return False | ||
raise IOError(f"Input file '{x}' not found") | ||
|
||
with open(f) as f: | ||
data = json.load(f) | ||
return json.load(f) | ||
|
||
return data | ||
# Map key,value list | ||
def forEach(list,func): | ||
for i,v in enumerate(list): | ||
func(v,i,list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import json | ||
|
||
from .Functions import * | ||
from .settings import * | ||
|
||
# Merge insert two objects | ||
# Merge new vehicle data with existing vehicle data | ||
class Merge: | ||
def __init__(self,data_from,data_to): | ||
self.input = self.assigned_list(data_from) # Merge this.. | ||
self.output = data_to # ..With this | ||
|
||
# Merge lists | ||
self.output.update(self.input) | ||
|
||
def __init__(self,this,that): | ||
self.data_target = load_JSON(data_vehicles) | ||
self.data_insert = load_JSON(data_vehicles_new) | ||
# Create assigned list from EVDB array of objects | ||
def assigned_list(self,data): | ||
output = {} | ||
for vehicle in data: | ||
key = str(vehicle["Vehicle_ID"]) | ||
output[key] = vehicle | ||
return output | ||
|
||
def run(self): | ||
print(data_vehicles_new) | ||
# Save merged output to file | ||
def write(self,dest): | ||
with open(dest,"w") as f: | ||
json.dump(self.output,f) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class VehicleData: | ||
def __init__(self,data): | ||
self.valid = True | ||
self.data = data | ||
|
||
if(data["Availability_Status"] > 1): | ||
self.valid = False | ||
|
||
# Return compatible cables ordered by best-fit | ||
def compatibility(self,cables): | ||
plug = self.data["Charge_Plug"] | ||
phase = self.data["Charge_Standard_Phase"] | ||
ampere = self.data["Charge_Standard_PhaseAmp"] | ||
|
||
output = [] | ||
|
||
# -- Best-fit hierarchy -- | ||
|
||
# Plug; Type 1 | ||
if(plug == "Type 1"): | ||
output = cables["Type 1"]["1-Phase"]["16A"] | ||
return output | ||
|
||
# Plug; Type 2 | ||
if(phase > 1): | ||
if(ampere > 16): | ||
output = cables["Type 2"]["3-Phase"]["32A"] + output | ||
output = output + cables["Type 2"]["3-Phase"]["16A"] | ||
|
||
if(ampere > 16): | ||
output = output + cables["Type 2"]["1-Phase"]["32A"] | ||
output = output + cables["Type 2"]["1-Phase"]["16A"] | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
from .settings import * | ||
|
||
from .Functions import * | ||
from .Merge import * | ||
from .Merge import Merge | ||
from .Build import Build |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
]; | ||
} | ||
|
||
echo json_encode($output); | ||
echo $output; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
import os | ||
import json | ||
from shutil import copyfile | ||
from pathlib import Path | ||
|
||
import classes | ||
|
||
merge = classes.Merge() | ||
merge.run() | ||
# Fetch raw data from this endpoint | ||
endpoint = os.environ.get("ECHARGE_CONFIGURATOR_ENDPOINT") | ||
|
||
files = { | ||
"vehicles_processed": "data/vehicles.json", | ||
"vehicles_stored": "data/vehicles_stored.json", | ||
"vehicles_new": "data/vehicles_new.json", | ||
"cables": "cables.json" | ||
} | ||
|
||
# Load JSON into memory | ||
def load_json(f): | ||
if not Path(f).is_file(): | ||
raise IOError(f"Input file '{x}' not found") | ||
|
||
with open(f) as f: | ||
return json.load(f) | ||
|
||
def backup(f): | ||
try: | ||
copyfile(f,f"{f}.backup") | ||
except IOError as error: | ||
print(error) | ||
|
||
# Clone existing vehicle archives before processing | ||
backup(files["vehicles_processed"]) | ||
backup(files["vehicles_stored"]) | ||
|
||
# Merge new vehicle data with stored vehicle data | ||
merge = classes.Merge(load_json(files["vehicles_new"]),load_json(files["vehicles_stored"])) | ||
merge.write(files["vehicles_stored"]) # Overwrite archive with new data | ||
|
||
# Create echarge-configurator compatible JSON from vehicle and cable data | ||
process = classes.Build(merge.output,load_json(files["cables"])) | ||
process.write(files["vehicles_processed"]) |