Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.breedinginsight.brapps.importer.services.processors.experiment.appendoverwrite.middleware.process;

import io.micronaut.context.annotation.Prototype;
import lombok.Setter;
import org.breedinginsight.brapps.importer.model.response.ImportPreviewStatistics;

import java.util.HashSet;
Expand All @@ -32,6 +33,8 @@ public class AppendStatistic {
private int newCount;
private int existingCount;
private int mutatedCount;
@Setter
private int obsVarCount;

public AppendStatistic() {
this.clearData();
Expand All @@ -44,6 +47,7 @@ public void clearData() {
this.newCount = 0;
this.existingCount = 0;
this.mutatedCount = 0;
this.obsVarCount = 0;
}
public int incrementNewCount(Integer value) {
int increment = 0;
Expand Down Expand Up @@ -94,14 +98,16 @@ public Map<String, ImportPreviewStatistics> constructPreviewMap() {
ImportPreviewStatistics newStats = ImportPreviewStatistics.builder().newObjectCount(newCount).build();
ImportPreviewStatistics existingStats = ImportPreviewStatistics.builder().newObjectCount(existingCount).build();
ImportPreviewStatistics mutatedStats = ImportPreviewStatistics.builder().newObjectCount(mutatedCount).build();
ImportPreviewStatistics obsVarStats = ImportPreviewStatistics.builder().newObjectCount(obsVarCount).build();

return Map.of(
"Environments", environmentStats,
"Observation_Units", observationUnitsStats,
"GIDs", gidStats,
"Observations", newStats,
"Existing_Observations", existingStats,
"Mutated_Observations", mutatedStats
"Mutated_Observations", mutatedStats,
"Observation_Variables", obsVarStats
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public AppendOverwriteMiddlewareContext process(AppendOverwriteMiddlewareContext
*/
if (phenotypeCols.isEmpty()) {
processedData = processedDataFactory.undefinedDatasetBean();
updatePreviewStatistics(processedData, context, studyName, unitId);
updatePreviewStatistics(processedData, context, studyName, unitId, phenotypeCols.size());
}

// Assemble the pending observation data for all phenotypes
Expand Down Expand Up @@ -332,7 +332,7 @@ public AppendOverwriteMiddlewareContext process(AppendOverwriteMiddlewareContext
processedData.getValidationErrors().ifPresent(errList -> errList.forEach(e -> validationErrors.addError(rowNum + 2, e))); // +2 to account for header row and excel file 1-based row index

// Update import preview statistics and set in the context
updatePreviewStatistics(processedData, context, studyName, unitId);
updatePreviewStatistics(processedData, context, studyName, unitId, varNames.size());

// Construct a pending observation
Optional<PendingImportObject<BrAPIObservation>> pendingProcessedData = Optional.ofNullable(processedData.constructPendingObservation());
Expand Down Expand Up @@ -395,12 +395,14 @@ private boolean isChanged(String cellData, BrAPIObservation observation, String
private void updatePreviewStatistics(VisitedObservationData processedData,
AppendOverwriteMiddlewareContext context,
String studyName,
String unitId) {
String unitId,
int obsVarCount) {
// Update import preview statistics and set in the context
processedData.updateTally(statistic);
statistic.addEnvironmentName(studyName);
statistic.addObservationUnitId(unitId);
statistic.addGid(context.getAppendOverwriteWorkflowContext().getPendingGermplasmByOUId().get(unitId).getBrAPIObject().getAccessionNumber());
statistic.setObsVarCount(obsVarCount);
context.getAppendOverwriteWorkflowContext().setStatistic(statistic);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ private Map<String, ImportPreviewStatistics> generateStatisticsMap(PendingData p
.count()
);

// Assume observationVariableName is set when pending observations are created.
int obsVarCount = Math.toIntExact(
observationByHash.values()
.stream()
.map(o -> o.getBrAPIObject().getObservationVariableName())
.distinct()
.count()
);

ImportPreviewStatistics environmentStats = ImportPreviewStatistics.builder()
.newObjectCount(environmentNameCounter.size())
.build();
Expand All @@ -276,14 +285,18 @@ private Map<String, ImportPreviewStatistics> generateStatisticsMap(PendingData p
ImportPreviewStatistics mutatedObservationStats = ImportPreviewStatistics.builder()
.newObjectCount(numMutatedObservations)
.build();
ImportPreviewStatistics obsVarStats = ImportPreviewStatistics.builder()
.newObjectCount(obsVarCount)
.build();

return Map.of(
"Environments", environmentStats,
"Observation_Units", obdUnitStats,
"GIDs", gidStats,
"Observations", observationStats,
"Existing_Observations", existingObservationStats,
"Mutated_Observations", mutatedObservationStats
"Mutated_Observations", mutatedObservationStats,
"Observation_Variables", obsVarStats
);
}

Expand Down
Loading