Skip to content

Commit 7a3b63b

Browse files
committed
✨ Добавлены новые пайплайны для обработки данных: achievements.ts, dynamic.ts, ladder.ts, metrics.ts, race.ts, ruler.ts, seasons.ts и users.ts
1 parent 46bbdc1 commit 7a3b63b

9 files changed

Lines changed: 817 additions & 0 deletions

File tree

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
import type { PipelineStage } from "mongoose";
2+
3+
const tz = "Europe/Moscow";
4+
5+
export const pAchTotalPulls = (userId: number): PipelineStage[] => [
6+
{ $match: { user_id: userId } },
7+
{ $count: "count" },
8+
];
9+
10+
export const pAchTotalSize = (userId: number): PipelineStage[] => [
11+
{ $match: { user_id: userId } },
12+
{ $group: { _id: null, total: { $sum: "$size" } } },
13+
];
14+
15+
export const pAchSniper30cm = (userId: number): PipelineStage[] => [
16+
{ $match: { user_id: userId, size: 30 } },
17+
{ $count: "count" },
18+
];
19+
20+
export const pAchHalfHundred50cm = (userId: number): PipelineStage[] => [
21+
{ $match: { user_id: userId, size: 50 } },
22+
{ $count: "count" },
23+
];
24+
25+
export const pAchMaximalist61cm = (userId: number): PipelineStage[] => [
26+
{ $match: { user_id: userId, size: 61 } },
27+
{ $count: "count" },
28+
];
29+
30+
export const pAchBeautifulNumbers = (userId: number): PipelineStage[] => [
31+
{ $match: { user_id: userId, size: { $in: [11, 22, 33, 44, 55] } } },
32+
{ $group: { _id: "$size" } },
33+
{ $count: "count" },
34+
];
35+
36+
export const pAchRecent10 = (userId: number): PipelineStage[] => [
37+
{ $match: { user_id: userId } },
38+
{ $sort: { requested_at: -1 } },
39+
{ $limit: 10 },
40+
{ $sort: { requested_at: 1 } },
41+
];
42+
43+
export const pAchMaxSize = (userId: number): PipelineStage[] => [
44+
{ $match: { user_id: userId } },
45+
{ $group: { _id: null, max: { $max: "$size" } } },
46+
];
47+
48+
export const pAchMinSize = (userId: number): PipelineStage[] => [
49+
{ $match: { user_id: userId } },
50+
{ $group: { _id: null, min: { $min: "$size" } } },
51+
];
52+
53+
export const pAchEarlyBird = (userId: number): PipelineStage[] => [
54+
{ $match: { user_id: userId } },
55+
{ $project: { hour: { $hour: { date: "$requested_at", timezone: tz } } } },
56+
{ $match: { hour: { $lt: 6 } } },
57+
{ $count: "count" },
58+
];
59+
60+
export const pAchSpeedrunner = (userId: number): PipelineStage[] => [
61+
{ $match: { user_id: userId } },
62+
{
63+
$project: {
64+
hour: { $hour: { date: "$requested_at", timezone: tz } },
65+
minute: { $minute: { date: "$requested_at", timezone: tz } },
66+
second: { $second: { date: "$requested_at", timezone: tz } },
67+
},
68+
},
69+
{ $match: { hour: 0, minute: 0, second: { $lt: 30 } } },
70+
{ $count: "count" },
71+
];
72+
73+
export const pAchMidnightPuller = (userId: number): PipelineStage[] => [
74+
{ $match: { user_id: userId } },
75+
{ $project: { hour: { $hour: { date: "$requested_at", timezone: tz } } } },
76+
{ $match: { hour: 23 } },
77+
{ $count: "count" },
78+
];
79+
80+
export const pAchValentine = (userId: number): PipelineStage[] => [
81+
{ $match: { user_id: userId } },
82+
{
83+
$project: {
84+
size: 1,
85+
month: { $month: { date: "$requested_at", timezone: tz } },
86+
day: { $dayOfMonth: { date: "$requested_at", timezone: tz } },
87+
},
88+
},
89+
{ $match: { month: 2, day: 14, size: 14 } },
90+
{ $count: "count" },
91+
];
92+
93+
export const pAchNewYearGift = (userId: number): PipelineStage[] => [
94+
{ $match: { user_id: userId } },
95+
{
96+
$project: {
97+
size: 1,
98+
month: { $month: { date: "$requested_at", timezone: tz } },
99+
day: { $dayOfMonth: { date: "$requested_at", timezone: tz } },
100+
},
101+
},
102+
{ $match: { month: 12, day: 31, size: { $gte: 60 } } },
103+
{ $count: "count" },
104+
];
105+
106+
export const pAchMensSolidarity = (userId: number): PipelineStage[] => [
107+
{ $match: { user_id: userId } },
108+
{
109+
$project: {
110+
size: 1,
111+
month: { $month: { date: "$requested_at", timezone: tz } },
112+
day: { $dayOfMonth: { date: "$requested_at", timezone: tz } },
113+
},
114+
},
115+
{ $match: { month: 11, day: 19, size: 19 } },
116+
{ $count: "count" },
117+
];
118+
119+
export const pAchFriday13th = (userId: number): PipelineStage[] => [
120+
{ $match: { user_id: userId } },
121+
{
122+
$project: {
123+
size: 1,
124+
day: { $dayOfMonth: { date: "$requested_at", timezone: tz } },
125+
day_of_week: { $dayOfWeek: { date: "$requested_at", timezone: tz } },
126+
},
127+
},
128+
{ $match: { day: 13, day_of_week: 6, size: 0 } },
129+
{ $count: "count" },
130+
];
131+
132+
export const pAchLeapCock = (userId: number): PipelineStage[] => [
133+
{ $match: { user_id: userId } },
134+
{
135+
$project: {
136+
month: { $month: { date: "$requested_at", timezone: tz } },
137+
day: { $dayOfMonth: { date: "$requested_at", timezone: tz } },
138+
},
139+
},
140+
{ $match: { month: 2, day: 29 } },
141+
{ $count: "count" },
142+
];
143+
144+
export const pAchLightning = (userId: number): PipelineStage[] => [
145+
{ $match: { user_id: userId } },
146+
{ $sort: { requested_at: 1 } },
147+
{
148+
$setWindowFields: {
149+
sortBy: { requested_at: 1 },
150+
output: { prev_size: { $shift: { output: "$size", by: -1 } } },
151+
},
152+
},
153+
{ $project: { growth: { $subtract: ["$size", { $ifNull: ["$prev_size", "$size"] }] } } },
154+
{ $match: { growth: { $gte: 50 } } },
155+
{ $count: "count" },
156+
];
157+
158+
export const pAchLast31 = (userId: number): PipelineStage[] => [
159+
{ $match: { user_id: userId } },
160+
{ $sort: { requested_at: -1 } },
161+
{ $limit: 31 },
162+
];
163+
164+
export const pAchRecent3 = (userId: number): PipelineStage[] => [
165+
{ $match: { user_id: userId } },
166+
{ $sort: { requested_at: -1 } },
167+
{ $limit: 3 },
168+
{ $sort: { requested_at: 1 } },
169+
];
170+
171+
export const pGlobalMaxMin = (): PipelineStage[] => [
172+
{ $group: { _id: null, max: { $max: "$size" }, min: { $min: "$size" } } },
173+
];
174+
175+
export const pCountSeasons = (userId: number): PipelineStage[] => [
176+
{ $group: { _id: null, first_cock_date: { $min: "$requested_at" } } },
177+
{
178+
$lookup: {
179+
from: "cocks",
180+
let: { first_date: "$first_cock_date" },
181+
pipeline: [
182+
{ $match: { user_id: userId } },
183+
{
184+
$project: {
185+
requested_at: 1,
186+
year: { $year: { date: "$requested_at", timezone: tz } },
187+
month: { $month: { date: "$requested_at", timezone: tz } },
188+
first_year: { $year: { date: "$$first_date", timezone: tz } },
189+
first_month: { $month: { date: "$$first_date", timezone: tz } },
190+
},
191+
},
192+
{
193+
$project: {
194+
months_diff: {
195+
$subtract: [
196+
{ $add: [{ $multiply: ["$year", 12] }, "$month"] },
197+
{ $add: [{ $multiply: ["$first_year", 12] }, "$first_month"] },
198+
],
199+
},
200+
},
201+
},
202+
{ $project: { season_number: { $floor: { $divide: ["$months_diff", 3] } } } },
203+
{ $group: { _id: "$season_number" } },
204+
],
205+
as: "seasons",
206+
},
207+
},
208+
{ $unwind: "$seasons" },
209+
{ $count: "count" },
210+
];
211+
212+
export const pCheckTraveler = (userId: number): PipelineStage[] => [
213+
{ $match: { user_id: userId } },
214+
{ $group: { _id: "$size" } },
215+
{ $count: "unique_sizes" },
216+
];
217+
218+
export const pCheckMuscovite = (userId: number, startDate: Date): PipelineStage[] => [
219+
{ $match: { user_id: userId, size: 50, requested_at: { $gte: startDate } } },
220+
{ $count: "count" },
221+
];

0 commit comments

Comments
 (0)