Created
May 3, 2014 19:06
-
-
Save danhammer/3a268aac4a6a7f9b37a2 to your computer and use it in GitHub Desktop.
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
# Accepts a results dictionary and writes an short analysis based on | |
# the stored results. Example: | |
# test_res_dict = { | |
# 'address' : '1460 Golden Gate Avenue, San Francisco, CA', | |
# 'sold_date' : '2008-04-21', | |
# # baseline level of vegetation or some other sort of indicator of | |
# # the property. | |
# 'pre_ndvi' : 100, | |
# # value at maximal change and test statistic after the selling | |
# # date | |
# 'post_ndvi' : 50, | |
# 'diff_statistic' : 2.1, | |
# # The date that the empirical fluctuation process exceeded the | |
# # confidence threshold | |
# 'stats_date' : '2009-05-12' | |
# } | |
# >>> story(test_res_dict) | |
# 'The property at 1460 Golden Gate Avenue, San Francisco, CA was last | |
# sold on Tuesday, May 12, 2009. The property was subject to | |
# redevelopment after it was sold. Approximately 386 days after the | |
# property was sold, 50 percent of the land underwent significant | |
# development' | |
from datetime import datetime | |
def _intro(res_dict): | |
d = datetime.strptime(res_dict['stats_date'], '%Y-%m-%d') | |
date = d.strftime("%A, %B %d, %Y") | |
text = ('The property at %s' % res_dict['address'], | |
'was last sold on %s.' % date) | |
return [' '.join(text)] | |
def _analysis(res_dict): | |
"""If there is analysis to do""" | |
sold = datetime.strptime(res_dict['sold_date'], '%Y-%m-%d') | |
stat = datetime.strptime(res_dict['stats_date'], '%Y-%m-%d') | |
days = (stat-sold).days | |
p = int(float(res_dict['post_ndvi']) / res_dict['pre_ndvi'] * 100) | |
s1 = ['The property was subject to redevelopment after it was sold.'] | |
s2 = ['Approximately %s days after the property was sold,' % days, | |
'%s percent of the land underwent significant development' % p] | |
return [' '.join(s1 + s2)] | |
def story(res_dict): | |
s1 = _intro(res_dict) | |
if abs(res_dict['diff_statistic']) > 1.96: | |
s2 = _analysis(res_dict) | |
else: | |
s2 = ['There was no significant redevelopment of ' + | |
'the property after it was sold'] | |
return ' '.join(s1 + s2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment