Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Last active August 29, 2015 14:06
Show Gist options
  • Save sangheestyle/af394542bdbe10db6c4d to your computer and use it in GitHub Desktop.
Save sangheestyle/af394542bdbe10db6c4d to your computer and use it in GitHub Desktop.
Summary sp
import sys
import json
from os import listdir
from os.path import isfile, join, basename
def get_file_paths(root):
file_paths = []
for f in listdir(root):
if isfile((join(root, f))):
file_paths.append(join(root, f))
return file_paths
def get_summary(root):
summary = {}
for path in get_file_paths(root):
print ">>> Processing: " + path + ": ",
sp = json.load(open(path, 'r'))
total = sum(sp)
length = len(sp)
maximum = max(sp)
mean = total/length
summary[basename(path)] = {"number": length, "total": total,
"max": maximum, "mean": mean}
print "max:", maximum, "mean:", mean, "number:", length
return summary
def to_json(data, file_name):
json.dump(data, open(file_name, "w"))
if __name__=="__main__":
"""
example: $ python summary.py sp_folder output_file_name
"""
root = sys.argv[1]
output_file_name = sys.argv[2]
summary = get_summary(root)
to_json(summary, output_file_name)
@sangheestyle
Copy link
Author

Do!

$ curl "https://gist.githubusercontent.com/sangheestyle/af394542bdbe10db6c4d/raw/379268043975349ff15bf4f1221e87d00bdb058a/summary.py" -o "summary.py"
$ python summary.py out summary.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment