<commit_before>// Fill-in Alert Details Template
var logger = 0,
    fromDate = "",
    limit = "",
    timer;

var hb_threshold = 300; // 5 minutes

function updateLimit(lim) {
  if (lim > 0) {
    limit = '&limit=' + lim
  } else {
    limit = '';
  }
  $('#refresh-all').trigger('click');
}

function updateFromDate(seconds) {
  if (seconds > 0) {
    fromDate = '&from-date=' + new Date(new Date() - seconds * 1000).toISOString();
  } else {
    fromDate = '';
  }
  $('#refresh-all').trigger('click');
}

function loadStatus(statusfilter, refresh) {
    setTimeout(function() {
      getStatus(statusfilter, refresh);
    }, 0);
}

function loadAlerts(services, refresh) {
  var delayer = 0;
  $.each(services, function(service, filter) {
    setTimeout(function() { 
      getAlerts(service, filter, refresh);
    }, delayer);
    delayer += 100;
  });
}

function sev2label(severity) {

        switch (severity) {
          case 'CRITICAL': label='label-important'; break;
          case 'MAJOR':    label='label-warning'; break;
          case 'MINOR':    label='label-minor'; break;
          case 'WARNING':  label='label-info'; break;
          case 'DEBUG':    label='label-inverse'; break;
          case 'UNKNOWN':  label=''; break;
          default:         label='label-success'; 
        }
        return('<span class="label '+label+'">' + severity + '</span>');
}

function date2str(datetime) {
        var d = new Date(datetime);
        return d.toLocaleString();
}

// Update Register Components
function heartbeatAlerts() {

  $.getJSON('http://'+ document.domain + '/alerta/management/healthcheck?callback=?', function(data) {

      var hbalerts ='';
      $.each(data.heartbeats, function(i, hb) {

        var diff = (new Date().getTime() - new Date(hb.receiveTime).getTime()) / 1000;
        var mins = Math.floor(diff / 60);
        var secs = Math.floor(diff % 60);

        var since = '';
        if (mins > 0) {
            since = mins + ' minutes ' + secs + ' seconds';
        } else {
            since = secs + ' seconds';
        }

        if (diff > hb_threshold) {
          hbalerts += '<div class="alert alert-error">' +
                      '<button class="close" data-dismiss="alert" onclick="">&times;</button>' +
                      '<strong>Important!</strong> ' + hb.origin + ' has not sent a heartbeat for ' + since +
                      '</div>';
        }
      });
      $('#heartbeat-alerts').html(hbalerts);
  });
};

function getHeartbeats(refresh) {

  $.getJSON('http://'+ document.domain + '/alerta/management/healthcheck?callback=?', function(data) {

      var rows ='';
      $.each(data.heartbeats, function(i, hb) {

        var diff = (new Date().getTime() - new Date(hb.receiveTime).getTime()) / 1000;
        var mins = Math.floor(diff / 60);
        var secs = Math.floor(diff % 60);

        var since = '';
        if (mins > 0) {
            since = mins + ' minutes ' + secs + ' seconds';
        } else {
            since = secs + ' seconds';
        }

        rows += '<tr class="">' +
                  '<td>' + hb.origin + '</td>' +
                  '<td>' + hb.version + '</td>' +
                  '<td>' + date2str(hb.createTime) + '</td>' +
                  '<td>' + since + '</td>' +
                '</tr>';
      });
      $('#heartbeat-info').html(rows);

    if (refresh) {
      timer = setTimeout(function() { getHeartbeats(refresh); }, 120000);
    }
  });
};

// Update Alert Status
function getStatus(statusfilter, refresh) {

  $.getJSON('http://'+ document.domain + '/alerta/api/v1/alerts?callback=?&hide-alert-details=true&' + statusfilter + limit + fromDate, function(data) {

    if (data.response.warning) {
      $('#warning-text').text(data.response.warning);
      $('#console-alert').toggle();
    }

    $.each(data.response.alerts.statusCounts, function(stat, count) {
      $("#alert-" + stat).text(count);
    });
    if (refresh) {
      timer = setTimeout(function() { getStatus(statusfilter, refresh); }, 120000);
    }
  });
};

// Update Alert Summaries
function getAlerts(service, filter, refresh) {

  $('#' + service +' th').addClass('loader');

  $.getJSON('http://'+ document.domain + '/alerta/api/v1/alerts?callback=?&sort-by=lastReceiveTime&' + filter + limit + fromDate, function(data) {

      var sev_id = '#' + service;

      data.response.alerts.severityCounts.normal += data.response.alerts.severityCounts.inform;

      $.each(data.response.alerts.severityCounts, function(sev, count) {
        $(sev_id + "-" + sev).text(count);

        switch (count) {
          case 0: $(sev_id + "-" + sev).removeClass(sev).addClass('zero'); break;
          default: $(sev_id + "-" + sev).addClass(sev).removeClass('zero');
        }

      });

        if (data.response.alerts.severityCounts.critical > 0) {
          scolor = 'red';
        } else if (data.response.alerts.severityCounts.major > 0) {
          scolor = 'orange';
        } else if (data.response.alerts.severityCounts.minor > 0) {
          scolor = 'yellow';
        } else if (data.response.alerts.severityCounts.warning > 0) {
          scolor = 'dodgerblue';
        } else {
          scolor = 'lime';
        }
      $(sev_id + "-status").css('background-color',scolor);

      var rows ='';
      $.each(data.response.alerts.alertDetails, function(i, ad) {

        var historydata = '<td colspan="2"><b>History </b>', graphsdata = tagsdata = '';

        if (ad.history) {
          var reverseHistory = ad.history.reverse();
          $.each(reverseHistory, function (y, hist) {
            if (hist.event) {
              historydata += '<hr/>' +
                          '<table class="table table-condensed table-striped">' +
                          '<tr><td><b>Event</b></td><td>' + hist.event + '</td></tr>' +
                          '<tr><td><b>Severity</b></td><td>' + sev2label(hist.severity) + '</td></tr>' +
                          '<tr><td><b>Alert ID</b></td><td>' + hist.id + '</td></tr>' +
                          '<tr><td><b>Create Time</b></td><td>' + date2str(hist.createTime) + '</td></tr>' +
                          '<tr><td><b>Receive Time</b></td><td>' + date2str(hist.receiveTime) + '</td></tr>' +
                          '<tr><td><b>Text</b></td><td>' + hist.text + '</td></tr>' +
                          '<tr><td><b>Value</b></td><td>' + hist.value + '</td></tr>' +
                          '</table>' +
                        '';
            }
            if (hist.status) {
              historydata += '<hr/>' +
                          '<table class="table table-condensed table-striped">' +
                          '<tr><td><b>Status</b></td><td><span class="label">' + hist.status + '</span></td></tr>' +
                          '<tr><td><b>Update Time</b></td><td>' + date2str(hist.updateTime) + '</td></tr>' +
                          '</table>' +
                        '';
            }
          });
          historydata += '</td>'
        }

        if (ad.tags) {
          tagsdata += '';
          $.each (ad.tags, function(y, tag) {
            tagsdata += '<span class="label">' + tag + '</span> ';
          });
        }

        if (ad.graphs) {
          graphsdata += '';
          $.each (ad.graphs, function(y, graph) {
            graphsdata += '<a href="' + graph + '" target="_blank">Graph ' + y + '</a> ';
          });
          graphsdata += '</ul>';
        }

        switch (ad.severity) {
          case 'CRITICAL': label='label-important'; break;
          case 'MAJOR': label='label-warning'; break;
          case 'MINOR': label='label-warning'; break;
          case 'WARNING': label='label-info'; break;
          default: label='label-success';
        }

        rows += '<tr class="' + service + ' latest ' + ad.severity + ' ' + ad.status + '">' +
                  '<td class="ad-more"><a id="' + service + 'details' + i + '" class="show-details">' +
                    '<span class="show-d"><i class="icon-chevron-up icon-chevron-down"></i></span></a></td>' +
                  '<td class="ad-sev-td">' + sev2label(ad.severity) + '</td>' +
                  '<td class="ad-stat-td"><span class="label">' + ad.status + '</span></td>' +
                  '<td>'+ date2str(ad.lastReceiveTime) + '</td>' +
                  '<td>' + ad.duplicateCount + '</td>' +
                  '<td>' + ad.environment + '</td>' +
                  '<td>' + ad.service + '</td>' +
                  '<td>' + ad.resource + '</td>' +
                  '<td>' + ad.event + '</td>' +
                  '<td>' + ad.value + '</td>' +
                  '<td class="alert-text">' + ad.text;
        if (ad.status == 'OPEN') {
          rows +=     '<a id="' + ad.id + '" class="ack-alert" rel="tooltip" title="Acknowledge"><i class="icon-star-empty"></i></a>';
        }
        if (ad.status == 'ACK') {
          rows +=     '<a id="' + ad.id + '" class="unack-alert" rel="tooltip" title="Unacknowledge"><i class="icon-star"></i></a>';
        }
        rows += '<a id="' + ad.id + '" href="mailto:?subject=' + ad.summary + '&body=' + ad.text + '%0D%0A%0D%0ASee http://' + document.domain + '/alerta/details.php?id=' + ad.id + '" class="email-alert" rel="tooltip" title="Email Alert" target="_blank"><i class="icon-envelope"></i></a>';
        rows +=  '<a id="' + ad.id + '" class="tag-alert" rel="tooltip" title="Tag Alert"><i class="icon-tags"></i></a>';<commit_msg>Shorten displayed date in alert console<commit_after>// Fill-in Alert Details Template
var logger = 0,
    fromDate = "",
    limit = "",
    timer;

var hb_threshold = 300; // 5 minutes

function updateLimit(lim) {
  if (lim > 0) {
    limit = '&limit=' + lim
  } else {
    limit = '';
  }
  $('#refresh-all').trigger('click');
}

function updateFromDate(seconds) {
  if (seconds > 0) {
    fromDate = '&from-date=' + new Date(new Date() - seconds * 1000).toISOString();
  } else {
    fromDate = '';
  }
  $('#refresh-all').trigger('click');
}

function loadStatus(statusfilter, refresh) {
    setTimeout(function() {
      getStatus(statusfilter, refresh);
    }, 0);
}

function loadAlerts(services, refresh) {
  var delayer = 0;
  $.each(services, function(service, filter) {
    setTimeout(function() { 
      getAlerts(service, filter, refresh);
    }, delayer);
    delayer += 100;
  });
}

function sev2label(severity) {

        switch (severity) {
          case 'CRITICAL': label='label-important'; break;
          case 'MAJOR':    label='label-warning'; break;
          case 'MINOR':    label='label-minor'; break;
          case 'WARNING':  label='label-info'; break;
          case 'DEBUG':    label='label-inverse'; break;
          case 'UNKNOWN':  label=''; break;
          default:         label='label-success'; 
        }
        return('<span class="label '+label+'">' + severity + '</span>');
}

function date2iso8601(datetime) {
        var d = new Date(datetime);
        return d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + ' ' + d.toLocaleTimeString()
}
function date2str(datetime) {
        var d = new Date(datetime);
        return d.toLocaleString();
}

// Update Register Components
function heartbeatAlerts() {

  $.getJSON('http://'+ document.domain + '/alerta/management/healthcheck?callback=?', function(data) {

      var hbalerts ='';
      $.each(data.heartbeats, function(i, hb) {

        var diff = (new Date().getTime() - new Date(hb.receiveTime).getTime()) / 1000;
        var mins = Math.floor(diff / 60);
        var secs = Math.floor(diff % 60);

        var since = '';
        if (mins > 0) {
            since = mins + ' minutes ' + secs + ' seconds';
        } else {
            since = secs + ' seconds';
        }

        if (diff > hb_threshold) {
          hbalerts += '<div class="alert alert-error">' +
                      '<button class="close" data-dismiss="alert" onclick="">&times;</button>' +
                      '<strong>Important!</strong> ' + hb.origin + ' has not sent a heartbeat for ' + since +
                      '</div>';
        }
      });
      $('#heartbeat-alerts').html(hbalerts);
  });
};

function getHeartbeats(refresh) {

  $.getJSON('http://'+ document.domain + '/alerta/management/healthcheck?callback=?', function(data) {

      var rows ='';
      $.each(data.heartbeats, function(i, hb) {

        var diff = (new Date().getTime() - new Date(hb.receiveTime).getTime()) / 1000;
        var mins = Math.floor(diff / 60);
        var secs = Math.floor(diff % 60);

        var since = '';
        if (mins > 0) {
            since = mins + ' minutes ' + secs + ' seconds';
        } else {
            since = secs + ' seconds';
        }

        rows += '<tr class="">' +
                  '<td>' + hb.origin + '</td>' +
                  '<td>' + hb.version + '</td>' +
                  '<td>' + date2str(hb.createTime) + '</td>' +
                  '<td>' + since + '</td>' +
                '</tr>';
      });
      $('#heartbeat-info').html(rows);

    if (refresh) {
      timer = setTimeout(function() { getHeartbeats(refresh); }, 120000);
    }
  });
};

// Update Alert Status
function getStatus(statusfilter, refresh) {

  $.getJSON('http://'+ document.domain + '/alerta/api/v1/alerts?callback=?&hide-alert-details=true&' + statusfilter + limit + fromDate, function(data) {

    if (data.response.warning) {
      $('#warning-text').text(data.response.warning);
      $('#console-alert').toggle();
    }

    $.each(data.response.alerts.statusCounts, function(stat, count) {
      $("#alert-" + stat).text(count);
    });
    if (refresh) {
      timer = setTimeout(function() { getStatus(statusfilter, refresh); }, 120000);
    }
  });
};

// Update Alert Summaries
function getAlerts(service, filter, refresh) {

  $('#' + service +' th').addClass('loader');

  $.getJSON('http://'+ document.domain + '/alerta/api/v1/alerts?callback=?&sort-by=lastReceiveTime&' + filter + limit + fromDate, function(data) {

      var sev_id = '#' + service;

      data.response.alerts.severityCounts.normal += data.response.alerts.severityCounts.inform;

      $.each(data.response.alerts.severityCounts, function(sev, count) {
        $(sev_id + "-" + sev).text(count);

        switch (count) {
          case 0: $(sev_id + "-" + sev).removeClass(sev).addClass('zero'); break;
          default: $(sev_id + "-" + sev).addClass(sev).removeClass('zero');
        }

      });

        if (data.response.alerts.severityCounts.critical > 0) {
          scolor = 'red';
        } else if (data.response.alerts.severityCounts.major > 0) {
          scolor = 'orange';
        } else if (data.response.alerts.severityCounts.minor > 0) {
          scolor = 'yellow';
        } else if (data.response.alerts.severityCounts.warning > 0) {
          scolor = 'dodgerblue';
        } else {
          scolor = 'lime';
        }
      $(sev_id + "-status").css('background-color',scolor);

      var rows ='';
      $.each(data.response.alerts.alertDetails, function(i, ad) {

        var historydata = '<td colspan="2"><b>History </b>', graphsdata = tagsdata = '';

        if (ad.history) {
          var reverseHistory = ad.history.reverse();
          $.each(reverseHistory, function (y, hist) {
            if (hist.event) {
              historydata += '<hr/>' +
                          '<table class="table table-condensed table-striped">' +
                          '<tr><td><b>Event</b></td><td>' + hist.event + '</td></tr>' +
                          '<tr><td><b>Severity</b></td><td>' + sev2label(hist.severity) + '</td></tr>' +
                          '<tr><td><b>Alert ID</b></td><td>' + hist.id + '</td></tr>' +
                          '<tr><td><b>Create Time</b></td><td>' + date2str(hist.createTime) + '</td></tr>' +
                          '<tr><td><b>Receive Time</b></td><td>' + date2str(hist.receiveTime) + '</td></tr>' +
                          '<tr><td><b>Text</b></td><td>' + hist.text + '</td></tr>' +
                          '<tr><td><b>Value</b></td><td>' + hist.value + '</td></tr>' +
                          '</table>' +
                        '';
            }
            if (hist.status) {
              historydata += '<hr/>' +
                          '<table class="table table-condensed table-striped">' +
                          '<tr><td><b>Status</b></td><td><span class="label">' + hist.status + '</span></td></tr>' +
                          '<tr><td><b>Update Time</b></td><td>' + date2str(hist.updateTime) + '</td></tr>' +
                          '</table>' +
                        '';
            }
          });
          historydata += '</td>'
        }

        if (ad.tags) {
          tagsdata += '';
          $.each (ad.tags, function(y, tag) {
            tagsdata += '<span class="label">' + tag + '</span> ';
          });
        }

        if (ad.graphs) {
          graphsdata += '';
          $.each (ad.graphs, function(y, graph) {
            graphsdata += '<a href="' + graph + '" target="_blank">Graph ' + y + '</a> ';
          });
          graphsdata += '</ul>';
        }

        switch (ad.severity) {
          case 'CRITICAL': label='label-important'; break;
          case 'MAJOR': label='label-warning'; break;
          case 'MINOR': label='label-warning'; break;
          case 'WARNING': label='label-info'; break;
          default: label='label-success';
        }

        rows += '<tr class="' + service + ' latest ' + ad.severity + ' ' + ad.status + '">' +
                  '<td class="ad-more"><a id="' + service + 'details' + i + '" class="show-details">' +
                    '<span class="show-d"><i class="icon-chevron-up icon-chevron-down"></i></span></a></td>' +
                  '<td class="ad-sev-td">' + sev2label(ad.severity) + '</td>' +
                  '<td class="ad-stat-td"><span class="label">' + ad.status + '</span></td>' +
                  '<td>'+ date2iso8601(ad.lastReceiveTime) + '</td>' +
                  '<td>' + ad.duplicateCount + '</td>' +
                  '<td>' + ad.environment + '</td>' +
                  '<td>' + ad.service + '</td>' +
                  '<td>' + ad.resource + '</td>' +
                  '<td>' + ad.event + '</td>' +
                  '<td>' + ad.value + '</td>' +
                  '<td class="alert-text">' + ad.text;
        if (ad.status == 'OPEN') {
          rows +=     '<a id="' + ad.id + '" class="ack-alert" rel="tooltip" title="Acknowledge"><i class="icon-star-empty"></i></a>';
        }
        if (ad.status == 'ACK') {
          rows +=     '<a id="' + ad.id + '" class="unack-alert" rel="tooltip" title="Unacknowledge"><i class="icon-star"></i></a>';
        }
        rows += '<a id="' + ad.id + '" href="mailto:?subject=' + ad.summary + '&body=' + ad.text + '%0D%0A%0D%0ASee http://' + document.domain + '/alerta/details.php?id=' + ad.id + '" class="email-alert" rel="tooltip" title="Email Alert" target="_blank"><i class="icon-envelope"></i></a>';
        rows +=  '<a id="' + ad.id + '" class="tag-alert" rel="tooltip" title="Tag Alert"><i class="icon-tags"></i></a>';
{'fraction_non_alphanumeric': 0.20314218381775334, 'fraction_numerical': 0.007541241162608013, 'mean_word_length': 1.9978021978021978, 'pattern_counts': {'":': 0, '<': 309, '<?xml version=': 0, '>': 327, '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': '4512548', 'n_tokens_mistral': 6194, 'n_tokens_neox': 5949, 'n_words': 1117}