Merge branch 'main' of http://113.45.157.195:3003/linfeng/training_data
This commit is contained in:
commit
cacc36b723
|
@ -7,6 +7,17 @@ import { Prisma } from "@nice/common";
|
|||
const SportStandardArgsSchema:ZodType<Prisma.SportStandardCreateArgs> = z.any()
|
||||
const SportStandardUpdateArgsSchema:ZodType<Prisma.SportStandardUpdateArgs> = z.any()
|
||||
const SportStandardFindManyArgsSchema:ZodType<Prisma.SportStandardFindManyArgs> = z.any()
|
||||
const SportStandardCreateStandardArgsSchema:ZodType<Prisma.SportStandardCreateArgs> = z.any()
|
||||
|
||||
interface AgeRange {
|
||||
start: number | null;
|
||||
end: number | null;
|
||||
label: string;
|
||||
}
|
||||
interface Record {
|
||||
[key: string]: number[];
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SportStandardRouter {
|
||||
constructor(
|
||||
|
@ -15,10 +26,10 @@ export class SportStandardRouter {
|
|||
) { }
|
||||
|
||||
router = this.trpc.router({
|
||||
create:this.trpc.procedure.input(SportStandardArgsSchema)
|
||||
.mutation(async ({input})=>{
|
||||
return this.sportStandardService.create(input)
|
||||
}),
|
||||
// create:this.trpc.procedure.input(SportStandardArgsSchema)
|
||||
// .mutation(async ({input})=>{
|
||||
// return this.sportStandardService.create(input)
|
||||
// }),
|
||||
update:this.trpc.procedure.input(SportStandardUpdateArgsSchema)
|
||||
.mutation(async ({input})=>{
|
||||
return this.sportStandardService.update(input)
|
||||
|
@ -26,6 +37,17 @@ export class SportStandardRouter {
|
|||
findMany:this.trpc.procedure.input(SportStandardFindManyArgsSchema)
|
||||
.query(async ({input})=>{
|
||||
return this.sportStandardService.findMany(input)
|
||||
}),
|
||||
createStandard:this.trpc.procedure.input(SportStandardCreateStandardArgsSchema)
|
||||
.mutation(async ({input})=>{
|
||||
const data = {
|
||||
projectId: input.data.projectId,
|
||||
gender: input.data.gender,
|
||||
personType: input.data.personType,
|
||||
ageRanges: input.data.ageRanges as any as AgeRange[],
|
||||
scoreTable: input.data.scoreTable as Record
|
||||
}
|
||||
return this.sportStandardService.createStandard(data,input.select,input.include)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ interface AgeRange {
|
|||
end: number | null;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface Record {
|
||||
[key: string]: number[];
|
||||
}
|
||||
interface ScoreStandard {
|
||||
ageRanges: AgeRange[];
|
||||
scoreTable: {
|
||||
[score: string]: number[];
|
||||
}
|
||||
scoreTable: Record;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
|
@ -53,6 +53,54 @@ export class SportStandardService extends BaseService<Prisma.SportStandardDelega
|
|||
});
|
||||
}
|
||||
|
||||
async createStandard(
|
||||
data: {
|
||||
projectId: string;
|
||||
gender: boolean;
|
||||
personType: string;
|
||||
ageRanges: AgeRange[];
|
||||
scoreTable: Record;
|
||||
},
|
||||
select?: Prisma.SportStandardSelect<DefaultArgs>,
|
||||
include?: Prisma.SportStandardInclude<DefaultArgs>
|
||||
) {
|
||||
this.validateAgeRanges(data.ageRanges);
|
||||
this.validateScoreTable(data.scoreTable, data.ageRanges.length);
|
||||
return this.create({
|
||||
data: {
|
||||
projectId: data.projectId,
|
||||
gender: data.gender,
|
||||
personType: data.personType,
|
||||
ageRanges: JSON.stringify(data.ageRanges),
|
||||
scoreTable: JSON.stringify(data.scoreTable)
|
||||
},
|
||||
select,
|
||||
include
|
||||
})
|
||||
}
|
||||
private validateAgeRanges(ranges: AgeRange[]) {
|
||||
// 检查年龄段是否按顺序排列且无重叠
|
||||
for (let i = 0; i < ranges.length - 1; i++) {
|
||||
const current = ranges[i];
|
||||
const next = ranges[i + 1];
|
||||
|
||||
if (current.end !== next.start) {
|
||||
throw new Error('年龄段必须连续且不重叠');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private validateScoreTable(
|
||||
scoreTable: Record,
|
||||
expectedLength: number
|
||||
) {
|
||||
Object.values(scoreTable).forEach(standards => {
|
||||
if (standards.length !== expectedLength) {
|
||||
throw new Error('分数表的每行数据长度必须与年龄段数量匹配');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SportScoreCalculator(performance: number, age: number, scoreStandard: ScoreStandard): number {
|
||||
// 1. 找到对应的年龄段索引
|
||||
const ageRangeIndex = scoreStandard.ageRanges.findIndex(range => {
|
||||
|
|
Loading…
Reference in New Issue