Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/db/models/training_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type TrainingDataset struct {
gorm.Model
Name string `gorm:"type:varchar(255);not null;uniqueIndex"`
AODFiles []jalien.AODFile `gorm:"serializer:json"`
IsONe bool
AnchorProdTimestampFrom time.Time
AnchorProdTimestampTo time.Time
UserId uint
Expand Down
4 changes: 4 additions & 0 deletions internal/handler/queue_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ func (qh *QueueHandler) QueryTask(w http.ResponseWriter, r *http.Request) {
response := struct {
ID uint
AODFiles []jalien.AODFile
IsONe bool
IsData bool
Configuration interface{}
}{
ID: tt.ID,
AODFiles: tt.TrainingDataset.AODFiles,
IsONe: tt.TrainingDataset.IsONe,
IsData: false, // For now we don't use any real experimental data (simulated data only).
Configuration: tt.Configuration,
}

Expand Down
29 changes: 29 additions & 0 deletions internal/service/training_dataset_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func (s *TrainingDatasetService) Create(td *models.TrainingDataset) error {
td.AnchorProdTimestampFrom = timestampFrom
td.AnchorProdTimestampTo = timestampTo

isONe, err := resolveDatasetIsONe(td.AODFiles, s.MonalisaService)
if err != nil {
var external *ErrExternalServiceTimeout
if errors.As(err, &external) {
return err
}
return InternalError("resolve training dataset IsONe", err)
}
td.IsONe = isONe

err = s.TrainingDataset.Create(td)

if err != nil {
Expand Down Expand Up @@ -154,3 +164,22 @@ func (s *TrainingDatasetService) FindAods(path string) ([]jalien.AODFile, error)

return aodFiles, nil
}

func resolveDatasetIsONe(aodFiles []jalien.AODFile, monalisaService IMonalisaService) (bool, error) {
runList, err := monalisaService.GetRunList()
if err != nil {
return false, mapMonalisaError("GetRunList", err)
}

for _, aod := range aodFiles {
if aod.LHCPeriod != "" {
desc := runList.TagToDesc[aod.LHCPeriod]
if strings.Contains(desc, "O-O") || strings.Contains(desc, "OO") ||
strings.Contains(desc, "Ne-Ne") || strings.Contains(desc, "NeNe") {
return true, nil
}
}
}

return false, nil
}
2 changes: 1 addition & 1 deletion test/integration/training_dataset_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func mockDatasetTimestampRange(ut *IntegrationTestUtils, period string, minRun,
TagToRuns: map[string][]uint64{
period: {minRun, maxRun},
},
}, nil).Once()
}, nil)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since IsONe feature is added, the method "GetRunList" is called twice, not once. It had to be removed so the test passes.

ut.CCDB.On("GetRunInformation", minRun).Return(&ccdb.RunInformation{
RunNumber: minRun,
SOR: uint64(time.Now().Add(-time.Hour).UnixMilli()),
Expand Down
2 changes: 1 addition & 1 deletion test/repository/training_dataset_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestTrainingDatasetRepository_Create(t *testing.T) {

mock.ExpectBegin()
mock.ExpectQuery(`INSERT INTO "training_datasets" (.+) RETURNING "id"`).
WithArgs(AnyTime(), AnyTime(), AnyTime(), trainingDataset.Name, marshalAODFiles(t, trainingDataset), AnyTime(), AnyTime(), 1).
WithArgs(AnyTime(), AnyTime(), AnyTime(), trainingDataset.Name, marshalAODFiles(t, trainingDataset), false, AnyTime(), AnyTime(), 1).
WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))
mock.ExpectCommit()

Expand Down
2 changes: 1 addition & 1 deletion test/repository/training_task_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestTrainingTaskRepository_Create(t *testing.T) {

mock.ExpectBegin()
mock.ExpectQuery(`INSERT INTO "training_datasets" (.+) RETURNING "id"`).
WithArgs(AnyTime(), AnyTime(), AnyTime(), trainingDataset.Name, marshalAODFiles(t, trainingDataset), AnyTime(), AnyTime(), 1).
WithArgs(AnyTime(), AnyTime(), AnyTime(), trainingDataset.Name, marshalAODFiles(t, trainingDataset), false, AnyTime(), AnyTime(), 1).
WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))
mock.ExpectQuery(`INSERT INTO "training_tasks" (.+) RETURNING "id"`).
WithArgs(AnyTime(), AnyTime(), AnyTime(), trainingTask.Name, trainingTask.Status, 1, 1, nil, marshalTrainingTaskConfig(t, trainingTask)).
Expand Down
Loading