Skip to content

Commit

Permalink
Create schemas (#92)
Browse files Browse the repository at this point in the history
* Significant progress

Created all schema files and made progress in them.

* Tried with schemas

Tried to fix the schemas. Will need to revisit all changes on this branch.

* synce server to master (#90) (#91)

* Base file (#80)

Made base file and folder structure.

* Game generation tweak (#89)

* Tweaked game generation

* Tweaked game generation names

* Added type

* moved to actual function

* cleaned up ternary

* Added comments

* documentation updates

---------



---------

Co-authored-by: Ian <[email protected]>
Co-authored-by: KingPhilip14 <[email protected]>

* Fixed private issue

Made team_id_uuid its own schema for privacy.

---------

Co-authored-by: Jean A. Eckelberg <[email protected]>
  • Loading branch information
KingPhilip14 and JeanAEckelberg authored Oct 1, 2023
1 parent 5ce7239 commit 951e3e7
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/models/group_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class GroupRun(Base):
launcher_version: Mapped[str] = mapped_column(String(10), nullable=False)
runs_per_client: Mapped[int] = mapped_column(Integer(), nullable=False)
is_finished: Mapped[bool] = mapped_column(Boolean(), default=False, nullable=False)
runs: Mapped[list[Run]] = relationship()
runs: Mapped[list[Run]] = relationship(back_populates='group_run')
4 changes: 3 additions & 1 deletion server/models/university.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sqlalchemy import Integer, CheckConstraint, String
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import relationship, Mapped, mapped_column
import team

from .base import Base

Expand All @@ -8,3 +9,4 @@ class University(Base):
__tablename__: str = 'university'
uni_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
uni_name: Mapped[str] = mapped_column(String(100), CheckConstraint("uni_name != ''"), nullable=False, unique=True)
teams: Mapped[list[team.Team]] = relationship(back_populates='teams')
18 changes: 18 additions & 0 deletions server/schemas/errors_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations
from pydantic import BaseModel
import run_schema, submission_schema


class ErrorsBase(BaseModel):
error_id: int
run_id: int
submission_id: int
error_txt: str

class Config:
from_attributes = True


class ErrorsSchema(ErrorsBase):
runs_id: list[run_schema.RunBase] = []
submission_id: list[submission_schema.SubmissionBase] = []
18 changes: 18 additions & 0 deletions server/schemas/group_run_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations
from pydantic import BaseModel
import run_schema


class GroupRunBase(BaseModel):
group_run_id: int
start_run: str
launcher_version: str
runs_per_client: int
is_finished: bool

class Config:
from_attributes = True


class GroupRunSchema(GroupRunBase):
runs: list[run_schema.RunBase] = []
22 changes: 22 additions & 0 deletions server/schemas/run_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations
from pydantic import BaseModel
import group_run_schema, errors_schema, turn_table_schema


class RunBase(BaseModel):
run_id: int
group_run_id: int
run_time: str
winner: bool
player_1: int
player_2: int
seed: int

class Config:
from_attributes = True


class RunSchema(RunBase):
group_run: group_run_schema.GroupRunBase
errors: errors_schema.ErrorsBase
turn_tables: list[turn_table_schema.TurnTableBase] = []
18 changes: 18 additions & 0 deletions server/schemas/submission_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations
from pydantic import BaseModel
import team_schema, errors_schema


class SubmissionBase(BaseModel):
submission_id: int
team_id_uuid: int
submission_time: str
file_txt: str

class Config:
from_attributes = True


class SubmissionSchema(SubmissionBase):
team_id: list[team_schema.TeamBase] = []
errors: list[errors_schema.ErrorsBase] = []
23 changes: 23 additions & 0 deletions server/schemas/team_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations
from pydantic import BaseModel
import university_schema, team_type_schema, submission_schema


class TeamBase(BaseModel):
uni_id: int
team_type_id: int
team_name: str

class Config:
from_attributes = True


class TeamIdSchema(TeamBase):
team_id_uuid: int


# University <-> Team: Many to One
class TeamSchema(TeamBase):
uni_id: int = university_schema.UniversityBase
team_type_id: int = team_type_schema.TeamTypeBase
submissions: list[submission_schema.SubmissionBase] = []
15 changes: 15 additions & 0 deletions server/schemas/team_type_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations
from pydantic import BaseModel
import team_schema


class TeamTypeBase(BaseModel):
team_type_id: int
team_type_name: str

class Config:
from_attributes = True


class TeamTypeSchema(TeamTypeBase):
teams: list[team_schema.TeamBase] = []
17 changes: 17 additions & 0 deletions server/schemas/turn_table_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations
from pydantic import BaseModel
import run_schema


class TurnTableBase(BaseModel):
turn_id: int
turn_number: int
run_id: int
turn_data: str

class Config:
from_attributes = True


class TurnTableSchema(TurnTableBase):
run: run_schema.RunBase
16 changes: 16 additions & 0 deletions server/schemas/university_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations
from pydantic import BaseModel
import team_schema


class UniversityBase(BaseModel):
uni_id: id
uni_name: str

class Config:
from_attributes = True


# University <-> Team: Many to One
class UniversitySchema(UniversityBase):
teams: list[team_schema.TeamBase] = []

0 comments on commit 951e3e7

Please sign in to comment.