From e89d44e9fd237b73ff00e1033cd951589e47b00c Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 15 May 2018 16:58:56 -0400 Subject: [PATCH] render all login timespans to chart --- webapp/server.js | 378 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 261 insertions(+), 117 deletions(-) diff --git a/webapp/server.js b/webapp/server.js index 2a42ffc..b0f3e4f 100644 --- a/webapp/server.js +++ b/webapp/server.js @@ -19,6 +19,7 @@ var app = express(); //app.set('view engine', 'handlebars'); var players = []; var player_indices = {}; +var play_dates = []; //see https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction var prev_line = null; @@ -41,7 +42,8 @@ var unique_flags = [ ]; //#endregion derived from mtsenliven.py -function process_logline(line, line_number, selected_date_s) { +function process_logline(line, line_number) { + //selected_date_s //TODO: use store_unique_log_data instead of this function var player_name = null; var verb = ""; @@ -72,7 +74,7 @@ function process_logline(line, line_number, selected_date_s) { verb_number = uf_i; verb = unique_flags[uf_i]; date_s = line.substring(0,10).trim(); - if (selected_date_s==null || selected_date_s==date_s) { + //if (selected_date_s==null || selected_date_s==date_s) { //console.log("(verbose message in process_logline) using '" + date_s + "' since selected '"+selected_date_s+"'"); time_s = line.substring(time_start_i, time_start_i+8); //console.log("using time "+time_s); @@ -88,11 +90,11 @@ function process_logline(line, line_number, selected_date_s) { else { player_name = "<missing msgprefix&rt;"; } - } - else { - skip_date_enable = true; + //} + //else { + // skip_date_enable = true; //console.log("WARNING in process_logline: skipping '" + date_s + "' since not '"+selected_date_s+"'"); - } + //} break; } } @@ -116,18 +118,66 @@ function process_logline(line, line_number, selected_date_s) { console.log("WARNING in process_logline: zero-length player name"); } } - if (index<0 && !skip_date_enable) { - //console.log("(verbose message in process_logline) "+index_msg+"index was '"+index+"' but date was good '" + date_s + "' for '"+line+"'"); + if (index<0 && (verb=="leaves game"||verb=="joins game")) { + console.log("(ERROR in process_logline) " + index_msg + + "index was '"+index+"' but date was present '" + + date_s + "' for '"+line+"' (no player found, but" + + "verb is a player verb)."); } + var play_date_enable = false; if (verb == "leaves game") { if (index > -1) { - players[index].logout_time = time_s; + var play_i = -1; + if (!players[index].hasOwnProperty("plays")) { + players[index].plays = {}; + } + if (!players[index].plays.hasOwnProperty(date_s)) { + //leave login time blank--player must have logged in before the available part of the log began + players[index].plays[date_s] = []; + players[index].plays[date_s].push({}); + play_i = 0; + } + else { + if (players[index].plays[date_s].length==0) players[index].plays[date_s].push({}); + play_i = players[index].plays[date_s].length - 1; + if (players[index].plays[date_s][play_i].hasOwnProperty("logout_time")) { + //If last entry is incomplete, start a new one: + players[index].plays[date_s].push({}); + play_i++; + } + } + players[index].plays[date_s][play_i].logout_time = time_s; + play_date_enable = true; } } else if (verb == "joins game") { if (index > -1) { - //console.log("using index " + index); - players[index].login_time = time_s; + if (player_ip!=null) { + players[index].player_ip = player_ip; + var play_i = -1; + if (!players[index].hasOwnProperty("plays")) { + players[index].plays = {}; + } + if (!players[index].plays.hasOwnProperty(date_s)) { + players[index].plays[date_s] = []; + play_i = 0; + } + else play_i = players[index].plays[date_s].length; + players[index].plays[date_s].push({}); + //console.log(verb+" on "+date_s+" (length "+players[index].plays[date_s].length+") play "+play_i+"+1 for player ["+index+"] "+player_name+"..."); + players[index].plays[date_s][play_i].login_time = time_s; + play_date_enable = true; + } + // else redundant (server writes " joins game " again + // and shows list of players instead of ip). + //TODO: else analyze list of players to confirm in case player logged in all day + } + } + if (play_date_enable) { + if (date_s.length>0) { + if (play_dates.indexOf(date_s) < 0) { + play_dates.push(date_s); + } } } } @@ -188,7 +238,40 @@ function store_unique_log_data(output, line_number, err_flag=false) { } return ret; } -var cached_date = null; + +function read_log() { + if (players==null) players = []; + if (player_indices==null) player_indices = {}; + // os.homedir() + "/.minetest/debug_archived/2018/05/08.txt", + var log_paths = [os.homedir() + "/.minetest/debug.txt"]; + var lp_len = log_paths.length; + for (var lp_i=0; lp_i\n"; ret += "timezone (tz_offset/60*-1): " + (Math.floor(tz_offset/60)*-1) + "
\n"; - ret += "date (this YYYY-MM-DD filter limits all log processing): " + selected_date_s + "
\n"; - if (selected_date_s==null) { - ret += '2018-05-08'; - } - if (cached_date!=selected_date_s && selected_date_s!=null) { - cached_date = selected_date_s; - players = []; - player_indices = []; - var log_paths = [os.homedir() + "/.minetest/debug_archived/2018/05/08.txt", os.homedir() + "/.minetest/debug.txt"]; - var lp_len = log_paths.length; - for (var lp_i=0; lp_i\n"; + //ret += 'var play_dates = [];'; + var pdLength = 0; + if (play_dates != null) pdLength = play_dates.length; + for (var pd_i = 0; pd_i < pdLength; pd_i++) { + //ret += 'play_dates.push("' + play_dates[pd_i] + '");'; + if (selected_date_s!=play_dates[pd_i]) { + ret += ''+play_dates[pd_i]+' '; + } + else { + ret += play_dates[pd_i]+' '; } - } - + //if (selected_date_s==null) { + //ret += '2018-05-08'; + //} //see ~/.minetest/debug.txt //and logs archived by EnlivenMinetest: //~/.minetest/debug_archived/2018/05/08.txt - ret += ` + ret += ` +
+ Your browser does not support the canvas element.
loading...
`; + */ + ret += ``; ret += ''; res.send(ret); //res.render('home'); @@ -359,5 +501,7 @@ var server = app.listen(3000, function () { //console.log('express-handlebars example server listening on: 3000'); var host = server.address().address; var port = server.address().port; + console.log("reading log..."); + read_log(); console.log("EnlivenMinetest webapp listening at http://%s:%s", host, port); });