Created
September 23, 2022 15:04
-
-
Save danielfoehrKn/c1b5f4d42f7a36466915c990cf17b73e to your computer and use it in GitHub Desktop.
This file contains 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 json | |
with open('clone.json', 'r') as fh: | |
now = json.load(fh) | |
with open('clone_before.json', 'r') as fh: | |
before = json.load(fh) | |
timestamps = {before['clones'][i]['timestamp']: i for i in range(len(before['clones']))} | |
latest = dict(before) | |
for i in range(len(now['clones'])): | |
timestamp = now['clones'][i]['timestamp'] | |
if timestamp in timestamps: | |
latest['clones'][timestamps[timestamp]] = now['clones'][i] | |
else: | |
latest['clones'].append(now['clones'][i]) | |
latest['count'] = sum(map(lambda x: int(x['count']), latest['clones'])) | |
latest['uniques'] = sum(map(lambda x: int(x['uniques']), latest['clones'])) | |
if len(timestamps) > 100: | |
remove_this = [] | |
clones = latest['clones'] | |
for i in range(len(timestamps) - 35): | |
clones[i]['timestamp'] = clones[i]['timestamp'][:7] | |
if clones[i]['timestamp'] == clones[i+1]['timestamp'][:7]: | |
clones[i+1]['count'] += clones[i]['count'] | |
clones[i+1]['uniques'] += clones[i]['uniques'] | |
remove_this.append(clones[i]) | |
for item in remove_this: | |
clones.remove(item) | |
with open('clone.json', 'w', encoding='utf-8') as fh: | |
json.dump(latest, fh, ensure_ascii=False, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment