Skip to content

Commit b5d8497

Browse files
authored
Merge pull request #333 from NullorNone/feature-current-contest-display
添加了近期竞赛列表
2 parents 25bf517 + d53502d commit b5d8497

File tree

17 files changed

+521
-5
lines changed

17 files changed

+521
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- 增加 cpp、js、py3 一些题目的 debug(参考 wangtao0101 项目,有问题提 issues)
3232
- [有些题目原插件无法调试,请尝试配置区域调试参数](#区域调试参数的一些说明)
3333
- [国际站修改登录方式 cRUL 方式登录](#cRUL 登录)
34+
- [增加近期竞赛回顾](#近期竞赛回顾)
3435

3536
# 关于本项目
3637

@@ -52,6 +53,13 @@
5253

5354
![search](https://www.ccagml.com/wp-content/uploads/2022/10/search.gif)
5455

56+
## 近期竞赛回顾
57+
58+
![search](./resources/leetcode-extension-recentcontests.gif)
59+
60+
- 近期比赛数据和比赛的题目通过中文官网在线获取
61+
- 国际站并无对应api,因此即使在国际站点下也是通过中文站点获取的数据,同时由于没有登录参数,可能存在无法获取数据的情况。
62+
5563
## 区块测试用例
5664

5765
### 例子(cpp 文件为例)
@@ -141,7 +149,11 @@
141149
- 获取提交历史(直接找官方的提交数据)
142150
- 提交答案与期望答案不同的地方?
143151
- (完成)做题目计时
144-
- 还没出分前周赛题目显示 未评分(需要官网获取最新几期的题目编号) -->
152+
- (完成)还没出分前周赛题目显示 未评分(需要官网获取最新几期的题目编号)
153+
- (完成)在线获取周赛编号下的题目
154+
- 将搜索功能中的竞赛修改为在线获取题目,将周赛与双周赛分开,同时可以检索未出分前的竞赛题目
155+
- 将近期竞赛的显示数量修改为可配置选项
156+
- -->
145157

146158
## 搬砖功能的说明
147159

Loading

src/BABA.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export enum BabaStr {
8888
TreeData_rebuildTreeData = "TreeData_rebuildTreeData",
8989
QuestionData_ReBuildQuestionDataFinish = "QuestionData_ReBuildQuestionDataFinish",
9090
TreeData_searchTodayFinish = "TreeData_searchTodayFinish",
91+
TreeData_searchRecentContestFinish = "TreeData_searchRecentContestFinish",
92+
TreeData_searchContestQuestionFinish = "TreeData_searchContestQuestionFinish",
9193
TreeData_searchUserContest = "TreeData_searchUserContest",
9294
TreeData_searchUserContestFinish = "TreeData_searchUserContestFinish",
9395
TreeData_searchScoreRangeFinish = "TreeData_searchScoreRangeFinish",
@@ -134,6 +136,10 @@ export enum BabaStr {
134136
BricksData_removeQidFromGroupFinish = "BricksData_removeQidFromGroupFinish",
135137
TodayDataProxy = "TodayDataProxy",
136138
TodayDataMediator = "TodayDataMediator",
139+
RecentContestProxy = "RecentContestProxy",
140+
RecentContestMediator = "RecentContestMediator",
141+
ContestQuestionProxy = "ContestQuestionProxy",
142+
ContestQuestionMediator = "ContestQuestionMediator",
137143
}
138144

139145
export class BABA {

src/childCall/childCallModule.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ class ExecuteService implements Disposable {
291291
return solution;
292292
}
293293

294+
public async getRecentContest(needTranslation: boolean): Promise<string> {
295+
// solution don't support translation
296+
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "query", "-i"];
297+
if (!needTranslation) {
298+
cmd.push("-T");
299+
}
300+
const solution: string = await this.callWithMsg("正在获取近期竞赛~", this.nodeExecutable, cmd);
301+
return solution;
302+
}
303+
304+
public async getContestQuestion(contestName: string): Promise<string> {
305+
// solution don't support translation
306+
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "query", "-j", contestName];
307+
const solution: string = await this.callWithMsg("正在获取近期竞赛的题目~", this.nodeExecutable, cmd);
308+
return solution;
309+
}
310+
294311
public async getDescription(problemNodeId: string, needTranslation: boolean): Promise<string> {
295312
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", problemNodeId, "-x"];
296313
if (!needTranslation) {

src/controller/TreeViewController.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
getBelongingWorkspaceFolderUri,
4747
selectWorkspaceFolder,
4848
} from "../utils/ConfigUtils";
49-
import { CreateTreeNodeModel, ITodayDataResponse, TreeNodeModel, TreeNodeType } from "../model/TreeNodeModel";
49+
import { CreateTreeNodeModel, ITodayDataResponse, TreeNodeModel, TreeNodeType, ITreeDataNormal } from "../model/TreeNodeModel";
5050
import { ISearchSet } from "../model/ConstDefind";
5151

5252
import { ShowMessage, promptForSignIn, promptHintMessage } from "../utils/OutputUtils";
@@ -1032,6 +1032,14 @@ class TreeViewController implements Disposable {
10321032
},
10331033
TreeNodeType.Tree_contest
10341034
),
1035+
CreateTreeNodeModel(
1036+
{
1037+
id: Category.RecentContestList,
1038+
name: Category.RecentContestList,
1039+
rootNodeSortId: RootNodeSort.RecentContestList,
1040+
},
1041+
TreeNodeType.Tree_recentContestList
1042+
),
10351043
];
10361044

10371045
// 获取每日一题的数据
@@ -1148,6 +1156,30 @@ class TreeViewController implements Disposable {
11481156
return sortNodeList(sorceNode);
11491157
}
11501158

1159+
public getRecentContestList(): TreeNodeModel[] {
1160+
const sorceNode: TreeNodeModel[] = [];
1161+
let recentContestNodeList: ITreeDataNormal[] | undefined = BABA.getProxy(BabaStr.RecentContestProxy).getAllContestTreeNode();
1162+
1163+
if (recentContestNodeList != undefined) {
1164+
for (let i = 0; i < recentContestNodeList.length; i++) {
1165+
sorceNode.push(CreateTreeNodeModel(recentContestNodeList[i], TreeNodeType.Tree_recentContestList_contest));
1166+
}
1167+
}
1168+
return sortNodeList(sorceNode);
1169+
}
1170+
1171+
public getContestQuestionNodes(element: TreeNodeModel): TreeNodeModel[] {
1172+
const sorceNode: TreeNodeModel[] = [];
1173+
let questionList = BABA.getProxy(BabaStr.ContestQuestionProxy).getContestQuestionData(element.id);
1174+
for (let question of questionList) {
1175+
let DayQuestionNode: TreeNodeModel | undefined = BABA.getProxy(BabaStr.QuestionDataProxy).getNodeByQid(question);
1176+
if (DayQuestionNode != undefined) {
1177+
sorceNode.push(CreateTreeNodeModel(DayQuestionNode.get_data(), TreeNodeType.Tree_recentContestList_contest_leaf));
1178+
}
1179+
}
1180+
return sortNodeList(sorceNode);
1181+
}
1182+
11511183
public getAllNodes(): TreeNodeModel[] {
11521184
const res: TreeNodeModel[] = [];
11531185

src/debug/DoPy3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class DebugPy3 {
5252
if (!moduleExportsReg.test(fileContent.toString())) {
5353
await fse.writeFile(
5454
filePath,
55-
`# @lcpr-before-debug-begin\nfrom python3problem${temp_meta_id.toString()} import *\nfrom typing import *\n# @lcpr-before-debug-end\n\n` +
55+
`# @lcpr-before-debug-begin\nfrom python3problem${temp_meta_id.toString()} import * # type: ignore \nfrom typing import *\n# @lcpr-before-debug-end\n\n` +
5656
fileContent.toString()
5757
);
5858
}

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { PreviewMediator, PreviewProxy } from "./preView/PreviewModule";
2929
import { DebugMediator, DebugProxy } from "./debug/DebugModule";
3030
import { RankScoreDataMediator, RankScoreDataProxy } from "./rankScore/RankScoreDataModule";
3131
import { TodayDataMediator, TodayDataProxy } from "./todayData/TodayDataModule";
32+
import { RecentContestMediator, RecentContestProxy } from "./recentContestData/RecentContestDataModule";
33+
import { ContestQuestionMediator, ContestQuestionProxy } from "./recentContestData/ContestQuestionDataModule";
3234

3335
//==================================BABA========================================
3436

@@ -73,6 +75,10 @@ export async function activate(context: ExtensionContext): Promise<void> {
7375
RankScoreDataMediator,
7476
TodayDataProxy,
7577
TodayDataMediator,
78+
RecentContestProxy,
79+
RecentContestMediator,
80+
ContestQuestionProxy,
81+
ContestQuestionMediator,
7682
]);
7783

7884
// 资源管理

src/model/ConstDefind.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export enum RootNodeSort {
136136
Score = 8,
137137
ScoreRange = 9,
138138
Contest = 9,
139+
RecentContestList = 10,
139140
DIFEASY = 1,
140141
DIFMID = 2,
141142
DIFHARD = 3,
@@ -196,6 +197,7 @@ export enum Category {
196197
Score = "Score",
197198
Choice = "Choice",
198199
Contest = "Contest",
200+
RecentContestList = "RecentContestList",
199201
}
200202

201203
export enum DescriptionConfiguration {

src/model/TreeNodeModel.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export interface ITodayDataResponse {
7171
time: number;
7272
}
7373

74+
// 竞赛的数据
75+
export interface IContestData {
76+
index: number;
77+
title: string;
78+
titleSlug: string;
79+
startTime: number;
80+
duration: number;
81+
}
82+
7483
export enum TreeNodeType {
7584

7685
// 功能节点
@@ -127,6 +136,9 @@ export enum TreeNodeType {
127136
Tree_search_score_leaf = 10911, // 分数范围的叶子
128137
Tree_search_contest_leaf = 10921, // 分数范围的叶子
129138

139+
Tree_recentContestList = 11000, // 题目列表 最近比赛列表
140+
Tree_recentContestList_contest = 11010, // 题目列表 最近比赛列表/比赛
141+
Tree_recentContestList_contest_leaf = 11011, // 题目列表 最近比赛列表/比赛/题目
130142

131143
// 工地=================
132144

@@ -167,7 +179,8 @@ export function is_problem_by_nodeType(nt) {
167179
nodeType == TreeNodeType.Tree_contest_Q4_leaf ||
168180
nodeType == TreeNodeType.Bricks_NeedReview_Day_leaf ||
169181
nodeType == TreeNodeType.Bricks_TodaySubmit_leaf ||
170-
nodeType == TreeNodeType.Bricks_Diy_leaf
182+
nodeType == TreeNodeType.Bricks_Diy_leaf ||
183+
nodeType == TreeNodeType.Tree_recentContestList_contest_leaf
171184
);
172185

173186
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { BABAMediator, BABAProxy, BabaStr, BaseCC, BABA } from "../BABA";
2+
import { OutPutType } from "../model/ConstDefind";
3+
import { promptForSignIn, ShowMessage } from "../utils/OutputUtils";
4+
5+
class ContestQuestionData {
6+
fidInfo: Map<string, number[]> = new Map<string, number[]>();
7+
8+
setFidInfo(fid, data) {
9+
this.fidInfo.set(fid, data);
10+
}
11+
12+
getFidInfo(fid) {
13+
return this.fidInfo.get(fid);
14+
}
15+
}
16+
17+
const contestQuestionData: ContestQuestionData = new ContestQuestionData();
18+
19+
export class ContestQuestionProxy extends BABAProxy {
20+
static NAME = BabaStr.ContestQuestionProxy;
21+
constructor() {
22+
super(ContestQuestionProxy.NAME);
23+
}
24+
25+
public getAllRecentContestQuestionData() {
26+
return contestQuestionData.fidInfo;
27+
}
28+
29+
public getContestQuestionData(contestName) {
30+
return contestQuestionData.getFidInfo(contestName);
31+
}
32+
33+
public async searchContestQuestionData(contestName): Promise<void> {
34+
let sbp = BABA.getProxy(BabaStr.StatusBarProxy);
35+
if (!sbp.getUser()) {
36+
promptForSignIn();
37+
return;
38+
}
39+
try {
40+
const solution: string = await BABA.getProxy(BabaStr.ChildCallProxy)
41+
.get_instance()
42+
.getContestQuestion(contestName);
43+
const query_result = JSON.parse(solution);
44+
45+
for (let i = 0; i < query_result.length; i++) {
46+
let data = query_result[i].questions.map((item) => item.question_id);
47+
contestQuestionData.setFidInfo(query_result[i].contest, data);
48+
}
49+
BABA.sendNotification(BabaStr.TreeData_searchContestQuestionFinish);
50+
} catch (error) {
51+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
52+
await ShowMessage("Failed to fetch question of" + contestName + ". 请查看控制台信息~", OutPutType.error);
53+
}
54+
}
55+
}
56+
57+
export class ContestQuestionMediator extends BABAMediator {
58+
static NAME = BabaStr.ContestQuestionMediator;
59+
constructor() {
60+
super(ContestQuestionMediator.NAME);
61+
}
62+
63+
listNotificationInterests(): string[] {
64+
return [
65+
BabaStr.TreeData_searchRecentContestFinish,
66+
];
67+
}
68+
async handleNotification(_notification: BaseCC.BaseCC.INotification) {
69+
switch (_notification.getName()) {
70+
case BabaStr.TreeData_searchRecentContestFinish:
71+
let ContestList = BABA.getProxy(BabaStr.RecentContestProxy).getAllRecentContestData();
72+
let contestName = Array.from(ContestList.keys()).join(",");
73+
await BABA.getProxy(BabaStr.ContestQuestionProxy).searchContestQuestionData(contestName);
74+
break;
75+
default:
76+
break;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)