about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/julia-modules/tests/process_top_n.py
blob: 90de70ccec4d4d7bafb0cbbfb2ec237d65614b2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ pyyaml toml ])"

import csv
from pathlib import Path
import sys
import toml
import yaml

requests_csv_path = Path(sys.argv[1])
registry_path = Path(sys.argv[2])

# Generate list of tuples (UUID, count)
rows = []
with open(requests_csv_path) as f:
  reader = csv.reader(f)
  for row in reader:
    if row[2] == "user":
      # Get UUID and request_count
      rows.append((row[0], int(row[4])))
rows.sort(key=(lambda x: x[1]), reverse=True)

# Build a map from UUID -> name
registry = toml.load(registry_path / "Registry.toml")
uuid_to_name = {k: v["name"] for k, v in registry["packages"].items()}

results = []
for (uuid, count) in rows:
  name = uuid_to_name.get(uuid)
  if not name: continue
  results.append({ "uuid": uuid, "name": uuid_to_name.get(uuid), "count": count })

yaml.dump(results, sys.stdout, default_flow_style=False)