<commit_before>'use strict';

var _ = require('lodash');
var moment = window.moment;
var times = require('../times');
var d3 = (global && global.d3) || require('d3');

var weektoweek = {
  name: 'weektoweek'
  , label: 'Week to week'
  , pluginType: 'report'
};

function init() {
  return weektoweek;
}

module.exports = init;

weektoweek.html = function html(client) {
  var translate = client.translate;
  var ret =
    '<h2>' + translate('Week to week') + '</h2>'
    + '<b>' + translate('To see this report, press SHOW while in this view') + '</b><br>'
    + '&nbsp;'+translate('Size')
    + ' <select id="wrp_size">'
    + '  <option x="800" y="250">800x250px</option>'
    + '  <option x="1000" y="300" selected>1000x300px</option>'
    + '  <option x="1200" y="400">1200x400px</option>'
    + '  <option x="1550" y="600">1550x600px</option>'
    + '</select>'
    + '<br>'
    + translate('Scale') + ': '
    + '<input type="radio" name="wrp_scale" id="wrp_linear" checked>'
    + translate('Linear')
    + '<input type="radio" name="wrp_scale" id="wrp_log">'
    + translate('Logarithmic')
    + '<br>'
    + '<div id="weektoweekcharts">'
    + '</div>'
    ;
    return ret;
};

weektoweek.prepareHtml = function weektoweekPrepareHtml(weekstoshow) {
  $('#weektoweekcharts').html('');
  weekstoshow.forEach(function eachWeek(d) {
    $('#weektoweekcharts').append($('<table><tr><td><div id="weektoweekchart-' + d[0] + '-' + d[d.length-1] + '"></div></td><td><div id="weektoweekstatchart-' + d[0] + '-' + d[d.length-1] + '"></td></tr></table>'));
  });
};

weektoweek.report = function report_weektoweek(datastorage,sorteddaystoshow,options) {
  var Nightscout = window.Nightscout;
  var client = Nightscout.client;
  var translate = client.translate;
  var profile = client.sbx.data.profile;
  var report_plugins = Nightscout.report_plugins;
  var scaledTreatmentBG = report_plugins.utils.scaledTreatmentBG;
  
  var TOOLTIP_TRANS_MS = 300;

  var padding = { top: 15, right: 22, bottom: 30, left: 35 };

  var tddSum = 0;
  var carbsSum = 0;

  var weekstoshow = [ ];
  weekstoshow[0] = [ ];
  var weekIdx = 0;
  var dayIdx = 0;
  var reset_day = 0;

  if (sorteddaystoshow[0] > sorteddaystoshow[sorteddaystoshow.length]) {
    reset_day = moment.localeData().firstDayOfWeek() - 1;
    if (reset_day < 0) {
      reset_day += 7;
    }
  } else {
    reset_day = moment.localeData().firstDayOfWeek();
  }

  sorteddaystoshow.forEach( function eachDay(day) {
    if (moment(day).day() === reset_day) {
      weekIdx += 1;
      weekstoshow[weekIdx] = [ ];
      weekstoshow[weekIdx][0] = day;
      dayIdx = 0;
    } else {
      weekstoshow[weekIdx][dayIdx] = day;<commit_msg>Fix it for real this time<commit_after>'use strict';

var _ = require('lodash');
var moment = window.moment;
var times = require('../times');
var d3 = (global && global.d3) || require('d3');

var weektoweek = {
  name: 'weektoweek'
  , label: 'Week to week'
  , pluginType: 'report'
};

function init() {
  return weektoweek;
}

module.exports = init;

weektoweek.html = function html(client) {
  var translate = client.translate;
  var ret =
    '<h2>' + translate('Week to week') + '</h2>'
    + '<b>' + translate('To see this report, press SHOW while in this view') + '</b><br>'
    + '&nbsp;'+translate('Size')
    + ' <select id="wrp_size">'
    + '  <option x="800" y="250">800x250px</option>'
    + '  <option x="1000" y="300" selected>1000x300px</option>'
    + '  <option x="1200" y="400">1200x400px</option>'
    + '  <option x="1550" y="600">1550x600px</option>'
    + '</select>'
    + '<br>'
    + translate('Scale') + ': '
    + '<input type="radio" name="wrp_scale" id="wrp_linear" checked>'
    + translate('Linear')
    + '<input type="radio" name="wrp_scale" id="wrp_log">'
    + translate('Logarithmic')
    + '<br>'
    + '<div id="weektoweekcharts">'
    + '</div>'
    ;
    return ret;
};

weektoweek.prepareHtml = function weektoweekPrepareHtml(weekstoshow) {
  $('#weektoweekcharts').html('');
  weekstoshow.forEach(function eachWeek(d) {
    $('#weektoweekcharts').append($('<table><tr><td><div id="weektoweekchart-' + d[0] + '-' + d[d.length-1] + '"></div></td><td><div id="weektoweekstatchart-' + d[0] + '-' + d[d.length-1] + '"></td></tr></table>'));
  });
};

weektoweek.report = function report_weektoweek(datastorage,sorteddaystoshow,options) {
  var Nightscout = window.Nightscout;
  var client = Nightscout.client;
  var translate = client.translate;
  var profile = client.sbx.data.profile;
  var report_plugins = Nightscout.report_plugins;
  var scaledTreatmentBG = report_plugins.utils.scaledTreatmentBG;
  
  var TOOLTIP_TRANS_MS = 300;

  var padding = { top: 15, right: 22, bottom: 30, left: 35 };

  var tddSum = 0;
  var carbsSum = 0;

  var weekstoshow = [ ];
  weekstoshow[0] = [ ];
  var weekIdx = 0;
  var dayIdx = 0;
  var reset_day = 0;

  if (sorteddaystoshow[0] > sorteddaystoshow[sorteddaystoshow.length]) {
    reset_day = moment.localeData().firstDayOfWeek() - 1;
    if (reset_day < 0) {
      reset_day += 7;
    }
  } else {
    reset_day = moment.localeData().firstDayOfWeek();
  }

  sorteddaystoshow.forEach( function eachDay(day) {
    if (moment(day).day() === reset_day) {
      weekIdx += 1;
      weekstoshow[weekIdx] = [ ];
      weekstoshow[weekIdx][0] = day;
      dayIdx = 1;
    } else {
      weekstoshow[weekIdx][dayIdx] = day;
{'fraction_non_alphanumeric': 0.18722139673105498, 'fraction_numerical': 0.03231797919762259, 'mean_word_length': 3.6989528795811517, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, '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': '2209037', 'n_tokens_mistral': 2138, 'n_tokens_neox': 1996, 'n_words': 382}