From 11427fed012b02919da8080951f761b052650f32 Mon Sep 17 00:00:00 2001 From: Mark Botterill Date: Fri, 3 May 2024 17:11:37 +0000 Subject: [PATCH] Add graphic ability to metric reporting --- backend/requirements/default.txt | 2 + backend/scripts/send_slack_report/queries.py | 88 +++++++++++++++----- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/backend/requirements/default.txt b/backend/requirements/default.txt index eab0f89357a..8c376b4f276 100644 --- a/backend/requirements/default.txt +++ b/backend/requirements/default.txt @@ -23,6 +23,7 @@ httpx[http2]==0.23.3 httpx-oauth==0.11.2 huggingface-hub==0.20.1 jira==3.5.1 +kaleido==0.2.1 langchain==0.1.9 litellm==1.34.21 llama-index==0.9.45 @@ -35,6 +36,7 @@ oauthlib==3.2.2 openai==1.3.5 openpyxl==3.1.2 playwright==1.41.2 +plotly==5.22.0 psutil==5.9.5 psycopg2-binary==2.9.9 pycryptodome==3.19.1 diff --git a/backend/scripts/send_slack_report/queries.py b/backend/scripts/send_slack_report/queries.py index 3ad6cfbbf7c..f25b7b15e3f 100644 --- a/backend/scripts/send_slack_report/queries.py +++ b/backend/scripts/send_slack_report/queries.py @@ -1,27 +1,77 @@ # This script stores all SQL queries which are used # to get HubGPT usage stats -SLACK_MESSAGES_QUERY = """SELECT COUNT(*) - FROM chat_session - WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - - INTERVAL '7 days') - AND user_id IS NULL -""" +MEDIUMS = ["slack_messages", "web_messages", "distinct_web_users"] -WEB_MESSAGES_QUERY = """SELECT COUNT(*) - FROM chat_session - WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - - INTERVAL '7 days') - AND user_id IS NOT NULL -""" -WEB_USERS_QUERY = """ - SELECT COUNT(DISTINCT user_id) - FROM chat_session - WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - - INTERVAL '7 days') - AND user_id IS NOT NULL -""" +USAGE_QUERIES = { + "last_7_days": { + "slack_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days') + AND user_id IS NULL + """, + "web_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days') + AND user_id IS NOT NULL + """, + "distinct_web_users": """ + SELECT COUNT(DISTINCT user_id) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days') + AND user_id IS NOT NULL + """, + }, + "day_14_to_7": { + "slack_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '14 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days' + AND user_id IS NULL + """, + "web_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '14 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days' + AND user_id IS NOT NULL + """, + "distinct_web_users": """ + SELECT COUNT(DISTINCT user_id) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '14 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '7 days' + AND user_id IS NOT NULL + """, + }, + "day_35_to_28": { + "slack_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '35 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '28 days' + AND user_id IS NULL + """, + "web_messages": """ + SELECT COUNT(*) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '35 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '28 days' + AND user_id IS NOT NULL + """, + "distinct_web_users": """ + SELECT COUNT(DISTINCT user_id) + FROM chat_session + WHERE (time_created >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '35 days') + AND time_created < (NOW() AT TIME ZONE 'UTC') - INTERVAL '28 days' + AND user_id IS NOT NULL + """, + }, +} INITIAL_MESSAGES_QUERY = """ SELECT message as initial_query FROM ( SELECT *,