-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
data.py
63 lines (53 loc) · 1.68 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
from sqlalchemy import desc
from app.models import User, Event
def print_data():
count = User.query.count()
users = User.query.all()
print("Total Users: " + str(count))
print("\n")
for u in users:
print(u.email)
print("articles " + str(u.articles.count()))
print("highlights " + str(u.highlights.count()))
print("topics " + str(u.topics.count()))
print("tags " + str(u.tags.count()))
print("\n")
def data_dashboard():
users = (
User.query.filter_by(test_account=False)
.order_by(desc(User.last_active))
.limit(15)
)
user_list = []
for u in users:
ev = u.events.order_by(Event.date.desc()).limit(1).first()
created = u.account_created_date
today = datetime.datetime.utcnow()
days_old = (today - created).days
try:
last_active = ev.date
except Exception:
last_active = u.last_active
try:
last_action = ev.name
except Exception:
last_action = u.last_action
user = {
"id": u.id,
"email": u.email if u.email else f"deleted-{u.id}",
"articles": u.articles.count(),
"highlights": u.highlights.count(),
"topics": u.topics.count(),
"tags": u.tags.count(),
"last_active": last_active,
"test_account": u.test_account,
"last_action": last_action,
"days_old": days_old,
}
try:
user["suggestion"] = u.suggestion.title
except Exception:
user["suggestion"] = None
user_list.append(user)
return user_list