2 # Ju's statistics for mattermost
3 # written 2019-2020 by ju <daju@fsinf.at>
4 # fix'd 2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
6 # Different active users within a time range (last 24h, last 7 days, begin of the semester)
7 # and their number of posts
11 import psycopg2.extras
17 msg = "Users: Active different users and their posts within a certain time.\n\n||different users|# of posts\n|---|---:|---:|\n"
20 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
21 cur.execute("""SELECT COUNT(DISTINCT UserId), COUNT(id) FROM posts WHERE posts.deleteat=0 AND posts.createat > EXTRACT(EPOCH FROM (NOW() - INTERVAL '1 day'))*1000""")
22 # list size n where n = number of different UserIds and all values are the same - the count of posts
24 msg += "|24 hours|"+str(row[0])+"|"+str(row[1])+"|\n"
27 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
28 cur.execute("""SELECT COUNT(DISTINCT UserId), COUNT(id) FROM posts WHERE posts.deleteat=0 AND posts.createat > EXTRACT(EPOCH FROM (NOW() - INTERVAL '1 week'))*1000""")
30 msg += "|7 days|"+str(row[0])+"|"+str(row[1])+"|\n"
33 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
34 cur.execute("""SELECT COUNT(DISTINCT UserId), COUNT(id) FROM posts WHERE posts.deleteat=0 AND posts.createat > EXTRACT(EPOCH FROM TIMESTAMP '"""+config.cutoff_date+"""')*1000""")
36 msg += "|since "+config.cutoff_date+"|"+str(row[0])+"|"+str(row[1])+"|\n"