-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add manage task for importing mapping preset. flake8 issues
- Loading branch information
Showing
6 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
seed/data_importer/tests/data/mappings/example-data-properties.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Raw Columns,units,SEED Table,SEED Columns | ||
jurisdiction property identifier,,PropertyState,JPID | ||
custom id 1,,PropertyState,custom_id_1 | ||
pm property id,,PropertyState,pm_property_id | ||
pm parent propery id,,PropertyState,pm_parent_property_id | ||
UBID,,PropertyState,ubid | ||
property name,,PropertyState,property_name | ||
address line 1,,PropertyState,address_line_1 | ||
city,,PropertyState,city | ||
jurisdiction tax lot id,,TaxLotState,jurisdiction_tax_lot_id | ||
use description,,PropertyState,use_description | ||
energy score,,PropertyState,energy_star_score | ||
site eui,kBtu/ft**2/year,PropertyState,site_eui | ||
year ending,,PropertyState,year_ending | ||
gross floor area,ft**2,PropertyState,gross_floor_area | ||
owner,,PropertyState,owner | ||
owner email,,PropertyState,owner_email | ||
owner telephone,,PropertyState,owner_telephone | ||
property notes,,PropertyState,property_notes | ||
latitude,,PropertyState,latitude | ||
longitude,,PropertyState,longitude | ||
recent sale date,,PropertyState,recent_sale_date | ||
generation date,,PropertyState,generation_date | ||
release date,,PropertyState,release_date | ||
extra data 1,,PropertyState,extra 1 | ||
extra data 2,,PropertyState,extra 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
:copyright (c) 2014 - 2020, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. # NOQA | ||
:author | ||
""" | ||
import csv | ||
import os | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from seed.lib.superperms.orgs.models import ( | ||
Organization, | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Add a mapping profile to an organization from a CSV file' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--organization_name', | ||
help='Organization name', | ||
action='store') | ||
|
||
parser.add_argument('--csv_file', | ||
help='Mapping profile CSV file, must follow specific format. Relative to location ' | ||
'of manage.py call.', | ||
action='store', | ||
required=True) | ||
|
||
parser.add_argument('--name', | ||
help='Name of the mapping profile', | ||
action='store') | ||
|
||
parser.add_argument('--overwrite', | ||
help='Overwrite if column mapping profile name exists', | ||
action='store_true') | ||
|
||
def handle(self, *args, **options): | ||
# verify that the user exists | ||
org = Organization.objects.filter(name=options['organization_name']).first() | ||
if not org: | ||
self.stdout.write("No organization found for %s" % options['organization_name']) | ||
exit(1) | ||
|
||
if not os.path.exists(options['csv_file']): | ||
self.stdout.write(f"Mapping CSV file does not exist: {options['csv_file']}") | ||
exit(1) | ||
|
||
mappings = [] | ||
with open(options['csv_file'], 'r') as f: | ||
data = csv.reader(f, delimiter=',', quotechar="\"") | ||
data.__next__() # skip the header row | ||
for row in data: | ||
units = row[1] | ||
if units == '': | ||
units = None | ||
mappings.append( | ||
{ | ||
'from_field': row[0], | ||
'from_units': units, | ||
'to_table_name': row[2], | ||
'to_field': row[3], | ||
} | ||
) | ||
|
||
# create the mapping preset | ||
cmp, created = org.columnmappingpreset_set.get_or_create(name=options['name']) | ||
if not created and not options['overwrite']: | ||
self.stdout.write(f"Column mapping preset already exists: {options['name']}") | ||
self.stdout.write("Pass --overwrite to overwrite existing mappings in preset if desired") | ||
exit(0) | ||
|
||
cmp.mappings = mappings | ||
cmp.save() | ||
|
||
self.stdout.write(f"Finished adding column mapping preset for {options['name']}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Raw Columns,units,SEED Table,SEED Columns | ||
UBI,,TaxLotState,jurisdiction_tax_lot_id | ||
UBID,,PropertyState,ubid | ||
GBA,ft**2,PropertyState,gross_floor_area | ||
BLDGS,,PropertyState,building_count | ||
Address,,PropertyState,address_line_1 | ||
Owner,,PropertyState,owner | ||
State,,PropertyState,state_province | ||
City,,PropertyState,city | ||
Zip,,PropertyState,postal_code | ||
Property Type,,PropertyState,use_description | ||
AYB_YearBuilt,,PropertyState,year_built | ||
Note,,PropertyState,property_notes |
1 change: 0 additions & 1 deletion
1
seed/tests/data/mappings/covered-buildings-sample-with-errors-mappings.csv
This file was deleted.
Oops, something went wrong.