Skip to content

Commit

Permalink
feat(xl_app): Update Excel interop
Browse files Browse the repository at this point in the history
- Update Excel .wb prop and excel startup to cache
- Udate xl protocols (typing)
- Add new 'read' excel / phpp methods (verification, climate)
- Update phpp shapefiles
- update tests
  • Loading branch information
ed-p-may committed Apr 15, 2023
1 parent 46b678c commit d18dc24
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 33 deletions.
12 changes: 12 additions & 0 deletions PHX/PHPP/phpp_localization/EN_10_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@
"unit": "C"
}
}
},
"named_ranges": {
"country": "Klima_Region",
"region": "Klima_Region2",
"data_set": "Klima_Standort"
},
"defined_ranges": {
"climate_zone": "D13",
"weather_station_altitude": "D17",
"site_altitude": "D18",
"latitude": "F25",
"longitude": "H25"
}
},
"UVALUES": {
Expand Down
12 changes: 12 additions & 0 deletions PHX/PHPP/phpp_localization/EN_10_4A.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@
"unit": "C"
}
}
},
"named_ranges": {
"country": "Klima_Region",
"region": "Klima_Region2",
"data_set": "Klima_Standort"
},
"defined_ranges": {
"climate_zone": "D13",
"weather_station_altitude": "D17",
"site_altitude": "D18",
"latitude": "F25",
"longitude": "H25"
}
},
"UVALUES": {
Expand Down
12 changes: 12 additions & 0 deletions PHX/PHPP/phpp_localization/EN_9_6A.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@
"unit": "C"
}
}
},
"named_ranges": {
"country": "Klima_Region",
"region": "Klima_Region2",
"data_set": "Klima_Standort"
},
"defined_ranges": {
"climate_zone": "D13",
"weather_station_altitude": "D17",
"site_altitude": "D18",
"latitude": "F23",
"longitude": "H23"
}
},
"UVALUES": {
Expand Down
12 changes: 12 additions & 0 deletions PHX/PHPP/phpp_localization/EN_9_7IP.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@
"unit": "F"
}
}
},
"named_ranges": {
"country": "Klima_Region",
"region": "Klima_Region2",
"data_set": "Klima_Standort"
},
"defined_ranges": {
"climate_zone": "D13",
"weather_station_altitude": "D17",
"site_altitude": "D18",
"latitude": "F23",
"longitude": "H23"
}
},
"UVALUES": {
Expand Down
16 changes: 16 additions & 0 deletions PHX/PHPP/phpp_localization/shape_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ class Variants(BaseModel):
# -----------------------------------------------------------------------------


class ClimateNamedRanges(BaseModel):
country: str
region: str
data_set: str


class ClimateDefinedRanges(BaseModel):
climate_zone: str
weather_station_altitude: str
site_altitude: str
latitude: str
longitude: str


class ClimateActiveDatasetCol(BaseModel):
country: str
region: str
Expand Down Expand Up @@ -164,6 +178,8 @@ class Climate(BaseModel):
name: str
active_dataset: ClimateActiveDataset
ud_block: ClimateUDBlock
named_ranges: Optional[ClimateNamedRanges]
defined_ranges: Optional[ClimateDefinedRanges]


# -----------------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions PHX/PHPP/sheet_io/io_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,48 @@ def write_active_climate(
start_row = 9
for item in _active_climate.create_xl_items(self.shape.name, start_row):
self.xl.write_xl_item(item)

def read_active_country(self) -> str:
return str(
self.xl.get_single_data_item(self.shape.name, self.shape.named_ranges.country)
)

def read_active_region(self) -> str:
return str(
self.xl.get_single_data_item(self.shape.name, self.shape.named_ranges.region)
)

def read_active_data_set(self) -> str:
return str(
self.xl.get_single_data_item(
self.shape.name, self.shape.named_ranges.data_set
)
)

def read_station_elevation(self) -> str:
return str(
self.xl.get_single_data_item(
self.shape.name, self.shape.defined_ranges.weather_station_altitude
)
)

def read_site_elevation(self) -> str:
return str(
self.xl.get_single_data_item(
self.shape.name, self.shape.defined_ranges.site_altitude
)
)

def read_latitude(self) -> float:
return float(
self.xl.get_single_data_item(
self.shape.name, self.shape.defined_ranges.latitude
)
)

def read_longitude(self) -> float:
return float(
self.xl.get_single_data_item(
self.shape.name, self.shape.defined_ranges.longitude
)
)
70 changes: 70 additions & 0 deletions PHX/PHPP/sheet_io/io_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""Controller Class for the PHPP Climate worksheet."""

from __future__ import annotations
from dataclasses import dataclass
from typing import List

from PHX.xl import xl_app
from PHX.PHPP.phpp_localization import shape_model
Expand Down Expand Up @@ -47,6 +49,44 @@ def find_input_row(self, _row_start: int = 1, _row_end: int = 200) -> int:
)


@dataclass
class TeamMemberData:
"""A Dataclass to store team-member information when read in from the PHPP."""

name: str
street_name: str
post_code: str
city: str
state: str
country: str

@classmethod
def from_raw_excel_data(cls, _xl_data) -> TeamMemberData:
"""Create a new TeamMemberData object from raw excel data read in from PHPP
Arguments:
----------
* _xl_data: List[List[str]]: A list of lists containing the data read
in from PHPP.
Returns:
--------
* (TeamMemberData): A new TeamMemberData object with the values from the
input data set.
"""
try:
return cls(
name=_xl_data[0][0],
street_name=_xl_data[1][0],
post_code=_xl_data[2][0],
city=_xl_data[2][1],
state=_xl_data[3][0],
country=_xl_data[3][2],
)
except:
msg = f"Error reading in Team Member Data from the PHPP? Got:\n{_xl_data}"
raise Exception(msg)


class Verification:
def __init__(self, _xl: xl_app.XLConnection, _shape: shape_model.Verification):
self.xl = _xl
Expand All @@ -73,3 +113,33 @@ def write_item(self, _phpp_model_obj: verification_data.VerificationInput) -> No
input_row = input_object.find_input_row()
xl_item = _phpp_model_obj.create_xl_item(self.shape.name, input_row)
self.xl.write_xl_item(xl_item)

def read_architect(self) -> TeamMemberData:
"""Return a TeamMemberData object with the architect info from PHPP."""
data = self.xl.get_data(self.shape.name, "F18:H21")
return TeamMemberData.from_raw_excel_data(data)

def read_energy_consultant(self) -> TeamMemberData:
"""Return a TeamMemberData object with the consultant info from PHPP."""
data = self.xl.get_data(self.shape.name, "F23:H26")
return TeamMemberData.from_raw_excel_data(data)

def read_building(self) -> TeamMemberData:
"""Return a TeamMemberData object with the Building address from PHPP."""
data = self.xl.get_data(self.shape.name, "K5:M8")
return TeamMemberData.from_raw_excel_data(data)

def read_site_owner(self) -> TeamMemberData:
"""Return a TeamMemberData object with the owner info from PHPP."""
data = self.xl.get_data(self.shape.name, "K13:M16")
return TeamMemberData.from_raw_excel_data(data)

def read_mech_engineer(self) -> TeamMemberData:
data = self.xl.get_data(self.shape.name, "K18:M21")
"""Return a TeamMemberData object with the ME info from PHPP."""
return TeamMemberData.from_raw_excel_data(data)

def read_ph_certification(self) -> TeamMemberData:
"""Return a TeamMemberData object with the Certifier info from PHPP."""
data = self.xl.get_data(self.shape.name, "K23:M26")
return TeamMemberData.from_raw_excel_data(data)
Loading

0 comments on commit d18dc24

Please sign in to comment.