def get_all_assessment_items()

in common_ml/src/common_ml/item_selection.py [0:0]


def get_all_assessment_items(learning_unit_id: str, activity_type: str,
                             reviewed, disable_items: dict = None) -> list:
  """
  Returns all assessments for a given lu and activity

  Parameters
  ----------
  learning_unit_id: str
  activity_type: str
  disable_items: dict
  reviewed: bool

  Returns
  -------
  assessments: list
  """
  learning_unit = LearningUnit.find_by_id(learning_unit_id)
  if activity_type == "choose_the_fact" and reviewed is not None:
    items = ChooseTheFactItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).filter(reviewed=True).fetch()
  elif activity_type == "choose_the_fact" and reviewed is None:
    items = ChooseTheFactItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).fetch()
  elif activity_type == "answer_a_question" and reviewed is not None:
    items = AnswerAQuestionItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).filter(reviewed=True).fetch()
  elif activity_type == "answer_a_question" and reviewed is None:
    items = AnswerAQuestionItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).fetch()
  elif activity_type == "paraphrasing_practice" and reviewed is not None:
    items = ParaphrasingPracticeItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).filter(reviewed=True).fetch()
  elif activity_type == "paraphrasing_practice" and reviewed is None:
    items = ParaphrasingPracticeItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).fetch()
  elif activity_type == "create_knowledge_notes" and reviewed is not None:
    items = CreateKnowledgeNotesItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).filter(reviewed=True).fetch()
  elif activity_type == "create_knowledge_notes" and reviewed is None:
    items = CreateKnowledgeNotesItem.collection.filter(
      learning_unit=learning_unit.key).filter(
      flag_problematic_question=False).fetch()
  else:
    raise Exception("Invalid activity type")

  if disable_items and activity_type in disable_items:
    filter_types = disable_items[activity_type]
    items = [item for item in items if item.question_type not in filter_types]
  return list(items)