Skip to content

Commit

Permalink
feat(assignments-service): Better status and filter for solutions wit…
Browse files Browse the repository at this point in the history
…h only CodeSearch or similarity origin
  • Loading branch information
Clashsoft committed Nov 18, 2023
1 parent 926114b commit cf48ea0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export class SolutionController {
postAnd.push({assignee: regex});
break;
case 'origin':
isMongoId(subTerm) && postAnd.push({'_evaluations._id': new Types.ObjectId(subTerm)});
if (isMongoId(subTerm)) {
const origin = new Types.ObjectId(subTerm);
postAnd.push({$or: [
{'_evaluations.codeSearch.origin': origin},
{'_evaluations.similarity.origin': origin},
]});
}
break;
case 'status':
postAnd.push({status: subTerm});
Expand Down
49 changes: 26 additions & 23 deletions services/apps/assignments/src/solution/solution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {UserToken} from '@app/keycloak-auth';
import {Injectable} from '@nestjs/common';
import {InjectModel} from '@nestjs/mongoose';
import {FilterQuery, Model, Types, UpdateQuery} from 'mongoose';
import {BatchUpdateSolutionDto, RichSolutionDto} from './solution.dto';
import {BatchUpdateSolutionDto, RichSolutionDto, SolutionStatus} from './solution.dto';
import {Solution, SOLUTION_COLLATION, SOLUTION_SORT, SolutionDocument} from './solution.schema';

@Injectable()
Expand Down Expand Up @@ -37,9 +37,10 @@ export class SolutionService extends MongooseRepository<Solution> {
as: '_evaluations',
pipeline: [
{
$group: {
_id: '$codeSearch.origin',
count: {$sum: 1},
$project: {
_id: 1,
'codeSearch.origin': 1,
'similarity.origin': 1,
},
},
],
Expand All @@ -49,35 +50,37 @@ export class SolutionService extends MongooseRepository<Solution> {
$addFields: {
assignee: {$first: '$_assignee.assignee'},
// if points are set: SolutionStatus.graded
// else if all evaluations have author 'Code Search': SolutionStatus.codeSearch
// else if there are any evaluations: SolutionStatus.started
// otherwise: SolutionStatus.todo
// else if there are no evaluations: SolutionStatus.todo
// else if all evaluations have an origin: SolutionStatus.codeSearch
// else: SolutionStatus.started
status: {
$cond: {
if: {$gt: ['$points', null]},
then: 'graded',
then: SolutionStatus.graded,
else: {
$cond: {
if: {$gt: [{$size: '$_evaluations'}, 0]},
then: {
if: {$eq: [{$size: '$_evaluations'}, 0]},
then: SolutionStatus.todo,
else: {
$cond: {
if: {
// no evaluations has _id === null
$eq: [{
$size: {
$filter: {
input: '$_evaluations',
as: 'e',
cond: {$eq: ['$$e._id', null]}
}
}
}, 0]
$allElementsTrue: {
$map: {
input: '$_evaluations',
as: 'evaluation',
in: {
$or: [
{$gt: ['$$evaluation.codeSearch.origin', null]},
{$gt: ['$$evaluation.similarity.origin', null]},
],
},
},
},
},
then: 'code-search',
else: 'started',
then: SolutionStatus.codeSearch,
else: SolutionStatus.started,
},
},
else: 'todo',
},
},
},
Expand Down

0 comments on commit cf48ea0

Please sign in to comment.