File reading bugs fixed

master
sigonasr2 2 years ago
parent b54bbd9994
commit e92c273d26
  1. 44
      inventory_monitor.js

@ -11,30 +11,32 @@ function update(){
fs.readFile("C:\\Users\\sigon\\Documents\\memory",
(err,data)=>{
var fileContents = data.toString().split("\n");
for (i=0;i<fileContents.length;i++){
line=fileContents[i]
item=line.split(" ")
itemID=item[1]
itemAmt=item[0]
hq=(item[2]!==undefined)?item[2].replace("\r",""):""
itemHQ=hq==="0"?false:true
//console.log(itemID+" x"+itemAmt+" "+(itemHQ))
if(firstLoad){
finalData=[...finalData,{"id":Number(itemID),"amt":Number(itemAmt),"hq":itemHQ}]
}else
if (finalData[i]!==undefined&&(Number.isInteger(finalData[i].id)^Number.isInteger(itemID))){
if (finalData[i].id!=Number(itemID)||finalData[i].amt!==Number(itemAmt)||finalData[i].hq!==Boolean(itemHQ)){
console.log(JSON.stringify(finalData[i])+" !== "+JSON.stringify({"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}))
finalData[i]={"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}
changed=true;
if (fileContents.length>=387){
for (i=0;i<fileContents.length;i++){
line=fileContents[i]
item=line.split(" ")
itemID=item[1]
itemAmt=item[0]
hq=(item[2]!==undefined)?item[2].replace("\r",""):""
itemHQ=hq==="0"?false:true
//console.log(itemID+" x"+itemAmt+" "+(itemHQ))
if(firstLoad){
finalData=[...finalData,{"id":Number(itemID),"amt":Number(itemAmt),"hq":itemHQ}]
}else
if (finalData[i]!==undefined&&(Number.isInteger(finalData[i].id)^Number.isInteger(itemID))){
if (finalData[i].id!=Number(itemID)||finalData[i].amt!==Number(itemAmt)||finalData[i].hq!==Boolean(itemHQ)){
console.log(JSON.stringify(finalData[i])+" !== "+JSON.stringify({"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}))
finalData[i]={"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}
changed=true;
}
}
}
if (changed){
console.log("Changes occurred...")
axios.post("http://projectdivar.com/inventoryData",finalData)
}
firstLoad=false
}
if (changed){
console.log("Changes occurred...")
axios.post("http://projectdivar.com/inventoryData",finalData)
}
firstLoad=false
setTimeout(update,1000)
})
}

Loading…
Cancel
Save