Created
January 9, 2020 18:09
-
-
Save hughdbrown/8ad10d998086bff494d714912758870d to your computer and use it in GitHub Desktop.
Code to check that create_index.js has collections listed in sequence
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
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