@xcpcio/core 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -177,6 +177,14 @@ class TeamProblemStatistics {
177
177
  }
178
178
  }
179
179
 
180
+ class Group {
181
+ constructor() {
182
+ this.names = /* @__PURE__ */ new Map();
183
+ this.defaultLang = "zh-CN";
184
+ this.isDefault = false;
185
+ }
186
+ }
187
+
180
188
  class Contest {
181
189
  constructor() {
182
190
  this.name = "";
@@ -195,6 +203,8 @@ class Contest {
195
203
  incorrect: true,
196
204
  pending: true
197
205
  };
206
+ this.group = /* @__PURE__ */ new Map();
207
+ this.tag = /* @__PURE__ */ new Map();
198
208
  }
199
209
  getContestDuration(timeFormat = "HH:mm:ss") {
200
210
  return dayjs__default.duration(this.endTime.diff(this.startTime)).format(timeFormat);
@@ -292,8 +302,29 @@ function createContest(contestJSON) {
292
302
  c.badge = contestJSON.badge;
293
303
  c.medal = contestJSON.medal;
294
304
  c.organization = contestJSON.organization;
295
- c.group = contestJSON.group;
296
- c.tag = contestJSON.tag;
305
+ {
306
+ const g = new Group();
307
+ g.names.set("en", "All");
308
+ g.names.set("zh-CN", "\u6240\u6709\u961F\u4F0D");
309
+ g.isDefault = true;
310
+ c.group.set("all", g);
311
+ }
312
+ for (const [k, v] of Object.entries(contestJSON?.group ?? {})) {
313
+ let key = k;
314
+ const g = new Group();
315
+ g.names.set("zh-CN", v);
316
+ if (k === "official") {
317
+ g.names.set("en", "Official");
318
+ }
319
+ if (k === "unofficial") {
320
+ g.names.set("en", "Unofficial");
321
+ }
322
+ if (k === "girl" || k === "girls") {
323
+ g.names.set("en", "Girls");
324
+ key = "girl";
325
+ }
326
+ c.group.set(key, g);
327
+ }
297
328
  c.banner = contestJSON.banner;
298
329
  c.logo = contestJSON.logo;
299
330
  c.boardLink = contestJSON.board_link;
@@ -693,6 +724,8 @@ class RankOptions {
693
724
  this.enableFilterSubmissionsByTimestamp = false;
694
725
  this.width = 0;
695
726
  this.timestamp = 0;
727
+ this.enableFilterTeamsByGroup = false;
728
+ this.group = "";
696
729
  }
697
730
  setWidth(width, contest) {
698
731
  this.width = width;
@@ -702,6 +735,16 @@ class RankOptions {
702
735
  disableFilterSubmissionByTimestamp() {
703
736
  this.enableFilterSubmissionsByTimestamp = false;
704
737
  }
738
+ setGroup(group) {
739
+ this.group = group;
740
+ this.enableFilterTeamsByGroup = true;
741
+ if (this.group === "all") {
742
+ this.disableFilterTeamsByGroup();
743
+ }
744
+ }
745
+ disableFilterTeamsByGroup() {
746
+ this.enableFilterTeamsByGroup = false;
747
+ }
705
748
  }
706
749
  class Rank {
707
750
  constructor(contest, teams, submissions) {
@@ -715,6 +758,15 @@ class Rank {
715
758
  }
716
759
  buildRank() {
717
760
  (() => {
761
+ (() => {
762
+ this.teams = [];
763
+ for (const [_k, v] of this.teamsMap) {
764
+ if (this.filterTeamByOrg(v)) {
765
+ continue;
766
+ }
767
+ this.teams.push(v);
768
+ }
769
+ })();
718
770
  for (const t of this.teams) {
719
771
  t.reset();
720
772
  t.problemStatistics = this.contest.problems.map((p) => {
@@ -744,7 +796,7 @@ class Rank {
744
796
  const team = this.teamsMap.get(teamId);
745
797
  const problem = this.contest.problemsMap.get(problemId);
746
798
  (() => {
747
- if (team === void 0 || problem === void 0) {
799
+ if (team === void 0 || this.filterTeamByOrg(team) || problem === void 0) {
748
800
  return;
749
801
  }
750
802
  const problemStatistics = team.problemStatisticsMap.get(problemId);
@@ -851,6 +903,15 @@ class Rank {
851
903
  preTeam = t;
852
904
  }
853
905
  }
906
+ filterTeamByOrg(team) {
907
+ const o = this.options;
908
+ if (o.enableFilterTeamsByGroup) {
909
+ if (!team.group?.includes(o.group)) {
910
+ return true;
911
+ }
912
+ }
913
+ return false;
914
+ }
854
915
  getSubmissions() {
855
916
  if (this.options.enableFilterSubmissionsByTimestamp === false) {
856
917
  return this.submissions;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import dayjs from 'dayjs';
2
2
  export { default as dayjs } from 'dayjs';
3
- import { SubmissionStatus, Submission as Submission$1, Submissions as Submissions$1, BalloonColor, Problem as Problem$1, Problems as Problems$1, StatusTimeDisplay, Image, ContestState, Contest as Contest$1, ContestIndex as ContestIndex$1, Team as Team$1, Teams as Teams$1 } from '@xcpcio/types';
3
+ import { SubmissionStatus, Submission as Submission$1, Submissions as Submissions$1, BalloonColor, Problem as Problem$1, Problems as Problems$1, Lang, StatusTimeDisplay, Image, ContestState, Contest as Contest$1, ContestIndex as ContestIndex$1, Team as Team$1, Teams as Teams$1 } from '@xcpcio/types';
4
4
 
5
5
  declare class Submission {
6
6
  id: string;
@@ -77,6 +77,13 @@ declare function createDayJS(time?: Date | string | number | undefined): dayjs.D
77
77
  declare function getTimestamp(time: number | dayjs.Dayjs): number;
78
78
  declare function getTimeDiff(seconds: number): string;
79
79
 
80
+ declare class Group {
81
+ names: Map<Lang, string>;
82
+ defaultLang: Lang;
83
+ isDefault: boolean;
84
+ constructor();
85
+ }
86
+
80
87
  declare class Contest {
81
88
  name: string;
82
89
  startTime: dayjs.Dayjs;
@@ -92,8 +99,8 @@ declare class Contest {
92
99
  badge?: string;
93
100
  medal?: Record<string, Record<string, number>>;
94
101
  organization?: string;
95
- group?: Record<string, string>;
96
- tag?: Record<string, string>;
102
+ group: Map<string, Group>;
103
+ tag: Map<string, string>;
97
104
  logo?: Image;
98
105
  banner?: Image;
99
106
  boardLink?: string;
@@ -179,9 +186,13 @@ declare class RankOptions {
179
186
  enableFilterSubmissionsByTimestamp: boolean;
180
187
  width: number;
181
188
  timestamp: number;
189
+ enableFilterTeamsByGroup: boolean;
190
+ group: string;
182
191
  constructor();
183
192
  setWidth(width: number, contest: Contest): void;
184
193
  disableFilterSubmissionByTimestamp(): void;
194
+ setGroup(group: string): void;
195
+ disableFilterTeamsByGroup(): void;
185
196
  }
186
197
  declare class Rank {
187
198
  readonly contest: Contest;
@@ -195,6 +206,7 @@ declare class Rank {
195
206
  buildRank(): this;
196
207
  buildTeamRank(): void;
197
208
  buildOrgRank(): void;
209
+ filterTeamByOrg(team: Team): boolean;
198
210
  getSubmissions(): Submissions;
199
211
  }
200
212
 
package/dist/index.mjs CHANGED
@@ -161,6 +161,14 @@ class TeamProblemStatistics {
161
161
  }
162
162
  }
163
163
 
164
+ class Group {
165
+ constructor() {
166
+ this.names = /* @__PURE__ */ new Map();
167
+ this.defaultLang = "zh-CN";
168
+ this.isDefault = false;
169
+ }
170
+ }
171
+
164
172
  class Contest {
165
173
  constructor() {
166
174
  this.name = "";
@@ -179,6 +187,8 @@ class Contest {
179
187
  incorrect: true,
180
188
  pending: true
181
189
  };
190
+ this.group = /* @__PURE__ */ new Map();
191
+ this.tag = /* @__PURE__ */ new Map();
182
192
  }
183
193
  getContestDuration(timeFormat = "HH:mm:ss") {
184
194
  return dayjs.duration(this.endTime.diff(this.startTime)).format(timeFormat);
@@ -276,8 +286,29 @@ function createContest(contestJSON) {
276
286
  c.badge = contestJSON.badge;
277
287
  c.medal = contestJSON.medal;
278
288
  c.organization = contestJSON.organization;
279
- c.group = contestJSON.group;
280
- c.tag = contestJSON.tag;
289
+ {
290
+ const g = new Group();
291
+ g.names.set("en", "All");
292
+ g.names.set("zh-CN", "\u6240\u6709\u961F\u4F0D");
293
+ g.isDefault = true;
294
+ c.group.set("all", g);
295
+ }
296
+ for (const [k, v] of Object.entries(contestJSON?.group ?? {})) {
297
+ let key = k;
298
+ const g = new Group();
299
+ g.names.set("zh-CN", v);
300
+ if (k === "official") {
301
+ g.names.set("en", "Official");
302
+ }
303
+ if (k === "unofficial") {
304
+ g.names.set("en", "Unofficial");
305
+ }
306
+ if (k === "girl" || k === "girls") {
307
+ g.names.set("en", "Girls");
308
+ key = "girl";
309
+ }
310
+ c.group.set(key, g);
311
+ }
281
312
  c.banner = contestJSON.banner;
282
313
  c.logo = contestJSON.logo;
283
314
  c.boardLink = contestJSON.board_link;
@@ -677,6 +708,8 @@ class RankOptions {
677
708
  this.enableFilterSubmissionsByTimestamp = false;
678
709
  this.width = 0;
679
710
  this.timestamp = 0;
711
+ this.enableFilterTeamsByGroup = false;
712
+ this.group = "";
680
713
  }
681
714
  setWidth(width, contest) {
682
715
  this.width = width;
@@ -686,6 +719,16 @@ class RankOptions {
686
719
  disableFilterSubmissionByTimestamp() {
687
720
  this.enableFilterSubmissionsByTimestamp = false;
688
721
  }
722
+ setGroup(group) {
723
+ this.group = group;
724
+ this.enableFilterTeamsByGroup = true;
725
+ if (this.group === "all") {
726
+ this.disableFilterTeamsByGroup();
727
+ }
728
+ }
729
+ disableFilterTeamsByGroup() {
730
+ this.enableFilterTeamsByGroup = false;
731
+ }
689
732
  }
690
733
  class Rank {
691
734
  constructor(contest, teams, submissions) {
@@ -699,6 +742,15 @@ class Rank {
699
742
  }
700
743
  buildRank() {
701
744
  (() => {
745
+ (() => {
746
+ this.teams = [];
747
+ for (const [_k, v] of this.teamsMap) {
748
+ if (this.filterTeamByOrg(v)) {
749
+ continue;
750
+ }
751
+ this.teams.push(v);
752
+ }
753
+ })();
702
754
  for (const t of this.teams) {
703
755
  t.reset();
704
756
  t.problemStatistics = this.contest.problems.map((p) => {
@@ -728,7 +780,7 @@ class Rank {
728
780
  const team = this.teamsMap.get(teamId);
729
781
  const problem = this.contest.problemsMap.get(problemId);
730
782
  (() => {
731
- if (team === void 0 || problem === void 0) {
783
+ if (team === void 0 || this.filterTeamByOrg(team) || problem === void 0) {
732
784
  return;
733
785
  }
734
786
  const problemStatistics = team.problemStatisticsMap.get(problemId);
@@ -835,6 +887,15 @@ class Rank {
835
887
  preTeam = t;
836
888
  }
837
889
  }
890
+ filterTeamByOrg(team) {
891
+ const o = this.options;
892
+ if (o.enableFilterTeamsByGroup) {
893
+ if (!team.group?.includes(o.group)) {
894
+ return true;
895
+ }
896
+ }
897
+ return false;
898
+ }
838
899
  getSubmissions() {
839
900
  if (this.options.enableFilterSubmissionsByTimestamp === false) {
840
901
  return this.submissions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcpcio/core",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "XCPCIO Core",
5
5
  "author": "Dup4 <lyuzhi.pan@gmail.com>",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "dayjs": "^1.11.8",
44
44
  "lodash": "^4.17.21",
45
- "@xcpcio/types": "0.5.2"
45
+ "@xcpcio/types": "0.5.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@babel/types": "^7.22.4",
package/src/contest.ts CHANGED
@@ -4,6 +4,7 @@ import { ContestState, VERSION } from "@xcpcio/types";
4
4
  import type { Problem, Problems } from "./problem";
5
5
  import { createProblems, createProblemsByProblemIds } from "./problem";
6
6
  import { createDayJS, dayjs, getTimeDiff } from "./utils";
7
+ import { Group } from "./group";
7
8
 
8
9
  export class Contest {
9
10
  name = "";
@@ -27,8 +28,8 @@ export class Contest {
27
28
  medal?: Record<string, Record<string, number>>;
28
29
  organization?: string;
29
30
 
30
- group?: Record<string, string>;
31
- tag?: Record<string, string>;
31
+ group: Map<string, Group>;
32
+ tag: Map<string, string>;
32
33
 
33
34
  logo?: Image;
34
35
  banner?: Image;
@@ -56,6 +57,9 @@ export class Contest {
56
57
  incorrect: true,
57
58
  pending: true,
58
59
  };
60
+
61
+ this.group = new Map<string, Group>();
62
+ this.tag = new Map<string, string>();
59
63
  }
60
64
 
61
65
  getContestDuration(timeFormat = "HH:mm:ss"): string {
@@ -189,8 +193,36 @@ export function createContest(contestJSON: IContest): Contest {
189
193
  c.medal = contestJSON.medal;
190
194
  c.organization = contestJSON.organization;
191
195
 
192
- c.group = contestJSON.group;
193
- c.tag = contestJSON.tag;
196
+ {
197
+ const g = new Group();
198
+ g.names.set("en", "All");
199
+ g.names.set("zh-CN", "所有队伍");
200
+ g.isDefault = true;
201
+
202
+ c.group.set("all", g);
203
+ }
204
+
205
+ for (const [k, v] of Object.entries(contestJSON?.group ?? {})) {
206
+ let key = k;
207
+
208
+ const g = new Group();
209
+ g.names.set("zh-CN", v);
210
+
211
+ if (k === "official") {
212
+ g.names.set("en", "Official");
213
+ }
214
+
215
+ if (k === "unofficial") {
216
+ g.names.set("en", "Unofficial");
217
+ }
218
+
219
+ if (k === "girl" || k === "girls") {
220
+ g.names.set("en", "Girls");
221
+ key = "girl";
222
+ }
223
+
224
+ c.group.set(key, g);
225
+ }
194
226
 
195
227
  c.banner = contestJSON.banner;
196
228
 
package/src/group.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Lang } from "@xcpcio/types";
2
+
3
+ export class Group {
4
+ names: Map<Lang, string>;
5
+ defaultLang: Lang;
6
+ isDefault: boolean;
7
+
8
+ constructor() {
9
+ this.names = new Map<Lang, string>();
10
+ this.defaultLang = "zh-CN";
11
+ this.isDefault = false;
12
+ }
13
+ }
package/src/rank.ts CHANGED
@@ -13,10 +13,16 @@ export class RankOptions {
13
13
  width: number;
14
14
  timestamp: number;
15
15
 
16
+ enableFilterTeamsByGroup: boolean;
17
+ group: string;
18
+
16
19
  constructor() {
17
20
  this.enableFilterSubmissionsByTimestamp = false;
18
21
  this.width = 0;
19
22
  this.timestamp = 0;
23
+
24
+ this.enableFilterTeamsByGroup = false;
25
+ this.group = "";
20
26
  }
21
27
 
22
28
  setWidth(width: number, contest: Contest) {
@@ -28,6 +34,19 @@ export class RankOptions {
28
34
  disableFilterSubmissionByTimestamp() {
29
35
  this.enableFilterSubmissionsByTimestamp = false;
30
36
  }
37
+
38
+ setGroup(group: string) {
39
+ this.group = group;
40
+ this.enableFilterTeamsByGroup = true;
41
+
42
+ if (this.group === "all") {
43
+ this.disableFilterTeamsByGroup();
44
+ }
45
+ }
46
+
47
+ disableFilterTeamsByGroup() {
48
+ this.enableFilterTeamsByGroup = false;
49
+ }
31
50
  }
32
51
 
33
52
  export class Rank {
@@ -59,6 +78,18 @@ export class Rank {
59
78
 
60
79
  buildRank() {
61
80
  (() => {
81
+ (() => {
82
+ this.teams = [];
83
+
84
+ for (const [_k, v] of this.teamsMap) {
85
+ if (this.filterTeamByOrg(v)) {
86
+ continue;
87
+ }
88
+
89
+ this.teams.push(v);
90
+ }
91
+ })();
92
+
62
93
  for (const t of this.teams) {
63
94
  t.reset();
64
95
 
@@ -97,7 +128,7 @@ export class Rank {
97
128
  const problem = this.contest.problemsMap.get(problemId);
98
129
 
99
130
  (() => {
100
- if (team === undefined || problem === undefined) {
131
+ if (team === undefined || this.filterTeamByOrg(team) || problem === undefined) {
101
132
  return;
102
133
  }
103
134
 
@@ -238,6 +269,18 @@ export class Rank {
238
269
  }
239
270
  }
240
271
 
272
+ filterTeamByOrg(team: Team) {
273
+ const o = this.options;
274
+
275
+ if (o.enableFilterTeamsByGroup) {
276
+ if (!team.group?.includes(o.group)) {
277
+ return true;
278
+ }
279
+ }
280
+
281
+ return false;
282
+ }
283
+
241
284
  getSubmissions() {
242
285
  if (this.options.enableFilterSubmissionsByTimestamp === false) {
243
286
  return this.submissions;