<commit_before><?php
class Team extends ModelEx {

  
  function __construct($oid=0,$cid=0) {
    parent::__construct('OID','CID','t_team'); 
    $this->rs['OID'] = $oid;
    $this->rs['CID'] = $cid;
    $this->rs['name'] = '';
    $this->rs['schoolId'] = -1;
    $this->rs['pin'] = "generated";
    $this->rs['totalScore'] = 0;
    $this->rs['totalDuration'] = 0;
    
    $this->rs['regScore'] = 0;
    $this->rs['ctsScore'] = 0;
    $this->rs['fslScore'] = 0;
    $this->rs['hmbScore'] = 0;
    $this->rs['cpaScore'] = 0;
    
    $this->rs['regDuration'] = 0;
    $this->rs['ctsDuration'] = 0;
    $this->rs['fslDuration'] = 0;
    $this->rs['hmbDuration'] = 0;
    $this->rs['cpaDuration'] = 0;
    
    //todo ext score lat,lng,height abs(height) abs(location)?
    $this->rs['extDuration'] = 0;
    $this->rs['towerH'] = 0;
    $this->rs['towerD'] = 0;
    
    $this->rs['count'] = 0;
    $this->rs['started'] = 0;
    $this->rs['json'] = ""; // json string holding challenge data
    
    if ($oid && $cid)
    $this->retrieve($oid,$cid);
  }
  
  function getSchoolName() {
  	return School::getSchoolNameFromId($this->rs['schoolId']);
  }

  // setup the common data fields needed to start a challenge
  private function startXXXChallenge($jsonObject=null) {
  	$this->rs['count'] = 0;
  	$this->rs['started'] = time();                       // get system time
  	$this->rs['json']    = $jsonObject?json_encode($jsonObject):"";
  	return $this->update();  	
  }

  // Must be called to put the challenge data into the started state
  //  basiclly the try count is cleared the started time is set (used to calculate duration) and the
  // the station type code is needed to clear any stale challenge data when a team restarts a challenge like when their phone dies
  // option challenge data can be saved to the DB.
  function startRegChallenge($jsonObject=null) {	
    $this->set('regScore',0);
    $this->set('regDuration',0);
    return $this->startXXXChallenge($jsonObject);
  }
  function startCTSChallenge($jsonObject=null)
  {
  	$this->set('ctsScore',0);
  	$this->set('ctsDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startFSLChallenge($jsonObject=null)
  {
  	$this->set('fslScore',0);
  	$this->set('fslDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startHMBChallenge($jsonObject=null)
  {
  	$this->set('hmbScore',0);
  	$this->set('hmbDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startCPAChallenge($jsonObject=null)
  {
  	$this->set('cpaScore',0);
  	$this->set('cpaDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startEXTChallenge($jsonObject=null) 
  {
  	$this->set('towerH',0);
  	$this->set('towerD',0);
  	$this->set('extDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  
  // get the json object holding the challenge state
  function getChallengeData()  {
  	return json_decode($this->rs['json'],true);
  }
  
  // set the json object holding the challenge state
  function setChallengeData($json) {
  	$this->rs['json'] = json_encode($json);
  }
  
  // must be called at end of challenge to clear challenge state
  function endChallenge() {
  	$this->rs['count'] = 0;
  	$this->rs['started'] = 0;
  	$this->rs['json']    = '';
  	return $this->update();  	
  }
  // Must be called to update team's score, this method is designed to be called 
  // after every submit.  The last call will be the final score.  This allows the leader board
  // to dyamiclly converge to the final score (duration goes up, points go down) with each submit.
  // TODO deprecate this
  function updateScore($stationType,$points) {
  
  	$duration = time()-$this->get('started');
  	switch ($stationType->get('typeCode'))
  	{
  		case StationType::STATION_TYPE_REG:
  			$this->set('regScore',$points);
  			$this->set('regDuration',0);
  			break;
  		case StationType::STATION_TYPE_CTS:
  			$this->set('ctsScore',$points);
  			$this->set('regDuration',$duration);
  			break;
  		case StationType::STATION_TYPE_FSL:
  			$this->set('fslScore',$points);
  			$this->set('regDuration',$duration);
  			break;
  		case StationType::STATION_TYPE_HMB:
  			$this->set('hmbScore',$points);
  			$this->set('regDuration',$duration);
  			break;
  		case StationType::STATION_TYPE_CPA:
  			$this->set('cpaScore',$points);
  			$this->set('regDuration',$duration);
  			break;
  	}
  	$this->set('totalScore',$this->get('regScore')+$this->get('ctsScore')+$this->get('fslScore')+$this->get('cpaScore'));
  	$this->set('totalDuration',$this->get('regDuration')+$this->get('ctsDuration')+$this->get('fslDuration')+$this->get('cpaDuration'));
  	return $this->update();
  }
  
  // called after updateXXXScore to compute new totals and update the DB.<commit_msg>rework depreciated _updateScore method to reuse non-depreciated logic<commit_after><?php
class Team extends ModelEx {

  
  function __construct($oid=0,$cid=0) {
    parent::__construct('OID','CID','t_team'); 
    $this->rs['OID'] = $oid;
    $this->rs['CID'] = $cid;
    $this->rs['name'] = '';
    $this->rs['schoolId'] = -1;
    $this->rs['pin'] = "generated";
    $this->rs['totalScore'] = 0;
    $this->rs['totalDuration'] = 0;
    
    $this->rs['regScore'] = 0;
    $this->rs['ctsScore'] = 0;
    $this->rs['fslScore'] = 0;
    $this->rs['hmbScore'] = 0;
    $this->rs['cpaScore'] = 0;
    
    $this->rs['regDuration'] = 0;
    $this->rs['ctsDuration'] = 0;
    $this->rs['fslDuration'] = 0;
    $this->rs['hmbDuration'] = 0;
    $this->rs['cpaDuration'] = 0;
    
    //todo ext score lat,lng,height abs(height) abs(location)?
    $this->rs['extDuration'] = 0;
    $this->rs['towerH'] = 0;
    $this->rs['towerD'] = 0;
    
    $this->rs['count'] = 0;
    $this->rs['started'] = 0;
    $this->rs['json'] = ""; // json string holding challenge data
    
    if ($oid && $cid)
    $this->retrieve($oid,$cid);
  }
  
  function getSchoolName() {
  	return School::getSchoolNameFromId($this->rs['schoolId']);
  }

  // setup the common data fields needed to start a challenge
  private function startXXXChallenge($jsonObject=null) {
  	$this->rs['count'] = 0;
  	$this->rs['started'] = time();                       // get system time
  	$this->rs['json']    = $jsonObject?json_encode($jsonObject):"";
  	return $this->update();  	
  }

  // Must be called to put the challenge data into the started state
  //  basiclly the try count is cleared the started time is set (used to calculate duration) and the
  // the station type code is needed to clear any stale challenge data when a team restarts a challenge like when their phone dies
  // option challenge data can be saved to the DB.
  function startRegChallenge($jsonObject=null) {	
    $this->set('regScore',0);
    $this->set('regDuration',0);
    return $this->startXXXChallenge($jsonObject);
  }
  function startCTSChallenge($jsonObject=null)
  {
  	$this->set('ctsScore',0);
  	$this->set('ctsDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startFSLChallenge($jsonObject=null)
  {
  	$this->set('fslScore',0);
  	$this->set('fslDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startHMBChallenge($jsonObject=null)
  {
  	$this->set('hmbScore',0);
  	$this->set('hmbDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startCPAChallenge($jsonObject=null)
  {
  	$this->set('cpaScore',0);
  	$this->set('cpaDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  function startEXTChallenge($jsonObject=null) 
  {
  	$this->set('towerH',0);
  	$this->set('towerD',0);
  	$this->set('extDuration',0);
  	return $this->startXXXChallenge($jsonObject);
  }
  
  // get the json object holding the challenge state
  function getChallengeData()  {
  	return json_decode($this->rs['json'],true);
  }
  
  // set the json object holding the challenge state
  function setChallengeData($json) {
  	$this->rs['json'] = json_encode($json);
  }
  
  // must be called at end of challenge to clear challenge state
  function endChallenge() {
  	$this->rs['count'] = 0;
  	$this->rs['started'] = 0;
  	$this->rs['json']    = '';
  	return $this->update();  	
  }
  // Must be called to update team's score, this method is designed to be called 
  // after every submit.  The last call will be the final score.  This allows the leader board
  // to dyamiclly converge to the final score (duration goes up, points go down) with each submit.
  // TODO deprecate this
  function _updateScore($stationType,$points) {
  
  	switch ($stationType->get('typeCode'))
  	{
  		case StationType::STATION_TYPE_REG:
  			return $this->updateREGScore($points);
  		case StationType::STATION_TYPE_CTS:
  			return $this->updateCTSSCore($points);
  		case StationType::STATION_TYPE_FSL:
  			return $this->updateFSLScore($points);
  		case StationType::STATION_TYPE_HMB:
  			return $this->updateHMBScore($points);
  		case StationType::STATION_TYPE_CPA:
  			return $this->updateCPAScore($points);
  	}
  }
  
  // called after updateXXXScore to compute new totals and update the DB.
{'fraction_non_alphanumeric': 0.17395593554751726, 'fraction_numerical': 0.00800175380905404, 'mean_word_length': 3.6527281998980112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 140, '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': '1761827', 'n_tokens_mistral': 3310, 'n_tokens_neox': 3160, 'n_words': 659}