diff --git a/backend/packages/Upgrade/src/api/repositories/AnalyticsRepository.ts b/backend/packages/Upgrade/src/api/repositories/AnalyticsRepository.ts index 2265c823df..e329d6560a 100644 --- a/backend/packages/Upgrade/src/api/repositories/AnalyticsRepository.ts +++ b/backend/packages/Upgrade/src/api/repositories/AnalyticsRepository.ts @@ -453,13 +453,22 @@ export class AnalyticsRepository extends Repository { '"individualEnrollment"."experimentId" as "experimentId"', '"individualEnrollment"."conditionId" as "conditionId"', '"individualEnrollment"."partitionId" as "partitionId"', + '"decisionPointData"."site" as "site"', + '"decisionPointData"."target" as "target"', ]) + .leftJoin( + DecisionPoint, + 'decisionPointData', + 'decisionPointData.experimentId = individualEnrollment.experimentId AND decisionPointData.id = individualEnrollment.partitionId' + ) .groupBy('individualEnrollment.userId') .addGroupBy('individualEnrollment.groupId') .addGroupBy('individualEnrollment.enrollmentCode') .addGroupBy('individualEnrollment.experimentId') .addGroupBy('individualEnrollment.conditionId') .addGroupBy('individualEnrollment.partitionId') + .addGroupBy('decisionPointData.site') + .addGroupBy('decisionPointData.target') .orderBy('individualEnrollment.userId', 'ASC') .where('individualEnrollment.experimentId = :experimentId::uuid', { experimentId }); @@ -515,6 +524,8 @@ export class AnalyticsRepository extends Repository { enrollmentCode: individualEnrollmentQueryResult.enrollmentCode, expDecisionPointId: individualEnrollmentQueryResult.partitionId, expConditionId: individualEnrollmentQueryResult.conditionId, + site: individualEnrollmentQueryResult.site, + target: individualEnrollmentQueryResult.target, }); } }); @@ -549,16 +560,22 @@ export class AnalyticsRepository extends Repository { const userMonitoredResults = groupedMonitoredDecisionPointQueryResults[individualEnrollmentExperiment.userId] || []; - return userMonitoredResults.map((monitoredDecisionPointQueryResult) => ({ - ...individualEnrollmentExperiment, - site: monitoredDecisionPointQueryResult.site, - target: monitoredDecisionPointQueryResult.target, - markExperimentPointTime: monitoredDecisionPointQueryResult.markExperimentPointTime, - stratificationValue: experimentsData.stratification - ? userStratificationFactorQueryResult.find((user) => user.userId === individualEnrollmentExperiment.userId) - ?.stratificationFactorValue - : null, - })); + return userMonitoredResults + .filter( + (monitoredDecisionPointQueryResult) => + monitoredDecisionPointQueryResult.site === individualEnrollmentExperiment.site && + monitoredDecisionPointQueryResult.target === individualEnrollmentExperiment.target + ) + .map((monitoredDecisionPointQueryResult) => ({ + ...individualEnrollmentExperiment, + site: monitoredDecisionPointQueryResult.site, + target: monitoredDecisionPointQueryResult.target, + markExperimentPointTime: monitoredDecisionPointQueryResult.markExperimentPointTime, + stratificationValue: experimentsData.stratification + ? userStratificationFactorQueryResult.find((user) => user.userId === individualEnrollmentExperiment.userId) + ?.stratificationFactorValue + : null, + })); }); return combinedCSVExportData; }