Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- def convert_time(s):
- date, time = s.split(" ")
- date = tuple(map(int, date.split("/")))
- time = tuple(map(int, time.split(":")))
- return date + time
- def create_worker(username):
- worker = dict()
- worker["username"] = username
- worker["commits"] = 0
- worker["changed_lines"] = 0
- worker["new_files"] = 0
- return worker
- with open("input.json", "r") as f:
- data = json.load(f)
- data.sort(key=lambda el: convert_time(el["commit_time"]))
- created_files = set()
- workers = dict()
- for commit in data:
- username = commit["username"]
- if username not in workers:
- workers[username] = create_worker(username)
- worker = workers[username]
- worker["commits"] += 1
- for file in commit["files"]:
- worker["changed_lines"] += file["changed_lines"]
- if file["name"] not in created_files:
- created_files.add(file["name"])
- worker["new_files"] += 1
- with open("output.tsv", "w") as tsv:
- tsv.write("username\tcommits\tchanged_lines\tnew_files\n")
- for worker in sorted(workers.values(), key=lambda el: el["username"]):
- tsv.write("{username}\t{commits}\t{changed_lines}\t{new_files}\n".format(
- **worker
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement