Skip to content

Commit

Permalink
Fix plots
Browse files Browse the repository at this point in the history
  • Loading branch information
rflprr committed Jun 29, 2017
1 parent 855826e commit 7fa2074
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dw-pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "nba-plots"
},
"transform": {
"image": "rflprr/custom-pipeline:release-0.1.0",
"image": "rflprr/custom-pipeline:release-0.1.1",
"cmd": [
"/usr/src/custom-pipeline/table_plots.py",
"/pfs/nba-tables"
Expand Down
32 changes: 19 additions & 13 deletions table_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@
import pandas as pd


@click.command
@click.argument('input_path', 'output_path')
@click.command()
@click.argument('input_path')
@click.option('-o', '--output_path', default='/pfs/out')
def plots(input_path, output_path='/pfs/out'):
dp = datapackage.DataPackage(descriptor=os.path.join(input_path,
'datapackage.json'))

dp_out = datapackage.DataPackage()
dp_out['name'] = 'nba-plots'
dp_out['title'] = 'nba-plots'
dp_out['description'] = 'My NBA Plots'
dp_out['x-visibility'] = 'PRIVATE'
dp_out['licenses'] = [
dp_out.descriptor['name'] = 'nba-plots'
dp_out.descriptor['title'] = 'nba-plots'
dp_out.descriptor['description'] = 'My NBA Plots'
dp_out.descriptor['x-visibility'] = 'PRIVATE'
dp_out.descriptor['licenses'] = [
{'name': 'Other'}
]
dp_out['resources'] = []
dp_out.descriptor['resources'] = []
for r in dp.descriptor['resources']:
df = pd.read_csv(r['path'])
fig = df.plot().get_figure()
plot_name = '{}.png'.format(r['name'])
fig.savefig(os.path.join(output_path, plot_name))
dp_out['resources'].append({'name': plot_name, 'path': plot_name})
if r.get('mediatype', '') == 'text/csv':
df = pd.read_csv(os.path.join(dp.base_path, r['path']))
try:
fig = df.plot().get_figure()
plot_name = os.path.basename('{}.png'.format(r['name']))
fig.savefig(os.path.join(output_path, plot_name))
dp_out.descriptor['resources'].append({'name': plot_name, 'path':
plot_name})
except:
pass

with open(os.path.join(output_path, 'datapackage.json'), 'w') as f:
f.write(dp_out.to_json())
Expand Down

0 comments on commit 7fa2074

Please sign in to comment.