<commit_before>package models.quiz.question

import com.artclod.mathml.slick.MathMLMapper.string2mathML
import com.artclod.slick.NumericBoolean
import com.artclod.slick.JodaUTC.timestamp2DateTime
import com.artclod.slick.NumericBoolean
import com.artclod.tuple._
import models.quiz._
import models.quiz.answer.Answer
import models.quiz.answer.table.AnswersTable
import models.quiz.question.table.QuestionsTable
import models.quiz.table._
import models.support._
import models.user.User
import org.joda.time.DateTime
import play.api.db.slick.Config.driver.simple._
import com.artclod.util.optionElse

import scala.language.postfixOps

object Questions {

  // ======= FIND ======
  def list()(implicit session: Session) : List[Question] =
    questionTables.->(_.list, _.list, _.list, _.list, _.list)
      .toList[Question](a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]])

  def apply(questionId: QuestionId)(implicit session: Session) : Option[Question] =
    questionTables.->(
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list)
      .toList[Question](a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]])
      .headOption

  // ======= REMOVE ======
  def remove(quiz: Quiz, question: Question)(implicit session: Session) =
    question match {
      case q: DerivativeQuestion => DerivativeQuestions.remove(quiz, q)
      case q: DerivativeGraphQuestion => DerivativeGraphQuestions.remove(quiz, q)
      case q: TangentQuestion => TangentQuestions.remove(quiz, q)
      case q: GraphMatchQuestion => GraphMatchQuestions.remove(quiz, q)
    }

  // ======= RESULTS ======
  def results(user: User, asOfOp: Option[DateTime] = None, quizOp: Option[Quiz] = None)(implicit session: Session) : List[QuestionResults] =
    questionAndAnswerTables.->(
      t => DerivativeQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => DerivativeGraphQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => TangentQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => GraphMatchQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => PolynomialZoneQuestions.results(user, asOfOp, quizOp)(t.question, t.answer))
      .toList[QuestionResults](a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]])

  def correctResults(user: User, num: Int)(implicit session: Session) : List[(QuestionResults, DateTime)] =
    questionAndAnswerTables.->(
      t => DerivativeQuestions.correctResults(user, num)(t.question, t.answer),
      t => DerivativeGraphQuestions.correctResults(user, num)(t.question, t.answer),
      t => TangentQuestions.correctResults(user, num)(t.question, t.answer),
      t => GraphMatchQuestions.correctResults(user, num)(t.question, t.answer),
      t => PolynomialZoneQuestions.correctResults(user, num)(t.question, t.answer))<commit_msg>fixing remove functionality for Poly Zone question<commit_after>package models.quiz.question

import com.artclod.mathml.slick.MathMLMapper.string2mathML
import com.artclod.slick.NumericBoolean
import com.artclod.slick.JodaUTC.timestamp2DateTime
import com.artclod.slick.NumericBoolean
import com.artclod.tuple._
import models.quiz._
import models.quiz.answer.Answer
import models.quiz.answer.table.AnswersTable
import models.quiz.question.table.QuestionsTable
import models.quiz.table._
import models.support._
import models.user.User
import org.joda.time.DateTime
import play.api.db.slick.Config.driver.simple._
import com.artclod.util.optionElse

import scala.language.postfixOps

object Questions {

  // ======= FIND ======
  def list()(implicit session: Session) : List[Question] =
    questionTables.->(_.list, _.list, _.list, _.list, _.list)
      .toList[Question](a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]])

  def apply(questionId: QuestionId)(implicit session: Session) : Option[Question] =
    questionTables.->(
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list,
      _.where(_.id === questionId).list)
      .toList[Question](a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]], a => a.asInstanceOf[List[Question]])
      .headOption

  // ======= REMOVE ======
  def remove(quiz: Quiz, question: Question)(implicit session: Session) =
    question match {
      case q: DerivativeQuestion => DerivativeQuestions.remove(quiz, q)
      case q: DerivativeGraphQuestion => DerivativeGraphQuestions.remove(quiz, q)
      case q: TangentQuestion => TangentQuestions.remove(quiz, q)
      case q: GraphMatchQuestion => GraphMatchQuestions.remove(quiz, q)
      case q: PolynomialZoneQuestion => PolynomialZoneQuestions.remove(quiz, q)
    }

  // ======= RESULTS ======
  def results(user: User, asOfOp: Option[DateTime] = None, quizOp: Option[Quiz] = None)(implicit session: Session) : List[QuestionResults] =
    questionAndAnswerTables.->(
      t => DerivativeQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => DerivativeGraphQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => TangentQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => GraphMatchQuestions.results(user, asOfOp, quizOp)(t.question, t.answer),
      t => PolynomialZoneQuestions.results(user, asOfOp, quizOp)(t.question, t.answer))
      .toList[QuestionResults](a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]], a => a.asInstanceOf[List[QuestionResults]])

  def correctResults(user: User, num: Int)(implicit session: Session) : List[(QuestionResults, DateTime)] =
    questionAndAnswerTables.->(
      t => DerivativeQuestions.correctResults(user, num)(t.question, t.answer),
      t => DerivativeGraphQuestions.correctResults(user, num)(t.question, t.answer),
      t => TangentQuestions.correctResults(user, num)(t.question, t.answer),
      t => GraphMatchQuestions.correctResults(user, num)(t.question, t.answer),
      t => PolynomialZoneQuestions.correctResults(user, num)(t.question, t.answer))
{'fraction_non_alphanumeric': 0.1527918049343529, 'fraction_numerical': 0.0005771172990910403, 'mean_word_length': 4.894557823129252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3092453', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2155, 'n_words': 398}