buildcodes.js
12.8 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
import Vue from "vue";
class Codes {
constructor() {
this.allTypes = ["vehicle", "xcycle", "pflow", "pedestrian"];
}
/**
* INIT
* 初始化所需参数
* 返回得到的结果
*/
getCodeList(name) {
console.log(JSON.parse(window.localStorage.getItem(name)));
return JSON.parse(window.localStorage.getItem(name));
}
init(allData) {
this.cate = allData.event_cate;
this.event_type = allData.event_type;
this.allData = allData;
this.result = {};
this.result = allData;
this.classify();
console.log(this.result);
return this.result;
}
// 分类
classify() {
if (!this.allData) {
return "";
}
if (this.cate === "traffic") {
this.trafficCode();
}
if (this.cate === "behavior") {
this.beheiverCode();
}
}
// 安防事件处理
beheiverCode() {
this.publicCode();
this.behavior();
}
// 交通事件处理
trafficCode() {
this.publicCode();
if (this.event_type === "vehicle") {
this.vehicle();
}
if (this.event_type === "xcycle" || this.event_type === "pedestrian") {
this.xcycle();
}
if (this.event_type === "pflow") {
this.pflow();
}
}
// *根据不同event_type做不同处理*
// 公共字段提取
publicCode() {
try {
// eslint-disable-next-line camelcase
let shoot_dt = this.timeForm(this.result.pics[0].shoot_dt, "local").split(
" "
);
this.result.shoot_date = shoot_dt[0];
this.result.shoot_time = shoot_dt[1];
} catch (error) {
if (this.curType === 1) {
// eslint-disable-next-line camelcase
let shoot_dt = this.timeForm(this.result.event_dt, "local").split(" ");
this.result.shoot_date = shoot_dt[0];
this.result.shoot_time = shoot_dt[1];
} else {
this.result.shoot_dt = "未识别";
}
}
// 时间
try {
this.result.event_dt = this.allData.event_dt;
} catch (err) {
this.result.event_dt = "";
}
try {
this.result.location_speed = this.allData.event_data.speed;
} catch (err) {
this.result.location_speed = "";
}
}
//安防
behavior() {
if (this.allData.event_type === "32") {
this.result.number = this.allData.event_data.number;
} else {
this.result.number = "--";
}
try {
this.result.event_type = this.getCode(
"安防事件",
this.allData.event_type
);
} catch (error) {
this.result.event_type = "未识别";
}
try {
this.result.direction_text = this.getCode(
"卡口方向",
this.allData.event_data.direction.code
);
} catch (err) {
this.result.direction_text = "未识别";
}
try {
this.result.lane_text = this.getCode(
"车道类型",
this.allData.event_data.lane.code
);
} catch (err) {
this.result.lane_text = "未识别";
}
}
// 交通
vehicle() {
try {
if (
(this.allData.event_data.vehicle.body &&
this.allData.event_data.vehicle.body.type.special_type) ||
this.allData.event_data.vehicle.body.type.special_type == 0
) {
if (this.allData.event_data.vehicle.body.type.special_type == 0) {
this.result.special_text = "正常车辆";
} else if (
this.allData.event_data.vehicle.body.type.special_type == 1
) {
this.result.special_text = "车辆运输车";
} else if (
this.allData.event_data.vehicle.body.type.special_type == 2
) {
this.result.special_text = "危险品运输车";
} else if (
this.allData.event_data.vehicle.body.type.special_type == 3
) {
this.result.special_text = "救护车";
}
} else {
this.result.special_text = "未知";
}
} catch (error) {
this.result.special_text = "未知";
}
try {
this.result.vehicle_plate_text =
this.allData.event_data.vehicle.plate.text || "未识别";
} catch (err) {
this.result.vehicle_plate_text = "未识别";
}
// 违法类型
try {
this.result.illegalType =
parseInt(this.allData.event_data.illegal.state) === 1
? this.getCode("违法类型", this.allData.event_data.illegal.code)
: "正常";
} catch (err) {
this.result.illegalType = "未识别";
}
try {
this.result.location_name =
this.allData.event_data.location.name === ""
? "无"
: this.allData.event_data.location.name;
} catch (e) {
this.result.location_name = "未识别";
}
try {
this.result.vehicle_body_type_text = this.getCode(
"车辆类型",
this.allData.event_data.vehicle.body.type.code
);
} catch (err) {
this.result.vehicle_body_type_text = "未识别";
}
try {
this.result.vehicle_body_logo_text = this.getCode(
"车辆品牌",
this.allData.event_data.vehicle.body.logo.code
);
} catch (err) {
this.result.vehicle_body_logo_text = "未识别";
}
try {
this.result.plate_type_text = this.getCode(
"号牌类型",
this.allData.event_data.vehicle.plate.type_code
);
} catch (err) {
this.result.plate_type_text = "未识别";
}
try {
this.result.vehicle_body_color_text = this.getCode(
"车身颜色",
this.allData.event_data.vehicle.body.color.code
);
} catch (err) {
this.result.vehicle_body_color_text = "未识别";
}
let ary = [];
try {
if (this.allData.event_data.RefinedFeature.rAnnualInspection) {
ary.push("年检标志");
}
} catch (e) {
console.log("年检标志无");
}
try {
if (this.allData.event_data.RefinedFeature.rDecoration) {
ary.push("摆件");
}
} catch (e) {
console.log("摆件无");
}
try {
if (this.allData.event_data.RefinedFeature.rPendant) {
ary.push("吊坠");
}
} catch (e) {
console.log("吊坠无");
}
try {
if (this.allData.event_data.RefinedFeature.rSunshading) {
ary.push("遮阳板");
}
} catch (e) {
console.log("遮阳板无");
}
if (ary.length) {
this.result.RefinedFeature_text = ary.join("");
} else {
this.result.RefinedFeature_text = "未识别";
}
}
// 非机动车
xcycle() {
// 性别
try {
switch (this.allData.event_data.driver.face[0].sex) {
case "1":
this.result.driver_face_sex = "男";
break;
case "2":
this.result.driver_face_sex = "女";
break;
case "0":
this.result.driver_face_sex = "不确定";
break;
default:
break;
}
} catch (err) {
this.result.driver_face_sex = "未识别";
}
// 身高
try {
this.result.pedestrian_height = this.allData.event_data.pedestrian.height.toFixed(
2
);
} catch (err) {
this.result.pedestrian_height = "未识别";
}
// 是否戴帽子
try {
switch (this.allData.event_data.driver.face[0].with_hats) {
case 0:
this.result.driver_face_with_hats = "不确定";
break;
case 1:
this.result.driver_face_with_hats = "戴帽子";
break;
case 2:
this.result.driver_face_with_hats = "未戴帽";
break;
default:
break;
}
} catch (err) {
this.result.driver_face_with_hats = "未识别";
}
// 车辆颜色
try {
this.result.xcycle_color_type =
this.allData.event_data.xcycle.color.name || "未识别";
} catch (error) {
this.result.xcycle_color_type = "未识别";
}
// 违法类型
try {
this.result.illegalType =
parseInt(this.allData.event_data.illegal.state) === 1
? this.getCode("违法类型", this.allData.event_data.illegal.code)
: "正常";
} catch (err) {
this.result.illegalType = "未识别";
}
//身高
try {
this.result.driver_height = this.allData.event_data.pedestrian.height.toFixed(
2
);
} catch (err) {
this.result.driver_height = "未识别";
}
// 行人上身颜色
try {
this.result.driver_face_upbody_text = this.getCode(
"车身颜色",
this.allData.event_data.driver.face[0].upbody.code
);
} catch (err) {
this.result.driver_face_upbody_text = "未识别";
}
// 行人下身颜色
try {
this.result.driver_face_lobody_text = this.getCode(
"车身颜色",
this.allData.event_data.driver.face[0].lobody.code
);
} catch (err) {
this.result.driver_face_lobody_text = "未识别";
}
// 车辆品牌
try {
this.result.vehicle_body_logo_text = this.getCode(
"车辆品牌",
this.result.event_data.vehicle.body.logo.code
);
} catch (err) {
this.result.vehicle_body_logo_text = "未识别";
}
// 地点名称
try {
this.result.location_name =
this.allData.event_data.location.name === ""
? "未知"
: this.allData.event_data.location.name;
} catch (e) {
this.result.location_name = "未识别";
}
// 车牌号码
try {
this.result.xcycle_plate_text =
this.allData.event_data.xcycle.plate.text || "未识别";
} catch (error) {
this.result.xcycle_plate_text = "未识别";
}
// 骑车类型
console.log(this.allData.event_data.xcycle_type)
if(!this.allData.event_data.xcycle_type){
this.result.xcycle_type_text = "行人";
}else{
try {
switch (this.allData.event_data.xcycle_type) {
case "motorcycle":
this.result.xcycle_type_text = "摩托车";
break;
case "bicycle":
this.result.xcycle_type_text = "自行车";
break;
case "tricycle":
this.result.xcycle_type_text = "三轮车";
break;
default:
break;
}
} catch (err) {
this.result.xcycle_type_text = "未识别";
}
}
try {
if (this.result.xcycle_type_text === "自行车") {
this.result.company = this.allData.event_data.xcycle.company.name;
} else if (this.result.xcycle_type_text === "摩托车") {
if (typeof this.allData.event_data.xcycle.company.code !== "number") {
this.result.company = "未识别";
} else {
this.result.company = this.getCode(
"外卖公司",
this.allData.event_data.xcycle.company.code
);
}
} else if (this.result.xcycle_type_text === "三轮车") {
if (typeof this.allData.event_data.xcycle.company.code !== "number") {
this.result.company = "未识别";
} else {
this.result.company = this.getCode(
"快递公司",
this.allData.event_data.xcycle.company.code
);
}
} else {
this.result.company = "无";
}
} catch (error) {
this.result.company = "未识别";
}
}
// 客流
pflow() {}
/**
* buildError
*/
buildError() {
throw new Error("检测字段是否存在");
}
getCode(codeName, code) {
var name = window.localStorage.getItem(codeName + "-" + code);
name = name || "";
return name;
}
/**
* timerfrom
*/
timeForm(time, str, boo) {
var bjTime;
if (time === undefined || time === "") {
bjTime = new Date();
} else if (str === "local") {
try {
// 兼容
var _dayTime = time.split(" ");
var d = _dayTime[0].split("-");
var mi = _dayTime[_dayTime.length - 1].split(":");
bjTime = new Date();
// 给date赋值年月日
bjTime.setUTCFullYear(d[0], d[1] - 1, d[2]);
// 给date赋值时分秒
bjTime.setUTCHours(mi[0] - 8, mi[1], mi[2]);
} catch (err) {
// console.log('转化本地时间异常:', err.message);
bjTime = new Date(time);
}
if (boo) {
bjTime = new Date(bjTime.getTime() + 28800000 - 86400000);
} else {
bjTime = new Date(bjTime.getTime() + 28800000);
}
} else if (str === "utc") {
if (typeof time === "object") {
if (boo) {
bjTime = new Date(time.getTime() - 28800000 + 1000);
} else {
bjTime = new Date(time.getTime() - 28800000);
}
} else {
if (boo) {
bjTime = new Date(new Date(time).getTime() - 28800000 + 1000);
} else {
bjTime = new Date(new Date(time).getTime() - 28800000);
}
}
} else {
bjTime = new Date(time);
}
var standardTime = [
[bjTime.getFullYear(), bjTime.getMonth() + 1, bjTime.getDate()].join("-"),
[bjTime.getHours(), bjTime.getMinutes(), bjTime.getSeconds()].join(":")
]
.join(" ")
.replace(/(?=\b\d\b)/g, "0");
return standardTime;
}
}
export let buildCode = new Codes();