Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created January 9, 2020 18:09
Show Gist options
  • Save hughdbrown/8ad10d998086bff494d714912758870d to your computer and use it in GitHub Desktop.
Save hughdbrown/8ad10d998086bff494d714912758870d to your computer and use it in GitHub Desktop.
Code to check that create_index.js has collections listed in sequence
def load():
with open("config/create_index.js") as handle:
data = [line.rstrip() for line in handle]
coll_iter = (line.split('.') for line in data)
return [
(i, coll[0] + '.' + coll[1])
for i, coll in enumerate(coll_iter)
if len(coll) >= 2 and coll[0] == 'db'
]
def aggregate(colls):
from collections import defaultdict
d = defaultdict(list)
for i, c in colls:
d[c].append(i)
return d
def summarize(d):
def consecutive(nums):
return nums[-1] - nums[0] == len(nums) - 1
for key, value in d.items():
if not consecutive(value):
print(key, value)
summarize(aggregate(load()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment