getStationInitials corrected - now returns a list of initials as a technology...

getStationInitials corrected - now returns a list of initials as a technology can be performed at stations with different initials
parent 57fef693
...@@ -32,9 +32,11 @@ class ReadJSSkillsToStations(UpdateStationList.UpdateStationList): ...@@ -32,9 +32,11 @@ class ReadJSSkillsToStations(UpdateStationList.UpdateStationList):
for technology in technologyList: for technology in technologyList:
tech = technology.split("-")[0] tech = technology.split("-")[0]
for station in data["graph"]["node"]: for station in data["graph"]["node"]:
if station.startswith(self.getStationInitials(tech))\ for initial in self.getStationInitials(tech):
and data["graph"]["node"][station]["_class"] in self.STATION_CLASS_SET: if station.startswith(initial)\
stationList.append(station) and data["graph"]["node"][station]["_class"] in self.STATION_CLASS_SET:
stationList.append(station)
break
''' '''
the skillDict has the form of the skillDict has the form of
{"load": {"stationIdList": [] {"load": {"stationIdList": []
......
...@@ -31,11 +31,12 @@ class UpdateStationList(plugin.InputPreparationPlugin): ...@@ -31,11 +31,12 @@ class UpdateStationList(plugin.InputPreparationPlugin):
def getStationInitials(self,technology): def getStationInitials(self,technology):
'''get the stations that correspond to that technology''' '''get the stations that correspond to that technology'''
initialsList = []
for initials, corresponding_tech_list in self.getStationTechnologies().iteritems(): for initials, corresponding_tech_list in self.getStationTechnologies().iteritems():
for tech in corresponding_tech_list: for tech in corresponding_tech_list:
if tech == technology: if tech == technology and not initials in initialsList:
return initials initialsList.append(initials)
return None return initialsList
def getStationNames(self): def getStationNames(self):
node = self.data["graph"]["node"] node = self.data["graph"]["node"]
...@@ -61,19 +62,20 @@ class UpdateStationList(plugin.InputPreparationPlugin): ...@@ -61,19 +62,20 @@ class UpdateStationList(plugin.InputPreparationPlugin):
for index, step in enumerate(route): for index, step in enumerate(route):
technology = step.get("technology", None) technology = step.get("technology", None)
technology = technology.split("-")[0] technology = technology.split("-")[0]
assert self.getStationInitials(technology), 'there is no corresponding station initial for that technology' assert len(self.getStationInitials(technology)), 'there is no corresponding station initial for that technology'
step["technology"] = technology step["technology"] = technology
technologyStations = [] technologyStations = []
for station in stations: for station in stations:
if station.startswith(self.getStationInitials(technology))\ for initials in self.getStationInitials(technology):
and data["graph"]["node"][station]["_class"] in self.STATION_CLASS_SET: if station.startswith(initials)\
found = False # check that the id of the station provided by the db BOM exist in the nodes of the graph and data["graph"]["node"][station]["_class"] in self.STATION_CLASS_SET:
for node in nodes.keys(): found = False # check that the id of the station provided by the db BOM exist in the nodes of the graph
if node == station: for node in nodes.keys():
found = True if node == station:
break found = True
assert found == True, "the station ids in the DB must be the same with the stations ids provided by the model" break
technologyStations.append(station) assert found == True, "the station ids in the DB must be the same with the stations ids provided by the model"
technologyStations.append(station)
assert len(technologyStations)>0, "the stations corresponding to the defined technology must be more than 0" assert len(technologyStations)>0, "the stations corresponding to the defined technology must be more than 0"
step["stationIdsList"] = technologyStations step["stationIdsList"] = technologyStations
return data return data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment