<commit_before><!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.css">
<title>hi monde</title>
</head>
<body data-exercice="<%- data.doc._id %>" data-student="<%- data.name %>" data-ponderation="<%- data.doc.ponderation %>">
<div class="row column">
<h1 class="title">Résultat d'exercice de <%- data.name %></h1>
<nav aria-label="You are here:" role="navigation">
  <ul class="breadcrumbs">
    <li><a href="/">Accueil</a></li>
    <li><a href="/exercices">Exercices</a></li>
    <li class="disabled"><%- data.doc.title %></li>
    <li>
      <span class="show-for-sr">Actuel: </span> Score
    </li>
  </ul>
</nav>
<h2><%- data.doc.title %></h2>
<ul>
<li>Thème: <span class="label"><%- data.doc.theme %></span></li>
<li>Pondération sur <span class="stat"><%- data.doc.ponderation %></span></li>
</ul>
<p><%- data.doc.descriptif || data.doc.description %></p>
<h3>Score</h3>
<pre id="json-score"></pre>

</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.js"></script>
<script>
$(function () {
  const score = function ($form, ponderation) {
    const ret = { ponderation: ponderation }
    $form.serializeArray().forEach(function (x) { ret[x.name] = x.value })
    ret.note = parseFloat(ret.note)
    ret.ponderation = parseFloat(ret.ponderation)
    ret.createdAt = new Date().toISOString()
    return ret
  }

  $(document).foundation()
  const $body = $('body')
  const bodyData = $body.data()
  const userUrl = '/_users/org.couchdb.user:' + bodyData.student
  const $score = $('pre#json-score')

  const submitJpeg =  function (bodyData, self, rev, ev) {
    // see http://stackoverflow.com/a/11910333/1154755
    const $self = $(self)
    // const exid = $self.data('exid')
    const exid = bodyData.exercice
    const docUrl = $self.parents('form').attr('action')
    const file = $self[0].files[0]
    const putRequest = new XMLHttpRequest()
    const fileReader = new FileReader()
    putRequest.open('PUT', docUrl + '/' + exid + '.jpg' + '?rev=' + rev, true)
    putRequest.setRequestHeader('Content-Type', file.type)
    fileReader.readAsArrayBuffer(file)
    fileReader.onload = function (readerEvent) { putRequest.send(readerEvent.target.result) }
    putRequest.onreadystatechange = function (response) {
      if (putRequest.readyState === 4 && putRequest.status === 201) {
        $('label[for="fichier-label"]').addClass('success').text('Merci!')
        $self.prop('disabled', true)
      } else {
        $('label[for="fichier-label"]').addClass('warning').text('Erreur #1...')
      }
    }
  }

  const showUpload = function (student, $score) {
    $score.after([
      '<form id="upload-jpeg" action="/_users/org.couchdb.user:'+ student + '">',
      '  <fieldset class="fieldset callout primary">',
      '  <h1 class="title text-center">Téléverser jpeg</h1>',
      '  <div class="row">',
      '    <div class="small-offset-4 small-8 medium-6 medium-offset-6 column">',
      '      <label for="fichier-label" class="button expanded">Choisir le fichier</label>',
      '      <input type="file" id="fichier-label" class="show-for-sr" name="jpeg" required>',
      '    </div>',
      '  </div>',
      '  </fieldset>',
      '</form>'
    ].join())
  }

  const showJpeg = function (exercice, userDoc) {
    $score.after('<img src="/_users/' + userDoc._id + '/' + exercice + '.jpg' + '" alt="jpeg">')
  }

  const showScore = function (bodyData, userDoc, $score, score) {
    score.percent = Math.round(1000 * score.note / score.ponderation) / 10
    $score.text(JSON.stringify(score, null, ' '))
    if (userDoc._attachments && userDoc._attachments[bodyData.exercice + '.jpg']) {
      showJpeg(bodyData.exercice, userDoc)
    } else {
      showUpload(bodyData.student, $score)
    }
    $body.on('change', 'input#fichier-label', submitJpeg.bind(null, bodyData, 'input#fichier-label', userDoc._rev))
  }

  $.getJSON(userUrl, function (userDoc) {
    const score = userDoc.corrections && userDoc.corrections[bodyData.exercice]
    if (score) {
      showScore(bodyData, userDoc, $score, score)
    } else {
      $score.text('Aucun résultat disponible.')
    }
  })
})
</script>
</body>
</html><commit_msg>Improve score display.<commit_after><!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.css">
<title>hi monde</title>
</head>
<body data-exercice="<%- data.doc._id %>" data-student="<%- data.name %>" data-ponderation="<%- data.doc.ponderation %>">
<div class="row column">
<h1 class="title">Résultat d'exercice de <%- data.name %></h1>
<nav aria-label="You are here:" role="navigation">
  <ul class="breadcrumbs">
    <li><a href="/">Accueil</a></li>
    <li><a href="/exercices">Exercices</a></li>
    <li class="disabled"><%- data.doc.title %></li>
    <li>
      <span class="show-for-sr">Actuel: </span> Score
    </li>
  </ul>
</nav>
<h2><%- data.doc.title %></h2>
<ul>
<li>Thème: <span class="label"><%- data.doc.theme %></span></li>
<li>Pondération sur <span class="stat"><%- data.doc.ponderation %></span></li>
</ul>
<p><%- data.doc.descriptif || data.doc.description %></p>
<h3>Score</h3>
<div class="callout" id="json-score"></div>

</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.js"></script>
<script>
$(function () {
  'use strict'
  const score = function ($form, ponderation) {
    const ret = { ponderation: ponderation }
    $form.serializeArray().forEach(function (x) { ret[x.name] = x.value })
    ret.note = parseFloat(ret.note)
    ret.ponderation = parseFloat(ret.ponderation)
    ret.createdAt = new Date().toISOString()
    return ret
  }

  $(document).foundation()
  const $body = $('body')
  const bodyData = $body.data()
  const userUrl = '/_users/org.couchdb.user:' + bodyData.student
  const $score = $('#json-score')

  const submitJpeg =  function (bodyData, self, rev, ev) {
    // see http://stackoverflow.com/a/11910333/1154755
    const $self = $(self)
    const exid = bodyData.exercice
    const docUrl = $self.parents('form').attr('action')
    const file = $self[0].files[0]
    const putRequest = new XMLHttpRequest()
    const fileReader = new FileReader()
    putRequest.open('PUT', docUrl + '/' + exid + '.jpg' + '?rev=' + rev, true)
    putRequest.setRequestHeader('Content-Type', file.type)
    fileReader.readAsArrayBuffer(file)
    fileReader.onload = function (readerEvent) { putRequest.send(readerEvent.target.result) }
    putRequest.onreadystatechange = function (response) {
      if (putRequest.readyState === 4 && putRequest.status === 201) {
        $('label[for="fichier-label"]').addClass('success').text('Merci!')
        $self.prop('disabled', true)
      } else {
        $('label[for="fichier-label"]').addClass('warning').text('Erreur #1...')
      }
    }
  }

  const showUpload = function (student, $score) {
    $score.after([
      '<form id="upload-jpeg" action="/_users/org.couchdb.user:'+ student + '">',
      '  <fieldset class="fieldset callout primary">',
      '  <h1 class="title text-center">Téléverser jpeg</h1>',
      '  <div class="row">',
      '    <div class="small-offset-4 small-8 medium-6 medium-offset-6 column">',
      '      <label for="fichier-label" class="button expanded">Choisir le fichier</label>',
      '      <input type="file" id="fichier-label" class="show-for-sr" name="jpeg" required>',
      '    </div>',
      '  </div>',
      '  </fieldset>',
      '</form>'
    ].join())
  }

  const showJpeg = function (exercice, userDoc) {
    $score.after('<img src="/_users/' + userDoc._id + '/' + exercice + '.jpg' + '" alt="jpeg">')
  }

  const makeHtml = function (score) {
    return ('<p><span class="stat">' + score.percent + '%' + '</span> ' + score.note + '/' + score.ponderation + '</p>'
     + '<p><i>' + score.createdAt.split('T')[0] + '</i> ' + score.commentaires + '</p>')
  }

  const showScore = function (bodyData, userDoc, $score, score) {
    score.percent = Math.round(1000 * score.note / score.ponderation) / 10
    $score.addClass('success').html(makeHtml(score))
    if (userDoc._attachments && userDoc._attachments[bodyData.exercice + '.jpg']) {
      showJpeg(bodyData.exercice, userDoc)
    } else {
      showUpload(bodyData.student, $score)
    }
    $body.on('change', 'input#fichier-label', submitJpeg.bind(null, bodyData, 'input#fichier-label', userDoc._rev))
  }

  $.getJSON(userUrl, function (userDoc) {
    const score = userDoc.corrections && userDoc.corrections[bodyData.exercice]
    if (score) {
      showScore(bodyData, userDoc, $score, score)
    } else {
      $score.addClass('warning').text('Aucun résultat disponible.')
    }
  })
})
</script>
</body>
</html>
{'fraction_non_alphanumeric': 0.2038366734540778, 'fraction_numerical': 0.011252813203300824, 'mean_word_length': 3.666, 'pattern_counts': {'":': 0, '<': 175, '<?xml version=': 0, '>': 175, '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': '313028', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3298, 'n_words': 597}