Last active
August 29, 2015 14:06
-
-
Save sangheestyle/af394542bdbe10db6c4d to your computer and use it in GitHub Desktop.
Summary sp
This file contains hidden or 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do!