Skip to content

Commit

Permalink
gabled azimuths, as lists in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Mar 22, 2022
1 parent 0371e4d commit 29c56e5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
27 changes: 23 additions & 4 deletions heman/api/pvcalculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ def get_last_scenario(self, contract_name):
)


def parseMongoAzimuth(azimuth):
"""
This function turns mongo representation of azimuth into a int tuple.
Currently, Mongo objects represents azimuths either as a float like 120.0
or as a string like "120#300" when it is a gabled roof.
The first azimuth is always the one towards south or 90 if W-E orientation.
TODO: change the mongo representation to be a more uniform one.
"""
if type(azimuth) is float:
return (int(azimuth),)
return tuple(int(a) for a in azimuth.split('#'))

def queryAzimuth(queryAzimuth):
"""
This turns a list of strings representing the azimuths into
a hashable tuple of ints.
"""
return tuple(int(a) for a in queryAzimuth)

class ScenarioReport(PVCalculatorResource):

"""Given some parameter values chooses the matching scenario with least payback
Expand All @@ -33,7 +52,7 @@ def get(self, contract):
current_app.logger.debug('PVCalculator Report, contract {}'.format(contract))

tiltDegrees = float(request.args.get('tilt'))
azimuthDegrees = request.args.get('azimuth')
azimuthDegrees = queryAzimuth(request.args.getlist('azimuth'))
powerKwh = request.args.get('power')

scenario_report = self.get_last_scenario(contract_name=contract)
Expand All @@ -55,7 +74,7 @@ def get(self, contract):
scenario
for i,scenario in enumerate(scenarios)
if scenario['settings']['tilt'] == tiltDegrees
and scenario['settings']['azimuth'] == azimuthDegrees
and parseMongoAzimuth(scenario['settings']['azimuth']) == azimuthDegrees
and (scenario['settings']['power'] == powerKwh or not powerKwh)
]
if not selectedScenarios:
Expand Down Expand Up @@ -86,7 +105,7 @@ def get(self, contract):
savingsEuroYear = bestScenario['generation']['savings'],
paybackYears = bestScenario['economics']['payback'],
installationCostEuro = bestScenario['settings']['cost'],
azimuthDegrees= bestScenario['settings']['azimuth'],
azimuthDegrees= parseMongoAzimuth(bestScenario['settings']['azimuth']),
tiltDegrees= bestScenario['settings']['tilt'],
areaM2 = bestScenario['settings']['area'],
nModules = bestScenario['settings']['numModules'],
Expand Down Expand Up @@ -128,7 +147,7 @@ def get(self, contract):
tilts, azimuths, powers = zip(*[
(
scenario['settings']['tilt'],
scenario['settings']['azimuth'],
parseMongoAzimuth(scenario['settings']['azimuth']),
scenario['settings']['power'],
)
for i,scenario in enumerate(scenarios)
Expand Down
8 changes: 4 additions & 4 deletions heman/api/pvcalculator/pvcalculator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test__scenario_report__with_power(api, scenario_data, snapshot):
r = api.get('/api/ScenarioReport/{}'.format(contract),
query_string=dict(
tilt=30.0,
azimuth='180#0', # TODO: split both azimuths
azimuth=[180,0], # TODO: split both azimuths
power='10.640 kWp', # TODO: Remove units from value
),
headers=dict(
Expand All @@ -118,7 +118,7 @@ def test__scenario_report__optimal_payback(api, scenario_data, snapshot):
r = api.get('/api/ScenarioReport/{}'.format(contract),
query_string=dict(
tilt=30.0,
azimuth='180#0',
azimuth=[180,0],
),
headers=dict(
Authorization = 'token {}'.format(token)
Expand All @@ -131,7 +131,7 @@ def test__scenario_report__parameter_value_not_found(api, scenario_data):
r = api.get('/api/ScenarioReport/{}'.format(contract),
query_string=dict(
tilt=31.0, # Value for tilt not found
azimuth='180#0',
azimuth=[180,0],
),
headers=dict(
Authorization = 'token {}'.format(token)
Expand All @@ -153,7 +153,7 @@ def test__scenario_params(api, scenario_data):

assert r.get_json() == {
'tilt': [15.0, 30.0],
'azimuth': [100.0, 140.0, 180.0, '100#280', '140#320', '180#0'],
'azimuth': [[100], [100,280], [140], [140,320], [180], [180,0]],
'power': [
'10.640 kWp',
'2.280 kWp',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
snapshot:
areaM2: 1.87
azimuthDegrees: 180#0
azimuthDegrees:
- 180
- 0
dailyLoadProfileKwh:
- 0.24
- 0.235
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
snapshot:
areaM2: 1.87
azimuthDegrees: 180#0
azimuthDegrees:
- 180
- 0
dailyLoadProfileKwh:
- 0.24
- 0.235
Expand Down

0 comments on commit 29c56e5

Please sign in to comment.