Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some classes and students #60

Merged
merged 4 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spamdb/modules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ def parse_args() -> argparse.Namespace:
default=80,
help="(default: 80)",
)
parser.add_argument(
"--classes",
type=int,
default=3,
help="""
(default: 3)
Classes are managed by special user teacher.
"""
)
parser.add_argument(
"--students",
type=int,
default=10,
help="(default: 10)"
)
parser.add_argument(
"--games",
type=int,
Expand Down
94 changes: 94 additions & 0 deletions spamdb/modules/clas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import random
from string import ascii_letters, digits
from modules.env import env
import modules.util as util
from modules.user import User

def update_clas_colls() -> None:
args = env.args
db = env.db

if args.drop:
db.clas_clas.drop()
db.clas_student.drop()
db.clas_invite.drop()

classes: list[Clas] = []
students: list[Student] = []
users: list[User] = []
student_index = 0

if args.classes < 1:
return

for clas_index in range(args.classes):
clas_name = "Class " + str(clas_index + 1)
clas_id = ''.join(random.sample(ascii_letters + digits, 8))
classes.append({
"_id": clas_id,
"name": clas_name,
"teachers": ["teacher"],
"created": {
"by": "teacher",
"at": util.time_since_days_ago(2)
},
"desc": "Description for " + clas_name,
"wall": "Last news",
"viewedAt": util.time_since_days_ago(1)
})

if args.students < 1:
continue
for _ in range(args.students):
student_index += 1
students.append({
"_id": "student" + str(student_index) + ":" + clas_id,
"userId": "student" + str(student_index),
"clasId": clas_id,
"realName": "Student " + str(student_index) + " in class " + clas_name,
"notes": "",
"managed": True,
"created": {
"by": "teacher",
"at": util.time_since_days_ago(1)
}
})
users.append(User("student" + str(student_index), [], [], False))
users[-1].kid = True

if not args.no_create:
util.bulk_write(db.clas_clas, classes)
util.bulk_write(db.clas_student, students)
util.bulk_write(db.user4, users)
return classes


class Clas:
def __init__(self, clas: dict):
self._id = clas["_id"]
self.name = clas["name"]
self.desc = clas["desc"]
self.wall = clas["wall"]
self.teachers = clas["teachers"]
self.created = clas["created"]
self.viewedAt = clas["viewedAt"]


class Student:
def __init__(self, student: dict):
self._id = student["_id"]
self.userId = student["userId"]
self.clasId = student["clasId"]
self.realName = student["realName"]
self.notes = student["notes"]
self.managed = student["managed"]
self.created = student["created"]


class Invite:
def __init__(self, invite: dict):
self._id = invite["_id"]
self.userId = invite["userId"]
self.realName = invite["realName"]
self.clasId = invite["clasId"]
self.created = invite["created"]
2 changes: 2 additions & 0 deletions spamdb/spamdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def main():
import modules.video as video
import modules.study as study
import modules.local as local
import modules.clas as clas
from modules.env import env

if env.args.list_ratings:
Expand Down Expand Up @@ -74,6 +75,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
video.update_video_colls()
study.update_study_colls()
local.update_local_colls()
clas.update_clas_colls()

if __name__ == "__main__":
main()