生成JSON从来都不一样

时间:2019-06-13 08:51:38

标签: javascript

启动脚本时我不明白。我的JSON从来都不一样... 我尝试更改“超时”的时间,但问题仍然存在

//   Call the file functions.js
var functions = require('./functions.js')

/* 
Function getAllIssueForSCII displays all the issues in the form of a JSON and that browses all the keys that are in the SCII project
Function pushInitialization initializes the computer score card to 80 on Jira

*/

functions.getAllIssueForSCII().then(function(json){
    for (let i=0; i<50;i++){      
        console.log(json.issues[i].key);


        /* 
        A delay is added so that Jira can correctly recover the value 80.
        Thanks to this value, we can do all the calculation  (Function calculate)  
        Function pushComputerScoreCard  push the final value into the computer score card.
        Function generateJSON generates a JSON.
        Function replaceCharacter solve the problem of array inside the JSON 
        */

        setTimeout(function() {

            functions.calculate(json.issues[i]);
            functions.generateJSON(json.issues[i].key);
            functions.replaceCharacter();


        }, 1000)
    }
});

函数getAllIssueForSCII()

function getAllIssueForSCII(){
    var options = {
        method: 'GET',
        url: 'https://***.atlassian.net/rest/api/3/search?jql=project=SCII+AND+issuetype=Story+AND+resolution=Unresolved+AND+status%20in("In%20Review","In%20Inspection","Inspected","Inspection%20Needed","Feedback")',
        headers: {  
            'Accept': 'application/json',
            'Authorization': "Basic ***"
        }
    };


    return new Promise(function (resolve) {
        request(options, function (error, response, data) {
            if (!error && response.statusCode === 200) {
                console.log('JIRA login success!!')
                var json = JSON.parse(data);
                console.log("Filtered Issues: ", { issues: json.issues.filter(issue => issue.expand.key) });
                resolve(json);            
            } else {
            }

        })
    })
}

compute()函数只是一些计算

函数generateJson()

function generateJSON(key){
    var table = []


    table.push({"executionDate":dateTime,
    "issueID":key,
    "priority":{
        "jira": priority, 
        "computed":score1
    },
    "expectedValue":{
        "jira": expected, 
        "computed":score2
    },
    "customerCr":{  
        "jira":customer,
        "computed":score3
    },
    "effortEstimate":{  
        "jira":effort_estimate,
        "computed":score4
    },
    "pmWeight":{  
        "jira":pm_weight,
        "computed":score5
    },
    "netRevenue":{  
        "jira":net_revenue,
        "computed":score6
    },
    "scoreCard":{  
        "original":score_card,
        "computed":total
    }
})

var json = JSON.stringify(table,null, 2);

fs.appendFile('templateLog.json', json, 'utf8', function (err) {
    if (err) console.error(err)

});

}

函数replaceCharacter(用替换] [

function replaceCharacter(){
    const options = {
        files: 'templateLog.json',
        from: /]\[/g,
            to: ',',
        };

        replace(options, (error, results) => {
            if (error) {
                return console.error('Error occurred:', error);
            }
            console.log('Replacement results:', results);
        });
    }

实际结果:

  • 启动1rt:获取1641个元素
  • 第二次launh:得到947个元素,最后一个元素像这样完成:

      {
      "executionDate": "13-6-2019",
      "issueID": "SCII-56",
      "priority": {
        "jira": "Highest",
        "computed": 25
      },
      "expectedValue": {
        "jira": "High",
        "computed": 25
      },
      "customerCr": {
        "jira": "No",
        "computed": 0
      },
      "effortEstima
    

预期结果:

  • 启动1rt:获取1641个元素
  • 第二次发射:获得1641元素
  • 相同且相同

感谢您的帮助

0 个答案:

没有答案