Skip to content

Commit

Permalink
- Updated the criteria for generic oils category.
Browse files Browse the repository at this point in the history
- Updated the Adios and Test data files.
- Added initial Norway oils data file.
  • Loading branch information
JamesMakela-NOAA committed Mar 10, 2017
1 parent 8d53b80 commit 21861ac
Show file tree
Hide file tree
Showing 7 changed files with 883 additions and 755 deletions.
1,443 changes: 733 additions & 710 deletions oil_library/OilLib

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions oil_library/OilLibNorway

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions oil_library/OilLibTest

Large diffs are not rendered by default.

32 changes: 12 additions & 20 deletions oil_library/init_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ def link_generic_oils(session):
- Other->Generic
Criteria:
- Any oils that have been generically generated. These are found
in the OilLibTest data file. For now, this needs to be a
hard-coded list.
in the OilLibTest data file. Basically these oils have a name
that is prefixed with '*GENERIC'.
'''
try:
top_category = (session.query(Category)
Expand All @@ -403,31 +403,23 @@ def link_generic_oils(session):
return

categories = [c for c in top_category.children
if c.name in ('Generic',)
]
if c.name in ('Generic',)]

if len(categories) == 0:
logger.warning('Category "Other->Generic" not found!!')
return

oil_id_list = ['AD02542', 'AD02543', 'AD02544', 'AD02545',
'AD02546', 'AD02547', 'AD02549', 'AD02550',
'AD02551', 'AD02552', 'AD02553', 'AD02554',
'AD02555', 'AD02556', 'AD02557', 'AD02558',
'AD02559', 'AD02560', 'AD02561', 'AD02562',
'AD02563', 'AD02564', 'AD02565', 'AD02566',
'AD02567']
oils = session.query(Oil).filter(Oil.name.like('*GENERIC%')).all()

for oil_id in oil_id_list:
try:
oil = session.query(Oil).filter(Oil.adios_oil_id == oil_id).one()
count = 0
for o in oils:
for category in categories:
o.categories.append(category)

for category in categories:
oil.categories.append(category)
count += 1

logger.info('Generic oil {0} added to categories {1}.'
.format(oil_id, [n.name for n in categories]))
except NoResultFound:
logger.warning('Generic oil {0} not found.'.format(oil_id, ))
logger.info('{0} oils added to {1}.'
.format(count, [n.name for n in categories]))

transaction.commit()

Expand Down
10 changes: 6 additions & 4 deletions oil_library/initializedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def load_database(settings):
logger.info('Purging old records in database')
imported_recs_purged, oil_recs_purged = purge_old_records(session)
logger.info('finished!!!\n'
' {0} imported records purged.\n'
' {0} oil records purged.'
.format(imported_recs_purged, oil_recs_purged))
' {0} imported records purged.\n'
' {0} oil records purged.'
.format(imported_recs_purged, oil_recs_purged))

for fn in settings['oillib.files'].split('\n'):
logger.info('opening file: {0} ...'.format(fn))
Expand Down Expand Up @@ -87,7 +87,9 @@ def make_db(oillib_files=None, db_file=None):

if not oillib_files:
oillib_files = '\n'.join([os.path.join(pck_loc, fn)
for fn in ('OilLib', 'OilLibTest')])
for fn in ('OilLib',
'OilLibTest',
'OilLibNorway')])

sqlalchemy_url = 'sqlite:///{0}'.format(db_file)
settings = {'sqlalchemy.url': sqlalchemy_url,
Expand Down
2 changes: 1 addition & 1 deletion oil_library/scripts/oil_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_application_name(file_obj):


def get_chosen_app_name():
apps = ['adios', 'adios test records']
apps = ['adios', 'adios test records', 'adios norway imports']
app_num = -1

while app_num == -1:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run_tests(self):
package_data={'oil_library': ['OilLib.db',
'OilLib',
'OilLibTest',
'OilLibNorway',
'tests/*.py',
'tests/sample_data/*']},
cmdclass={'remake_oil_db': remake_oil_db,
Expand Down

0 comments on commit 21861ac

Please sign in to comment.