Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
06136db
stratification tab, table and import csv button and dialog box with c…
Yagnik56 Aug 25, 2023
7419b68
stratification factor delete pop up and import popup fix
Yagnik56 Aug 31, 2023
494c3a4
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Aug 31, 2023
e18838e
Merge branch 'dev' into feature/stratification-UI-changes
danoswaltCL Aug 31, 2023
710b218
added stratification backend model changes
Sep 4, 2023
c6fcdc6
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Sep 4, 2023
4b3d6c4
stratification drop down in experiment overview
Yagnik56 Sep 4, 2023
026e355
Added experiment-stratification connections
Sep 4, 2023
e5e1573
added stratification validator
Sep 5, 2023
8414e8b
creating stratificationFactor when not found
Sep 5, 2023
97a9073
solve updating experiment issue
Sep 5, 2023
07c4362
added userStratificationRepo
Sep 5, 2023
43ecf0a
stratification drop down and summary format in table
Yagnik56 Sep 6, 2023
eb9571a
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Sep 6, 2023
74dfd63
fetch stratification factor store
Yagnik56 Sep 6, 2023
996447c
resolved store issue for stratification table fetch
ppratikcr7 Sep 18, 2023
ef99a0b
Updated stratification controller APIs
Sep 19, 2023
a7bcd22
Merge branch 'feature/stratification-UI-changes' of https://github.co…
Yagnik56 Sep 19, 2023
a04eb1c
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Sep 19, 2023
59436db
Merge branch 'fetch-stratification-factor-bugfix' into feature/strati…
Yagnik56 Sep 19, 2023
7b57499
delete factors from view feature
Yagnik56 Sep 20, 2023
41a637e
completed all stratification controller and service
Sep 20, 2023
4e448b7
export factor store actions
Yagnik56 Sep 21, 2023
560bdde
solve csv download related errors
Sep 21, 2023
4a9a921
fetch, delete and download stratification factors functionality
Yagnik56 Sep 21, 2023
2ddcd0e
upload strata csv feature
ppratikcr7 Sep 21, 2023
6ef44ae
solve stratificationFactor creating multiple doc
Sep 21, 2023
b4ff9bb
Merge branch 'feature/stratification-UI-changes' of https://github.co…
Sep 21, 2023
cd1a90b
solve empty string as factorValue error
Sep 22, 2023
1515390
fixing frontend test cases
ppratikcr7 Sep 22, 2023
35fe86e
fixing backend test cases
ppratikcr7 Sep 22, 2023
4caf928
solved srs bugs
Sep 25, 2023
89a3a30
page refresh on importing strata factor
Yagnik56 Sep 25, 2023
a95e451
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Sep 25, 2023
4e9e87e
solve experiment creation bug
Sep 26, 2023
9ab8c97
import, export SRS experiment and setting random assign algo as default
Yagnik56 Sep 26, 2023
ced6c64
adding stratification details and experiment design type on details page
ppratikcr7 Sep 28, 2023
983a8f1
added stratificationAlgorithm for assignment
Sep 28, 2023
51e0d4c
fixed backend unit and integration test cases
ppratikcr7 Sep 29, 2023
b2fdd6b
Merge branch 'dev' into feature/stratification-UI-changes
ppratikcr7 Sep 29, 2023
330a17b
refresh strata factor on import and delete, error not selecting facto…
Yagnik56 Sep 29, 2023
ea8c76c
removed N/A data & removed id from stratificationFactor
Oct 3, 2023
74951f3
make assignmentAlogrithm optional
Oct 3, 2023
c0fdcf7
N/A and factorId removing model changes, error on importing experimen…
Yagnik56 Oct 3, 2023
f06977a
Merge branch 'feature/stratification-UI-changes' of https://github.co…
Yagnik56 Oct 3, 2023
28575ed
backend integration test cases for stratification
ppratikcr7 Oct 4, 2023
8dac405
change stratificationFactorName name as FK in db
Oct 5, 2023
a65b92d
added swagger for stratification
Oct 5, 2023
9120553
solve empty csv upload error
Oct 5, 2023
b5f9b1d
updated Stratification migration file
Oct 5, 2023
cd76470
SRS backend controller and repo unit testcases
Yagnik56 Oct 9, 2023
9fc3355
Resolved review comments
Yagnik56 Oct 13, 2023
eebe03c
Resolved review comments
Yagnik56 Oct 16, 2023
df4f186
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Oct 16, 2023
9ebf03c
Merge pull request #1039 from CarnegieLearningWeb/feature/SRS-backend…
Yagnik56 Oct 16, 2023
7efc01e
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Oct 16, 2023
64a39d9
Feature/SRS frontend test cases (#1052)
ppratikcr7 Oct 17, 2023
7393b09
Merge branch 'dev' into feature/stratification-UI-changes
danoswaltCL Oct 17, 2023
63c752a
resolved frontend review comments
Yagnik56 Oct 18, 2023
94fe116
solve any related code
Oct 18, 2023
7c834c9
resolve any issue for backend testcases
Oct 18, 2023
715449a
Resolved review comments and failed test cases
Yagnik56 Oct 18, 2023
07d95ef
Resolved failed test case
Yagnik56 Oct 18, 2023
1adfc66
resolved backend peer review comments
ppratikcr7 Oct 19, 2023
e78089e
resolved page reload issue in import and deleting factor
Yagnik56 Oct 19, 2023
19bbff1
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Oct 25, 2023
a2390a4
Stratification factor usage status feature (#1037)
ppratikcr7 Oct 26, 2023
3f1c751
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 Oct 27, 2023
e32db78
resolve testcase fail and review cmt
Yagnik56 Oct 27, 2023
00b1c02
missing papaparse dependency
ppratikcr7 Oct 27, 2023
851535f
remove papaparse from root Upgrade
Yagnik56 Oct 30, 2023
2e37d47
Remove N/A from code
Nov 9, 2023
80f20b1
Merge branch 'dev' of https://github.com/CarnegieLearningWeb/UpGrade …
ppratikcr7 Nov 9, 2023
5cb3fc8
handle failures for delete stratification factor unit test case and r…
ppratikcr7 Nov 10, 2023
959c135
Merge branch 'dev' of https://github.com/CarnegieLearningWeb/UpGrade …
ppratikcr7 Nov 10, 2023
0116cc0
resolve backend unit testcase fail
Yagnik56 Nov 10, 2023
097e8fb
fix unit test case and prettier updates
ppratikcr7 Nov 10, 2023
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
11 changes: 11 additions & 0 deletions backend/package-lock.json

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

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"license": "ISC",
"dependencies": {
"dayjs": "^1.11.10",
"jsonfile": "^6.0.1"
},
"devDependencies": {
Expand Down
12,201 changes: 12,201 additions & 0 deletions backend/packages/Upgrade/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/packages/Upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"nodemon": "^2.0.20",
"npm": "^8.5.1",
"objects-to-csv": "^1.3.6",
"papaparse": "^5.4.1",
"pg": "^8.3.0",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0",
Expand Down
16 changes: 16 additions & 0 deletions backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
PAYLOAD_TYPE,
REPEATED_MEASURE,
EXPERIMENT_TYPE,
ASSIGNMENT_ALGORITHM,
} from 'upgrade_types';
import { Type } from 'class-transformer';

Expand Down Expand Up @@ -315,6 +316,12 @@ class StateTimeLogValidator {
public timeLog: Date;
}

class StratificationFactor {
@IsString()
@IsNotEmpty()
public stratificationFactorName: string;
}

export class ExperimentDTO {
@IsString()
@IsOptional()
Expand Down Expand Up @@ -354,6 +361,10 @@ export class ExperimentDTO {
@IsEnum(POST_EXPERIMENT_RULE)
public postExperimentRule: POST_EXPERIMENT_RULE;

@IsOptional()
@IsEnum(ASSIGNMENT_ALGORITHM)
public assignmentAlgorithm?: ASSIGNMENT_ALGORITHM;

// TODO add conditional validity here ie endOn is null
@IsOptional()
public enrollmentCompleteCondition?: Partial<IEnrollmentCompleteCondition>;
Expand Down Expand Up @@ -388,6 +399,11 @@ export class ExperimentDTO {
@IsEnum(FILTER_MODE)
public filterMode: FILTER_MODE;

@IsOptional()
@ValidateNested()
@Type(() => StratificationFactor)
public stratificationFactor?: StratificationFactor;

@IsNotEmpty()
@IsArray()
@ValidateNested({ each: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { JsonController, Get, Delete, Param, Authorized, Post, Req, UseBefore, Res } from 'routing-controllers';
import { SERVER_ERROR } from 'upgrade_types';
import { AppRequest } from '../../types';
import { UserStratificationFactor } from '../models/UserStratificationFactor';
import { StratificationService } from '../services/StratificationService';
import { FactorStrata } from './validators/StratificationValidator';
import { StratificationFactor } from '../models/StratificationFactor';
import * as express from 'express';
import multer from 'multer';
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });

/**
* @swagger
* definitions:
* FactorStrata:
* description: ''
* type: object
* required:
* - factor
* - value
* properties:
* factor:
* type: string
* value:
* type: object
* UserStratificationFactor:
* description: ''
* type: object
* properties:
* user:
* type: object
* required:
* - id
* properties:
* id:
* type: string
* group:
* type: object
* workingGroup:
* type: object
* stratificationFactor:
* type: object
* required:
* - stratificationFactorName
* properties:
* stratificationFactorName:
* type: string
* stratificationFactorValue:
* type: string
*/

/**
* @swagger
* tags:
* - name: Stratification
* description: CRUD operations related to Stratification
*/
@Authorized()
@JsonController('/stratification')
export class StratificationController {
constructor(public stratificatonService: StratificationService) {}

/**
* @swagger
* /stratification:
* get:
* description: Get all stratification
* tags:
* - Stratification
* produces:
* - application/json
* responses:
* '200':
* description: Get all stratification
* schema:
* type: array
* items:
* $ref: '#/definitions/FactorStrata'
* '401':
* description: Authorization Required Error
*/
@Get()
public async getAllStratification(@Req() request: AppRequest): Promise<FactorStrata[]> {
return this.stratificatonService.getAllStratification(request.logger);
}

/**
* @swagger
* /stratification/download/{factor}:
* get:
* description: Get stratificationFactor CSV by factorName
* tags:
* - Stratification
* produces:
* - application/json
* parameters:
* - in: path
* name: factor
* description: Factor name
* required: true
* schema:
* type: string
* responses:
* '200':
* description: Get stratificationFactor detailed CSV by name
* '401':
* description: Authorization Required Error
* '404':
* description: Factor name not found
* '500':
* description: Internal Server Error, FactorName is not valid
*/
@Get('/download/:factor')
public async getStratificationByFactor(
@Param('factor') factor: string,
@Req() request: AppRequest,
@Res() res: express.Response
): Promise<express.Response> {
if (!factor) {
return Promise.reject(new Error(SERVER_ERROR.MISSING_PARAMS + ' : stratification Factor should not be null.'));
}

const csvData = await this.stratificatonService.getCSVDataByFactor(factor, request.logger);

// return csv file with appropriate headers to request;
res.setHeader('Content-Type', 'text/csv; charset=UTF-8');
res.setHeader('Content-Disposition', `attachment; filename=data-${factor}.csv`);
return res.send(csvData);
}

/**
* @swagger
* /stratification:
* post:
* description: Create a new stratificationFactor by CSV
* tags:
* - Stratification
* produces:
* - application/json
* parameters:
* - in: body
* name: file
* description: CSV file
* required: true
* schema:
* type: file
* responses:
* '200':
* description: Create a new UserStratificationFactors by CSV
* schema:
* type: array
* items:
* $ref: '#/definitions/UserStratificationFactor'
* '401':
* description: Authorization Required Error
* '500':
* description: Internal Server Error, Insert Error in database, CSV file is not valid
*/
@Post()
@UseBefore(upload.single('file'))
public insertStratification(@Req() request: AppRequest): Promise<UserStratificationFactor[]> {
return this.stratificatonService.insertStratification(request.body[0].file, request.logger);
}

/**
* @swagger
* /stratification/{factor}:
* delete:
* description: Delete a stratificationFactor by factorName
* tags:
* - Stratification
* produces:
* - application/json
* parameters:
* - in: path
* name: factor
* description: Factor name
* required: true
* schema:
* type: string
* responses:
* '200':
* description: Delete a stratificationFactor by factorName
* schema:
* $ref: '#/definitions/FactorStrata'
* '401':
* description: Authorization Required Error
* '500':
* description: Internal Server Error, FactorName is not valid
*/
@Delete('/:factor')
public deleteStratification(
@Param('factor') stratificationFactor: string,
@Req() request: AppRequest
): Promise<StratificationFactor> {
if (!stratificationFactor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add class-validator decorator with the @param('factor') for not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't find the right syntax

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you try @params decorator it has a validation option. The only drawback is that you will get an object of all the params.

Copy link
Collaborator

Choose a reason for hiding this comment

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

is this resolved?

return Promise.reject(new Error(SERVER_ERROR.MISSING_PARAMS + ' : stratification Factor should not be null.'));
}
return this.stratificatonService.deleteStratification(stratificationFactor, request.logger);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IsNotEmpty, IsObject, IsOptional, IsString, IsArray } from 'class-validator';

export class FactorStrata {
@IsNotEmpty()
@IsString()
public factor: string;

@IsObject()
public factorValue: Record<string, number>;
}

export class StratificationInputValidator {
@IsNotEmpty()
@IsString()
public userId: string;

@IsNotEmpty()
@IsString()
public factor: string;

@IsOptional()
@IsString()
public value?: string;

@IsNotEmpty()
@IsArray()
@IsString({ each: true })
public experimentIds: string[];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { Type } from 'class-transformer';
import { IsNotEmpty, IsString, IsEnum, IsOptional, IsUrl, IsTimeZone, ValidateNested, IsArray, IsJSON, IsEmail } from 'class-validator';
import {
IsNotEmpty,
IsString,
IsEnum,
IsOptional,
IsUrl,
IsTimeZone,
ValidateNested,
IsArray,
IsJSON,
IsEmail,
} from 'class-validator';
import { EXPERIMENT_LOG_TYPE, UserRole } from 'upgrade_types';

class ExperimentAuditLogValidator {
Expand All @@ -18,11 +29,11 @@ class ExperimentAuditLogValidator {

export class UserDetailsValidator {
@IsString()
@IsNotEmpty()
@IsOptional()
public firstName: string;

@IsString()
@IsNotEmpty()
@IsOptional()
public lastName: string;

@IsNotEmpty()
Expand All @@ -44,7 +55,7 @@ export class UserDetailsValidator {

@IsOptional()
@IsArray()
@ValidateNested({each: true})
@ValidateNested({ each: true })
@Type(() => ExperimentAuditLogValidator)
auditLogs?: ExperimentAuditLogValidator[]
auditLogs?: ExperimentAuditLogValidator[];
}
Loading