Skip to content

Commit

Permalink
Merge pull request #1744 from idaholab/cogljj/prescient_update
Browse files Browse the repository at this point in the history
Support current Prescient version
  • Loading branch information
mandd authored Jan 17, 2022
2 parents f941138 + 99c6083 commit f1a0f0c
Show file tree
Hide file tree
Showing 10 changed files with 3,676 additions and 3,670 deletions.
37 changes: 25 additions & 12 deletions framework/CodeInterfaces/Prescient/PrescientCodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def _readBusData(self, filename):
"""
Reads the electricity bus data into a dictionary
@ In, filename, string, the bus_detail.csv file
@ Out, (retDict,busList,datalist), (dictionary,list,list),
dictionary of each time, list of all the busses found and
the data that each bus has
@ Out, (retDict,busList,datalist,hasMinute), (dictionary,list,list,bool),
dictionary of each time, list of all the busses found,
the data that each bus has, and if the bus has minute by minute data
"""
with open(filename, "r") as inFile:
first = True
Expand All @@ -145,22 +145,31 @@ def _readBusData(self, filename):
line = line.strip()
if first:
first = False
if not line.startswith("Date,Hour,Bus,"): # != "Date,Hour,Bus,Shortfall,Overgeneration,LMP,LMP DA":
assert False, "Unexpected first line of bus detail:" + line
a = 1/0 #because debug might be disabled
if line.startswith("Date,Hour,Minute,Bus,"):
hasMinute = True
elif line.startswith("Date,Hour,Bus,"):
#line sorta looks like: "Date,Hour,Bus,Shortfall,Overgeneration,LMP,LMP DA"
hasMinute = False
else:
raise IOError("Unexpected first line of bus detail in Prescient Code Interface:" + line)
dataList = [s.replace(" ","_") for s in line.split(",")[3:]]
continue
splited = line.split(",")
date, hour, bus = splited[:3]
rest = splited[3:]
key = (date,hour)
if hasMinute:
date, hour, minute, bus = splited[:4]
rest = splited[4:]
key = (date,hour,minute)
else:
date, hour, bus = splited[:3]
rest = splited[3:]
key = (date,hour)
busSet.add(bus)
timeDict = retDict.get(key,{})
timeDict[bus] = rest
retDict[key] = timeDict
busList = list(busSet)
busList.sort()
return retDict, busList, dataList
return retDict, busList, dataList, hasMinute

def finalizeCodeOutput(self, command, codeLogFile, subDirectory):
"""
Expand All @@ -179,7 +188,7 @@ def finalizeCodeOutput(self, command, codeLogFile, subDirectory):
directory = subDirectory
readFile = os.path.join(directory, toRead)
if toRead.lower().startswith("hourly"):
busData, busList, busDataList = self._readBusData(os.path.join(directory, "bus_detail.csv"))
busData, busList, busDataList, hasMinute = self._readBusData(os.path.join(directory, "bus_detail.csv"))
outDict = {}
inFile = open(readFile+".csv","r")
hasNetDemand = False
Expand Down Expand Up @@ -214,7 +223,11 @@ def finalizeCodeOutput(self, command, codeLogFile, subDirectory):
netDemand = outDict["Demand"][-1] - outDict["RenewablesUsed"][-1]
outDict["NetDemand"].append(netDemand)
for bus in busList:
for dataName, data in zip(busDataList,busData[(date,hour)][bus]):
if hasMinute:
busTimeKey = (date, hour, '0')
else:
busTimeKey = (date, hour)
for dataName, data in zip(busDataList,busData[busTimeKey][bus]):
outDict[bus+"_"+dataName].append(float(data) if len(data) > 0 else float("NaN"))
return outDict

Expand Down
Loading

0 comments on commit f1a0f0c

Please sign in to comment.