sentItemStats for master is now working as well

This commit is contained in:
Danielv123 committed 2017-10-28 22:13:40 +02:00
1 parent 3d4c788788
commit 869b5f9ced
3 files changed
+27 -22

No files matched your search

+18 -15
View File
@@ -294,7 +294,7 @@ app.post("/api/remove", function(req, res) {
//console.log("removed: " + object.name + " " + object.count + " . " + item + " and sent to " + object.instanceID + " | " + object.instanceName);
db.items.removeItem(object);
// res.send("successier");
let sentItemStatistics = sentItemStatisticsBySlaveID[x.instanceID];
let sentItemStatistics = sentItemStatisticsBySlaveID[object.instanceID];
if(sentItemStatistics === undefined){
sentItemStatistics = new averagedTimeSeries({
maxEntries: config.itemStats.maxEntries,
@@ -306,6 +306,8 @@ app.post("/api/remove", function(req, res) {
key:object.name,
value:object.count,
});
//console.log(sentItemStatistics.data)
sentItemStatisticsBySlaveID[object.instanceID] = sentItemStatistics;
res.send(object);
} else {
// if we didn't have enough, attempt giving out a smaller amount next time
@@ -378,9 +380,9 @@ app.post("/api/logStats", function(req,res) {
// {slaveID: string, fromTime: Date, toTime, Date}
app.post("/api/getStats", function(req,res) {
if(typeof req.body == "string"){
req.body = JSON.stringify(req.body);
req.body = JSON.parse(req.body);
}
console.log(req.body);
// console.log(req.body);
if(typeof req.body == "object" && req.body.slaveID && req.body.statistic === undefined) {
// if not specified, get stats for last 24 hours
if(!req.body.fromTime) {
@@ -401,7 +403,7 @@ app.post("/api/getStats", function(req,res) {
});
} else if(typeof req.body == "object" && req.body.slaveID && typeof req.body.slaveID == "string" && req.body.itemName){
if(req.body.statistic == "place"){
console.log("sending place data...");
console.log(`sending place data for slaveID ${req.body.slaveID} ${req.body.itemName}`);
// Gather data
//console.log(recievedItemStatisticsBySlaveID)
let itemStats = recievedItemStatisticsBySlaveID[req.body.slaveID];
@@ -417,21 +419,22 @@ app.post("/api/getStats", function(req,res) {
data: data,
});
} else if(req.body.statistic == "remove"){
console.log("sending remove data...");
console.log(`sending remove data for slaveID ${req.body.slaveID} ${req.body.itemName}`);
// Gather data
//console.log(sentItemStatisticsBySlaveID)
console.log(sentItemStatisticsBySlaveID)
let itemStats = sentItemStatisticsBySlaveID[req.body.slaveID];
if(itemStats === undefined){
console.log(itemStats)
if(typeof itemStats == "object"){
let data = itemStats.get(config.itemStats.maxEntries, req.body.itemName);
//console.log(itemStats.get(config.itemStats.maxEntries, req.body.itemName));
res.send({
maxEntries:config.itemStats.maxEntries,
entriesPerSecond: config.itemStats.entriesPerSecond,
data: data,
});
} else {
res.send({statusForDebugging:"no data available"});
return false;
}
let data = itemStats.get(config.itemStats.maxEntries, req.body.itemName);
res.send({
maxEntries:config.itemStats.maxEntries,
entriesPerSecond: config.itemStats.entriesPerSecond,
data: data,
});
}
}
});
+7 -5
View File
@@ -26,8 +26,9 @@ debugTools = {
addItem: function(name, count){
console.log(`Attempting to add ${count} ${name}`)
postJSON("api/place", {
instanceName: "debug",
unique: "debug",
instanceName: "unknown",
instanceID: "unknown",
unique: "unknown",
name: name,
count: count,
}, function(data){
@@ -35,10 +36,11 @@ debugTools = {
});
},
removeItem: function(name, count){
console.log(name)
console.log(`Attempting to remove ${count} ${name}`)
postJSON("api/remove", {
instanceName: "debug",
unique: "debug",
instanceName: "unknown",
instanceID: "unknown",
unique: "unknown",
name: name,
count: count,
}, function(data){
+2 -2
View File
@@ -117,7 +117,7 @@ function makeItemGraphs(itemName){
slaveIDs.forEach(function(slaveID){
["place", "remove"].forEach(statistic => {
console.log("Making chart for "+slaveID+"'s "+statistic+" statistic")
HTML += '<div id="contentGraph'+slaveID+'" class="storageGraph" style="width: 100%;"></div>';
HTML += '<div id="'+statistic+'contentGraph'+slaveID+'" class="storageGraph" style="width: 100%;"></div>';
setTimeout(function(){
let xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
@@ -128,7 +128,7 @@ function makeItemGraphs(itemName){
if(xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) {
// console.log(xmlhttp.responseText);
if(isJSON(xmlhttp.responseText) && JSON.parse(xmlhttp.responseText).statusForDebugging === undefined){
drawChart("contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data], slaveID+" "+itemName);
drawChart(statistic+"contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data], slaveID+" "+itemName);
// console.log(JSON.parse(xmlhttp.response).data);
}
}