Skip to content

Instantly share code, notes, and snippets.

@p4ul
Last active December 7, 2017 22:16
Show Gist options
  • Save p4ul/4dea138fc5456b1794e6bc4d1ea20c35 to your computer and use it in GitHub Desktop.
Save p4ul/4dea138fc5456b1794e6bc4d1ea20c35 to your computer and use it in GitHub Desktop.
Identify jobs in returned data
/** copy and paste this in console (f12) after you have clicked log button on a device, tested on Calamp units **/
function checkLogs() {
var flag_type = {
"E":"Job on Working off",
"F":"Job on Working on",
"C":"Both off"
};
var data = $('#headunit_positions').text()
var processed = []
var current_flag = false
var in_job = 0
//assume these are ordered on page
data.replace(/(?:#)([\d-: ]+)(?:#).*([ECF])/g, function(match, date, flag){
if(flag === 'F') {
in_job++
} else if (in_job > 0) {
if(in_job === 1){
processed.push ({date:date.trim(), flag:"failed job, not enough points", count: in_job})
} else {
processed.push ({date:date.trim(), flag:"job created", count: in_job})
}
in_job = 0
}
if(flag === current_flag) {
processed[processed.length - 1].count ++;
return;
}
current_flag = flag
processed.push ({date:date.trim(), flag:flag_type[flag], count: 1})
})
console.table(processed)
}
checkLogs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment