@xcpcio/core 0.55.2 → 0.56.0

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
@@ -1405,13 +1405,13 @@ class GeneralExcelConverter {
1405
1405
  }
1406
1406
  convertToSheet(rank) {
1407
1407
  const aoa = this.convertToAoa(rank);
1408
- const sheet = XLSX__namespace.utils.aoa_to_sheet(aoa);
1408
+ const sheet = XLSX__namespace.utils.aoa_to_sheet(aoa.aoa);
1409
1409
  const cols = [];
1410
- const head = aoa[1];
1410
+ const head = aoa.aoa[1];
1411
1411
  for (let j = 0; j < head.length; j++) {
1412
1412
  let wch = 10;
1413
- for (let i = 1; i < aoa.length; i++) {
1414
- wch = Math.max(wch, stringWidth__default(aoa[i][j]) + 2);
1413
+ for (let i = 1; i < aoa.aoa.length; i++) {
1414
+ wch = Math.max(wch, stringWidth__default(aoa.aoa[i][j]) + 2);
1415
1415
  }
1416
1416
  cols.push({
1417
1417
  wch
@@ -1445,11 +1445,22 @@ class GeneralExcelConverter {
1445
1445
  },
1446
1446
  font
1447
1447
  };
1448
- for (let i = 1; i < aoa.length; i++) {
1449
- for (let j = 0; j < aoa[i].length; j++) {
1448
+ const firstSolvedCellStyle = {
1449
+ ...cellStyle,
1450
+ fill: {
1451
+ fgColor: { rgb: "009900" }
1452
+ }
1453
+ };
1454
+ for (let i = 1; i < aoa.aoa.length; i++) {
1455
+ for (let j = 0; j < aoa.aoa[i].length; j++) {
1450
1456
  const cellAddress = XLSX__namespace.utils.encode_cell({ r: i, c: j });
1451
1457
  const cell = sheet[cellAddress];
1452
- cell.s = cellStyle;
1458
+ const specialCell = aoa.specialCells.find((sc) => sc.row === i && sc.col === j);
1459
+ if (specialCell?.type === "firstSolved" /* FIRST_SOLVED */) {
1460
+ cell.s = firstSolvedCellStyle;
1461
+ } else {
1462
+ cell.s = cellStyle;
1463
+ }
1453
1464
  }
1454
1465
  }
1455
1466
  {
@@ -1464,6 +1475,7 @@ class GeneralExcelConverter {
1464
1475
  }
1465
1476
  convertToAoa(rank) {
1466
1477
  const aoa = [];
1478
+ const specialCells = [];
1467
1479
  const enableAwards = rank.contest.isEnableAwards(rank.options.group);
1468
1480
  const enableMembers = (Array.isArray(rank.teams) && rank.teams[0]?.members) ?? false;
1469
1481
  const enableCoach = rank.teams[0]?.coach ?? false;
@@ -1509,6 +1521,13 @@ class GeneralExcelConverter {
1509
1521
  }
1510
1522
  if (p.isSolved) {
1511
1523
  arr.push(`+${p.totalCount}(${p.solvedTimestampToMinute})`);
1524
+ if (p.isFirstSolved) {
1525
+ specialCells.push({
1526
+ row: aoa.length,
1527
+ col: arr.length - 1,
1528
+ type: "firstSolved" /* FIRST_SOLVED */
1529
+ });
1530
+ }
1512
1531
  }
1513
1532
  if (p.isWrongAnswer) {
1514
1533
  arr.push(`-${p.failedCount}`);
@@ -1543,7 +1562,7 @@ class GeneralExcelConverter {
1543
1562
  arr.push(team.isGirl ? "Y" : "N");
1544
1563
  aoa.push(arr);
1545
1564
  }
1546
- return aoa;
1565
+ return { aoa, specialCells };
1547
1566
  }
1548
1567
  }
1549
1568
 
package/dist/index.mjs CHANGED
@@ -1374,13 +1374,13 @@ class GeneralExcelConverter {
1374
1374
  }
1375
1375
  convertToSheet(rank) {
1376
1376
  const aoa = this.convertToAoa(rank);
1377
- const sheet = XLSX.utils.aoa_to_sheet(aoa);
1377
+ const sheet = XLSX.utils.aoa_to_sheet(aoa.aoa);
1378
1378
  const cols = [];
1379
- const head = aoa[1];
1379
+ const head = aoa.aoa[1];
1380
1380
  for (let j = 0; j < head.length; j++) {
1381
1381
  let wch = 10;
1382
- for (let i = 1; i < aoa.length; i++) {
1383
- wch = Math.max(wch, stringWidth(aoa[i][j]) + 2);
1382
+ for (let i = 1; i < aoa.aoa.length; i++) {
1383
+ wch = Math.max(wch, stringWidth(aoa.aoa[i][j]) + 2);
1384
1384
  }
1385
1385
  cols.push({
1386
1386
  wch
@@ -1414,11 +1414,22 @@ class GeneralExcelConverter {
1414
1414
  },
1415
1415
  font
1416
1416
  };
1417
- for (let i = 1; i < aoa.length; i++) {
1418
- for (let j = 0; j < aoa[i].length; j++) {
1417
+ const firstSolvedCellStyle = {
1418
+ ...cellStyle,
1419
+ fill: {
1420
+ fgColor: { rgb: "009900" }
1421
+ }
1422
+ };
1423
+ for (let i = 1; i < aoa.aoa.length; i++) {
1424
+ for (let j = 0; j < aoa.aoa[i].length; j++) {
1419
1425
  const cellAddress = XLSX.utils.encode_cell({ r: i, c: j });
1420
1426
  const cell = sheet[cellAddress];
1421
- cell.s = cellStyle;
1427
+ const specialCell = aoa.specialCells.find((sc) => sc.row === i && sc.col === j);
1428
+ if (specialCell?.type === "firstSolved" /* FIRST_SOLVED */) {
1429
+ cell.s = firstSolvedCellStyle;
1430
+ } else {
1431
+ cell.s = cellStyle;
1432
+ }
1422
1433
  }
1423
1434
  }
1424
1435
  {
@@ -1433,6 +1444,7 @@ class GeneralExcelConverter {
1433
1444
  }
1434
1445
  convertToAoa(rank) {
1435
1446
  const aoa = [];
1447
+ const specialCells = [];
1436
1448
  const enableAwards = rank.contest.isEnableAwards(rank.options.group);
1437
1449
  const enableMembers = (Array.isArray(rank.teams) && rank.teams[0]?.members) ?? false;
1438
1450
  const enableCoach = rank.teams[0]?.coach ?? false;
@@ -1478,6 +1490,13 @@ class GeneralExcelConverter {
1478
1490
  }
1479
1491
  if (p.isSolved) {
1480
1492
  arr.push(`+${p.totalCount}(${p.solvedTimestampToMinute})`);
1493
+ if (p.isFirstSolved) {
1494
+ specialCells.push({
1495
+ row: aoa.length,
1496
+ col: arr.length - 1,
1497
+ type: "firstSolved" /* FIRST_SOLVED */
1498
+ });
1499
+ }
1481
1500
  }
1482
1501
  if (p.isWrongAnswer) {
1483
1502
  arr.push(`-${p.failedCount}`);
@@ -1512,7 +1531,7 @@ class GeneralExcelConverter {
1512
1531
  arr.push(team.isGirl ? "Y" : "N");
1513
1532
  aoa.push(arr);
1514
1533
  }
1515
- return aoa;
1534
+ return { aoa, specialCells };
1516
1535
  }
1517
1536
  }
1518
1537
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcpcio/core",
3
- "version": "0.55.2",
3
+ "version": "0.56.0",
4
4
  "description": "XCPCIO Core",
5
5
  "author": "Dup4 <lyuzhi.pan@gmail.com>",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  "papaparse": "^5.5.2",
50
50
  "string-width": "^7.2.0",
51
51
  "xlsx-js-style": "^1.2.0",
52
- "@xcpcio/types": "0.55.2"
52
+ "@xcpcio/types": "0.56.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@babel/types": "^7.27.0",
@@ -6,8 +6,23 @@ import * as XLSX from "xlsx-js-style";
6
6
 
7
7
  import { isValidMedalType } from "../award";
8
8
 
9
+ enum SpecialCellType {
10
+ FIRST_SOLVED = "firstSolved",
11
+ }
12
+
13
+ interface SpecialCell {
14
+ row: number;
15
+ col: number;
16
+ type: SpecialCellType;
17
+ }
18
+
19
+ interface AoaConvertResult {
20
+ aoa: string[][];
21
+ specialCells: SpecialCell[];
22
+ }
23
+
9
24
  export class GeneralExcelConverter {
10
- constructor() {}
25
+ constructor() { }
11
26
 
12
27
  public convert(oriRank: Rank): XLSX.WorkBook {
13
28
  const rank = _.cloneDeep(oriRank);
@@ -40,14 +55,14 @@ export class GeneralExcelConverter {
40
55
 
41
56
  private convertToSheet(rank: Rank): XLSX.WorkSheet {
42
57
  const aoa = this.convertToAoa(rank);
43
- const sheet = XLSX.utils.aoa_to_sheet(aoa);
58
+ const sheet = XLSX.utils.aoa_to_sheet(aoa.aoa);
44
59
 
45
60
  const cols = [];
46
- const head = aoa[1];
61
+ const head = aoa.aoa[1];
47
62
  for (let j = 0; j < head.length; j++) {
48
63
  let wch = 10;
49
- for (let i = 1; i < aoa.length; i++) {
50
- wch = Math.max(wch, stringWidth(aoa[i][j]) + 2);
64
+ for (let i = 1; i < aoa.aoa.length; i++) {
65
+ wch = Math.max(wch, stringWidth(aoa.aoa[i][j]) + 2);
51
66
  }
52
67
 
53
68
  cols.push({
@@ -88,11 +103,23 @@ export class GeneralExcelConverter {
88
103
  font,
89
104
  };
90
105
 
91
- for (let i = 1; i < aoa.length; i++) {
92
- for (let j = 0; j < aoa[i].length; j++) {
106
+ const firstSolvedCellStyle = {
107
+ ...cellStyle,
108
+ fill: {
109
+ fgColor: { rgb: "009900" },
110
+ },
111
+ };
112
+
113
+ for (let i = 1; i < aoa.aoa.length; i++) {
114
+ for (let j = 0; j < aoa.aoa[i].length; j++) {
93
115
  const cellAddress = XLSX.utils.encode_cell({ r: i, c: j });
94
116
  const cell = sheet[cellAddress];
95
- cell.s = cellStyle;
117
+ const specialCell = aoa.specialCells.find(sc => sc.row === i && sc.col === j);
118
+ if (specialCell?.type === SpecialCellType.FIRST_SOLVED) {
119
+ cell.s = firstSolvedCellStyle;
120
+ } else {
121
+ cell.s = cellStyle;
122
+ }
96
123
  }
97
124
  }
98
125
 
@@ -108,8 +135,9 @@ export class GeneralExcelConverter {
108
135
  return sheet;
109
136
  }
110
137
 
111
- private convertToAoa(rank: Rank): string[][] {
138
+ private convertToAoa(rank: Rank): AoaConvertResult {
112
139
  const aoa: string[][] = [];
140
+ const specialCells: SpecialCell[] = [];
113
141
 
114
142
  const enableAwards = rank.contest.isEnableAwards(rank.options.group);
115
143
  const enableMembers = (Array.isArray(rank.teams) && rank.teams[0]?.members) ?? false;
@@ -152,6 +180,7 @@ export class GeneralExcelConverter {
152
180
  const arr: string[] = [];
153
181
 
154
182
  arr.push(team.rank.toString());
183
+
155
184
  if (team.organization) {
156
185
  if (team.organizationRank !== -1) {
157
186
  arr.push(team.organizationRank.toString());
@@ -171,6 +200,13 @@ export class GeneralExcelConverter {
171
200
 
172
201
  if (p.isSolved) {
173
202
  arr.push(`+${p.totalCount}(${p.solvedTimestampToMinute})`);
203
+ if (p.isFirstSolved) {
204
+ specialCells.push({
205
+ row: aoa.length,
206
+ col: arr.length - 1,
207
+ type: SpecialCellType.FIRST_SOLVED,
208
+ });
209
+ }
174
210
  }
175
211
 
176
212
  if (p.isWrongAnswer) {
@@ -216,6 +252,6 @@ export class GeneralExcelConverter {
216
252
  aoa.push(arr);
217
253
  }
218
254
 
219
- return aoa;
255
+ return { aoa, specialCells };
220
256
  }
221
257
  }