javascript - 生成 JSON 永远不一样
问题描述
我不明白什么时候启动脚本。我的 JSON 不一样了...我尝试更改 Timeout 的时间但同样的问题
// 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 {
}
})
})
}
函数 calculate() 它只是一些计算
函数 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);
});
}
实际结果:
- 第一次发射:获得 1641 个元素
2nd 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
预期结果:
- 第一次发射:获得 1641 个元素
- 第二次发布:获得 1641 个元素
- 一样的
谢谢你的帮助
解决方案
推荐阅读
- reactjs - VS Code 谷歌调试器未验证断点
- xamarin - 从事件调用时,Xamarin.Forms 导航不起作用
- java - JavaFX设置组合框导致空指针
- modelica - 带有特殊字符的路径
- vba - Copy from cell if two other cells meet criteria?
- node.js - 如何在不声明新变量的情况下正确更新 chokidar 文件选择?
- java - Mockito 用参数模拟一个新的实例调用
- java - Jersey JAX-RS注释接口而不是实现类导致错误
- google-cloud-platform - 谷歌云实例的带宽使用情况
- javascript - AdminLTE v2.3.8。数据表日期时间列排序