Created
April 17, 2023 07:02
-
-
Save xsuchy/eb5d8394cafd428176138ac4fbb881e2 to your computer and use it in GitHub Desktop.
copr-heatmap.py
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
from copr.v3 import Client | |
from copr.v3.pagination import next_page | |
from pprint import pprint | |
import datetime | |
import plotly.express as px | |
import pandas as pd | |
import json | |
import argparse | |
DAYS = 91 | |
parser = argparse.ArgumentParser(description='Display Copr statistics.') | |
parser.add_argument('--data', help='file with data') | |
args = parser.parse_args() | |
if not (args.data): | |
previous_date = datetime.datetime.today() - datetime.timedelta(days=DAYS) | |
previous_time = previous_date.timestamp() | |
client = Client.create_from_config_file() | |
USERS = {} | |
pagination = {"limit": 1000} | |
projects_page = client.project_proxy.get_list(pagination=pagination) | |
while projects_page: | |
for p in projects_page: | |
#pprint(p.ownername +" "+ p.name) | |
builds = client.build_proxy.get_list(p.ownername, p.name, pagination=pagination) | |
while builds: | |
for b in builds: | |
if b.started_on and b.started_on > previous_time: | |
USERS[p.ownername] = USERS.get(p.ownername, 0) + len(b.chroots) | |
builds = next_page(builds) | |
projects_page = next_page(projects_page) | |
print(len(USERS)) | |
with open('data.json', 'w') as fp: | |
json.dump(USERS, fp, sort_keys=True, indent=4) | |
else: | |
with open('data.json') as json_file: | |
USERS = json.load(json_file) | |
NAMES = [] | |
BUILDS = [] | |
for k,v in USERS.items(): | |
NAMES.append(k) | |
BUILDS.append(v) | |
df = pd.DataFrame({'names': NAMES, | |
'builds': BUILDS, | |
}) | |
fig = px.treemap(df, path=[px.Constant("all"), 'names'], values = 'builds', | |
# color='colors', | |
#color_discrete_map ={'(?)':'#262931', 'red':'red', 'indianred':'indianred','lightpink':'lightpink', 'lightgreen':'lightgreen','lime':'lime','green':'green'}, | |
#hover_data = {'delta':':.2p'} | |
) | |
fig.show() | |
pprint(USERS) |
@xsuchy Mirek wants a cron job running ~monthly. The script is run over API; that is slow - we should have a built-in query.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There exists also fig.dump() for complete web page, not just the graph