[add] 改成撈每周

This commit is contained in:
建喵 2022-04-15 14:34:05 +08:00
parent f5438c7f65
commit 760be5089b
5 changed files with 183 additions and 7 deletions

14
package-lock.json generated
View File

@ -11,6 +11,7 @@
"@ant-design/icons-vue": "^6.1.0",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
"moment": "^2.29.2",
"vue": "^3.2.25"
},
"devDependencies": {
@ -1061,6 +1062,14 @@
"sourcemap-codec": "^1.4.8"
}
},
"node_modules/moment": {
"version": "2.29.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==",
"engines": {
"node": "*"
}
},
"node_modules/nanoid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz",
@ -2348,6 +2357,11 @@
"sourcemap-codec": "^1.4.8"
}
},
"moment": {
"version": "2.29.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
},
"nanoid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz",

View File

@ -11,6 +11,7 @@
"@ant-design/icons-vue": "^6.1.0",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
"moment": "^2.29.2",
"vue": "^3.2.25"
},
"devDependencies": {

View File

@ -17,7 +17,7 @@ import BJ_Casino_Rank from './components/BJ_Casino_Rank.vue';
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
margin-top: 0px;
font-family: 'Zen Maru Gothic', sans-serif;
}
</style>

View File

@ -6,7 +6,8 @@ import { BJ_Casino_Rank } from "../script/BJ_Casino_Rank";
let Title = ref("BJ_Casino_Rank");
let RankData = ref([]);
const self = {
RankData: RankData
Title: Title,
RankData: RankData,
}
const Script = new BJ_Casino_Rank(self);
@ -23,6 +24,7 @@ const Script = new BJ_Casino_Rank(self);
<th align="left">倍率</th>
<th align="left">機台</th>
<th align="left">桌號</th>
<th align="left">日期</th>
</tr>
</thead>
<tbody>
@ -43,8 +45,12 @@ const Script = new BJ_Casino_Rank(self);
<td align="left">
<font size="5"><b>{{ item[3][1] }}</b></font>
</td>
<td align="left">
<font size="5"><b>{{ item[4] }}</b></font>
</td>
</tr>
</tbody>
</table> </div>
</table>
</div>
</template>

View File

@ -1,12 +1,36 @@
import moment from 'moment';
export class BJ_Casino_Rank {
//#region public
public ContestData: string[] = ["4/7~4/13", "4/14~4/20", "4/21~4/27"];
//#endregion
//#region private
private _client: any;
private _ws: any;
private _rankdata: any = null;
private _rankdata: any[] = [];
private _nowSearchContestID: number = 0;
private _nowContestIndex: number = 0;
private _nowContestStartIndex: number = 0;
private _nowContestEndIndex: number = 0;
private _nowContestID: number = 0;
private _nowContestDate: string = "";
private _nowContestStart: string = "";
private _nowContestEnd: string = "";
//#endregion
@ -109,7 +133,12 @@ export class BJ_Casino_Rank {
}
case "rank.info": {
this.SetRankData(Data);
this.RankDataCallBack(Data);
break;
}
case "rank.history": {
this.ParseRankData(Data);
this._ws.close();
break;
}
@ -119,13 +148,139 @@ export class BJ_Casino_Rank {
}
}
public SetRankData(data: any) {
let rankdata = data["rank"];
public RankDataCallBack(data: any) {
let id = +data["id"];
this._nowSearchContestID = id;
this._nowContestID = id;
this._nowContestDate = moment().format("MM/DD");
for (let i = 0; i < this.ContestData.length; i++) {
const contest: string = this.ContestData[i];
let str = contest.split("~");
let my = moment(this._nowContestDate);
let start = moment(str[0]);
let end = moment(str[1]);
let diff: number = my.diff(end, "days");
if (diff < 0) {
this._nowContestIndex = i;
this._nowContestStart = moment(start).format("MM/DD");
this._nowContestEnd = moment(end).format("MM/DD");
this._nowContestStartIndex = this._contestIDFormDate(this._nowContestStart);
this._nowContestEndIndex = this._contestIDFormDate(this._nowContestEnd);
break;
}
}
this._client.Title.value = `${this._nowContestStart}~${this._nowContestEnd}`;
this.ParseRankData(data);
}
public ParseRankData(data: any) {
let id = this._nowSearchContestID;
this.RankDataAddDate(id, data["rank"]);
this._rankdata = this._rankdata.concat(data["rank"]);
if (id !== this._nowContestStartIndex) {
this._nowSearchContestID = id - 1;
this.SendData("rank.history", { "id": this._nowSearchContestID, "t": 12, "p": 2 });
} else {
this.OrganizeRankData(this._rankdata);
this.SetRankData(this._rankdata);
}
}
public RankDataAddDate(id: number, rankdata: any) {
let date: string = this._contestDateFormID(id);
for (let i = 0; i < rankdata.length; i++) {
rankdata[i].push(date);
}
return rankdata;
}
public OrganizeRankData(rankdata: any) {
rankdata.sort((a: any, b: any) => {
return b[1] - a[1];
});
rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => {
return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index;
});
for (let i = 0; i < rankdata.length; i++) {
rankdata[i][0] = i + 1;
}
this._rankdata = rankdata;
}
public SetRankData(rankdata: any) {
this._client.RankData.value = rankdata;
}
//#endregion
//#region Get
private _contestIDFormDate(date: string): number {
let my = moment(this._nowContestDate);
let target = moment(date);
let diffday: number = my.diff(target, "days");
let id = this._nowContestID - diffday;
if (id < 0) {
return 0;
} else {
return id;
}
};
private _contestDateFormID(id: number): string {
let my: number = this._nowContestID;
let target: number = id;
let diffid: number = my - target;
if (diffid < 0) {
diffid = 0;
}
let date: string = moment().subtract(diffid, "days").format("MM/DD");
return date;
};
//#endregion
//#region Tools Function
/**
* asc&key陣列長度請一樣
* PS. boolean false是先true在false
* @link JavaScript Object http://www.eion.com.tw/Blogger/?Pid=1170#:~:text=JavaScript%20Object%20排序
* @param Arr
* @param asc ()
* @param key key()()
*/
public ObjectSort(Arr: any[], asc: boolean[] = [true], key?: string[]): any[] {
if (!key || key.length === 0 || Arr.length === 0 || Arr[0][key[0]] === undefined) {
console.error(`ObjectSort key error`);
return Arr;
} else if (asc.length !== key.length) {
console.error(`ObjectSort key asc error asc.length: ${asc.length}, key.length: ${key.length}`);
return Arr;
}
let count: number = key ? key.length : 1;
for (let i: number = count - 1; i >= 0; i--) {
Arr = Arr.sort(function (a: any, b: any): 1 | -1 {
let mya: any = a;
let myb: any = b;
if (key) {
mya = a[key[i]];
myb = b[key[i]];
}
// 加個等於數字相同不要再去排序到
if (asc[i]) {
return mya >= myb ? 1 : -1;
} else {
return mya <= myb ? 1 : -1;
}
});
}
return Arr;
}
//#endregion
//#region WebSocke
public OnWebSocketMessage(e: any) {