|
@@ -134,17 +134,8 @@ class TFsmHitoryService extends Service {
|
|
|
return;
|
|
|
}
|
|
|
initData.start_time = new Date();
|
|
|
-
|
|
|
- // const length = 100;
|
|
|
- // let startNum = 0;
|
|
|
- // const vinArray = [];
|
|
|
- // while (startNum % 100 == 0) {
|
|
|
- // // const v = await this.group(startNum, length, timeRangData);
|
|
|
- // vinArray.push(v);
|
|
|
- // startNum += v.length;
|
|
|
- // }
|
|
|
const vins = await this.group(timeRangData);
|
|
|
-
|
|
|
+ const other = await this.other(timeRangData);
|
|
|
initData.end_time = new Date();
|
|
|
|
|
|
|
|
@@ -163,133 +154,196 @@ class TFsmHitoryService extends Service {
|
|
|
await ctx.service.statisticsService.save(ctx.model.Local.TFsmHitoryModel,
|
|
|
{ ...initData, vins }, isForceUpdate);
|
|
|
}
|
|
|
+ if (other.length > 1000) {
|
|
|
+ let end = 0;
|
|
|
+ while (end < other.length) {
|
|
|
+ const end2 = end + 1000;
|
|
|
+ const v = other.filter((item, index) => {
|
|
|
+ return index >= end && index < end2;
|
|
|
+ });
|
|
|
+ await ctx.service.statisticsService.save(ctx.model.Local.TFsmHitoryModel,
|
|
|
+ { ...initData, vins: v }, isForceUpdate);
|
|
|
+ end = end2;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (other.length != 0) {
|
|
|
+ await ctx.service.statisticsService.save(ctx.model.Local.TFsmHitoryModel,
|
|
|
+ { ...initData, vins: other }, isForceUpdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
// startNum = 0, lenth = 100,
|
|
|
async group({ startTime, endTime }) {
|
|
|
const { ctx } = this;
|
|
|
- const agg = [
|
|
|
- // { $addFields: { create_date: { $toLong: { $arrayElemAt: [{ $split: [ '$_id', '$vin' ] }, 1 ] } } } },
|
|
|
- { $match: ctx.helper.getTimeRangMatch(startTime, endTime, 'timeStamp') },
|
|
|
- { $group: { _id: '$vin',
|
|
|
- danger_drive_cnt: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [ '$ANALYSIS_LDW_STATUS', '1' ] },
|
|
|
- { $eq: [ '$ANALYSIS_BSD_STATUS', '1' ] },
|
|
|
- { $eq: [ '$ANALYSIS_FCW_STATUS', '1' ] },
|
|
|
- { $eq: [ '$ANALYSIS_LKA_STATUS', '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- safety_air_bag_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_SAFETY_AIR_BAG_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- fault_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_FAULT_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- long_drive_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_DSM_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- speeding_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_SPEEDING_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- un_tie_sb_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_UN_TIE_SB_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- leave_sw_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_LEAVE_SW_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- acceleration_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_ACCELERATION_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- decelerate_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_DECELERATE_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- turn_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_TURN_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
- clu_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_CLU_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ let vins = [];
|
|
|
+ let aggStart = startTime;
|
|
|
+ while (aggStart < endTime) {
|
|
|
+ const aggEnd = aggStart + 30 * 60 * 1000;
|
|
|
+ const agg = [
|
|
|
+ { $match: ctx.helper.getTimeRangMatch(aggStart, aggEnd, 'timeStamp') },
|
|
|
+ { $group: { _id: '$vin',
|
|
|
+ danger_drive_cnt: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [ '$ANALYSIS_LDW_STATUS', '1' ] },
|
|
|
+ { $eq: [ '$ANALYSIS_BSD_STATUS', '1' ] },
|
|
|
+ { $eq: [ '$ANALYSIS_FCW_STATUS', '1' ] },
|
|
|
+ { $eq: [ '$ANALYSIS_LKA_STATUS', '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ safety_air_bag_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_SAFETY_AIR_BAG_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ fault_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_FAULT_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ long_drive_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_DSM_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ speeding_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_SPEEDING_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ un_tie_sb_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_UN_TIE_SB_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ leave_sw_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_LEAVE_SW_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ acceleration_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_ACCELERATION_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ decelerate_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_DECELERATE_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ turn_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_TURN_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
+ clu_cnt: { $sum: { $cond: [{ $eq: [ '$ANALYSIS_CLU_STATUS', '1' ] }, 1, 0 ] } },
|
|
|
|
|
|
- fault_type1: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0100', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0102', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0116', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0107', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0152', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type2: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0149', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0148', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0110', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0123', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0136', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0164', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0147', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0130', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0135', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0118', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0169', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0104', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0114', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0162', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0170', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0165', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0171', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0172', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0127', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0131', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0132', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0159', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0160', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0166', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0167', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0168', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0126', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type3: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0101', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0158', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type4: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0106', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0115', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type5: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0105', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0109', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0111', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0157', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0145', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0113', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0117', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type6: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0141', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0112', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0161', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- fault_type7: { $sum: { $cond: [{ $or: [
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0103', 1 ] }, '1' ] },
|
|
|
- { $eq: [{ $arrayElemAt: [ '$_S0143', 1 ] }, '1' ] },
|
|
|
- ] }, 1, 0 ] } },
|
|
|
- v_parking_cnt: { $sum: { $cond: [{ $in: [{ $arrayElemAt: [ '$_S0210', 1 ] },
|
|
|
- [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]] }, 1, 0 ] } },
|
|
|
- acc_cnt: { $sum: { $cond: [{ $arrayElemAt: [ '$_S0508', 1 ] }, 1, 0 ] } },
|
|
|
- } },
|
|
|
- // { $skip: startNum },
|
|
|
- // { $limit: lenth },
|
|
|
- // { $group: {
|
|
|
- // _id: null,
|
|
|
- // vins: { $push: '$$ROOT' },
|
|
|
- // } },
|
|
|
- {
|
|
|
- $bucketAuto: {
|
|
|
- groupBy: '$_id',
|
|
|
- buckets: 100,
|
|
|
- output: {
|
|
|
- vins: { $push: '$$ROOT' },
|
|
|
+ fault_type1: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0100', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0102', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0116', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0107', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0152', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type2: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0149', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0148', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0110', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0123', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0136', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0164', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0147', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0130', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0135', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0118', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0169', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0104', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0114', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0162', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0170', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0165', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0171', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0172', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0127', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0131', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0132', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0159', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0160', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0166', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0167', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0168', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0126', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type3: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0101', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0158', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type4: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0106', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0115', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type5: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0105', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0109', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0111', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0157', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0145', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0113', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0117', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type6: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0141', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0112', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0161', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ fault_type7: { $sum: { $cond: [{ $or: [
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0103', 1 ] }, '1' ] },
|
|
|
+ { $eq: [{ $arrayElemAt: [ '$_S0143', 1 ] }, '1' ] },
|
|
|
+ ] }, 1, 0 ] } },
|
|
|
+ v_parking_cnt: { $sum: { $cond: [{ $in: [{ $arrayElemAt: [ '$_S0210', 1 ] },
|
|
|
+ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]] }, 1, 0 ] } },
|
|
|
+ acc_cnt: { $sum: { $cond: [{ $gte: [{ $size: { $ifNull: [ '$_S0508', []] } }, 1 ] }, 1, 0 ] } },
|
|
|
+ } },
|
|
|
+ {
|
|
|
+ $bucketAuto: {
|
|
|
+ groupBy: '$_id',
|
|
|
+ buckets: 100,
|
|
|
+ output: {
|
|
|
+ vins: { $push: '$$ROOT' },
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
- },
|
|
|
- ];
|
|
|
- // const vins = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime)).aggregate(agg)
|
|
|
- // .allowDiskUse(true);
|
|
|
+ ];
|
|
|
+ const obj = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime)).aggregate(agg)
|
|
|
+ .allowDiskUse(true);
|
|
|
+ for (const o of obj) {
|
|
|
+ vins = vins.concat(o.vins);
|
|
|
+ }
|
|
|
+ console.log('time', aggStart, vins.length);
|
|
|
+ aggStart = aggEnd;
|
|
|
+ }
|
|
|
+ return vins;
|
|
|
+ }
|
|
|
+
|
|
|
+ async other({ startTime, endTime }) {
|
|
|
+ const { ctx } = this;
|
|
|
+ // TODO 目前这个agg 查询非常费劲 在7.29以及以后
|
|
|
let vins = [];
|
|
|
- const obj = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime)).aggregate(agg)
|
|
|
- .allowDiskUse(true);
|
|
|
- for (const o of obj) {
|
|
|
- vins = vins.concat(o.vins);
|
|
|
+ let pvins = [];
|
|
|
+ let avins = [];
|
|
|
+ let aggStart = startTime;
|
|
|
+ while (aggStart < endTime) {
|
|
|
+ const aggEnd = aggStart + 30 * 60 * 1000;
|
|
|
+ const agg = [
|
|
|
+ { $match: { ...ctx.helper.getTimeRangMatch(aggStart, aggEnd, 'timeStamp'),
|
|
|
+ '_S0210.1': { $in: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ] },
|
|
|
+ } },
|
|
|
+ { $group: { _id: '$vin' } },
|
|
|
+ {
|
|
|
+ $bucketAuto: {
|
|
|
+ groupBy: '$_id',
|
|
|
+ buckets: 100,
|
|
|
+ output: {
|
|
|
+ vins: { $push: '$$ROOT' },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ const agg2 = [
|
|
|
+ { $match: { ...ctx.helper.getTimeRangMatch(aggStart, aggEnd, 'timeStamp'),
|
|
|
+ '_S0508.1': { $exists: true } },
|
|
|
+ },
|
|
|
+ { $group: { _id: '$vin' } },
|
|
|
+ {
|
|
|
+ $bucketAuto: {
|
|
|
+ groupBy: '$_id',
|
|
|
+ buckets: 100,
|
|
|
+ output: {
|
|
|
+ vins: { $push: '$$ROOT' },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ const obj = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime)).aggregate(agg)
|
|
|
+ .allowDiskUse(true);
|
|
|
+ const obj2 = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime)).aggregate(agg2)
|
|
|
+ .allowDiskUse(true);
|
|
|
+ for (const o of obj) {
|
|
|
+ pvins = pvins.concat(o.vins.map(item => item._id));
|
|
|
+ }
|
|
|
+ for (const o of obj2) {
|
|
|
+ avins = avins.concat(o.vins.map(item => item._id));
|
|
|
+ }
|
|
|
+ aggStart = aggEnd;
|
|
|
}
|
|
|
+ vins = [ ...new Set(pvins.concat(avins)) ];
|
|
|
console.log('size', vins.length);
|
|
|
-
|
|
|
- const packAll = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({ timeStamp: { $gte: startTime, $lt: endTime },
|
|
|
- '_S0210.1': { $in: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ] },
|
|
|
- });
|
|
|
- const accAll = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({ timeStamp: { $gte: startTime, $lt: endTime },
|
|
|
- '_S0508.1': { $exists: true },
|
|
|
- });
|
|
|
+ if (vins.length == 0) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
let num = 0;
|
|
|
for (const vin of vins) {
|
|
|
num++;
|
|
@@ -302,50 +356,35 @@ class TFsmHitoryService extends Service {
|
|
|
let accCount = 0;
|
|
|
let start = startTime - 1;
|
|
|
console.log('pointList', pointList.length);
|
|
|
- let packOne = null;
|
|
|
- let accOne = null;
|
|
|
- if (packAll) {
|
|
|
- packOne = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({ timeStamp: { $gte: startTime, $lt: endTime }, vin: vin._id,
|
|
|
- '_S0210.1': { $in: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ] },
|
|
|
- });
|
|
|
- }
|
|
|
- if (accAll) {
|
|
|
- accOne = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({ timeStamp: { $gte: startTime, $lt: endTime }, vin: vin._id,
|
|
|
- '_S0508.1': { $exists: true },
|
|
|
- });
|
|
|
- }
|
|
|
- if (packOne || accOne) {
|
|
|
- for (let i = 0; i < pointList.length; i++) {
|
|
|
- const end = pointList[i].timeStamp;
|
|
|
- let pack = null;
|
|
|
- let acc = null;
|
|
|
- if (packOne) {
|
|
|
- pack = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({ timeStamp: { $gt: start, $lte: end }, vin: vin._id,
|
|
|
- '_S0210.1': { $in: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ] },
|
|
|
- });
|
|
|
- }
|
|
|
- if (accOne) {
|
|
|
- acc = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
- .findOne({
|
|
|
- timeStamp: { $gt: start, $lte: end }, vin: vin._id,
|
|
|
- '_S0508.1': { $exists: true },
|
|
|
- });
|
|
|
- }
|
|
|
- if (pack || acc) {
|
|
|
- intelCount++;
|
|
|
- }
|
|
|
- if (pack) {
|
|
|
- packCount++;
|
|
|
- }
|
|
|
- if (acc) {
|
|
|
- accCount++;
|
|
|
- }
|
|
|
- start = end;
|
|
|
+ for (let i = 0; i < pointList.length; i++) {
|
|
|
+ const end = pointList[i].timeStamp;
|
|
|
+ let pack = null;
|
|
|
+ let acc = null;
|
|
|
+ if (pvins.indexOf(vin)!=-1) {
|
|
|
+ pack = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
+ .findOne({ timeStamp: { $gt: start, $lte: end }, vin: vin._id,
|
|
|
+ '_S0210.1': { $in: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ] },
|
|
|
+ });
|
|
|
}
|
|
|
+ if (avins.indexOf(vin)!=-1) {
|
|
|
+ acc = await this.app.getHistoryModel(ctx.helper.formatTime3(startTime))
|
|
|
+ .findOne({
|
|
|
+ timeStamp: { $gt: start, $lte: end }, vin: vin._id,
|
|
|
+ '_S0508.1': { $exists: true },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (pack || acc) {
|
|
|
+ intelCount++;
|
|
|
+ }
|
|
|
+ if (pack) {
|
|
|
+ packCount++;
|
|
|
+ }
|
|
|
+ if (acc) {
|
|
|
+ accCount++;
|
|
|
+ }
|
|
|
+ start = end;
|
|
|
}
|
|
|
+
|
|
|
vin.intel = intelCount;
|
|
|
vin.pack = packCount;
|
|
|
vin.acc = accCount;
|