UNPKG

@tucmc/hazel

Version:
96 lines (95 loc) 4.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimulatedDataPresets = void 0; const crypto = __importStar(require("crypto")); const DMap_1 = require("../../util/data/DMap"); const ID_1 = require("./ID/ID"); class SimulatedDataPresets { static randomNoise() { return (+new Date() * Math.random()).toString(36).substring(0, 6); } static randomStatus() { const foo = Math.random() * 100; if (foo < 80) { return { action: 'passed' }; } else if (foo < 92) { return { action: 'break' }; } else { return { action: 'failed' }; } } static rooms = [ 65, 66, 70, 71, 72, 276, 277, 278, 341, 342, 343, 344, 345, 437, 438, 446, 447, 448, 661, 662, 664, 665, 666, 667, 834, 835, 842, 843, 844, 845, 846, 942, 943, 945, 946, 947, 332, 333, 334, 335, 336, 431, 432, 436, 443, 444, 445, 642, 651, 652, 654, 655, 656, 657, 812, 813, 814, 815, 822, 823, 824, 825, 832, 833, 931, 932, 933, 934, 935, 936, 937, 941, 28, 29, 32, 38, 39, 48, 49, 58, 59, 73, 74, 75, 76, 77, 78, 79, 80, 81, 125, 126, 143, 144, 145, 146, 153, 154, 155, 156, 222, 223, 224, 225, 226, 227, 228, 229 ]; static titleList = ['นาย', 'นางสาว', 'เด็กหญิง', 'เด็กชาย']; static RandomStudents() { const data = new DMap_1.DMap({}); const roomC = 45; const count = this.rooms.length * roomC; for (let c = 0; c < count; c++) { const uuid = crypto.randomUUID(); const rn = this.randomNoise(); const title = this.titleList[Math.floor(Math.random() * this.titleList.length)]; data.set(`simulated-${uuid}`, { student_id: `id-${uuid}`, firstname: `firstname-${rn}`, lastname: `lastname-${rn}`, title: title, room: (this.rooms[Math.floor((c + 1) / roomC)] || '999').toString(10) || '999', level: (Math.floor(Math.floor((c + 1) / roomC) / 36) + 4).toString(10), number: (((c + 1) % roomC) + 1).toString(10), old_club: [...ID_1.ID.systemClubs.keys(), ''][Math.floor(Math.random() * ID_1.ID.systemClubs.keys().length + 1)], club: ID_1.ID.systemClubs.keys()[Math.floor(Math.random() * ID_1.ID.systemClubs.keys().length)] }); } return data.getRecord(); } static RandomEvaluation(studentDataCollection) { const data = new DMap_1.DMap({}); const grouped = studentDataCollection.groupBy((v) => v.get('club')); grouped.iterateSync((key, value, index, obj) => { const a = new DMap_1.DMap({}); value.map((v) => { const id = Object.values(v)[0]?.get('student_id'); if (!id) return; a.set(id, this.randomStatus()); }); data.set(key, a.getRecord()); }); return data.getRecord(); } } exports.SimulatedDataPresets = SimulatedDataPresets;