Skip to content

Commit 2403e21

Browse files
authored
Merge pull request #5 from NRCan/dev
v0.1 priority A and B
2 parents bd16994 + 6d869f4 commit 2403e21

File tree

344 files changed

+174165
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+174165
-374
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Installation
44
Typically, development should employ a virtual environment with pyqgis bindings.
55
We usually develop to target the most recent QGIS LTR.
6-
Some additional packages for testing are specified in `./requirements.txt`
6+
Some additional packages used for testing and deployment are specified in `./requirements.txt`
77

88
### PYTHONPATH
99
only the source directory should be included (`./CanCurve` not `./CanCurve/cancurve`)
@@ -22,7 +22,7 @@ the only compiling typically requied is when the qt `resources.qrc` file is chan
2222
Typically a `dev` QGIS profile is maintained with a custom `QGIS_PLUGINPATH` pointed to the project source directory. This facilitates plugin updating with the `plugin reload` (ie no real deployment)
2323

2424
### Pre-Release testing
25-
Pre-release testing (and full deployment) employ a zip of the plugin directory (see `./dev_tools/plug_zip.bat`):
25+
Pre-release testing (and full deployment) employs a zip of the plugin directory (see `./dev_tools/plug_zip.bat`):
2626
1) remove all `__pychace__`
2727
2) zip/archive the plugin directory
2828

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CanCurve
2-
CanCurve is an open-source tool which can develop depth-damage (stage-damage) functions for use in flood loss estimation and flood risk assessments.
2+
CanCurve is an open-source tool for developing flood depth-damage (stage-damage) functions for use flood assessments.
33

44
<p align="center">
55
<img src="./cancurve/img/icon.png" alt="CanCurve Icon">
@@ -9,6 +9,9 @@ CanCurve is an open-source tool which can develop depth-damage (stage-damage) fu
99
## Updates
1010
- 2024-05-09: small fixes and updates based on initial comments
1111
- 2024-05-01: initial working release (un tested) [v0.0.1](https://github.com/NRCan/CanCurve/releases/tag/v0.0.1)
12+
13+
14+
## Documentation
1215

1316

1417
## Installation
@@ -25,5 +28,10 @@ CanCurve is an open-source tool which can develop depth-damage (stage-damage) fu
2528
1) populate the **Building Details** and **Data Input** tabs to reflect your archetype and cost-item properties
2629
2) on the **Create Curve** tab, either click `Run All` to execute the full DDF compilation workflow, or select `Individual Steps` and click through the steps individually. The resulting DDF will be exported in CanFlood format.
2730

28-
### DEVELOPMENT TESTING
31+
## Development
32+
see [CONTRIBUTING.md](./CONTRIBUTING.md)
33+
34+
### Testing
2935
The **Welcome** tab contains a temporary `Load Testing Values` button where you can select from the pre-populated test cases. This should make playing with the tool easier.
36+
37+

cancurve/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#===============================================================================
22
# plugin metadata
33
#===============================================================================
4-
__version__='0.0.2'
4+
__version__='0.1.0'
55

66
#===============================================================================
77
# plugin entry point

cancurve/bldgs/assertions.py

+55-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@author: cef
55
'''
66

7-
import os
7+
import os, warnings
88
import sqlite3
99
import pandas as pd
1010

@@ -15,7 +15,7 @@
1515
expected_tables_base = ['project_meta','project_settings','c00_bldg_meta', 'c00_cost_items','c00_drf']
1616

1717

18-
def assert_ci_df(df):
18+
def assert_ci_df(df, msg=''):
1919
"""
2020
Asserts that the provided DataFrame conforms to CI data expectations.
2121
@@ -44,8 +44,15 @@ def assert_ci_df(df):
4444
else:
4545
if dstr != colns_dtypes[coln]: # More specific check
4646
raise AssertionError(f"Incorrect data type for column '{coln}'. Expected: {colns_dtypes[coln]}, Found: {dstr}")
47-
47+
#check storys
48+
msg1 = f'\nCanCurve only supports basement (-1) and main floor (0) cost items\n '+ msg
49+
#f'remove cost items with these designations\n '+\
4850

51+
if not df['story'].max()<=0:
52+
warnings.warn(f'CostItem maximum story value exceeds expectation of \'0\' '+msg1)
53+
54+
if not df['story'].min()>=-1:
55+
warnings.warn(f'CostItem minimum story value exceeds expectation \'-1\' '+msg1)
4956
#===============================================================================
5057
# Project database
5158
#===============================================================================
@@ -142,22 +149,62 @@ def assert_drf_df(df):
142149
if not 'float' in df[col].dtype.name: # Assuming you want specifically float64
143150
raise TypeError(f'DRF column \'{col}\' ({i}) expected as dtype float. instead got \'{df[col].dtype}\'')
144151

145-
def assert_bldg_meta_d(bldg_meta):
152+
def assert_bldg_meta_d(bldg_meta, msg=''):
146153
"""check the bldg_meta_d meets expectations"""
147154

148-
#check the minumn key requirements
149-
155+
#check the minumn key requirements
150156
miss_s = set(bldg_meta_rqmt_df['varName_core'].dropna().values.tolist()).difference(bldg_meta.keys())
151157
if not miss_s==set():
152-
raise KeyError(f'bldg_meta missing keys \'{miss_s}\'')
158+
raise KeyError(f'bldg_meta missing keys \'{miss_s}\'' + '\n'+msg)
153159

154160
#check types
155161
type_d = bldg_meta_rqmt_df.loc[:, ['varName_core', 'type']].dropna().set_index('varName_core').iloc[:, 0].to_dict()
156162
for k,v in type_d.items():
157163
if not v in type(bldg_meta[k]).__name__:
158-
raise TypeError(f'unrecognized type on \'{k}\' ({type(bldg_meta[k])})')
164+
raise TypeError(f'unrecognized type on \'{k}\' ({type(bldg_meta[k])})'+ '\n'+msg)
165+
166+
#check values
167+
if 'scale_factor' in bldg_meta:
168+
assert_scale_factor(bldg_meta['scale_factor'], msg=msg)
169+
170+
def assert_fixed_costs_d(d, msg=''):
171+
"""check the fixed_costs_d meets expectations
172+
173+
decided to allow len(d)>2 and just removing excess data
174+
for backwards compatability
175+
"""
176+
assert isinstance(d, dict)
159177

178+
#ssert len(d)<=2
179+
for k,v in d.items():
180+
181+
#key expectations
182+
assert isinstance(k, int)
183+
assert k>=-1
184+
#assert k<=0
185+
186+
#value exectations
187+
if not isinstance(v, float):
188+
raise TypeError(k)
189+
assert v>=0
190+
160191

192+
193+
def assert_CanFlood_ddf(df, msg=''):
194+
from cancurve.bldgs.core import DFunc
195+
from cancurve.hp.logr import get_log_stream
196+
197+
198+
log = get_log_stream()
199+
with DFunc(tabn=df.iloc[0, 1], logger=log) as wrkr:
200+
try: #build
201+
wrkr.build(df, log)
202+
except Exception as e:
203+
raise AssertionError(f'DDF failed to build as a CanFlood.Dfunc w/ \n {e}')
161204

162205

206+
def assert_scale_factor(v, msg=''):
207+
assert isinstance(v, float)
208+
assert v>0.0
209+
assert v<9e9
163210

cancurve/bldgs/bldg_meta_rqmts.csv

+39-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
varName_core,varName_ui,varName_canflood,type,required_core,required_canflood,default_canflood,widgetName,case1,case2,case3
2-
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509
3-
,,location,str,FALSE,FALSE,?,,,,
4-
,,date,str,FALSE,FALSE,?,,,,
5-
,,source,str,FALSE,FALSE,?,,,,
6-
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,
7-
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs
8-
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,
9-
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,
10-
,,scale_var,str,FALSE,FALSE,building footprint,,,,
11-
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default
12-
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0
13-
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m
14-
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0
15-
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344
16-
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2
17-
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344
18-
,,exposure,str,FALSE,TRUE,impact,,,,
19-
,occupancyClassification,,str,FALSE,FALSE,,occupancyClassification_ComboBox,,,Commercial
20-
,subClassification,,str,FALSE,FALSE,,subClassification_ComboBox,,,Construction
21-
,storeys,,str,FALSE,FALSE,,storeys_ComboBox,,,1
22-
,BedroomCount,,int,FALSE,FALSE,,BedroomCount_QSpinBox,,,0
23-
,BathroomCount,,float,FALSE,FALSE,,BathroomCount_DoubleSpinBox,,,1
24-
,heatingType,,str,FALSE,FALSE,,heatingType_ComboBox,,,Forced Air - Gas
25-
,coolingType,,str,FALSE,FALSE,,coolingType_ComboBox,,,Central air
26-
,garageType,,str,FALSE,FALSE,,garageType_ComboBox,,,None
27-
,garageSize,,str,FALSE,FALSE,,garageSize_ComboBox,,,
28-
,foundationType,,str,FALSE,FALSE,,foundationType_ComboBox,,,other
29-
,qualityOfBuildingMaterials,,str,FALSE,FALSE,,qualityOfBuildingMaterials_ComboBox,,,Average
30-
,taxesIncluded,,str,FALSE,FALSE,,taxesIncluded_ComboBox,,,
31-
,priceListSource,,str,FALSE,FALSE,,priceListSource_LineEdit,,,exactimate
32-
,country,,str,FALSE,FALSE,Canada,country_ComboBox,,,Canada
33-
,provinceTerritory,,str,FALSE,FALSE,,provinceTerritory_ComboBox,,,ON
34-
,pricingDate,,str,FALSE,FALSE,,,,,
35-
,basementFinish,,float,FALSE,FALSE,,basementFinish_DoubleSpinBox,,,100
36-
,createdBy,,str,FALSE,FALSE,,createdBy_LineEdit,,,hmcgrath
37-
,locationCityTownRegion,,str,FALSE,FALSE,,,,,
38-
,yearOfBuildingConstruction,,int,FALSE,FALSE,,yearOfBuildingConstruction_SpinBox,,,2500
1+
varName_core,varName_ui,varName_canflood,type,required_core,required_canflood,default_canflood,widgetName,case1,case2,case3,case4_R2,case5_crawl
2+
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509,R_2-L-BD-CU_ABCA,R_1-L-C-ST_ABCA
3+
,,location,str,FALSE,FALSE,?,,,,,,
4+
,,date,str,FALSE,FALSE,?,,,,,,
5+
,,source,str,FALSE,FALSE,?,,,,,,
6+
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,,,
7+
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs,,
8+
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,,,
9+
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,,,
10+
,,scale_var,str,FALSE,FALSE,building footprint,,,,,,
11+
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default,default,
12+
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,2.7,0
13+
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m,m,m
14+
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0,2.7,0
15+
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344,139,232
16+
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2,m2,m2
17+
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344,139,232
18+
,,exposure,str,FALSE,TRUE,impact,,,,,,
19+
,occupancyClassification,,str,FALSE,FALSE,,occupancyClassification_ComboBox,,,Commercial,Residential,Residential
20+
,subClassification,,str,FALSE,FALSE,,subClassification_ComboBox,,,Construction,Single Family,
21+
,storys,,str,FALSE,FALSE,,storys_ComboBox,,,1,2,1
22+
,BedroomCount,,int,FALSE,FALSE,,BedroomCount_QSpinBox,,,0,7,
23+
,BathroomCount,,float,FALSE,FALSE,,BathroomCount_DoubleSpinBox,,,1,4,
24+
,heatingType,,str,FALSE,FALSE,,heatingType_ComboBox,,,Forced Air - Gas,Forced Air - Unknown,
25+
,coolingType,,str,FALSE,FALSE,,coolingType_ComboBox,,,Central air,Central air,
26+
,garageType,,str,FALSE,FALSE,,garageType_ComboBox,,,None,None,
27+
,garageSize,,str,FALSE,FALSE,,garageSize_ComboBox,,,,,
28+
,foundationType,,str,FALSE,FALSE,,foundationType_ComboBox,,,Other,Basement,Crawlspace
29+
,qualityOfBuildingMaterials,,str,FALSE,FALSE,,qualityOfBuildingMaterials_ComboBox,,,Average,Custom,Average
30+
,taxesIncluded,,str,FALSE,FALSE,,taxesIncluded_ComboBox,,,,,
31+
,priceListSource,,str,FALSE,FALSE,,priceListSource_LineEdit,,,Xactimate,,
32+
,country,,str,FALSE,FALSE,Canada,country_ComboBox,,,Canada,Canada,Canada
33+
,provinceTerritory,,str,FALSE,FALSE,,provinceTerritory_ComboBox,,,ON,AB,AB
34+
,pricingDate,,str,FALSE,FALSE,,,,,,,
35+
,basementFinish,,float,FALSE,FALSE,,basementFinish_DoubleSpinBox,,,100,100,
36+
,createdBy,,str,FALSE,FALSE,,createdBy_LineEdit,Arcadis,Arcadis,hmcgrath,Arcadis,Arcadis
37+
,locationCityTownRegion,,str,FALSE,FALSE,,,,,,,
38+
,yearOfBuildingConstruction,,int,FALSE,FALSE,,yearOfBuildingConstruction_SpinBox,,,2500,2000,2000
39+
scale_factor,scaleFactor,,float,TRUE,FALSE,,scaleFactor_DoubleSpinBox,1.1,1,1,1,1

0 commit comments

Comments
 (0)