def make_plots(tweets, box, place): """Make plots from the extracted tweet data. Args: tweets: Iterable of tweets already filtered and within the bounding box. box = A pair of longitude and latitude pairs, with the southwest corner of the bounding box coming first. place = String for the place name of the bounding `box`. """ print 'Extracting tweets ...', data = list(process.extract_data(tweets)) print 'DONE' print 'Extracting census blocks ...', census_path = config.get('census', 'path') census_blocks = config.get('census', 'blocks') blocks = process.extract_blocks(os.path.join(census_path, census_blocks)) print 'DONE' print 'Processing data ...', longitude, latitude, time, users = process.process_data(data) print 'DONE' print 'Computing census block interactions ...', interactions = process.compute_block_interactions(users, blocks) print 'DONE' print 'Saving census block interactions ...', with open('census-block-interactions.tsv', mode='w') as f: process.dump_interactions(interactions, f) print 'DONE' print 'Making figures ...', figures = [] figures.append(make_map(longitude, latitude, time, box, place)) figures.append(make_user_map(longitude, latitude, users, box, place)) figures.append(make_user_checkins(users)) figures.append(make_heatmap(longitude, latitude, box, place)) figures.append(make_time(time)) print 'DONE' print 'Saving figures ...', for figure in figures: figure.savefig('{0}.png'.format(figure.get_label()), bbox_inches='tight', pad_inches=0.1) print 'DONE' plt.show()
logger.addHandler(file_handler) if __name__ == '__main__': config = get_config() setup_logging(config) logger = logging.getLogger('ui.web') git_version, git_commit = get_git_version() if git_version: logger.info('Version: {0} ({1})'.format(git_version, git_commit)) else: logger.warning('Could not detect current Git commit.') print 'Extracting census blocks ...', census_path = config.get('census', 'path') census_blocks = config.get('census', 'blocks') blocks = process.extract_blocks(os.path.join(census_path, census_blocks)) print 'DONE' print 'Loading census block interactions ...', with open('census-block-interactions.tsv') as f: interactions = process.load_interactions(f) print 'DONE' logger.info('Starting web server on port {}'.format(config.getint('web', 'port'))) start_server(config, blocks, interactions, (git_version, git_commit))