Skip to content

Commit

Permalink
Remove lms_url from DBStructuredGradingCriterion and update related q…
Browse files Browse the repository at this point in the history
…ueries
  • Loading branch information
LeonWehrhahn committed Jan 30, 2025
1 parent c0ee4d2 commit f6259c4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
1 change: 0 additions & 1 deletion athena/athena/models/db_structured_grading_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ class DBStructuredGradingCriterion(Base):
exercise_id = Column(BigIntegerWithAutoincrement, ForeignKey("exercise.id", ondelete="CASCADE"), index=True, unique=True) # Only one cached instruction per exercise
instructions_hash = Column(String, nullable=False)
structured_grading_criterion = Column(JSON, nullable=False)
lms_url = Column(String, nullable=False)

exercise = relationship("DBExercise", back_populates="structured_grading_criterion")
1 change: 0 additions & 1 deletion athena/athena/schemas/grading_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class StructuredGradingInstruction(Schema, ABC):
"""Part of a grading criterion (called "GradingInstruction" in LMS)."""

id: int = Field(example=1)
credits: float = Field(description="The number of credits assigned for this feedback.", example=1.0)
grading_scale: str = Field(description="The grading outcome for this instruction.", example="Weak example", default="")
Expand Down
7 changes: 3 additions & 4 deletions athena/athena/storage/structured_grading_criterion_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
def get_structured_grading_criterion(exercise_id: int, current_hash: Optional[str] = None) -> Optional[StructuredGradingCriterion]:
lms_url = get_lms_url()
with get_db() as db:
cache_entry = db.query(DBStructuredGradingCriterion).filter_by(
exercise_id=exercise_id, lms_url=lms_url
cache_entry = db.query(DBStructuredGradingCriterion).filter(
DBStructuredGradingCriterion.exercise_id == exercise_id,
DBStructuredGradingCriterion.exercise.has(lms_url=lms_url)
).first()
if cache_entry is not None and (current_hash is None or cache_entry.instructions_hash == current_hash): # type: ignore
return StructuredGradingCriterion.parse_obj(cache_entry.structured_grading_criterion)
Expand All @@ -18,12 +19,10 @@ def get_structured_grading_criterion(exercise_id: int, current_hash: Optional[st
def store_structured_grading_criterion(
exercise_id: int, hash: str, structured_instructions: StructuredGradingCriterion
):
lms_url = get_lms_url()
with get_db() as db:
db.merge(
DBStructuredGradingCriterion(
exercise_id=exercise_id,
lms_url=lms_url,
instructions_hash=hash,
structured_grading_criterion=structured_instructions.dict(),
)
Expand Down

0 comments on commit f6259c4

Please sign in to comment.