cheshire-cat-ai / plugins-backend

The backend of The Cheshire Cat plugin directory
GNU General Public License v3.0
7 stars 5 forks source link

Analytics endpoint for plot #29

Closed pieroit closed 9 months ago

pieroit commented 9 months ago

Could be useful to have an analytics endpoint to get some data and optionally a plot. Here is the code to make a plot out of analytics.json

import pandas as pd
import plotly.express as px

json = pd.read_json("analytics.json", typ="series")

df = pd.DataFrame({
    "plugin": json.index.values,
    "downloads": json.values,
})

df = df.sort_values("downloads", ascending=True)
df["plugin"] = df["plugin"].map(lambda p: p.split("/")[-1])

px.bar(df, y="plugin", x="downloads") # could be saved as file or sent as binary/base64/whatever