Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nllong committed Jun 2, 2024
1 parent b5789ee commit c494bb8
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 1,058 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ jobs:
run: |
python -m pip install --upgrade pip
poetry install
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
Expand Down
67 changes: 29 additions & 38 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
exclude: |
(?x)(
^docs/conf.py|
^docs/license.rst
)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
args: ["--maxkb=50000"]
- id: check-ast
- id: check-added-large-files
args: ['--maxkb=2000']
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-toml
- id: check-yaml
- id: check-json
- id: name-tests-test
args: ["--pytest-test-first"]
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ["--fix=auto"]
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.2
hooks:
- id: autopep8
args:
[
"--in-place",
"--aggressive",
"--aggressive",
"--recursive",
"--max-line-length=100",
"--ignore=E501,E402,W503,W504,E731",
]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--ignore=E501,E402,W503,W504,E731,F401"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.9-for-vscode
- id: pretty-format-json
args: ['--autofix', '--no-sort-keys']
exclude: examples/.*.ipynb
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: prettier
types_or: [css, yaml, markdown, html, scss, javascript]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
- id: nbstripout
# https://docs.astral.sh/ruff/integrations/#pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: isort
args: ["-m=VERTICAL_HANGING_INDENT"] # vertical hanging
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --output-format=full]
types_or: [python, pyi, jupyter]
# Run the formatter
- id: ruff-format
types_or: [python, pyi, jupyter]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ in with the correct credentials. The format of the SEED configuration should con

### Running Examples

There are two options for running the examples, either open the `ipynb` files or execute the scripts in the
There are two options for running the examples, either open the `ipynb` files or execute the scripts in the
examples directory. The `ipynb` files provide more flexibility to understand how the py-seed library works.

### TODO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
X,Y,PID,SSL,PMPROPERTYID,UBID,PROPERTYNAME,PMPARENTPROPERTYID,PARENTPROPERTYNAME,ADDRESSOFRECORD,OWNEROFRECORD,WARD,REPORTEDADDRESS,CITY,STATE,POSTALCODE,YEARBUILT,PRIMARYPROPERTYTYPE_EPACALC,TAXRECORDFLOORAREA,REPORTEDBUILDINGGROSSFLOORAREA,BEPS,BEPS_METRIC_TYPE,PROPERTY_BEPS_METRIC_YEAR,BEPS_PROPERTY_GROUP,PROPERTY_BEPS_METRIC,DISTANCE_FROM_BEPS_ESTIMATED,PERFORMANCE_REQUIREMENT_EST,MEETS_BEPS,LASTUPDATE,LATITUDE,LONGITUDE,XCOORD,YCOORD,MAR_ID,GIS_ID,GLOBALID,OBJECTID
X,Y,PID,SSL,PMPROPERTYID,UBID,PROPERTYNAME,PMPARENTPROPERTYID,PARENTPROPERTYNAME,ADDRESSOFRECORD,OWNEROFRECORD,WARD,REPORTEDADDRESS,CITY,STATE,POSTALCODE,YEARBUILT,PRIMARYPROPERTYTYPE_EPACALC,TAXRECORDFLOORAREA,REPORTEDBUILDINGGROSSFLOORAREA,BEPS,BEPS_METRIC_TYPE,PROPERTY_BEPS_METRIC_YEAR,BEPS_PROPERTY_GROUP,PROPERTY_BEPS_METRIC,DISTANCE_FROM_BEPS_ESTIMATED,PERFORMANCE_REQUIREMENT_EST,MEETS_BEPS,LASTUPDATE,LATITUDE,LONGITUDE,XCOORD,YCOORD,MAR_ID,GIS_ID,GLOBALID,OBJECTID
-76.9866964889765,38.9015954435042,PM12004199,4068 0828,12004199,,Engine Company 10,,,1342 FLORIDA AVENUE NE,DISTRICT OF COLUMBIA,5,1342 FLORIDA AVENUE NE,WASHINGTON,DC,20002,1925,Fire Station,13195,13195.0,185,WEATHERNORMALZEDSOUREUI_KBTUFT,2019,Fire station/police station,137.1,,,Meets BEPS,2023/09/16 04:00:00+00,38.90158765,-76.98669421,401154.16995547,137081.62750151,294519,,{0639A2BF-CEF0-2945-E063-782F520A104C},253952
-77.0330648823567,38.9322546166689,PM12004200,2678 0844,12004200,,Engine Company 11,,,3420 14TH STREET NW,DISTRICT OF COLUMBIA HOUSING AUTHORITY,1,3420 14TH STREET NW,WASHINGTON,DC,20010,1984,Fire Station,17479,14219.0,185,WEATHERNORMALZEDSOUREUI_KBTUFT,2019,Fire station/police station,238.1,-22.30%,-20.00%,Does Not Meet BEPS,2023/08/16 04:00:00+00,38.93224682,-77.03306259,397133.31970086,140485.48664446,234580,,{0639A2BF-CEF1-2945-E063-782F520A104C},253953
-76.9991457312753,38.9199158516898,PM12004201,PAR 01310216,12004201,,Engine Company 12,,,2225 5TH ST NE,"KRUPSAW, DAVID L",5,2225 5TH STREET NE,WASHINGTON,DC,20002,1986,Fire Station,14674,15913.0,185,WEATHERNORMALZEDSOUREUI_KBTUFT,2019,Fire station/police station,208.6,-11.31%,-20.00%,Does Not Meet BEPS,2023/09/16 04:00:00+00,38.91990806,-76.99914345,400074.27972152,139115.2600615,294541,,{0639A2BF-CEF2-2945-E063-782F520A104C},258114
Expand Down
53 changes: 53 additions & 0 deletions examples/lib/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from itertools import islice

# Helper functions
def clean_up_name(name):
return name.replace('/', '_').replace(' ', '_').lower()

def chunks(data, size):
it = iter(data)
for i in range(0, len(data), size):
yield {k:data[k] for k in islice(it, size)}

def map_months_to_date(year, values=None):
month_map = {
'JANUARY': { 'start_time': f'{year}-01-01', 'end_time': f'{year}-01-31' },
'FEBRUARY': { 'start_time': f'{year}-02-01', 'end_time': f'{year}-02-{29 if (year % 4) == 0 else 28}' },
'MARCH': { 'start_time': f'{year}-03-01', 'end_time': f'{year}-03-31' },
'APRIL': { 'start_time': f'{year}-04-01', 'end_time': f'{year}-04-30' },
'MAY': { 'start_time': f'{year}-05-01', 'end_time': f'{year}-05-31' },
'JUNE': { 'start_time': f'{year}-06-01', 'end_time': f'{year}-06-30' },
'JULY': { 'start_time': f'{year}-07-01', 'end_time': f'{year}-07-31' },
'AUGUST': { 'start_time': f'{year}-08-01', 'end_time': f'{year}-08-31' },
'SEPTEMBER': { 'start_time': f'{year}-09-01', 'end_time': f'{year}-09-30' },
'OCTOBER': { 'start_time': f'{year}-10-01', 'end_time': f'{year}-10-31' },
'NOVEMBER': { 'start_time': f'{year}-11-01', 'end_time': f'{year}-11-30' },
'DECEMBER': { 'start_time': f'{year}-12-01', 'end_time': f'{year}-12-31'}
}

results = []


if values:
# Check if all the values are zero, if so then do not add them to the payload
if all(value == 0 for value in values.values()):
return []

# add in the values to the dictionary if they match the key
# Values can be in the form of the following:
# "ELECTRICITYUSE_KBTU_JANUARY": 3017508.8,
# "ELECTRICITYUSE_KBTU_FEBRUARY": 2722907.3,
# "ELECTRICITYUSE_KBTU_MARCH": 2728590.7,

for key, value in values.items():
for month in month_map:
if month in key:
month_map[month]['reading'] = value
month_map[month]['source_unit'] = 'kBtu (Thousand BTU)'
month_map[month]['conversion_factor'] = 1
results.append(month_map[month])
else:
for key, value in month_map.items():
results.append(value)

return results
16 changes: 8 additions & 8 deletions examples/seed_better.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

from pyseed.seed_client import SeedClient

seed_config = Path('seed-config-dev.json')
data_dir = Path(__file__).parent.absolute() / 'data' / 'better'
seed_config = Path("seed-config-dev.json")
data_dir = Path(__file__).parent.absolute() / "data" / "better"

client = SeedClient(None, connection_config_filepath=seed_config)
client.get_org_by_name('better', set_org_id=True)
client.get_org_by_name("better", set_org_id=True)

# get or create the cycle
cycle = client.get_or_create_cycle('BETTER Cycle', date(2020, 1, 1), date(2020, 12, 31), set_cycle_id=True)
cycle = client.get_or_create_cycle("BETTER Cycle", date(2020, 1, 1), date(2020, 12, 31), set_cycle_id=True)

# upload the data to seed
client.upload_and_match_datafile(
'better-data',
str(data_dir / 'better-test-data.xlsx'),
'better mappings',
str(data_dir / 'better-mappings.csv'),
"better-data",
str(data_dir / "better-test-data.xlsx"),
"better mappings",
str(data_dir / "better-mappings.csv"),
import_meters_if_exist=True,
)
51 changes: 26 additions & 25 deletions examples/seed_bps.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# # ./manage.py create_test_user_json --username [email protected] --file ../py-seed/seed-config.json --pyseed

import sys
from datetime import date
from pathlib import Path

from pyseed.seed_client import SeedClient

# Location to SEED BPS Data -- this will be a checkout of the SEED repo and point to the {seed_repo}/seed/data/bps directory.

seed_config = Path('seed-config-local.json')
org_name = 'Program Tracking 1'
seed_config = Path("seed-config-local.json")
org_name = "Program Tracking 1"
# path to seed repo checkout at the same level as pyseed-examples
data_dir = Path(__file__).parent.parent.parent.absolute() / 'seed' / 'seed' / 'tests' / 'data' / 'bps'
data_dir = Path(__file__).parent.parent.parent.absolute() / "seed" / "seed" / "tests" / "data" / "bps"
# path to where the mapping files exist
mappings_dir = Path(__file__).parent.absolute() / 'data' / 'bps'
mappings_dir = Path(__file__).parent.absolute() / "data" / "bps"

client = SeedClient(
None,
Expand All @@ -30,59 +31,59 @@
print()
print("If this is not the correct instance, then verify the seed config file.")
cont_resp = input("Continue [y/n]: ")
if cont_resp.lower() == 'y':
if cont_resp.lower() == "y":
print("Continuing...")
else:
print("Exiting...")
exit()
sys.exit()

# verify if they have the correct organization
orgs = client.get_organizations()
if org_name not in [org['name'] for org in orgs]:
if org_name not in [org["name"] for org in orgs]:
print(f"Organization '{org_name}' not found. Please create the organization and try again. You belong to the following organizations:")
for org in orgs:
print(f"\t{org['name']}")
exit()
sys.exit()

# You will need to make sure that the org name is already created on SEED.
client.get_org_by_name(org_name, set_org_id=True)

# upload mapping profile for the ESPM webservice
client.create_or_update_column_mapping_profile_from_file('ESPM Webservice', mappings_dir / 'espm-webservice-mappings.csv')
client.create_or_update_column_mapping_profile_from_file("ESPM Webservice", mappings_dir / "espm-webservice-mappings.csv")

# for cycle_year in range(2019, 2024):
for cycle_year in range(2019, 2020):
cycle = client.get_or_create_cycle(f"{str(cycle_year)}", date(cycle_year, 1, 1), date(cycle_year, 12, 31), set_cycle_id=True)
cycle = client.get_or_create_cycle(f"{cycle_year!s}", date(cycle_year, 1, 1), date(cycle_year, 12, 31), set_cycle_id=True)

# upload CBL data
upload_file_name = f'CBL-building-performance-standards-sample-{cycle_year}.xlsx'
upload_file_name = f"CBL-building-performance-standards-sample-{cycle_year}.xlsx"
if (data_dir / upload_file_name).exists():
print(f'uploading {upload_file_name}')
print(f"uploading {upload_file_name}")
client.upload_and_match_datafile(
'cbl-data',
"cbl-data",
str(data_dir / upload_file_name),
'cbl mappings',
str(mappings_dir / 'cbl-mappings.csv'),
"cbl mappings",
str(mappings_dir / "cbl-mappings.csv"),
import_meters_if_exist=False,
)
else:
print(f'Could not find {data_dir / upload_file_name}, exiting...')
exit()
print(f"Could not find {data_dir / upload_file_name}, exiting...")
sys.exit()

# upload targets
upload_file_name = f'BPS-sample-Targets-{cycle_year}.xlsx'
upload_file_name = f"BPS-sample-Targets-{cycle_year}.xlsx"
if (data_dir / upload_file_name).exists():
print(f'uploading {upload_file_name}')
print(f"uploading {upload_file_name}")
client.upload_and_match_datafile(
'bps-target-data',
"bps-target-data",
str(data_dir / upload_file_name),
'bps target mappings',
str(mappings_dir / 'bps-targets-mappings.csv'),
"bps target mappings",
str(mappings_dir / "bps-targets-mappings.csv"),
import_meters_if_exist=False,
)
else:
print(f'Could not find {data_dir / upload_file_name}, exiting...')
exit()
print(f"Could not find {data_dir / upload_file_name}, exiting...")
sys.exit()

# upload performance data
# upload_file_name = f'BPS-sample-Targets-{cycle_year}.xlsx'
Expand All @@ -97,4 +98,4 @@
# )
# else:
# print(f'Could not find {data_dir / upload_file_name}, exiting...')
# exit()
# sys.exit()
Loading

0 comments on commit c494bb8

Please sign in to comment.