Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created May 2, 2017 15:51
Show Gist options
  • Select an option

  • Save mtholder/81a6378d668dc87204515005b36e8c59 to your computer and use it in GitHub Desktop.

Select an option

Save mtholder/81a6378d668dc87204515005b36e8c59 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import json
import datetime
synth_j, unix_ts_and_num_studies = sys.argv[1:]
ts_ns = []
with open(unix_ts_and_num_studies, 'r') as inp:
for line in inp:
ls = line.strip().split()
if ls:
num_seconds, num_studies = [int(w) for w in ls]
ts_ns.append([num_seconds, num_studies])
ts_ns.sort()
with open(synth_j, 'r') as inp:
sd = json.load(inp)
start_time_str = "1970-01-01T00Z"
start_time = datetime.datetime.strptime(start_time_str, "%Y-%m-%dT%HZ")
num_synth_trees_by_time = []
for k in sd.keys():
obj = sd[k]
num_synth_trees = obj.get('tree_count')
if num_synth_trees is None:
num_synth_trees = 484
x = datetime.datetime.strptime(k, "%Y-%m-%dT%HZ")
ts = int((x - start_time).total_seconds())
num_synth_trees_by_time.append((ts, num_synth_trees))
num_synth_trees_by_time.sort()
sys.stdout.write('time\tnum_phyle_studies\tnum_synth_trees\tnum_non_synth_studies\n')
next_synth = num_synth_trees_by_time.pop(0)
next_synth_seconds, next_synth_trees = next_synth
for num_ps_seconds, num_ps_studies in ts_ns:
if num_ps_seconds > next_synth_seconds:
try:
next_synth = num_synth_trees_by_time.pop(0)
next_synth_seconds, next_synth_trees = next_synth
except:
pass
sys.stdout.write('{}\t{}\t{}\t{}\n'.format(num_ps_seconds, num_ps_studies, next_synth_trees, num_ps_studies - next_synth_trees))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment