test metrics insert 로직 수정

This commit is contained in:
2026-02-20 14:24:23 +09:00
parent 37786a1e44
commit db2bc32e7d

View File

@@ -65,16 +65,48 @@ public class ModelTestMetricsJobRepositoryImpl extends QuerydslRepositorySupport
@Override
public void insertModelMetricsTest(List<Object[]> batchArgs) {
String sql =
"""
insert into tb_model_metrics_test
(model_id, model, tp, fp, fn, precisions, recall, f1_score, accuracy, iou,
detection_count, gt_count
)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""";
// AS-IS
// String sql =
// """
// insert into tb_model_metrics_test
// (model_id, model, tp, fp, fn, precisions, recall, f1_score, accuracy, iou,
// detection_count, gt_count
// )
// values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
// """;
//
// jdbcTemplate.batchUpdate(sql, batchArgs);
jdbcTemplate.batchUpdate(sql, batchArgs);
// TO-BE: modelId, model(best_fscore_10) 같은 데이터가 있으면 update, 없으면 insert
String updateSql =
"""
UPDATE tb_model_metrics_test
SET tp=?, fp=?, fn=?, precisions=?, recall=?, f1_score=?, accuracy=?, iou=?,
detection_count=?, gt_count=?
WHERE model_id=? AND model=?
""";
String insertSql =
"""
INSERT INTO tb_model_metrics_test
(model_id, model, tp, fp, fn, precisions, recall, f1_score, accuracy, iou,
detection_count, gt_count)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""";
// row 단위 처리 (batch 안에서 upsert)
for (Object[] row : batchArgs) {
// row 순서: (model_id, model, tp, fp, fn, precisions, recall, f1_score, accuracy, iou,
// detection_count, gt_count)
int updated =
jdbcTemplate.update(
updateSql, row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10],
row[11], row[0], row[1]);
if (updated == 0) {
jdbcTemplate.update(insertSql, row);
}
}
}
@Override
@@ -99,11 +131,9 @@ public class ModelTestMetricsJobRepositoryImpl extends QuerydslRepositorySupport
.on(
modelMetricsTestEntity.model.eq(modelMetricsTrainEntity.model),
modelMasterEntity.bestEpoch.eq(modelMetricsTrainEntity.epoch))
.where(
modelMetricsTestEntity.model.id.eq(modelId),
modelMetricsTestEntity.model1.eq(
"best_changed_fscore_epoch_" + modelMasterEntity.bestEpoch))
.fetchOne();
.where(modelMetricsTestEntity.model.id.eq(modelId))
.orderBy(modelMetricsTestEntity.createdDttm.desc())
.fetchFirst();
}
@Override