Advertisement
AlexG2230954

Untitled

Jun 11th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import json
  2.  
  3.  
  4. def convert_time(s):
  5. date, time = s.split(" ")
  6.  
  7. date = tuple(map(int, date.split("/")))
  8. time = tuple(map(int, time.split(":")))
  9.  
  10. return date + time
  11.  
  12.  
  13. def create_worker(username):
  14. worker = dict()
  15. worker["username"] = username
  16. worker["commits"] = 0
  17. worker["changed_lines"] = 0
  18. worker["new_files"] = 0
  19.  
  20. return worker
  21.  
  22.  
  23. with open("input.json", "r") as f:
  24. data = json.load(f)
  25.  
  26. data.sort(key=lambda el: convert_time(el["commit_time"]))
  27. created_files = set()
  28. workers = dict()
  29.  
  30. for commit in data:
  31. username = commit["username"]
  32.  
  33. if username not in workers:
  34. workers[username] = create_worker(username)
  35.  
  36. worker = workers[username]
  37. worker["commits"] += 1
  38.  
  39. for file in commit["files"]:
  40. worker["changed_lines"] += file["changed_lines"]
  41.  
  42. if file["name"] not in created_files:
  43. created_files.add(file["name"])
  44. worker["new_files"] += 1
  45.  
  46.  
  47. with open("output.tsv", "w") as tsv:
  48. tsv.write("username\tcommits\tchanged_lines\tnew_files\n")
  49.  
  50. for worker in sorted(workers.values(), key=lambda el: el["username"]):
  51. tsv.write("{username}\t{commits}\t{changed_lines}\t{new_files}\n".format(
  52. **worker
  53. ))
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement