sqlite

var sqlite = require('./1').sqlite;
//console.log(sqlite)

let list=[];

for(let item in sqlite){
    //console.log(sqlite[item].DevSN)
    let mark = sqlite[item].Mark;
    
    //if(mark.indexOf("版本升级成功")>=0||mark.indexOf("Over1")>=0){}
    let row = sqlite[item];
    if(sqlite[item].Item=="升级版本"){
        //console.log(mark);
        //console.log(row)
        let dev={};
        //from thi thin 不初始化的时候为什么bug呢?
        dev.DevModel = row.DevModel;
        dev.mac=row.DevSN;
        dev.Result=row.Result;
        dev.Time=row.Time;
        dev.Item=row.Item;
        let  lDev=null
        for(let ii in list){
            if(dev.mac==list[ii].mac){
                //console.log("==")
                lDev=list[ii];
            }
        }
 

        let str = row.Mark.split("(");
        //console.log(str[1])
        let arr = str[1].split(",");
       
        if(str[0].substring(0, 5) == "Over1"){
           // console.log("over ",str[0])
            dev.version2=arr[0] 
            if(lDev!=null) lDev.version2=dev.version2

        }
        else{
            //console.log("not ",str[0])
            dev.version1=arr[0] 

            if(lDev!=null) {
                lDev.version1=dev.version1
                lDev.version2=""
                lDev.Result=dev.Result
                lDev.Time=dev.Time
            }
        }
        
        dev.sn=arr[1]
       // console.log(dev)
        //后续成功就成功,
       if(lDev==null){
           list.push(dev)
       }
    }
}

let succCount=0;

for(let ii in list){
    console.log(list[ii])
    let row = list[ii];
    if("成功"==row.Result)
        succCount++;
}


var fs = require('fs');


var npm = require('getmac');//获取mac地址
 
//获取机器mac地址
npm.getMac(function(err,macAddress){
    if (err)  throw err;
    var mac = macAddress; //获取mac地址
    console.log(mac);     

    fs.open('./'+mac+'.csv','w',function(err,fd){
        fs.writeSync(fd,"升级"+list.length+"个,成功"+succCount+"个,失败"
        +(list.length-succCount)+"个,成功率"+succCount/list.length*100+"%\n");
        for(let ii in list){
            //console.log(list[ii])
            let row = list[ii];
            fs.writeSync(fd,row.DevModel+","+row.sn+","+row.mac+","+row.version1+","
            +row.version2+","+row.Result+","+row.Time+"\n");
        }
    });
    
});

 

{
  "name": "sqllite",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "csv": "^5.1.1",
    "getmac": "^1.4.6"
  }
}
var sqlite= [ { ID: 1,
    Time: '2019-04-13 18:36:44',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e7',
    Result: '成功',
    Item: '升级版本',
    Mark:
     '版本升级成功!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 2,
    Time: '2019-04-13 18:37:49',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级配置',
    Mark:
     '配置升级成功!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 3,
    Time: '2019-04-13 18:37:49',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e3',
    Result: '成功',
    Item: '',
    Mark:
     'Over1  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 4,
    Time: '2019-04-13 18:40:45',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级配置',
    Mark:
     '配置升级成功!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 5,
    Time: '2019-04-13 18:40:45',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '',
    Mark:
     'Over1  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 6,
    Time: '2019-04-13 18:43:04',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 7,
    Time: '2019-04-13 18:43:46',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 8,
    Time: '2019-04-13 18:44:21',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 9,
    Time: '2019-04-13 18:45:10',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 10,
    Time: '2019-04-13 18:45:43',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 11,
    Time: '2019-04-13 18:46:23',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '未知错误!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 12,
    Time: '2019-04-13 18:47:31',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级配置',
    Mark:
     '配置升级成功!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 13,
    Time: '2019-04-13 18:47:31',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '',
    Mark:
     'Over1  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 14,
    Time: '2019-04-13 18:49:35',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级版本',
    Mark:
     '版本升级成功!  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4_T2-default,V2.0.0.0) ' },
  { ID: 15,
    Time: '2019-04-13 18:50:45',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '未知错误!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 16,
    Time: '2019-04-13 18:54:34',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '未知错误!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 17,
    Time: '2019-04-13 18:55:26',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 18,
    Time: '2019-04-13 18:55:45',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 19,
    Time: '2019-04-13 18:56:07',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级配置',
    Mark:
     '文件下载失败!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 20,
    Time: '2019-04-13 18:57:46',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '失败',
    Item: '升级版本',
    Mark:
     '文件下载失败!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 21,
    Time: '2019-04-13 19:00:51',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级版本',
    Mark:
     '版本升级成功!  (V2.0.3T1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' },
  { ID: 22,
    Time: '2019-04-13 19:01:51',
    DevModel: 'E8820C',
    DevSN: '7c:39:53:a8:c7:e8',
    Result: '成功',
    Item: '升级版本',
    Mark:
     'Over1  (V2.0.4_JSDXT1,HN5RN78J2800001,V2.0.1,V2.0.4T2-JSDX,V2.0.0.0) ' } ];

     module.exports.sqlite = sqlite;

 

转载于:https://www.cnblogs.com/cnchengv/p/10707368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值