-
Notifications
You must be signed in to change notification settings - Fork 13
Stratification Factor Feature #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 7419b68
stratification factor delete pop up and import popup fix
Yagnik56 494c3a4
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 e18838e
Merge branch 'dev' into feature/stratification-UI-changes
danoswaltCL 710b218
added stratification backend model changes
c6fcdc6
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 4b3d6c4
stratification drop down in experiment overview
Yagnik56 026e355
Added experiment-stratification connections
e5e1573
added stratification validator
8414e8b
creating stratificationFactor when not found
97a9073
solve updating experiment issue
07c4362
added userStratificationRepo
43ecf0a
stratification drop down and summary format in table
Yagnik56 eb9571a
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 74dfd63
fetch stratification factor store
Yagnik56 996447c
resolved store issue for stratification table fetch
ppratikcr7 ef99a0b
Updated stratification controller APIs
a7bcd22
Merge branch 'feature/stratification-UI-changes' of https://github.co…
Yagnik56 a04eb1c
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 59436db
Merge branch 'fetch-stratification-factor-bugfix' into feature/strati…
Yagnik56 7b57499
delete factors from view feature
Yagnik56 41a637e
completed all stratification controller and service
4e448b7
export factor store actions
Yagnik56 560bdde
solve csv download related errors
4a9a921
fetch, delete and download stratification factors functionality
Yagnik56 2ddcd0e
upload strata csv feature
ppratikcr7 6ef44ae
solve stratificationFactor creating multiple doc
b4ff9bb
Merge branch 'feature/stratification-UI-changes' of https://github.co…
cd1a90b
solve empty string as factorValue error
1515390
fixing frontend test cases
ppratikcr7 35fe86e
fixing backend test cases
ppratikcr7 4caf928
solved srs bugs
89a3a30
page refresh on importing strata factor
Yagnik56 a95e451
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 4e9e87e
solve experiment creation bug
9ab8c97
import, export SRS experiment and setting random assign algo as default
Yagnik56 ced6c64
adding stratification details and experiment design type on details page
ppratikcr7 983a8f1
added stratificationAlgorithm for assignment
51e0d4c
fixed backend unit and integration test cases
ppratikcr7 b2fdd6b
Merge branch 'dev' into feature/stratification-UI-changes
ppratikcr7 330a17b
refresh strata factor on import and delete, error not selecting facto…
Yagnik56 ea8c76c
removed N/A data & removed id from stratificationFactor
74951f3
make assignmentAlogrithm optional
c0fdcf7
N/A and factorId removing model changes, error on importing experimen…
Yagnik56 f06977a
Merge branch 'feature/stratification-UI-changes' of https://github.co…
Yagnik56 28575ed
backend integration test cases for stratification
ppratikcr7 8dac405
change stratificationFactorName name as FK in db
a65b92d
added swagger for stratification
9120553
solve empty csv upload error
b5f9b1d
updated Stratification migration file
cd76470
SRS backend controller and repo unit testcases
Yagnik56 9fc3355
Resolved review comments
Yagnik56 eebe03c
Resolved review comments
Yagnik56 df4f186
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 9ebf03c
Merge pull request #1039 from CarnegieLearningWeb/feature/SRS-backend…
Yagnik56 7efc01e
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 64a39d9
Feature/SRS frontend test cases (#1052)
ppratikcr7 7393b09
Merge branch 'dev' into feature/stratification-UI-changes
danoswaltCL 63c752a
resolved frontend review comments
Yagnik56 94fe116
solve any related code
7c834c9
resolve any issue for backend testcases
715449a
Resolved review comments and failed test cases
Yagnik56 07d95ef
Resolved failed test case
Yagnik56 1adfc66
resolved backend peer review comments
ppratikcr7 e78089e
resolved page reload issue in import and deleting factor
Yagnik56 19bbff1
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 a2390a4
Stratification factor usage status feature (#1037)
ppratikcr7 3f1c751
Merge branch 'dev' into feature/stratification-UI-changes
Yagnik56 e32db78
resolve testcase fail and review cmt
Yagnik56 00b1c02
missing papaparse dependency
ppratikcr7 851535f
remove papaparse from root Upgrade
Yagnik56 2e37d47
Remove N/A from code
80f20b1
Merge branch 'dev' of https://github.com/CarnegieLearningWeb/UpGrade …
ppratikcr7 5cb3fc8
handle failures for delete stratification factor unit test case and r…
ppratikcr7 959c135
Merge branch 'dev' of https://github.com/CarnegieLearningWeb/UpGrade …
ppratikcr7 0116cc0
resolve backend unit testcase fail
Yagnik56 097e8fb
fix unit test case and prettier updates
ppratikcr7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
202 changes: 202 additions & 0 deletions
202
backend/packages/Upgrade/src/api/controllers/StratificationController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
return Promise.reject(new Error(SERVER_ERROR.MISSING_PARAMS + ' : stratification Factor should not be null.')); | ||
} | ||
return this.stratificatonService.deleteStratification(stratificationFactor, request.logger); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/packages/Upgrade/src/api/controllers/validators/StratificationValidator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
danoswaltCL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@IsNotEmpty() | ||
@IsArray() | ||
@IsString({ each: true }) | ||
public experimentIds: string[]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this resolved?