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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"endOfLine": "auto",
"quoteProps": "as-needed",
"overrides": [
{
Expand Down
48 changes: 0 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/ab-testing/ab-testing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ import { ABTestingController } from './ab-testing.controller';
ABTestingReportsService,
],
})
export class ABTestingModule {
}
export class ABTestingModule {}
17 changes: 12 additions & 5 deletions src/ab-testing/analysis/statistical-analysis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ export class StatisticalAnalysisService {
return Math.max(0, Math.min(1, 1 / (1 + Math.exp(-zScore + 2))));
}

private calculateCohensD(controlMetrics: VariantMetric[], variantMetrics: VariantMetric[]): number {
private calculateCohensD(
controlMetrics: VariantMetric[],
variantMetrics: VariantMetric[],
): number {
if (controlMetrics.length === 0 || variantMetrics.length === 0) return 0;

const controlMean =
Expand All @@ -257,12 +260,16 @@ export class StatisticalAnalysisService {
const denomV = Math.max(variantMetrics.length - 1, 1);

const controlVar =
controlMetrics.reduce((sum, m) => sum + Math.pow(Number(m.value) - controlMean, 2), 0) / denomC;
controlMetrics.reduce((sum, m) => sum + Math.pow(Number(m.value) - controlMean, 2), 0) /
denomC;
const variantVar =
variantMetrics.reduce((sum, m) => sum + Math.pow(Number(m.value) - variantMean, 2), 0) / denomV;
variantMetrics.reduce((sum, m) => sum + Math.pow(Number(m.value) - variantMean, 2), 0) /
denomV;

const pooledStdDev = Math.sqrt(((controlMetrics.length - 1) * controlVar + (variantMetrics.length - 1) * variantVar) /
Math.max(controlMetrics.length + variantMetrics.length - 2, 1));
const pooledStdDev = Math.sqrt(
((controlMetrics.length - 1) * controlVar + (variantMetrics.length - 1) * variantVar) /
Math.max(controlMetrics.length + variantMetrics.length - 2, 1),
);

return pooledStdDev > 0 ? Math.abs(variantMean - controlMean) / pooledStdDev : 0;
}
Expand Down
15 changes: 6 additions & 9 deletions src/ab-testing/automation/automated-decision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export class AutomatedDecisionService {

const defaultCriteria: IWinnerSelectionCriteria = {
confidenceLevel: experiment.confidenceLevel ?? AB_TESTING_CONSTANTS.DEFAULT_CONFIDENCE_LEVEL,
minimumSampleSize:
experiment.minimumSampleSize ?? AB_TESTING_CONSTANTS.MINIMUM_SAMPLE_SIZE,
minimumSampleSize: experiment.minimumSampleSize ?? AB_TESTING_CONSTANTS.MINIMUM_SAMPLE_SIZE,
effectSizeThreshold: AB_TESTING_CONSTANTS.EFFECT_SIZE_THRESHOLD,
durationThreshold: AB_TESTING_CONSTANTS.DURATION_THRESHOLD_DAYS,
};
Expand Down Expand Up @@ -263,14 +262,13 @@ export class AutomatedDecisionService {
});
if (winner) {
recommendations.winnerCandidate = winner.id;
recommendations.recommendations.push(`Variant "${winner.name}" is the recommended winner`);
recommendations.recommendations.push(
`Variant "${winner.name}" is the recommended winner`,
);
}
}
} else {
const remainingDays = Math.max(
0,
AB_TESTING_CONSTANTS.DURATION_THRESHOLD_DAYS - duration,
);
const remainingDays = Math.max(0, AB_TESTING_CONSTANTS.DURATION_THRESHOLD_DAYS - duration);
recommendations.recommendations.push(
`Wait ${remainingDays} more days before making decision`,
);
Expand Down Expand Up @@ -300,8 +298,7 @@ export class AutomatedDecisionService {
for (let i = 0; i < variants.length; i++) {
const variant = variants[i];
const score = performanceScores[i];
variant.trafficAllocation =
totalScore > 0 ? score.score / totalScore : 1 / variants.length;
variant.trafficAllocation = totalScore > 0 ? score.score / totalScore : 1 / variants.length;
await this.variantRepository.save(variant);
}

Expand Down
10 changes: 5 additions & 5 deletions src/ab-testing/entities/experiment-metric.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
} from 'typeorm';
import { Experiment } from './experiment.entity';
export enum MetricType {
CONVERSION = 'conversion',
REVENUE = 'revenue',
ENGAGEMENT = 'engagement',
RETENTION = 'retention',
CUSTOM = 'custom'
CONVERSION = 'conversion',
REVENUE = 'revenue',
ENGAGEMENT = 'engagement',
RETENTION = 'retention',
CUSTOM = 'custom',
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/ab-testing/entities/experiment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import {
import { IExperimentVariant } from './experiment-variant.entity';
import { ExperimentMetric } from './experiment-metric.entity';
export enum ExperimentStatus {
DRAFT = 'draft',
RUNNING = 'running',
PAUSED = 'paused',
COMPLETED = 'completed',
ARCHIVED = 'archived'
DRAFT = 'draft',
RUNNING = 'running',
PAUSED = 'paused',
COMPLETED = 'completed',
ARCHIVED = 'archived',
}
export enum ExperimentType {
A_B_TEST = 'a_b_test',
MULTIVARIATE = 'multivariate',
MULTI_ARMED_BANDIT = 'multi_armed_bandit'
A_B_TEST = 'a_b_test',
MULTIVARIATE = 'multivariate',
MULTI_ARMED_BANDIT = 'multi_armed_bandit',
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/ab-testing/reporting/ab-testing-reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export interface IReportFilters {
*/
@Injectable()
export class ABTestingReportsService {
private readonly logger = new Logger(ABTestingReportsService.name);
constructor(
private readonly logger = new Logger(ABTestingReportsService.name);
constructor(
@InjectRepository(Experiment)
private experimentRepository: Repository<Experiment>,
@InjectRepository(IExperimentVariant)
Expand Down Expand Up @@ -256,7 +256,9 @@ export class ABTestingReportsService {
: 0,
bestPerforming:
performanceData.length > 0
? [...performanceData].sort((a, b) => b.improvementPercentage - a.improvementPercentage)[0]
? [...performanceData].sort(
(a, b) => b.improvementPercentage - a.improvementPercentage,
)[0]
: null,
performanceData,
};
Expand Down
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Controller, Get } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { SkipQuota } from './rate-limiting/decorators/quota.decorator';

@ApiTags('App')
@SkipQuota()
@Controller()
export class AppController {
@Get()
Expand Down
20 changes: 18 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';
import { AppController } from './app.controller';
import { SearchModule } from './search/search.module';
import { RateLimitingModule } from './rate-limiting/rate-limiting.module';
import { QuotaGuard } from './rate-limiting/guards/quota.guard';
import { getDatabaseConfig } from './config/database.config';
import { loadFeatureFlags } from './config/feature-flags.config';

const featureFlags = loadFeatureFlags();
import { DebuggingModule } from './debugging/debugging.module';

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRoot(getDatabaseConfig()),
ScheduleModule.forRoot(),
SearchModule,
...(featureFlags.ENABLE_RATE_LIMITING ? [RateLimitingModule] : []),
DebuggingModule,
],
controllers: [AppController],
providers: [],
providers: featureFlags.ENABLE_RATE_LIMITING
? [{ provide: APP_GUARD, useClass: QuotaGuard }]
: [],
})
export class AppModule {}
export class AppModule { }
21 changes: 10 additions & 11 deletions src/assessment/assessment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import { Module } from '@nestjs/common';
* Registers the assessments module.
*/
@Module({
imports: [TypeOrmModule.forFeature([Assessment, Question, AssessmentAttempt, Answer])],
controllers: [AssessmentsController],
providers: [
AssessmentsService,
QuestionBankService,
ScoreCalculationService,
FeedbackGenerationService,
],
exports: [AssessmentsService],
imports: [TypeOrmModule.forFeature([Assessment, Question, AssessmentAttempt, Answer])],
controllers: [AssessmentsController],
providers: [
AssessmentsService,
QuestionBankService,
ScoreCalculationService,
FeedbackGenerationService,
],
exports: [AssessmentsService],
})
export class AssessmentsModule {
}
export class AssessmentsModule {}
6 changes: 3 additions & 3 deletions src/assessment/assessments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { Question } from './entities/question.entity';
*/
@Injectable()
export class AssessmentsService {
constructor(
constructor(
@InjectRepository(Assessment)
private readonly assessmentRepo: Repository<Assessment>,
private readonly assessmentRepo: Repository<Assessment>,
@InjectRepository(AssessmentAttempt)
private readonly attemptRepo: Repository<AssessmentAttempt>,
private readonly attemptRepo: Repository<AssessmentAttempt>,
@InjectRepository(Answer)
private readonly answerRepo: Repository<Answer>,
private readonly scoringService: ScoreCalculationService,
Expand Down
Loading
Loading