Skip to content

Commit 0476308

Browse files
authored
Merge pull request #3 from jkh675/satistic
Satistic impl
2 parents 33b91ed + 3209fb5 commit 0476308

File tree

11 files changed

+324
-71
lines changed

11 files changed

+324
-71
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
build
44
ssl
55

6-
storage
6+
storage
7+
.vscode/.server-controller-port.log

.vscode/.server-controller-port.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"port": 13452,
3-
"time": 1715412240136,
2+
"port": 9145,
3+
"time": 1716083435791,
44
"version": "0.0.3"
55
}

src/graphql/Shooter/type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export const ShooterType = objectType({
2727
t.list.field("scores", {
2828
type: "Score",
2929
});
30-
t.list.field("rankings", {
30+
t.nullable.list.field("rankings", {
3131
type: "Ranking",
3232
});
33-
t.list.field("ratings", {
33+
t.nullable.list.field("ratings", {
3434
type: "Rating",
3535
});
3636
},

src/graphql/ShooterStatistic/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./type";
2+
export * from "./query";

src/graphql/ShooterStatistic/query.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { extendType, nonNull } from "nexus";
2+
3+
export const ShooterStatisticQuery = extendType({
4+
type: "Query",
5+
definition(t) {
6+
t.field("shooterStatistic", {
7+
type: "ShooterStatistic",
8+
args: {
9+
shooterId: nonNull("Int"),
10+
},
11+
resolve: (src, { shooterId }) => {
12+
return { shooterId: shooterId };
13+
},
14+
});
15+
},
16+
});

src/graphql/ShooterStatistic/type.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import { objectType } from "nexus";
2+
3+
export const ShooterStatistic = objectType({
4+
name: "ShooterStatistic",
5+
nonNullDefaults: {
6+
input: true,
7+
output: true,
8+
},
9+
definition(t) {
10+
t.int("shooterId");
11+
t.float("averageHitFactor", {
12+
async resolve(src, args, ctx) {
13+
return (await ctx.prisma.score.aggregate({
14+
_avg: {
15+
hitFactor: true,
16+
},
17+
where: {
18+
shooterId: src.shooterId,
19+
},
20+
}))._avg.hitFactor || 0;
21+
},
22+
});
23+
t.float("averageAccuracy", {
24+
async resolve(src, args, ctx) {
25+
return ( await ctx.prisma.score.aggregate({
26+
_avg: {
27+
accuracy: true,
28+
},
29+
where: {
30+
shooterId: src.shooterId,
31+
},
32+
}))._avg.accuracy || 0;
33+
},
34+
});
35+
t.float("runCount", {
36+
async resolve(src, args, ctx) {
37+
return await ctx.prisma.score.count({
38+
where: {
39+
shooterId: src.shooterId,
40+
},
41+
});
42+
},
43+
});
44+
t.float("finishedCount", {
45+
async resolve(src, args, ctx) {
46+
return await ctx.prisma.score.count({
47+
where: {
48+
state: "Scored",
49+
shooterId: src.shooterId,
50+
},
51+
});
52+
},
53+
});
54+
t.float("proErrorCount", {
55+
async resolve(src, args, ctx) {
56+
return(await ctx.prisma.score.aggregate({
57+
_sum: {
58+
proErrorCount: true,
59+
},
60+
where: {
61+
shooterId: src.shooterId,
62+
},
63+
}))._sum.proErrorCount || 0;
64+
},
65+
});
66+
t.float("dnfCount", {
67+
async resolve(src, args, ctx) {
68+
return await ctx.prisma.score.count({
69+
where: {
70+
state: "DidNotFinish",
71+
shooterId: src.shooterId,
72+
},
73+
});
74+
},
75+
});
76+
t.float("dqCount", {
77+
async resolve(src, args, ctx) {
78+
return await ctx.prisma.score.count({
79+
where: {
80+
state: "DQ",
81+
shooterId: src.shooterId,
82+
},
83+
});
84+
},
85+
});
86+
t.float("highestHitFactor", {
87+
async resolve(src, args, ctx) {
88+
return(await ctx.prisma.score.aggregate({
89+
_max: {
90+
hitFactor: true,
91+
},
92+
where: {
93+
shooterId: src.shooterId,
94+
},
95+
}))._max.hitFactor || 0;
96+
},
97+
});
98+
t.float("highestAccuracy", {
99+
async resolve(src, args, ctx) {
100+
return(await ctx.prisma.score.aggregate({
101+
_max: {
102+
accuracy: true,
103+
},
104+
where: {
105+
shooterId: src.shooterId,
106+
},
107+
}))._max.accuracy || 0;
108+
},
109+
});
110+
t.float("alphaCount", {
111+
async resolve(src, args, ctx) {
112+
return (await ctx.prisma.score.aggregate({
113+
_sum: {
114+
alphas: true,
115+
},
116+
where: {
117+
shooterId: src.shooterId,
118+
},
119+
}))._sum.alphas || 0;
120+
},
121+
});
122+
t.float("charlieCount", {
123+
async resolve(src, args, ctx) {
124+
return (await ctx.prisma.score.aggregate({
125+
_sum: {
126+
charlies: true,
127+
},
128+
where: {
129+
shooterId: src.shooterId,
130+
},
131+
}))._sum.charlies || 0;
132+
},
133+
});
134+
t.float("deltaCount", {
135+
async resolve(src, args, ctx) {
136+
return (await ctx.prisma.score.aggregate({
137+
_sum: {
138+
deltas: true,
139+
},
140+
where: {
141+
shooterId: src.shooterId,
142+
},
143+
}))._sum.deltas || 0;
144+
},
145+
});
146+
t.float("missCount", {
147+
async resolve(src, args, ctx) {
148+
return (await ctx.prisma.score.aggregate({
149+
_sum: {
150+
misses: true,
151+
},
152+
where: {
153+
shooterId: src.shooterId,
154+
},
155+
}))._sum.misses || 0;
156+
},
157+
});
158+
t.float("noShootCount", {
159+
async resolve(src, args, ctx) {
160+
return (await ctx.prisma.score.aggregate({
161+
_sum: {
162+
noshoots: true,
163+
},
164+
where: {
165+
shooterId: src.shooterId,
166+
},
167+
}))._sum.noshoots || 0;
168+
},
169+
});
170+
},
171+
});

0 commit comments

Comments
 (0)