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

Create student class #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions krummstab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def print_marks(_the_config: config.Config, sheet: sheets.Sheet) -> None:
if submission.team == team_to_print:
key = submission.team.get_team_key()
for student in submission.team.members:
full_name = f"{student[0]} {student[1]}"
full_name = f"{student.first_name} {student.last_name}"
output_str = f"{full_name:>35};"
if _the_config.points_per == "exercise":
# The value `marks` assigned to the team_dir key is a
Expand All @@ -661,8 +661,8 @@ def create_individual_marks_file(_the_config: config.Config, sheet: sheets.Sheet
student_marks = {}
for submission in sheet.get_relevant_submissions():
team_key = submission.team.get_team_key()
for first_name, last_name, email in submission.team.members:
student_key = email.lower()
for student in submission.team.members:
student_key = student.email.lower()
student_marks.update({student_key: team_marks.get(team_key)})
file_content = {
"tutor_name": _the_config.tutor_name,
Expand Down Expand Up @@ -1207,7 +1207,8 @@ def print_missing_submissions(_the_config: config.Config, sheet: sheets.Sheet) -
print(f"* {missing_team.last_names_to_string()}")


def lookup_teams(_the_config: config.Config, team_dir: pathlib.Path):
def lookup_teams(_the_config: config.Config,
team_dir: pathlib.Path) -> tuple[str, list[Team]]:
"""
Extracts the team ID from the directory name and searches for teams
based on the extracted email address from the subdirectory name.
Expand All @@ -1218,7 +1219,7 @@ def lookup_teams(_the_config: config.Config, team_dir: pathlib.Path):
teams = [
team
for team in _the_config.teams
if any(submission_email in student for student in team.members)
if any(student.email == submission_email for student in team.members)
]
return team_id, teams

Expand Down
12 changes: 7 additions & 5 deletions krummstab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(self, config_paths: list[Path]) -> None:
team.sort()
self.teams.sort()

self.teams = [Team(team, None) for team in self.teams]
self.teams = [Team([Student(*student) for student in team], None)
for team in self.teams]
_validate_teams(self.teams, self.max_team_size)
logging.info("Processed config successfully.")

Expand All @@ -50,7 +51,8 @@ def get_relevant_teams(self) -> list[Team]:
access relevant teams via `get_relevant_submissions()`.
"""
if self.marking_mode == "static":
return [Team(team, None) for team in self.classes[self.tutor_name]]
return [Team([Student(*student) for student in team], None)
for team in self.classes[self.tutor_name]]
elif self.marking_mode == "exercise":
return self.teams
else:
Expand All @@ -68,9 +70,9 @@ def _validate_teams(teams: list[Team], max_team_size) -> None:
if len(team.members) > max_team_size:
logging.critical(f"Team with size {len(team.members)} violates maximal "
f"team size.")
for first, last, email in team.members:
all_students.append((first, last))
all_emails.append(email)
for member in team.members:
all_students.append((member.first_name, member.last_name))
all_emails.append(member.email)
if len(all_students) != len(set(all_students)):
logging.critical("There are duplicate students in the config file!")
if len(all_emails) != len(set(all_emails)):
Expand Down
16 changes: 16 additions & 0 deletions krummstab/students.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Student:
def __init__(self, first_name: str, last_name: str, email: str):
self.first_name = first_name
self.last_name = last_name
self.email = email

def __eq__(self, other) -> bool:
return (self.first_name == other.first_name
and self.last_name == other.last_name
and self.email == other.email)

def to_tuple(self) -> tuple[str, str, str]:
"""
Get a tuple of strings representation of a student.
"""
return self.first_name, self.last_name, self.email
5 changes: 4 additions & 1 deletion krummstab/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jsonschema

from . import config, schemas, sheets
from .students import Student
from .teams import Team

SUBMISSION_INFO_FILE_NAME = "submission.json"
Expand Down Expand Up @@ -82,7 +83,9 @@ def _load(self):
resources.files(schemas).joinpath("submission-info-schema.json").read_text(encoding="utf-8"))
jsonschema.validate(submission_info, submission_info_schema, jsonschema.Draft7Validator)
self.team = Team(
submission_info.get("team"), submission_info.get("adam_id")
[Student(*student) for student
in submission_info.get("team")],
submission_info.get("adam_id")
)
self.relevant = submission_info.get("relevant")
except FileNotFoundError:
Expand Down
21 changes: 14 additions & 7 deletions krummstab/teams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from typing import Optional

from .students import *


class Team:
def __init__(self, members, adam_id):
def __init__(self, members: list[Student], adam_id: Optional[str] = None):
self.members = members
self.adam_id = adam_id

Expand All @@ -10,13 +15,13 @@ def get_first_names(self) -> list[str]:
"""
Get a list of the first names of all team members.
"""
return [member[0] for member in self.members]
return [member.first_name for member in self.members]

def get_emails(self) -> list[str]:
"""
Get a list of the emails of all team members.
"""
return [member[2] for member in self.members]
return [member.email for member in self.members]

def get_team_key(self) -> str:
"""
Expand All @@ -31,14 +36,16 @@ def last_names_to_string(self) -> str:
representation of a team.
"""
return "_".join(
sorted([member[1].replace(" ", "-") for member in self.members])
sorted(
[member.last_name.replace(" ", "-") for member in self.members]
)
)

def to_tuples(self) -> list[tuple[str, str, str]]:
"""
Get a tuples of strings representation of a team.
"""
return [(member[0], member[1], member[2]) for member in self.members]
return [member.to_tuple() for member in self.members]


def create_email_to_name_dict(teams: list[Team]) -> dict[str, tuple[str, str]]:
Expand All @@ -47,6 +54,6 @@ def create_email_to_name_dict(teams: list[Team]) -> dict[str, tuple[str, str]]:
"""
email_to_name = {}
for team in teams:
for first_name, last_name, email in team.members:
email_to_name[email] = (first_name, last_name)
for member in team.members:
email_to_name[member.email] = (member.first_name, member.last_name)
return email_to_name
Loading