diff --git a/src/health.ts b/src/health.ts new file mode 100644 index 0000000..a2795d0 --- /dev/null +++ b/src/health.ts @@ -0,0 +1,37 @@ +import {IJsonCourse} from "./types" +import {JsonCourseList} from "./poll" +import {findJsonCourse} from "./includes" +import {appConfig} from "./config" + +let lastJsonCourseList: { bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] } +let firstRunHealth = true + +export async function health() { + let totalAcquireCount = 0 + let totalExitCount = 0 + if (firstRunHealth) { + console.log('[health]程序health监控启动完毕') + firstRunHealth = false + } else { + for (let channel of appConfig.channels) { + for (let lastCourse of lastJsonCourseList[channel]) { + let currentCourse = findJsonCourse({ + kch: lastCourse.kch, + kxh: parseInt(lastCourse.kxh), + channel: channel + }) + if (currentCourse == undefined) { + continue + } + if (parseInt(currentCourse.syrs) > parseInt(lastCourse.syrs)) { + totalExitCount += parseInt(currentCourse.syrs) - parseInt(lastCourse.syrs) + } else { + totalAcquireCount += parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs) + } + } + } + console.log('[health]实时总退课人次:' + totalExitCount + ',总选课人次:' + totalAcquireCount) + } + lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList)) + setTimeout(health, 60 * 1000) +} diff --git a/src/index.ts b/src/index.ts index 5145eca..9e7059d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import {JsonCourseList, poll} from "./poll" import {appConfig} from "./config" import {acquireProcess, monitProcess, replaceProcess} from "./actions" import {sleep} from "./includes" +import {health} from "./health" async function start() { console.log('开始启动轮询进程') @@ -30,6 +31,7 @@ async function start() { replaceProcess(appConfig.replace.list, appConfig.replace.exit) } console.log('用户进程启动完毕') + health() } start() diff --git a/src/test.ts b/src/test.ts index 2de6b95..7e1544f 100644 --- a/src/test.ts +++ b/src/test.ts @@ -23,8 +23,8 @@ async function test() { let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody) fs.writeFileSync('arr.json', JSON.stringify(resp.data.aaData, null, 2)) let courseList: IJsonCourse[] = resp.data.aaData - courseList = courseList.filter(single => (single.kcmc.includes('稷下创新') || single.kcmc.includes('齐鲁创业')) - && single.xqmc == '软件园校区') + courseList = courseList.filter(single => single.kcmc.includes('稷下创新') + && single.xf >= 2) for (let course of courseList) { console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf) }