-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_category.js
53 lines (50 loc) · 1.48 KB
/
session_category.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const session_example = require("./session_example.json");
// console.table(session_example[0]["description"]);
/*
要加入的:
檔名: 駕照等級_dmvNo.json
result:
[
{
"category_id",
"count",
"description",
"date_list":[
]
}
]
*/
function category(search_table, dmvName, licenseTypeCode) {
let description_list = [];
let result_list = [];
for (const [key, value] of Object.entries(search_table)) {
const description = value["description"];
let category_id;
if (value["secId"] || value["divId"]) {
category_id = `${value["secId"]}_${value["divId"]}`;
}
if (!description_list.includes(description)) {
description_list.push(description);
result_list.push({
dmvName: dmvName,
licenseTypeCode: licenseTypeCode,
category_id: category_id ?? 0,
count: 1,
description: description,
date_list: [value["date"]],
});
} else {
// Add date
for (const [key, result] of Object.entries(result_list)) {
if (description === result["description"]) {
result["category_id"] = category_id ?? 0;
result["count"]++;
result["date_list"].push(value["date"]);
}
}
}
}
return result_list;
}
category(session_example);
module.exports = category;