package edu.mit.csail.db.ml.server.algorithm;

import edu.mit.csail.db.ml.server.storage.ProblemTypeConverter;
import jooq.sqlite.gen.Tables;
import modeldb.ProblemType;
import org.jooq.DSLContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProblemTypeGrouper {
  public static Map<ProblemType, List<Integer>> groupByProblemType(List<Integer> modelIds, DSLContext ctx) {
    Map<ProblemType, List<Integer>> modelIdsForType = new HashMap<>();

    ctx
      .select(Tables.FITEVENT.TRANSFORMER, Tables.FITEVENT.PROBLEMTYPE)
      .from(Tables.FITEVENT)
      .where(Tables.FITEVENT.TRANSFORMER.in(modelIds))
      .fetch()
      .into(pair -> {
        ProblemType ptype = ProblemTypeConverter.fromString(pair.value2());
        if (!modelIdsForType.containsKey(ptype)) {
          modelIdsForType.put(ptype, new ArrayList<>());
        }
        modelIdsForType.get(ptype).add(pair.value1());
      });

    return modelIdsForType;
  }
}

@@ -326,16 +326,269 @@
 ouper %7B%0A
+  /**%0A   * Given a list of model IDs, group them by problem type.%0A   * @param modelIds - The IDs of models.%0A   * @param ctx - The database context.%0A   * @return A map from ProblemType to a list of the IDs of the models of that given problem type.%0A   */%0A
   public

Comment ProblemTypeGrouper