-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseed.py
142 lines (130 loc) · 4.49 KB
/
seed.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from sqlalchemy.orm import Session
from models import QuotaDefinition, Quota
from schemas import ResetIntervalDefinition, QuotaScope
def seed_data(db: Session):
# Check whether data already exists to avoid duplicate entries
if db.query(QuotaDefinition).first() or db.query(Quota).first():
return
# Creating mock data for QuotaDefinition
quota_definitions = [
QuotaDefinition(
type='token',
description={
"en": "Token limit for users",
"de": "Tokenlimit für Nutzende"
},
reset_interval=ResetIntervalDefinition.daily,
scope=QuotaScope.user,
),
QuotaDefinition(
type='token',
description={
"en": "Token limit for gpt-3 users",
"de": "Tokenlimit für gpt-3 Nutzende"
},
reset_interval=ResetIntervalDefinition.monthly,
scope=QuotaScope.user,
feature='gpt-3',
),
QuotaDefinition(
type='number',
description={
"en": "Number of total images to generate",
"de": "Gesamtzahl zu generierender Bilder"
},
reset_interval=ResetIntervalDefinition.daily,
scope=QuotaScope.total,
),
QuotaDefinition(
type='token',
description={
"en": "Token limit for course user",
"de": "Tokenlimit für Kursmitglieder"
},
reset_interval=ResetIntervalDefinition.semester,
scope=QuotaScope.course_user,
),
QuotaDefinition(
type='token',
description={
"en": "Token limit for courses",
"de": "Tokenlimit für Kurse"
},
reset_interval=ResetIntervalDefinition.semester,
scope=QuotaScope.course,
),
]
# Adding QuotaDefinition mock data to the session
db.add_all(quota_definitions)
db.flush() # ensures that IDs are generated for foreign key assignments
# Create mock data for quota
quotas = [
Quota(
limit=1000,
type='token',
scope=QuotaScope.user,
quota_definition_id=quota_definitions[0].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=1000,
used=200,
type='token',
scope=QuotaScope.user,
user_id='user-456',
quota_definition_id=quota_definitions[0].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=1000,
type='token',
scope=QuotaScope.user,
feature='gpt-3',
quota_definition_id=quota_definitions[1].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=1000,
used=100,
type='token',
scope=QuotaScope.user,
feature='gpt-3',
user_id='user-456',
quota_definition_id=quota_definitions[1].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=10000,
used=50,
type='number',
scope=QuotaScope.total,
quota_definition_id=quota_definitions[2].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=500,
type='token',
scope=QuotaScope.course_user,
quota_definition_id=quota_definitions[3].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=100,
type='token',
scope=QuotaScope.course_user,
course_id="course-123",
quota_definition_id=quota_definitions[3].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=100,
used=200,
type='token',
scope=QuotaScope.course_user,
course_id="course-123",
user_id="user-456",
quota_definition_id=quota_definitions[3].id # refers to the actual ID of the QuotaDefinition entry
),
Quota(
limit=200,
type='token',
scope=QuotaScope.course,
quota_definition_id=quota_definitions[4].id # refers to the actual ID of the QuotaDefinition entry
),
]
# Adding quota mock data to the session
db.add_all(quotas)
db.commit()