Skip to content

Commit

Permalink
chore: pull and consume block and workflow apis
Browse files Browse the repository at this point in the history
  • Loading branch information
muselesscreator committed Aug 16, 2023
1 parent 7b18a71 commit fb4d7eb
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 146 deletions.
33 changes: 17 additions & 16 deletions openassessment/xblock/api/assessments/peer_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
)
from ..resolve_dates import DISTANT_FUTURE
from .problem_closed import ProblemClosedAPI
from .workflow import WorkflowAPI
from ..workflow import WorkflowAPI
from ..block import BlockAPI

class PeerAssessmentAPI:
def __init__(self, block):
self.block = block:
self._raw_block
self._block = BlockAPI(block)
self._is_closed = ProblemClosedAPI(block.is_closed(step="self-assessment"))
self._workflow = WorkflowAPI(block):

Expand Down Expand Up @@ -50,13 +52,9 @@ def is_cancelled(self):
def is_complete(self):
return self._workflow.is_done

@property
def student_item(self):
return self.block.get_student_item_dict()

@property
def file_upload_type(self):
return self.block.file_upload_type
return self._block.file_upload_type

@property
def is_past_due(self):
Expand All @@ -71,9 +69,9 @@ def is_peer
return self._workflow.is_peer

def format_submission_for_publish(self, submission):
student_item_dict = this.student_item
student_item_dict = self._block.student_item_dict
peer_submission = peer_api.get_submission_to_assess(
self.block.submission_uuid,
self._block.submission_uuid,
self.assessment["must_be_graded_by"]
)
return {
Expand All @@ -84,14 +82,14 @@ def format_submission_for_publish(self, submission):
}

def get_submission_dict(self, peer_sub):
return create_submission_dict(peer_sub, self.block.prompts)
return create_submission_dict(peer_sub, self._block.prompts)

def get_download_urls(self, peer_sub):
return self.block.get_download_urls_from_submission(peer_sub)
return self._raw_block.get_download_urls_from_submission(peer_sub)

def get_peer_submission(self):
return peer_api.get_submission_to_assess(
self.block.submission_uuid,
self._block.submission_uuid,
self.assessment["must_be_graded_by"]
)

Expand All @@ -101,10 +99,13 @@ def assessment_ui_model(self):

def create_assessment(self, data):
return peer_api.create_assessment(
self.bock.submission_uuid,
self.student_item["student_id"],
self._block.submission_uuid,
self._block.student_item_dict["student_id"],
data["options_selected"],
clean_criterion_feedback(self.block.rubric_criteria_with_labels, data["criterion_feedback"]),
create_rubric_dict(self.block.prompts, self.block.rubric_criteria_with_labels),
clean_criterion_feedback(
self._block.rubric_criteria_with_labels,
data["criterion_feedback"]
),
create_rubric_dict(self._block.prompts, self._block.rubric_criteria_with_labels),
self.assessment_ui_model["must_be_graded_by"]
)
20 changes: 11 additions & 9 deletions openassessment/xblock/api/assessments/self_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
)
from ..resolve_dates import DISTANT_FUTURE
from .problem_closed import ProblemClosedAPI
from .workflow import WorkflowAPI
from ..workflow import WorkflowAPI
from ..block import BlockAPI

class SelfAssessmentAPI:
def __init__(self, block):
self.block = block:
self._raw_block = block:
self._block = BlockAPI(block)
self._is_closed = ProblemClosedAPI(block.is_closed(step="self-assessment"))
self._workflow = WorkflowAPI(block):

Expand Down Expand Up @@ -56,22 +58,22 @@ def assessment(self):

@property
def submission(self):
return submission_api.get_submission(self.block.submission_uuid)
return submission_api.get_submission(self._block.submission_uuid)

@property
def submission_dict(self):
return create_submission_dict(self.submission, self.block.prompts)
return create_submission_dict(self.submission, self._block.prompts)

@property
def file_urls(self):
return self.block.get_download_urls_from_submission(self.submission)
return self._raw_block.get_download_urls_from_submission(self.submission)

def create_assessment(self, data):
return self_api.create_assessment(
self.block.submission_uuid,
self.block.get_student_item_dict()['student_id'],
self._block.submission_uuid,
self._block.student_item_dict['student_id'],
data['options_selected'],
clean_criterion_feedback(self.block.rubric_criteria, data['criterion_feedback']),
clean_criterion_feedback(self._block.rubric_criteria, data['criterion_feedback']),
data['overall_feedback'],
create_rubric_dict(self.prompts, self.rubric_criteria_with_labels)
create_rubric_dict(self._block.prompts, self._block.rubric_criteria_with_labels)
)
11 changes: 6 additions & 5 deletions openassessment/xblock/api/assessments/staff_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@

class StaffAssessmentAPI:
def __init__(self, block):
self.block = block:
self._raw_block = block
self._block = BlockAPI(block)


@property
def student_id(self):
return self.block.get_student_item_dict()['student_id']
return self._block.student_item_dict['student_id']

@property
def rubric_dict(self):
return create_rubric_dict(self.block.prompts, self.rubric_criteria_with_labels)
return create_rubric_dict(self._block.prompts, self._block.rubric_criteria_with_labels)

def create_team_assessment(self, data):
team_submission = team_sub_api.get_team_submission_from_individual(data['submission_uuid'])
return teams_api.create_assessment(
team_submission['team_submission_uuid']
self.student_id,
data['options_selected'],
clean_criterion_feedback(self.block.rubric_criteria, data['criterion_feedback']),
clean_criterion_feedback(self._block.rubric_criteria, data['criterion_feedback']),
data['overall_feedback'],
self.rubric_dict
), team_submission['team_submission_uuid']
Expand All @@ -44,7 +45,7 @@ def create_assessment(self, data):
data['submission_uuid'],
self.student_id,
data['options_selected'],
clean_criterion_feedback(self.block.rubric_criteria, data['criterion_feedback']),
clean_criterion_feedback(self._block.rubric_criteria, data['criterion_feedback']),
data['overall_feedback'],
self.rubric_dict
)
Expand Down
18 changes: 10 additions & 8 deletions openassessment/xblock/api/assessments/student_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
)
from ..resolve_dates import DISTANT_FUTURE
from .problem_closed import ProblemClosedAPI
from .workflow import WorkflowAPI
from ..workflow import WorkflowAPI
from ..block import BlockAPI

class StudentTrainingAPI:
def __init__(self, block):
self.block = block:
self._raw_block = block
self._block = BlockAPI(block)
self._is_closed = ProblemClosedAPI(block.is_closed(step="self-assessment"))
self._workflow = WorkflowAPI(block):

Expand Down Expand Up @@ -52,15 +54,15 @@ def is_not_available_yet(self):

@property
def training_module(self):
return self.block.get_assessment_module('student_training')
return self._block.get_assessment_module('student_training')

@property
def num_available(self):
return len(self.training_module['examples'])

@property
def num_completed(self):
return self.student_training.get_num_completed(self.block.submission_uuid)
return self.student_training.get_num_completed(self._block.submission_uuid)

@property
def examples(self):
Expand All @@ -69,8 +71,8 @@ def examples(self):
@property
def example(self):
return self.student_training.get_training_example(
self.block.submission_uuid,
{'prompt': self.prompt, 'criteria': self.block.rubric_criteria_with_labels},
self._block.submission_uuid,
{'prompt': self.prompt, 'criteria': self._block.rubric_criteria_with_labels},
self.examples
)

Expand All @@ -94,7 +96,7 @@ def _parse_answer_dict(self, answer):
parts = answer.get('parts', [])
if parts and isinstance(parts[0], dict):
if isinstance(parts[0].get('text'), str):
return create_submission_dict({'answer': answer}, self.block.prompts)
return create_submission_dict({'answer': answer}, self._block.prompts)
return None

def _parse_answer_list(self, answer):
Expand All @@ -111,7 +113,7 @@ def _parse_answer_string(self, answer):
"""
Helper to parse answer as a plain string
"""
return create_submission_dict({'answer': {'parts': [{'text': answer}]}}, self.block.prompts)
return create_submission_dict({'answer': {'parts': [{'text': answer}]}}, self._block.prompts)

def _parse_example(self, example):
"""
Expand Down
52 changes: 0 additions & 52 deletions openassessment/xblock/api/assessments/workflow.py

This file was deleted.

Loading

0 comments on commit fb4d7eb

Please sign in to comment.