<commit_before>(function () {
'use strict';

/*
 * This file contains the necessary functions to:
 *   - fetch the different resources in the task directories and put them in
 *        the PEM installation API object
 *   - display the task from the PEM installation API object filled with the
 *        different resources
 *
 * It uses SyntaxHighlighter to highlight code, and jQuery-ui-tabs to display
 * sources in tabs with different languages.
 *
 * The structure it can work on is the one as given in the same task, it is
 * meant to be both a complete example and the documentation.
 */

var extensionToLanguage = {
   cpp:  'cpp',
   c:    'c',
   pas:  'pascal',
   ml:   'ocaml',
   java: 'java',
   jvs:  'javascool',
   py:   'python'
};

// fills all the resources from FIOITaskMetaData into PEMInstallationAPIObject
// calls callback when done
// urlMode is true if we just want the url, not the content
function fillResources(FIOITaskMetaData, PEMInstallationAPIObject, callback, urlMode) {
   if (task.resourcesFilled) {
      callback();
   }
   var waiting = 1; // number of ajax fetches waiting
   // the result is an object containing the arrays to concat to
   // keep track of group -> resource mapping, to add the answerVersions
   var groupsResources = {
      task: {},
      solution: {}
   };
   //
   // ajax callback factories
   //
   // type is 'task' or 'solution'
   function sourceDone(groupName, sourceFile, type) {
      return function (answer) {
         var groupResource = groupsResources[type][groupName];
         if (!groupResource) {
            groupResource = {
               type: 'answer',
               name: groupName,
               answerVersions: []
            };
            groupsResources[type][groupName] = groupResource;
            PEMInstallationAPIObject[type].push(groupResource);
         }
         groupResource.answerVersions.push({
            params: {
               sLangProg: extensionToLanguage[sourceFile.substr(sourceFile.lastIndexOf('.') + 1)]
            },
            answerContent: answer
         });
      };
   }
   // keep track of test name -> resource mapping
   var samplesResources = {
      task: {},
      solution: {},
      grader: {}
   };
   // type is 'task' or 'solution'
   // direction is 'in' or 'out'
   function sampleDone(sampleName, type, direction) {
      return function (sample) {
         var sampleResource = samplesResources[type][sampleName];
         if (!sampleResource) {
            sampleResource = {
               type: 'sample',
               name: sampleName,
            };
            samplesResources[type][sampleName] = sampleResource;
         }
         if (direction == 'in') {
            sampleResource.inContent = sample;
         } else {
            sampleResource.outContent = sample;
         }
      };
   }

   function fetchFail(filename) {
      return function () {
         console.error("Unable to load '" + filename + "'");
      };
   }

   function copySampleResources() {
      for (var type in samplesResources) {
         var samples = samplesResources[type];
         for (var sampleName in samples) {
            PEMInstallationAPIObject[type].push(samples[sampleName]);
         }
      }
   }

   function fetchAlways() {
      waiting = waiting - 1;
      if (!waiting) {
         copySampleResources();
         callback();
      }
   }
   //
   // actual filling
   //
   // type is 'task' or 'grader'
   function fillSamples(samples, type) {
      if (!samples) return;
      for (var i = 0; i < samples.length; i++) {
         if (!urlMode) {
            waiting += 2;
            $.get("tests/" + samples[i] + ".in")
               .done(sampleDone(samples[i], type, 'in'))
               .fail(fetchFail("test/" + samples[i] + ".in"))
               .always(fetchAlways);
            $.get("tests/" + samples[i] + ".out")
               .done(sampleDone(samples[i], type, 'out'))
               .fail(fetchFail("test/" + samples[i] + ".out"))
               .always(fetchAlways);
         } else {
            PEMInstallationAPIObject[type].push({
               type: 'sample',
               name: samples[i],
               inUrl: "test/" + samples[i] + ".in",
               outUrl: "test/" + samples[i] + ".out"<commit_msg>fix directory of tests and samples<commit_after>(function () {
'use strict';

/*
 * This file contains the necessary functions to:
 *   - fetch the different resources in the task directories and put them in
 *        the PEM installation API object
 *   - display the task from the PEM installation API object filled with the
 *        different resources
 *
 * It uses SyntaxHighlighter to highlight code, and jQuery-ui-tabs to display
 * sources in tabs with different languages.
 *
 * The structure it can work on is the one as given in the same task, it is
 * meant to be both a complete example and the documentation.
 */

var extensionToLanguage = {
   cpp:  'cpp',
   c:    'c',
   pas:  'pascal',
   ml:   'ocaml',
   java: 'java',
   jvs:  'javascool',
   py:   'python'
};

// fills all the resources from FIOITaskMetaData into PEMInstallationAPIObject
// calls callback when done
// urlMode is true if we just want the url, not the content
function fillResources(FIOITaskMetaData, PEMInstallationAPIObject, callback, urlMode) {
   if (task.resourcesFilled) {
      callback();
   }
   var waiting = 1; // number of ajax fetches waiting
   // the result is an object containing the arrays to concat to
   // keep track of group -> resource mapping, to add the answerVersions
   var groupsResources = {
      task: {},
      solution: {}
   };
   //
   // ajax callback factories
   //
   // type is 'task' or 'solution'
   function sourceDone(groupName, sourceFile, type) {
      return function (answer) {
         var groupResource = groupsResources[type][groupName];
         if (!groupResource) {
            groupResource = {
               type: 'answer',
               name: groupName,
               answerVersions: []
            };
            groupsResources[type][groupName] = groupResource;
            PEMInstallationAPIObject[type].push(groupResource);
         }
         groupResource.answerVersions.push({
            params: {
               sLangProg: extensionToLanguage[sourceFile.substr(sourceFile.lastIndexOf('.') + 1)]
            },
            answerContent: answer
         });
      };
   }
   // keep track of test name -> resource mapping
   var samplesResources = {
      task: {},
      solution: {},
      grader: {}
   };
   // type is 'task' or 'solution'
   // direction is 'in' or 'out'
   function sampleDone(sampleName, type, direction) {
      return function (sample) {
         var sampleResource = samplesResources[type][sampleName];
         if (!sampleResource) {
            sampleResource = {
               type: 'sample',
               name: sampleName,
            };
            samplesResources[type][sampleName] = sampleResource;
         }
         if (direction == 'in') {
            sampleResource.inContent = sample;
         } else {
            sampleResource.outContent = sample;
         }
      };
   }

   function fetchFail(filename) {
      return function () {
         console.error("Unable to load '" + filename + "'");
      };
   }

   function copySampleResources() {
      for (var type in samplesResources) {
         var samples = samplesResources[type];
         for (var sampleName in samples) {
            PEMInstallationAPIObject[type].push(samples[sampleName]);
         }
      }
   }

   function fetchAlways() {
      waiting = waiting - 1;
      if (!waiting) {
         copySampleResources();
         callback();
      }
   }
   //
   // actual filling
   //
   // type is 'task' or 'grader'
   function fillSamples(samples, type) {
      if (!samples) return;
      for (var i = 0; i < samples.length; i++) {
         if (!urlMode) {
            waiting += 2;
            $.get("tests/files/" + samples[i] + ".in")
               .done(sampleDone(samples[i], type, 'in'))
               .fail(fetchFail("test/" + samples[i] + ".in"))
               .always(fetchAlways);
            $.get("tests/files/" + samples[i] + ".out")
               .done(sampleDone(samples[i], type, 'out'))
               .fail(fetchFail("test/" + samples[i] + ".out"))
               .always(fetchAlways);
         } else {
            PEMInstallationAPIObject[type].push({
               type: 'sample',
               name: samples[i],
               inUrl: "test/files/" + samples[i] + ".in",
               outUrl: "test/files/" + samples[i] + ".out"
{'fraction_non_alphanumeric': 0.11710144927536231, 'fraction_numerical': 0.0011594202898550724, 'mean_word_length': 1.9909847434119279, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2730240', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2325, 'n_words': 686}