Skip to content

Commit

Permalink
Merge pull request #5 from NRCan/dev
Browse files Browse the repository at this point in the history
v0.1 priority A and B
  • Loading branch information
cefect authored Aug 22, 2024
2 parents bd16994 + 6d869f4 commit 2403e21
Show file tree
Hide file tree
Showing 344 changed files with 174,165 additions and 374 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Installation
Typically, development should employ a virtual environment with pyqgis bindings.
We usually develop to target the most recent QGIS LTR.
Some additional packages for testing are specified in `./requirements.txt`
Some additional packages used for testing and deployment are specified in `./requirements.txt`

### PYTHONPATH
only the source directory should be included (`./CanCurve` not `./CanCurve/cancurve`)
Expand All @@ -22,7 +22,7 @@ the only compiling typically requied is when the qt `resources.qrc` file is chan
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)

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

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CanCurve
CanCurve is an open-source tool which can develop depth-damage (stage-damage) functions for use in flood loss estimation and flood risk assessments.
CanCurve is an open-source tool for developing flood depth-damage (stage-damage) functions for use flood assessments.

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


## Documentation


## Installation
Expand All @@ -25,5 +28,10 @@ CanCurve is an open-source tool which can develop depth-damage (stage-damage) fu
1) populate the **Building Details** and **Data Input** tabs to reflect your archetype and cost-item properties
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.

### DEVELOPMENT TESTING
## Development
see [CONTRIBUTING.md](./CONTRIBUTING.md)

### Testing
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.


2 changes: 1 addition & 1 deletion cancurve/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#===============================================================================
# plugin metadata
#===============================================================================
__version__='0.0.2'
__version__='0.1.0'

#===============================================================================
# plugin entry point
Expand Down
63 changes: 55 additions & 8 deletions cancurve/bldgs/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: cef
'''

import os
import os, warnings
import sqlite3
import pandas as pd

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


def assert_ci_df(df):
def assert_ci_df(df, msg=''):
"""
Asserts that the provided DataFrame conforms to CI data expectations.
Expand Down Expand Up @@ -44,8 +44,15 @@ def assert_ci_df(df):
else:
if dstr != colns_dtypes[coln]: # More specific check
raise AssertionError(f"Incorrect data type for column '{coln}'. Expected: {colns_dtypes[coln]}, Found: {dstr}")

#check storys
msg1 = f'\nCanCurve only supports basement (-1) and main floor (0) cost items\n '+ msg
#f'remove cost items with these designations\n '+\

if not df['story'].max()<=0:
warnings.warn(f'CostItem maximum story value exceeds expectation of \'0\' '+msg1)

if not df['story'].min()>=-1:
warnings.warn(f'CostItem minimum story value exceeds expectation \'-1\' '+msg1)
#===============================================================================
# Project database
#===============================================================================
Expand Down Expand Up @@ -142,22 +149,62 @@ def assert_drf_df(df):
if not 'float' in df[col].dtype.name: # Assuming you want specifically float64
raise TypeError(f'DRF column \'{col}\' ({i}) expected as dtype float. instead got \'{df[col].dtype}\'')

def assert_bldg_meta_d(bldg_meta):
def assert_bldg_meta_d(bldg_meta, msg=''):
"""check the bldg_meta_d meets expectations"""

#check the minumn key requirements

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

#check types
type_d = bldg_meta_rqmt_df.loc[:, ['varName_core', 'type']].dropna().set_index('varName_core').iloc[:, 0].to_dict()
for k,v in type_d.items():
if not v in type(bldg_meta[k]).__name__:
raise TypeError(f'unrecognized type on \'{k}\' ({type(bldg_meta[k])})')
raise TypeError(f'unrecognized type on \'{k}\' ({type(bldg_meta[k])})'+ '\n'+msg)

#check values
if 'scale_factor' in bldg_meta:
assert_scale_factor(bldg_meta['scale_factor'], msg=msg)

def assert_fixed_costs_d(d, msg=''):
"""check the fixed_costs_d meets expectations
decided to allow len(d)>2 and just removing excess data
for backwards compatability
"""
assert isinstance(d, dict)

#ssert len(d)<=2
for k,v in d.items():

#key expectations
assert isinstance(k, int)
assert k>=-1
#assert k<=0

#value exectations
if not isinstance(v, float):
raise TypeError(k)
assert v>=0



def assert_CanFlood_ddf(df, msg=''):
from cancurve.bldgs.core import DFunc
from cancurve.hp.logr import get_log_stream


log = get_log_stream()
with DFunc(tabn=df.iloc[0, 1], logger=log) as wrkr:
try: #build
wrkr.build(df, log)
except Exception as e:
raise AssertionError(f'DDF failed to build as a CanFlood.Dfunc w/ \n {e}')


def assert_scale_factor(v, msg=''):
assert isinstance(v, float)
assert v>0.0
assert v<9e9

77 changes: 39 additions & 38 deletions cancurve/bldgs/bldg_meta_rqmts.csv
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
varName_core,varName_ui,varName_canflood,type,required_core,required_canflood,default_canflood,widgetName,case1,case2,case3
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509
,,location,str,FALSE,FALSE,?,,,,
,,date,str,FALSE,FALSE,?,,,,
,,source,str,FALSE,FALSE,?,,,,
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,
,,scale_var,str,FALSE,FALSE,building footprint,,,,
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344
,,exposure,str,FALSE,TRUE,impact,,,,
,occupancyClassification,,str,FALSE,FALSE,,occupancyClassification_ComboBox,,,Commercial
,subClassification,,str,FALSE,FALSE,,subClassification_ComboBox,,,Construction
,storeys,,str,FALSE,FALSE,,storeys_ComboBox,,,1
,BedroomCount,,int,FALSE,FALSE,,BedroomCount_QSpinBox,,,0
,BathroomCount,,float,FALSE,FALSE,,BathroomCount_DoubleSpinBox,,,1
,heatingType,,str,FALSE,FALSE,,heatingType_ComboBox,,,Forced Air - Gas
,coolingType,,str,FALSE,FALSE,,coolingType_ComboBox,,,Central air
,garageType,,str,FALSE,FALSE,,garageType_ComboBox,,,None
,garageSize,,str,FALSE,FALSE,,garageSize_ComboBox,,,
,foundationType,,str,FALSE,FALSE,,foundationType_ComboBox,,,other
,qualityOfBuildingMaterials,,str,FALSE,FALSE,,qualityOfBuildingMaterials_ComboBox,,,Average
,taxesIncluded,,str,FALSE,FALSE,,taxesIncluded_ComboBox,,,
,priceListSource,,str,FALSE,FALSE,,priceListSource_LineEdit,,,exactimate
,country,,str,FALSE,FALSE,Canada,country_ComboBox,,,Canada
,provinceTerritory,,str,FALSE,FALSE,,provinceTerritory_ComboBox,,,ON
,pricingDate,,str,FALSE,FALSE,,,,,
,basementFinish,,float,FALSE,FALSE,,basementFinish_DoubleSpinBox,,,100
,createdBy,,str,FALSE,FALSE,,createdBy_LineEdit,,,hmcgrath
,locationCityTownRegion,,str,FALSE,FALSE,,,,,
,yearOfBuildingConstruction,,int,FALSE,FALSE,,yearOfBuildingConstruction_SpinBox,,,2500
varName_core,varName_ui,varName_canflood,type,required_core,required_canflood,default_canflood,widgetName,case1,case2,case3,case4_R2,case5_crawl
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509,R_2-L-BD-CU_ABCA,R_1-L-C-ST_ABCA
,,location,str,FALSE,FALSE,?,,,,,,
,,date,str,FALSE,FALSE,?,,,,,,
,,source,str,FALSE,FALSE,?,,,,,,
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,,,
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs,,
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,,,
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,,,
,,scale_var,str,FALSE,FALSE,building footprint,,,,,,
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default,default,
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,2.7,0
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m,m,m
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0,2.7,0
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344,139,232
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2,m2,m2
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344,139,232
,,exposure,str,FALSE,TRUE,impact,,,,,,
,occupancyClassification,,str,FALSE,FALSE,,occupancyClassification_ComboBox,,,Commercial,Residential,Residential
,subClassification,,str,FALSE,FALSE,,subClassification_ComboBox,,,Construction,Single Family,
,storys,,str,FALSE,FALSE,,storys_ComboBox,,,1,2,1
,BedroomCount,,int,FALSE,FALSE,,BedroomCount_QSpinBox,,,0,7,
,BathroomCount,,float,FALSE,FALSE,,BathroomCount_DoubleSpinBox,,,1,4,
,heatingType,,str,FALSE,FALSE,,heatingType_ComboBox,,,Forced Air - Gas,Forced Air - Unknown,
,coolingType,,str,FALSE,FALSE,,coolingType_ComboBox,,,Central air,Central air,
,garageType,,str,FALSE,FALSE,,garageType_ComboBox,,,None,None,
,garageSize,,str,FALSE,FALSE,,garageSize_ComboBox,,,,,
,foundationType,,str,FALSE,FALSE,,foundationType_ComboBox,,,Other,Basement,Crawlspace
,qualityOfBuildingMaterials,,str,FALSE,FALSE,,qualityOfBuildingMaterials_ComboBox,,,Average,Custom,Average
,taxesIncluded,,str,FALSE,FALSE,,taxesIncluded_ComboBox,,,,,
,priceListSource,,str,FALSE,FALSE,,priceListSource_LineEdit,,,Xactimate,,
,country,,str,FALSE,FALSE,Canada,country_ComboBox,,,Canada,Canada,Canada
,provinceTerritory,,str,FALSE,FALSE,,provinceTerritory_ComboBox,,,ON,AB,AB
,pricingDate,,str,FALSE,FALSE,,,,,,,
,basementFinish,,float,FALSE,FALSE,,basementFinish_DoubleSpinBox,,,100,100,
,createdBy,,str,FALSE,FALSE,,createdBy_LineEdit,Arcadis,Arcadis,hmcgrath,Arcadis,Arcadis
,locationCityTownRegion,,str,FALSE,FALSE,,,,,,,
,yearOfBuildingConstruction,,int,FALSE,FALSE,,yearOfBuildingConstruction_SpinBox,,,2500,2000,2000
scale_factor,scaleFactor,,float,TRUE,FALSE,,scaleFactor_DoubleSpinBox,1.1,1,1,1,1
Loading

0 comments on commit 2403e21

Please sign in to comment.