Skip to content

Commit

Permalink
Merge pull request #78 from johnb30/version
Browse files Browse the repository at this point in the history
Add data version to event IDs.
  • Loading branch information
ahalterman committed Mar 5, 2015
2 parents 41f52f7 + 95b73a0 commit d8f131b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 7 additions & 5 deletions pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def main(file_details, server_details, logger_file=None, run_filter=None,
run_date=''):
run_date='', version=''):
"""
Main function to run all the things.
Expand Down Expand Up @@ -112,8 +112,11 @@ def main(file_details, server_details, logger_file=None, run_filter=None,

logger.info("Running postprocess.py")
print("Running postprocess.py")
postprocess.main(formatted_results, date_string,
file_details, server_details)
if version:
postprocess.main(formatted_results, date_string, version, file_details,
server_details)
else:
print("Please specify a data version number. Program ending.")

logger.info("Running phox_uploader.py")
print("Running phox_uploader.py")
Expand All @@ -133,5 +136,4 @@ def main(file_details, server_details, logger_file=None, run_filter=None,
server_details, file_details = utilities.parse_config('PHOX_config.ini')

main(file_details, server_details, file_details.log_file,
run_filter=file_details.oneaday_filter)

run_filter=file_details.oneaday_filter, version='v0.0.0')
22 changes: 14 additions & 8 deletions postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import geolocation


def create_strings(events):
def create_strings(events, version):
"""
Formats the event tuples into a string that can be written to a file.close
Expand All @@ -17,6 +17,9 @@ def create_strings(events):
(DATE, SOURCE, TARGET, EVENT) tuples, values are lists of
IDs, sources, and issues.
version: String.
Data version. Something like v0.1.0
Returns
-------
Expand Down Expand Up @@ -54,8 +57,10 @@ def create_strings(events):
actor_info = '\t'.join(actors)
print('Event: {}\t{}\t{}\t{}\t{}'.format(story_date, actor_info, code,
ids, sources))
event_str = '{}\t{}\t{}\t{}\t{}\t{}'.format(id_count, story_date, year,
month, day, actor_info)
id_string = '{}_{}'.format(id_count, version)
event_str = '{}\t{}\t{}\t{}\t{}\t{}'.format(id_string, story_date,
year, month, day,
actor_info)

event_str += '\t{}\t{}\t{}\t{}'.format(code, root_code, quad_class,
goldstein)
Expand All @@ -66,10 +71,8 @@ def create_strings(events):
event_str += '\t'

if lat and lon and placeName:
ccode = ''
admin = ''
event_str += '\t{}\t{}\t{}\t{}\t{}'.format(lat, lon, placeName,
stateName, countryName)
stateName, countryName)
else:
event_str += '\t\t\t\t\t'

Expand Down Expand Up @@ -354,7 +357,7 @@ def process_actors(event):
return actors


def main(event_dict, this_date, file_details, server_details):
def main(event_dict, this_date, version, file_details, server_details):
"""
Pulls in the coded results from PETRARCH dictionary in the
{StoryID: [(record), (record)]} format and allows only one unique
Expand All @@ -371,6 +374,9 @@ def main(event_dict, this_date, file_details, server_details):
this_date: String.
The current date the pipeline is running.
version: String.
Data version. Something like v0.1.0
file_details: NamedTuple.
Container generated from the config file specifying file
stems and other relevant options.
Expand All @@ -382,7 +388,7 @@ def main(event_dict, this_date, file_details, server_details):
updated_events = geolocation.main(event_dict, file_details, server_details)

logger.info('Formatting events for output.')
event_write = create_strings(updated_events)
event_write = create_strings(updated_events, version)

logger.info('Writing event output.')
filename = '{}{}.txt'.format(file_details.fullfile_stem, this_date)
Expand Down

0 comments on commit d8f131b

Please sign in to comment.