/**
   * returns all the open Calibrations needed from the worker
   *
   * @param experimentID the experiment
   * @param platformID the id of the platform
   * @param worker the worker
   * @return a map where the keys are the detailed population the worker may belong to and the
   *     values are the answerOptions
   */
  public Map<CalibrationRecord, Result<CalibrationAnswerOptionRecord>> getCalibrations(
      int experimentID, String platformID, int worker) {
    SelectConditionStep<Record1<Integer>> alreadyAnsweredCalibrations =
        DSL.select(CALIBRATION_ANSWER_OPTION.CALIBRATION)
            .from(Tables.CALIBRATION_ANSWER_OPTION)
            .join(Tables.CALIBRATION_RESULT)
            .onKey()
            .where(Tables.CALIBRATION_RESULT.WORKER.eq(worker));

    Map<CalibrationRecord, Result<Record>> calibrationAndAnswers =
        create
            .select(CALIBRATION.fields())
            .select(CALIBRATION_ANSWER_OPTION.fields())
            .from(Tables.CALIBRATION_ANSWER_OPTION)
            .join(Tables.CALIBRATION)
            .onKey()
            // we want all the calibrations
            .where(
                CALIBRATION.ID_CALIBRATION.in(
                    // which belong to the chosen answer-option
                    DSL.select(CALIBRATION_ANSWER_OPTION.CALIBRATION)
                        .from(CALIBRATION_ANSWER_OPTION)
                        .where(
                            CALIBRATION_ANSWER_OPTION.ID_CALIBRATION_ANSWER_OPTION.in(
                                // from the experiment
                                DSL.select(EXPERIMENTS_CALIBRATION.ANSWER)
                                    .from(EXPERIMENTS_CALIBRATION)
                                    .where(
                                        EXPERIMENTS_CALIBRATION.EXPERIMENTS_PLATFORM.eq(
                                            // from the platform
                                            DSL.select(EXPERIMENTS_PLATFORM.IDEXPERIMENTS_PLATFORMS)
                                                .from(EXPERIMENTS_PLATFORM)
                                                .where(
                                                    EXPERIMENTS_PLATFORM.EXPERIMENT.eq(
                                                        experimentID))
                                                .and(
                                                    EXPERIMENTS_PLATFORM.PLATFORM.eq(
                                                        platformID))))))))
            .and(Tables.CALIBRATION.ID_CALIBRATION.notIn(alreadyAnsweredCalibrations))
            .fetchGroups(Tables.CALIBRATION);

    return mapMap(
        calibrationAndAnswers, result -> result.into(Tables.CALIBRATION_ANSWER_OPTION.asTable()));
  }