Skip to content

2.11.1 #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/controller/BricksViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ class BricksViewController implements Disposable {
}
// 今天搬的
public async getTodayNodes() {
// 增加tooltip
let all_qid: string[] = await bricksDao.getTodayBricksSubmit();
let qid_tip = await bricksDao.getTodayBricksSubmitToolTip(all_qid);
const baseNode: BricksNode[] = [];
all_qid.forEach((qid) => {
let node = treeViewController.getNodeByQid(qid);
if (node) {
baseNode.push(node);
let new_obj = new BricksNode(
Object.assign({}, node.data, {}),
true,
node.user_score,
TreeItemCollapsibleState.None,
0,
qid_tip.get(qid)
);
baseNode.push(new_obj);
}
});
return baseNode;
Expand Down
64 changes: 60 additions & 4 deletions src/dao/bricksDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
import { useWsl, toWinPath, getDayStart, getDayNow } from "../utils/SystemUtils";
import { useWsl, toWinPath, getDayStart, getDayNow, getYMD } from "../utils/SystemUtils";
import * as path from "path";
import * as fse from "fs-extra";
import { BricksType } from "../model/Model";
import { BricksType, BricksTypeName } from "../model/Model";

// let bricks_json = {
// version: 1,
Expand Down Expand Up @@ -75,7 +75,7 @@ class BricksDao {
return allData.all_bricks || {};
}

private getTimeByType(type: number, today_time: number) {
private getTimeByType(type: number, today_time: number, add_flag?: boolean) {
let need_day_ago = 7;
switch (type) {
case BricksType.TYPE_0:
Expand Down Expand Up @@ -108,7 +108,35 @@ class BricksDao {
default:
break;
}
return today_time - need_day_ago * 86400;

return add_flag ? today_time + need_day_ago * 86400 : today_time - need_day_ago * 86400;
}

private getTypeName(type: number) {
switch (type) {
case BricksType.TYPE_0:
return BricksTypeName.TYPE_0;
case BricksType.TYPE_1:
// 1:(14天搬砖simple)
return BricksTypeName.TYPE_1;
case BricksType.TYPE_2:
// 2:(7天后搬砖simple_error)
return BricksTypeName.TYPE_2;
case BricksType.TYPE_3:
// 3:(5天后搬砖simple_time)
return BricksTypeName.TYPE_3;
case BricksType.TYPE_4:
// 4:(3天后搬砖(time_limit))
return BricksTypeName.TYPE_4;
case BricksType.TYPE_5:
// 5:(2天后搬砖(medium))
return BricksTypeName.TYPE_5;
case BricksType.TYPE_6:
// 6: (1天后搬砖(hard))
return BricksTypeName.TYPE_6;
default:
return "";
}
}

public async getTodayBricks(): Promise<string[]> {
Expand Down Expand Up @@ -143,6 +171,34 @@ class BricksDao {
return all_qid;
}

public async getTodayBricksSubmitToolTip(qid_list: Array<string>) {
let today_time = getDayStart();
let all_bricks = await this.getAllBricks();
let result: Map<string, string> = new Map<string, string>();
qid_list.forEach((qid) => {
const value = all_bricks[qid];
if (value == undefined) {
result.set(qid, this.TypetimeToMan(BricksType.TYPE_2, this.getTimeByType(BricksType.TYPE_2, today_time, true)));
} else {
result.set(
qid,
this.TypetimeToMan(
value.type ? value.type : BricksType.TYPE_2,
this.getTimeByType(value.type ? value.type : BricksType.TYPE_2, today_time, true)
)
);
}
});
return result;
}
public TypetimeToMan(type, time: number) {
if (time < 10) {
return BricksTypeName.TYPE_0;
}

return `${this.getTypeName(type)}后${getYMD(time)}出现`; //this.getTypeName(type) + getYMD(time) + "出现";
}

public async getInfoByQid(qid: string) {
let all_bricks = await this.getAllBricks();
return all_bricks[qid] || {};
Expand Down
11 changes: 11 additions & 0 deletions src/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export enum BricksType {
TYPE_7 = 7,
}

export enum BricksTypeName {
TYPE_0 = "不再出现",
TYPE_1 = "14天",
TYPE_2 = "7天",
TYPE_3 = "5天",
TYPE_4 = "3天",
TYPE_5 = "2天",
TYPE_6 = "1天",
TYPE_7 = "999天",
}

export enum Category {
All = "All",
Difficulty = "Difficulty",
Expand Down
11 changes: 10 additions & 1 deletion src/model/NodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,19 @@ export class NodeModel {
export class BricksNode extends NodeModel {
public collapsibleState?;
public groupTime?;
constructor(data: IProblem, ipn: boolean = true, userscore: number = 0, collapsibleState = 0, groupTime?: number) {
public toolTip?;
constructor(
data: IProblem,
ipn: boolean = true,
userscore: number = 0,
collapsibleState = 0,
groupTime?: number,
toolTip?: string
) {
super(data, ipn, userscore);
this.isProblemNode = ipn;
this.collapsibleState = collapsibleState;
this.groupTime = groupTime;
this.toolTip = toolTip;
}
}
3 changes: 3 additions & 0 deletions src/service/BricksDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class BricksDataService implements TreeDataProvider<BricksNode> {
if (element.id === "ROOT") {
return "";
}
if (element.toolTip) {
return element.toolTip;
}
return "";
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils/SystemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ export function getRemakeName(): string {
const newDate = `${year}-${month}-${day} ${hours}:${min}:${s}`;
return newDate;
}

export function getYMD(timeSecond: number): string {
const date = timeSecond ? new Date(timeSecond * 1000) : new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`;
const day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`;
const newDate = `${year}-${month}-${day}`;
return newDate;
}