Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Last active August 29, 2015 14:06
Show Gist options
  • Save sangheestyle/ea8687f4d76f6ed31a14 to your computer and use it in GitHub Desktop.
Save sangheestyle/ea8687f4d76f6ed31a14 to your computer and use it in GitHub Desktop.
Run SSSP
#!/bin/bash
mkdir sssp
cd sssp
curl "https://dl.dropboxusercontent.com/u/7571776/facebook100_txt_only.zip" -o "facebook100_txt_only.zip"
unzip facebook100_txt_only.zip
curl https://gist.githubusercontent.com/sangheestyle/6335b209b4779dddc5ac/raw/47a803d6ccfa727efb80d5c32f5e7361d32c861a/ps16c.py > ps16c.py
mkdir out
python ps16c.py facebook100txt $1 $2
cd ..
@sangheestyle
Copy link
Author

Snippet

a = {}
a["file1"] = {"sum":10, "max": 20, "number": 30}
a["file2"] = {"sum":10, "max": 20, "number": 30}

import json
json.dump(a, open("test.json", "w"))
json.load(open("test.json", "r"))
r = json.load(open("test.json", "r"))
for item in r:
    print r[item]["max"]

So

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):
        sp = json.load(open(path, 'r'))
        sum = sum(sp)
        len = len(sp)
        max = max(sp)
        summary[basename(path)] = {"number": len, "sum": sum, "max": max, "avg": sum/len}
    return summary

def to_json(data, file_name):
    json.dump(data, open(file_name, "w"))

if __name__=="__main__":
    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