RKP64 commited on
Commit
e3b6978
·
1 Parent(s): f618dcd

Upload stats.py

Browse files
Files changed (1) hide show
  1. stats.py +31 -0
stats.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime, timedelta
2
+
3
+ # -- Create a table called "stats"
4
+ # create table
5
+ # stats (
6
+ # -- A column called "time" with data type "timestamp"
7
+ # time timestamp,
8
+ # -- A column called "details" with data type "text"
9
+ # chat boolean,
10
+ # embedding boolean,
11
+ # details text,
12
+ # metadata jsonb,
13
+ # -- An "integer" primary key column called "id" that is generated always as identity
14
+ # id integer primary key generated always as identity
15
+ # );
16
+
17
+
18
+ def get_usage_today(supabase):
19
+ # Returns the number of rows in the stats table for the last 24 hours
20
+ response = supabase.table("stats").select("id", count="exact").gte("time", datetime.now() - timedelta(hours=24)).execute()
21
+ return response.count
22
+
23
+ def add_usage(supabase, type, details, metadata):
24
+ # Adds a row to the stats table
25
+ supabase.table("stats").insert({
26
+ "time": datetime.now().isoformat(),
27
+ "chat": type == "chat",
28
+ "embedding": type == "embedding",
29
+ "details": details,
30
+ "metadata": metadata
31
+ }).execute()