Skip to content

Commit

Permalink
Refactoring for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ahobeost committed Jul 3, 2024
1 parent 5283dc0 commit cec2b14
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
53 changes: 36 additions & 17 deletions trnsysGUI/pythonInterface/regimeExporter/exportRegimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,52 @@ def getPumpsAndValvesWithValuesFromJson(projectJson):
blockItemsAndConnections = jsonValues["Blocks"].values()
blockItems = [bc for bc in blockItemsAndConnections if isinstance(bc, dict) and ".__BlockDict__" in bc]

pumps = [b for b in blockItems if b["BlockName"] == "Pump"]
for pump in pumps:
curBlockItem = _se.PumpModel.from_dict(pump)
data = _getPumps(blockItems, data)
data = _getValves(blockItems, data)
data = _getTaps(blockItems, data)
data = _getSourceSinks(blockItems, data)

componentsAndValues = _pd.DataFrame(data, index=["dummy_regime"])
componentsAndValues.index.name = "regimeName"

return componentsAndValues


def _getSourceSinks(blockItems, data):
sourceSinks = [b for b in blockItems if b["BlockName"] in ("Sink", "Source", "SourceSink", "Geotherm", "Water")]
for sourceSink in sourceSinks:
# This isn't in the json yet, so I am applying a default value directly at first.
blockDisplayName = sourceSink["BlockDisplayName"]
data[blockDisplayName] = 500.0

return data


def _getTaps(blockItems, data):
taps = [b for b in blockItems if b["BlockName"] in ("WTap_main", "WTap")]
for tap in taps:
curBlockItem = _se.TerminalWithPrescribedMassFlowModel.from_dict(tap)
data[curBlockItem.BlockDisplayName] = curBlockItem.blockItemWithPrescribedMassFlow.massFlowRateInKgPerH

return data


def _getValves(blockItems, data):
valves = [b for b in blockItems if b["BlockName"] == "TVentil"]
for valve in valves:
desiredValueName = "PositionForMassFlowSolver"
data = getData(valve, data, desiredValueName)

taps = [b for b in blockItems if b["BlockName"] in ("WTap_main", "WTap")]
for tap in taps:
curBlockItem = _se.TerminalWithPrescribedMassFlowModel.from_dict(tap)
data[curBlockItem.BlockDisplayName] = curBlockItem.blockItemWithPrescribedMassFlow.massFlowRateInKgPerH
return data

sourceSinks = [
b for b in blockItems if b["BlockName"] in ("Sink", "Source", "SourceSink", "Geotherm", "Water")
]
for sourceSink in sourceSinks:
# This isn't in the json yet, so I am applying a default value directly at first.
blockDisplayName = sourceSink["BlockDisplayName"]
data[blockDisplayName] = 500.0

componentsAndValues = _pd.DataFrame(data, index=["dummy_regime"])
componentsAndValues.index.name = "regimeName"
def _getPumps(blockItems, data):
pumps = [b for b in blockItems if b["BlockName"] == "Pump"]
for pump in pumps:
curBlockItem = _se.PumpModel.from_dict(pump)
data[curBlockItem.BlockDisplayName] = curBlockItem.blockItemWithPrescribedMassFlow.massFlowRateInKgPerH

return componentsAndValues
return data


def getData(curDict, data, desiredValueName):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def getRelevantBlockItems(self, relevantNames: _tp.Sequence[str]) -> _tp.Sequenc

return pumpsAndValvesAndTaps

def _simulateAndVisualizeMassFlows(self, relevantBlockItems: _tp.Sequence[_BlockItem], regimeValues: _pd.DataFrame) -> None:
def _simulateAndVisualizeMassFlows(
self, relevantBlockItems: _tp.Sequence[_BlockItem], regimeValues: _pd.DataFrame
) -> None:

for regimeName in regimeValues.index:
regimeRow = regimeValues.loc[regimeName]
Expand Down

0 comments on commit cec2b14

Please sign in to comment.