<commit_before>/*
¹
²
³
×
°
·
*/


var blessed = require('blessed');
var contrib = require('blessed-contrib');
var ttys     = require('ttys');
var geoip = require('geoip-lite');


/**/
var MAP_AR = 162 / 36; // 4.5
var terminalAr = process.stdout.columns / process.stdout.rows;

var matrix = 
  terminalAr > MAP_AR
  ? /* log on left */
    /*   w      h     l      t */  
    [
      ["80%", "100%", 0    , 0    ],
      ["20%", "100%", "80%", 0    ]
    ]
  : /* log on bottom */
    [
      ["100%", "80%", 0    , 0    ],
      ["100%", "20%", 0    , "80%"]
    ]

var screen = blessed.screen({
  input: ttys.stdin, 
  output: process.stdout
});

var grid = new contrib.grid({rows: 2, cols: 2, screen: screen})

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
 return process.exit(0);
});

//var map = grid.set(0, 0, 2, 2, contrib.map, {label: 'Map'});
var map = contrib.map({
  label: 'Map',
  width:  matrix[0][0],
  height: matrix[0][1],
  left:   matrix[0][2],
  top:    matrix[0][3],
  xPadding: 0,
  border: {type: "line", fg: "cyan"}
});
screen.append(map);

//var log = grid.set(1, 0, 1, 2, contrib.log, { fg: "green" , selectedFg: "green" , label: 'Log'});
var log = contrib.log({ 
  fg: "green" , 
  selectedFg: "green" , 
  label: "Log",
  width:  matrix[1][0],
  height: matrix[1][1],
  left:   matrix[1][2],
  top:    matrix[1][3],
  xPadding: 0,
  border: {type: "line", fg: "cyan"}
});
log.log(process.stdout.columns + 'x' + process.stdout.rows);
//console.log(process.stdout.columns + 'x' + process.stdout.rows);
screen.append(log);
/**/


var data = process.argv.slice(2);
if(data.length){
  drawMarkers(data);
} else {
  var input_data = [];
  var stream = process.stdin;
  stream.on('data', function(data) {
    input_data = [].concat(data.toString().split("\n").slice(0, -1)); 
    drawMarkers(input_data);
  });
  stream.on('end', function() { 
  });
  stream.on('error', function(){});
}



function drawMarkers(ipList){

  ipList.forEach(function(ip){
    var geo = geoip.lookup(ip);
    map.addMarker({"lon" : "" + geo.ll[1], "lat" : "" + geo.ll[0], color: "red", char: "·" })
    log.log(ip + " (" + (geo.city || "<unknown city>") + ", " + geo.country + ")");
  });

  screen.render();

}


//  w        h   aspect ratio    matrix 
//150-170 / 36 ~ 4                1x4
//75-105 / 36  ~ 2                1x2
//
//
// matrix formula: 1 / (apect ratio)  if AR >= 2<commit_msg>version 1.0<commit_after>/*
¹
²
³
×
°
·
*/


var blessed = require('blessed');
var contrib = require('blessed-contrib');
var ttys     = require('ttys');
var geoip = require('geoip-lite');


var map, log, screen;
function drawApp(){
  var MAP_AR = 162 / 36; // map aspect ratio, 4.5
  var terminalAr = process.stdout.columns / process.stdout.rows; // terminal aspect ratio

  var matrix = 
    terminalAr > MAP_AR
      ? /* log on left */
      /*   w      h     l      t */  
      [
        ["80%", "100%", 0    , 0      ], /* map */
        ["20%", "100%", "80%", 0      ]  /* log */
      ]
        : /* log on bottom */
        [
          ["100%", "80%", 0    , 0    ],
          ["100%", "20%", 0    , "80%"]
        ]

  screen = blessed.screen({
    input: ttys.stdin, 
    output: process.stdout
  });

  screen.key(['escape', 'q', 'C-c'], function(ch, key) {
    return process.exit(0);
  });

  map = contrib.map({
    label: 'Map',
    width:  matrix[0][0],
    height: matrix[0][1],
    left:   matrix[0][2],
    top:    matrix[0][3],
    xPadding: 0,
    border: {type: "line", fg: "cyan"}
  });
  screen.append(map);

  log = contrib.log({ 
    fg: "green" , 
    selectedFg: "green" , 
    label: "Log",
    width:  matrix[1][0],
    height: matrix[1][1],
    left:   matrix[1][2],
    top:    matrix[1][3],
    xPadding: 0,
    border: {type: "line", fg: "cyan"}
  });
  screen.append(log);
}
drawApp();


function drawMarkers(ipList){
  ipList.forEach(function(ip){
    var geo = geoip.lookup(ip);
    map.addMarker({"lon" : "" + geo.ll[1], "lat" : "" + geo.ll[0], color: "red", char: "°" })
    log.log(ip + " (" + (geo.city || "<unknown city>") + ", " + geo.country + ")");
  });
  screen.render();
}


var data = process.argv.slice(2);
if(data.length){
  drawMarkers(data);
} else {
  var input_data = [];
  var stream = process.stdin;
  stream.on('data', function(data) {
    input_data = [].concat(data.toString().split("\n").slice(0, -1)); 
    drawMarkers(input_data);
  });
  stream.on('end', function() { 
  });
  stream.on('error', function(){});
}



{'fraction_non_alphanumeric': 0.22165292938293607, 'fraction_numerical': 0.03497438182223212, 'mean_word_length': 2.5105551211884283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6824221', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1712, 'n_words': 388}