<commit_before>$(function() {

  // Fetch email from cookie
  var email;
  if (document.cookie) {
    var cookies = document.cookie.split('; ');
    for (var i = 0; i < cookies.length; ++i) {
      var cookie = cookies[i];
      if (cookie.substring(0, 6) === 'email=') {
        email = cookie.substring(6);
        break;
      }
    }
  }
  $('#email').val(email);

  // Initialize tooltips
  $('.control-label a').tooltip();

  // Initialize pager
  var last_page, page,
      frstpage = $('#frstpage'),
      lastpage = $('#lastpage'),
      prevpage = $('#prevpage'),
      nextpage = $('#nextpage'),
      whatpage = $('#whatpage');
  frstpage.click(function() {
    if (frstpage.hasClass('disabled')) return;
    page = 1;
    refresh();
  });
  lastpage.click(function() {
    if (lastpage.hasClass('disabled')) return;
    page = last_page;
    refresh();
  });
  prevpage.click(function() {
    if (prevpage.hasClass('disabled')) return;
    page -= 1;
    refresh();
  });
  nextpage.click(function() {
    if (nextpage.hasClass('disabled')) return;
    page += 1;
    refresh();
  });
  whatpage.change(function() {
    var p = parseInt(whatpage.val());
    if ((p < 1) || (p > last_page) || (p === page)) return;
    page = p;
    refresh();
  });

  // Construct td's of a tr from a job
  function tr(job) {
    var tds = new Array(5);
    if (job === undefined) {
      tds[0] = '&nbsp;';
      tds[1] = '&nbsp;';
      tds[2] = '&nbsp;';
      tds[3] = '&nbsp;';
      tds[4] = '&nbsp;';
      return tds;
    }
    var status, progress;
    if (!job.scheduled) {
      status = 'Queued for execution';
      progress = 0;
    } else if (job.completed < 100) {
      status = 'Phase 1 in progress';
      var num_completed_ligands = 0;
      for (var i = 0; i < job.scheduled; ++i) {
        num_completed_ligands += parseInt(job[i.toString()]);
      }
      progress = num_completed_ligands / job.ligands;
    } else if (!job.done) {
      status = 'Phase 2 in progress';
      progress = job.phase2 / Math.min(job.ligands, 1000);
    } else {
      status = 'Done on ' + $.format.date(new Date(job.done), 'yyyy/MM/dd HH:mm:ss');
      progress = 1;
    }
    tds[0] = $.comma(job.ligands);
    tds[1] = $.format.date(new Date(job.submitted), 'yyyy/MM/dd HH:mm:ss');
    tds[2] = status;
    tds[3] = (100 * progress).toFixed(5) + '%';
    tds[4] = job.done ? '<a href="jobs/' + job._id + '/result.tar.gz"><img src="/excel.png" alt="result.tar.gz"/></a>' : null;
    return tds;
  }

  // Refresh the table of jobs and its pager
  var jobs = [], jobs_trs = $('#jobs tr');
  function refresh() {
    var offset = 8 * (page - 1);
    jobs_trs.each(function(i) {
      var tds = tr(jobs[offset + i]);
      $('td', $(this)).each(function(j) {
        $(this).html(tds[j]);
      });
    });
    if (page === 1) {
      frstpage.addClass('disabled');
      prevpage.addClass('disabled');
    } else {
      frstpage.removeClass('disabled');
      prevpage.removeClass('disabled');
    }
    if (page === last_page) {
      lastpage.addClass('disabled');
      nextpage.addClass('disabled');
    } else {
      lastpage.removeClass('disabled');
      nextpage.removeClass('disabled');
    }
    whatpage.val(page);
  }

  // Fade selected cells
  function fade(row, col) {
    var offset = 8 * (page - 1);
    jobs_trs.each(function(i) {
      if (!row(offset + i)) return;
      var tds = tr(jobs[offset + i]);
      $('td', $(this)).each(function(j) {
        if (col(j)) $(this).html(tds[j]);
      });
    });
  }

  // Initialize the table of jobs
  var dones;
  $.get('jobs', { email: email }, function(res) {
    jobs = res;
    for (dones = jobs.length; dones && !jobs[dones - 1].done; --dones);
    last_page = jobs.length ? ((jobs.length + 7) >> 3) : 1;
    page = last_page;
    refresh();
  });

  // Activate the timer to refresh result every second
  setInterval(function() {
    $.get('done', { email: email, skip: dones }, function(res) {
      if (!res.length) return;
      var new_dones = 0;
      res.forEach(function(job, i) {
        jobs[dones + i].scheduled = job.scheduled;
        jobs[dones + i].completed = job.completed;
        if (job.done) {
          jobs[dones + i].done = job.done;
          ++new_dones;
        }
        for (var i = 0; i < job.scheduled; ++i) {
          jobs[dones + i][i.toString()] = job[i.toString()];
        }
      });
      fade(function(i) {
        return (dones <= i) && (i < dones + res.length);
      }, function(j) {<commit_msg>Fade only new content. Replaced fade by direct html(). Display phase2<commit_after>$(function() {

  // Fetch email from cookie
  var email;
  if (document.cookie) {
    var cookies = document.cookie.split('; ');
    for (var i = 0; i < cookies.length; ++i) {
      var cookie = cookies[i];
      if (cookie.substring(0, 6) === 'email=') {
        email = cookie.substring(6);
        break;
      }
    }
  }
  $('#email').val(email);

  // Initialize tooltips
  $('.control-label a').tooltip();

  // Initialize pager
  var last_page, page,
      frstpage = $('#frstpage'),
      lastpage = $('#lastpage'),
      prevpage = $('#prevpage'),
      nextpage = $('#nextpage'),
      whatpage = $('#whatpage');
  frstpage.click(function() {
    if (frstpage.hasClass('disabled')) return;
    page = 1;
    refresh();
  });
  lastpage.click(function() {
    if (lastpage.hasClass('disabled')) return;
    page = last_page;
    refresh();
  });
  prevpage.click(function() {
    if (prevpage.hasClass('disabled')) return;
    page -= 1;
    refresh();
  });
  nextpage.click(function() {
    if (nextpage.hasClass('disabled')) return;
    page += 1;
    refresh();
  });
  whatpage.change(function() {
    var p = parseInt(whatpage.val());
    if ((p < 1) || (p > last_page) || (p === page)) return;
    page = p;
    refresh();
  });

  // Construct td's of a tr from a job
  function tr(job) {
    var tds = new Array(5);
    if (job === undefined) {
      tds[0] = '&nbsp;';
      tds[1] = '&nbsp;';
      tds[2] = '&nbsp;';
      tds[3] = '&nbsp;';
      tds[4] = '&nbsp;';
      return tds;
    }
    var status, progress;
    if (!job.scheduled) {
      status = 'Queued for execution';
      progress = 0;
    } else if (job.completed < 100) {
      status = 'Phase 1 in progress';
      var num_completed_ligands = 0;
      for (var i = 0; i < job.scheduled; ++i) {
        num_completed_ligands += parseInt(job[i.toString()]);
      }
      progress = num_completed_ligands / job.ligands;
    } else if (!job.done) {
      status = 'Phase 2 in progress';
      progress = job.phase2 / Math.min(job.ligands, 1000);
    } else {
      status = 'Done on ' + $.format.date(new Date(job.done), 'yyyy/MM/dd HH:mm:ss');
      progress = 1;
    }
    tds[0] = $.comma(job.ligands);
    tds[1] = $.format.date(new Date(job.submitted), 'yyyy/MM/dd HH:mm:ss');
    tds[2] = status;
    tds[3] = (100 * progress).toFixed(5) + '%';
    tds[4] = job.done ? '<a href="jobs/' + job._id + '/result.tar.gz"><img src="/excel.png" alt="result.tar.gz"/></a>' : null;
    return tds;
  }

  // Refresh the table of jobs and its pager
  var jobs = [], jobs_trs = $('#jobs tr');
  function refresh() {
    var offset = 8 * (page - 1);
    jobs_trs.each(function(i) {
      var tds = tr(jobs[offset + i]);
      $('td', $(this)).each(function(j) {
        $(this).html(tds[j]);
      });
    });
    if (page === 1) {
      frstpage.addClass('disabled');
      prevpage.addClass('disabled');
    } else {
      frstpage.removeClass('disabled');
      prevpage.removeClass('disabled');
    }
    if (page === last_page) {
      lastpage.addClass('disabled');
      nextpage.addClass('disabled');
    } else {
      lastpage.removeClass('disabled');
      nextpage.removeClass('disabled');
    }
    whatpage.val(page);
  }

  // Fade selected cells
  function fade(row, col) {
    var offset = 8 * (page - 1);
    jobs_trs.each(function(i) {
      if (!row(offset + i)) return;
      var tds = tr(jobs[offset + i]);
      $('td', $(this)).each(function(j) {
        if (col(j) && ($(this).html() !== tds[j])) $(this).html(tds[j]);
      });
    });
  }

  // Initialize the table of jobs
  var dones;
  $.get('jobs', { email: email }, function(res) {
    jobs = res;
    for (dones = jobs.length; dones && !jobs[dones - 1].done; --dones);
    last_page = jobs.length ? ((jobs.length + 7) >> 3) : 1;
    page = last_page;
    refresh();
  });

  // Activate the timer to refresh result every second
  setInterval(function() {
    $.get('done', { email: email, skip: dones }, function(res) {
      if (!res.length) return;
      var new_dones = 0;
      res.forEach(function(job, i) {
        jobs[dones + i].scheduled = job.scheduled;
        jobs[dones + i].completed = job.completed;
        jobs[dones + i].phase2 = job.phase2;
        if (job.done) {
          jobs[dones + i].done = job.done;
          ++new_dones;
        }
        for (var s = 0; s < job.scheduled; ++s) {
          jobs[dones + i][s.toString()] = job[s.toString()];
        }
      });
      fade(function(i) {
        return (dones <= i) && (i < dones + res.length);
      }, function(j) {
{'fraction_non_alphanumeric': 0.19029932270045882, 'fraction_numerical': 0.010814944286650644, 'mean_word_length': 2.3945124212087503, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, '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': '2810361', 'n_tokens_mistral': 3277, 'n_tokens_neox': 3174, 'n_words': 721}