<commit_before><?php
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */

require_once("../shared/common.php");
require_once("commonAdmin.php");

function generateAlgoreaCodes($db, $contestID) {
   // retrieving awarded contestants through "award1" model
   $modelName = 'award1';
   $model = getViewModel($modelName);
   $request = array(
      "modelName" => $modelName,
      "model" => $model,
      "filters" => array()
   );
   foreach($model["fields"] as $fieldName => $field) {
      $request["fields"][] = $fieldName;
   }
   $request["filters"] = array('awarded' => true, 'contestID' => $contestID);
   if (!$_SESSION["isAdmin"]) {
      $request["filters"]["userID"] = $_SESSION["userID"];
   }

   $result = selectRows($db, $request);
   $awarded = $result['items'];

   if (!count($awarded)) {
      return;
   }
   // we hope that there will be no collision in a serie of generated codes
   $query = "INSERT ignore INTO `contestant` (`ID`, `algoreaCode`) values ";
   $first = true;
   foreach($awarded as $contestant) {
      if (!$first) {
         $query = $query.', ';
      }
      $first = false;
      $query = $query.'('.$contestant->ID.', \''.genAccessCode($db).'\')';
   }
   $query = $query.' on duplicate key update `algoreaCode` = values(`algoreaCode`)';
   $db->exec($query);<commit_msg>teacherInterface: improve straightforwardness of algorea code generation<commit_after><?php
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */

require_once("../shared/common.php");
require_once("commonAdmin.php");

function generateAlgoreaCodes($db, $contestID) {
   // retrieving awarded contestants through "award1" model
   $query = "update contestant
      join team on contestant.teamID = team.ID
      join `group` on `group`.ID = team.groupID
      join award_threshold on award_threshold.nbContestants = team.nbContestants and award_threshold.contestID = :contestID and award_threshold.gradeID = contestant.grade and award_threshold.awardID = 1
      set algoreaCode =  CONCAT(CONCAT('', FLOOR(RAND()*10000000)), CONCAT('', FLOOR(RAND()*10000000)))
      where
      group.contestID = :contestID and
      team.participationType = 'Official' and
      contestant.algoreaCode is null
      and team.score >= award_threshold.minScore;";
   $stmt = $db->prepare($query);
   $stmt->execute(['contestID' => $contestID]);
{'fraction_non_alphanumeric': 0.16227347611202636, 'fraction_numerical': 0.011532125205930808, 'mean_word_length': 3.8775100401606424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '120601', 'n_tokens_mistral': 799, 'n_tokens_neox': 763, 'n_words': 175}