Skip to content

Commit

Permalink
Add graphic ability to metric reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
markbotterill committed May 3, 2024
1 parent 0329d39 commit 11427fe
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
2 changes: 2 additions & 0 deletions backend/requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
88 changes: 69 additions & 19 deletions backend/scripts/send_slack_report/queries.py
Original file line number Diff line number Diff line change
@@ -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 *,
Expand Down

0 comments on commit 11427fe

Please sign in to comment.