Skip to content

Commit

Permalink
Jerahmeel: add task to delete problem
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Dec 20, 2024
1 parent 51df95c commit b7bfc0c
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ private void runJerahmeel(JudgelsServerApplicationConfiguration config, Environm
component.gradingResponsePoller());
}

env.admin().addTask(component.deleteProblemTask());
env.admin().addTask(component.moveProblemToChapterTask());
env.admin().addTask(component.problemSetStatsTask());
env.admin().addTask(component.contestStatsTask());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import judgels.jerahmeel.course.chapter.CourseChapterResource;
import judgels.jerahmeel.curriculum.CurriculumResource;
import judgels.jerahmeel.hibernate.JerahmeelHibernateDaoModule;
import judgels.jerahmeel.problem.DeleteProblemTask;
import judgels.jerahmeel.problem.MoveProblemToChapterTask;
import judgels.jerahmeel.problem.ProblemModule;
import judgels.jerahmeel.problem.ProblemResource;
Expand Down Expand Up @@ -86,6 +87,7 @@ public interface JerahmeelComponent {
JudgelsScheduler scheduler();
GradingResponsePoller gradingResponsePoller();

DeleteProblemTask deleteProblemTask();
MoveProblemToChapterTask moveProblemToChapterTask();
ProblemSetStatsTask problemSetStatsTask();
ContestStatsTask contestStatsTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import judgels.jerahmeel.persistence.ProgrammingGradingModel;
import judgels.persistence.hibernate.HibernateDaoData;
import judgels.sandalphon.hibernate.AbstractProgrammingGradingHibernateDao;
import org.hibernate.query.Query;

public class ProgrammingGradingHibernateDao extends AbstractProgrammingGradingHibernateDao<
ProgrammingGradingModel> implements ProgrammingGradingDao {
Expand All @@ -23,4 +24,15 @@ public ProgrammingGradingModel createGradingModel() {
public Class<ProgrammingGradingModel> getGradingModelClass() {
return ProgrammingGradingModel.class;
}

@Override
public void deleteAllByProblemJid(String problemJid) {
Query<?> query = currentSession().createQuery(
"DELETE FROM jerahmeel_programming_grading "
+ "WHERE submissionJid IN ("
+ "SELECT jid FROM jerahmeel_programming_submission WHERE problemJid = :problemJid) ");

query.setParameter("problemJid", problemJid);
query.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public ProgrammingSubmissionModel createSubmissionModel() {
}

@Override
public void updateContainer(String problemJid, String containerJid) {
Query query = currentSession().createQuery(
public void updateContainerJid(String problemJid, String containerJid) {
Query<?> query = currentSession().createQuery(
"UPDATE jerahmeel_programming_submission "
+ "SET containerJid = :containerJid "
+ "WHERE problemJid = :problemJid");
Expand All @@ -32,4 +32,14 @@ public void updateContainer(String problemJid, String containerJid) {
query.setParameter("problemJid", problemJid);
query.executeUpdate();
}

@Override
public void deleteAllByProblemJid(String problemJid) {
Query<?> query = currentSession().createQuery(
"DELETE FROM jerahmeel_programming_submission "
+ "WHERE problemJid = :problemJid");

query.setParameter("problemJid", problemJid);
query.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import judgels.persistence.QueryBuilder;
import judgels.persistence.hibernate.HibernateDao;
import judgels.persistence.hibernate.HibernateDaoData;
import org.hibernate.query.Query;

public class StatsUserProblemHibernateDao extends HibernateDao<StatsUserProblemModel> implements StatsUserProblemDao {
private final Clock clock;
Expand Down Expand Up @@ -193,4 +194,14 @@ public Map<String, Long> selectCountsVerdictByUserJid(String userJid) {
.stream()
.collect(Collectors.toMap(tuple -> tuple.get(0, String.class), tuple -> tuple.get(1, Long.class)));
}

@Override
public void deleteAllByProblemJid(String problemJid) {
Query<?> query = currentSession().createQuery(
"DELETE FROM jerahmeel_stats_user_problem "
+ "WHERE problemJid = :problemJid");

query.setParameter("problemJid", problemJid);
query.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface StatsUserProblemDao extends Dao<StatsUserProblemModel> {
long selectCountTriedByUserJid(String userJid);
int selectTotalScoreByUserJid(String userJid);
Map<String, Long> selectCountsVerdictByUserJid(String userJid);
void deleteAllByProblemJid(String problemJid);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package judgels.jerahmeel.problem;

import io.dropwizard.hibernate.UnitOfWork;
import io.dropwizard.servlets.tasks.Task;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
import judgels.jerahmeel.persistence.ProgrammingGradingDao;
import judgels.jerahmeel.persistence.ProgrammingSubmissionDao;
import judgels.jerahmeel.persistence.StatsUserProblemDao;
import judgels.sandalphon.persistence.ProblemDao;
import judgels.sandalphon.persistence.ProblemModel;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class DeleteProblemTask extends Task {
private final ProblemDao problemDao;
private final ChapterProblemDao chapterProblemDao;
private final ProblemSetProblemDao problemSetProblemDao;
private final ProgrammingSubmissionDao programmingSubmissionDao;
private final ProgrammingGradingDao programmingGradingDao;
private final StatsUserProblemDao statsUserProblemDao;

public DeleteProblemTask(
ProblemDao problemDao,
ChapterProblemDao chapterProblemDao,
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
StatsUserProblemDao statsUserProblemDao) {

super("jerahmeel-delete-problem");

this.problemDao = problemDao;
this.chapterProblemDao = chapterProblemDao;
this.problemSetProblemDao = problemSetProblemDao;
this.programmingSubmissionDao = programmingSubmissionDao;
this.programmingGradingDao = programmingGradingDao;
this.statsUserProblemDao = statsUserProblemDao;
}

@Override
@UnitOfWork
public void execute(Map<String, List<String>> parameters, PrintWriter out) {
List<String> problemSlugs = parameters.get("problemSlug");
if (problemSlugs == null || problemSlugs.isEmpty()) {
return;
}
String problemSlug = problemSlugs.get(0);

Optional<ProblemModel> maybeProblemModel = problemDao.selectBySlug(problemSlug);
if (maybeProblemModel.isEmpty()) {
return;
}
String problemJid = maybeProblemModel.get().jid;

statsUserProblemDao.deleteAllByProblemJid(problemJid);
programmingGradingDao.deleteAllByProblemJid(problemJid);
programmingSubmissionDao.deleteAllByProblemJid(problemJid);
chapterProblemDao.selectByProblemJid(problemJid).ifPresent(chapterProblemDao::delete);
problemSetProblemDao.selectAllByProblemJid(problemJid).forEach(problemSetProblemDao::delete);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public void execute(Map<String, List<String>> parameters, PrintWriter out) {
List<ProblemSetProblemModel> problemSetProblemModels = problemSetProblemDao.selectAllByProblemJid(problemJid);
problemSetProblemModels.forEach(problemSetProblemDao::delete);

programmingSubmissionDao.updateContainer(problemJid, toChapterJid);
programmingSubmissionDao.updateContainerJid(problemJid, toChapterJid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,44 @@
import judgels.jerahmeel.persistence.ChapterDao;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
import judgels.jerahmeel.persistence.ProgrammingGradingDao;
import judgels.jerahmeel.persistence.ProgrammingSubmissionDao;
import judgels.jerahmeel.persistence.StatsUserProblemDao;
import judgels.sandalphon.persistence.ProblemDao;

@Module
public class ProblemModule {
private ProblemModule() {}

@Provides
@Singleton
static DeleteProblemTask deleteProblemTask(
UnitOfWorkAwareProxyFactory unitOfWorkAwareProxyFactory,
ProblemDao problemDao,
ChapterProblemDao chapterProblemDao,
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
StatsUserProblemDao statsUserProblemDao) {

return unitOfWorkAwareProxyFactory.create(
DeleteProblemTask.class,
new Class<?>[] {
ProblemDao.class,
ChapterProblemDao.class,
ProblemSetProblemDao.class,
ProgrammingSubmissionDao.class,
ProgrammingGradingDao.class,
StatsUserProblemDao.class},
new Object[] {
problemDao,
chapterProblemDao,
problemSetProblemDao,
programmingSubmissionDao,
programmingGradingDao,
statsUserProblemDao});
}

@Provides
@Singleton
static MoveProblemToChapterTask problemMoveToChapterTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,13 @@ public Map<String, M> selectAllLatestWithDetailsBySubmissionJids(Collection<Stri
}

@Override
public void dump(PrintWriter output, Collection<String> submissionJids) {
List<M> results = select().where(columnIn(AbstractProgrammingGradingModel_.submissionJid, submissionJids)).orderBy(Model_.ID, OrderDir.ASC).all();
if (results.isEmpty()) {
return;
}
public void deleteAllByProblemJid(String problemJid) {
throw new UnsupportedOperationException();
}

output.write("INSERT IGNORE INTO uriel_contest_programming_grading (jid, submissionJid, verdictCode, verdictName, score, details, createdBy, createdAt, updatedAt) VALUES\n");

for (int i = 0; i < results.size(); i++) {
M m = results.get(i);
if (i > 0) {
output.write(",\n");
}
output.write(String.format("(%s, %s, %s, %s, %s, %s, %s, %s, %s)",
escape(m.jid),
escape(m.submissionJid),
escape(m.verdictCode),
escape(""),
escape(m.score),
escape(m.details),
escape(m.createdBy),
escape(m.createdAt),
escape(m.updatedAt)));
}
output.write(";\n");

@Override
public void dump(PrintWriter output, Collection<String> submissionJids) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public Map<String, Long> selectCounts(String containerJid, String userJid, Colle
}

@Override
public void updateContainer(String problemJid, String containerJid) {
public void updateContainerJid(String problemJid, String containerJid) {
throw new UnsupportedOperationException();
}

@Override
public void deleteAllByProblemJid(String problemJid) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface BaseProgrammingGradingDao<M extends AbstractProgrammingGradingM
Optional<M> selectLatestBySubmissionJid(String submissionJid);
Map<String, M> selectAllLatestBySubmissionJids(Collection<String> submissionJids);
Map<String, M> selectAllLatestWithDetailsBySubmissionJids(Collection<String> submissionJids);
void deleteAllByProblemJid(String problemJid);
void dump(PrintWriter output, Collection<String> submissionJids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public interface BaseProgrammingSubmissionDao<M extends AbstractProgrammingSubmi
M createSubmissionModel();
BaseProgrammingSubmissionQueryBuilder<M> select();
Map<String, Long> selectCounts(String containerJid, String userJid, Collection<String> problemJids);
void updateContainer(String problemJid, String containerJid);
void updateContainerJid(String problemJid, String containerJid);
void deleteAllByProblemJid(String problemJid);
Collection<String> dump(PrintWriter output, String containerJid);

interface BaseProgrammingSubmissionQueryBuilder<M extends AbstractProgrammingSubmissionModel> extends QueryBuilder<M> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package judgels.uriel.hibernate;

import javax.inject.Inject;
import judgels.persistence.Model_;
import judgels.persistence.api.OrderDir;
import judgels.persistence.hibernate.HibernateDaoData;
import judgels.sandalphon.hibernate.AbstractProgrammingGradingHibernateDao;
import judgels.sandalphon.persistence.AbstractProgrammingGradingModel_;
import judgels.uriel.persistence.ContestProgrammingGradingDao;
import judgels.uriel.persistence.ContestProgrammingGradingModel;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;

public class ContestProgrammingGradingHibernateDao extends AbstractProgrammingGradingHibernateDao<
ContestProgrammingGradingModel> implements ContestProgrammingGradingDao {
Expand All @@ -23,4 +29,33 @@ public ContestProgrammingGradingModel createGradingModel() {
public Class<ContestProgrammingGradingModel> getGradingModelClass() {
return ContestProgrammingGradingModel.class;
}

@Override
public void dump(PrintWriter output, Collection<String> submissionJids) {
List<ContestProgrammingGradingModel> results = select().where(columnIn(AbstractProgrammingGradingModel_.submissionJid, submissionJids)).orderBy(
Model_.ID, OrderDir.ASC).all();
if (results.isEmpty()) {
return;
}

output.write("INSERT IGNORE INTO uriel_contest_programming_grading (jid, submissionJid, verdictCode, verdictName, score, details, createdBy, createdAt, updatedAt) VALUES\n");

for (int i = 0; i < results.size(); i++) {
ContestProgrammingGradingModel m = results.get(i);
if (i > 0) {
output.write(",\n");
}
output.write(String.format("(%s, %s, %s, %s, %s, %s, %s, %s, %s)",
escape(m.jid),
escape(m.submissionJid),
escape(m.verdictCode),
escape(""),
escape(m.score),
escape(m.details),
escape(m.createdBy),
escape(m.createdAt),
escape(m.updatedAt)));
}
output.write(";\n");
}
}

0 comments on commit b7bfc0c

Please sign in to comment.