summaryrefslogtreecommitdiff
path: root/js/debug.js
blob: 9d83be71a3ad7299fdb5de6d5c8296ba93b74ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var poll_debug = function (url_prefix)
{
  setTimeout(function(){
     $.get(url_prefix+"/status_debug").done(function(response){
       $("#status").text(response);
       poll(url_prefix);
     });
  }, 3000);
}

$().ready(function() {

  // send commands using ajax
  $(".ajax").each(function(x) {
    $(this).click(function() {
       $.ajax({url: $(this).attr("tgt"), success: function(result){
          $("#control_reply").html(result);
      }});
    })
  })
  $("#features").click(function() { if (this.value=="Feature") this.value = ""; });
  $("#features").focusout(function() { if (this.value == "") this.value = "Feature"; });
  $("#features_get").click(function() { if (this.value=="Feature") this.value = ""; });
  $("#features_get").focusout(function() { if (this.value == "") this.value = "Feature"; });
  $("#features_value").click(function() { this.value = ""; });
  $("#features_value").focusout(function() { if (this.value == "") this.value = "1e-05"; });
  $("#features_value_get").click(function() { this.value = ""; });
  $("#features_value_get").focusout(function() { if (this.value == "") this.value = "1e-05"; });
  $("#feature_groups_value").click(function() { this.value = ""; });
  $("#feature_groups_value").focusout(function() { if (this.value == "") this.value = "1e-05"; });
  // set/get all sorts of learning rates
  $("#set_features").click(function() {
    k = $("#features").val();
    v = $("#features_value").val();
    if (k=="Feature" || k=="" || v=="" || isNaN(parseFloat(v))) {
      alert("Malformed request.");
    } else {
      url_prefix = $("#features_type").val();
      $.ajax({url: url_prefix+"/"+k+"/"+v, success: function(result){
         $("#control_reply").html(result);
      }});
    }
  });
  $("#set_feature_groups").click(function() {
    k = $("#feature_groups").val();
    v = $("#feature_groups_value").val();
    if (v=="" || !parseFloat(v)) {
      alert("Malformed request.");
    } else {
       $.ajax({url: "/set_learning_rates/"+k+"/"+v, success: function(result){
          $("#control_reply").html(result);
      }});
    }
  });
  $("#get_features").click(function () {
    $.get("http://"+document.URL.split("/")[2]+$("#features_type_get").val()+"/"+$("#features_get").val(),
    function (data) {
      $("#features_value_get").val(data);
    });
  });
  $("#get_feature_groups").click(function () {
    $.get("http://"+document.URL.split("/")[2]+"/get_rate/"+$("#feature_groups_get").val(),
    function (data) {
      $("#feature_groups_value_get").val(data);
    });
  });

  // sortable tables
  // src: http://stackoverflow.com/questions/4126206/javascript-parsefloat-1-23e-7-gives-1-23e-7-when-need-0-000000123
  $.tablesorter.addParser({
  id: 'scinot',
  is: function(s) {
    return /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/.test(s);
  },
  format: function(s) {
    return $.tablesorter.formatFloat(s);
  },
  type: 'numeric'
  });
  $("table.sortable").each(function(x) {
    $(this).tablesorter({widgets: ['zebra']});
  });
  $(".toggle").each(function(x) {
    $(this).click(function() {
      $(this).next().toggle();
    })
  });
  $("table.kbest_features tr:odd").css("background-color", "#87cefa");
  $("table.kbest_features tr:even").css("background-color", "#fff");

  // display svg
  var d = atob(document.getElementById("svg_b64").innerHTML);
  $('#svg').append(
    $('<svg width="100%">'+d+'</svg>')
  );
  $("#svg").width($("#svg").children()[0].getBBox().width+"px");
  d = atob(document.getElementById("original_svg_b64").innerHTML);
  $('#original_svg').append(
    $('<svg width="100%">'+d+'</svg>')
  );
  $("#original_svg").width($("#original_svg").children()[0].getBBox().width+"px");

  // mark stale content
  if ($("#up_val").text() != "true") {
    $(".updated").each(function(i,el){$(el).addClass("stale")})
  }

  // get current status + input ID
  poll_debug("http://"+document.URL.split("/")[2]);

});