<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Game extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this -> load -> model("usermodel");
        $this -> load -> model("Gamemodel");
    }
    public function getPlayHistory(){
        if(!isset($_GET['loginId'])|| !isset($_GET['plays']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId");
            $plays   = $this -> input -> get("plays");
            $uid = $this->usermodel->getUserIdFromLogin($loginId);
            echo $this->Gamemodel->addHistoryFields($plays,$uid);
        }
    }
    public function getLeaderboard(){
        if(!isset($_GET['loginId']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId");
            $uid = $this->usermodel->getUserIdFromLogin($loginId);
            $leaderboard = $this->Gamemodel->getLeaderboard();
            $resultString ="";
            foreach ($leaderboard as $user) {
                foreach ($user as $item) {
                    $resultString.=$item.",";
                }
                $resultString.=$item.";";
            }

            $meAndUp = $this->Gamemodel->getMyRankAndScore($uid);
            foreach ($meAndUp as $mup) {
                if($mup['userid']==$uid)
                    $myPoint = $mup['sum(score)'];
            }
            echo count($meAndUp).",".$myPoint.";";
            echo $resultString;
        }
    }
    public function sendEndLevelStats(){
        if(!isset($_GET['loginId']) || !isset($_GET['precisionValue'])|| !isset($_GET['perfectionValue'])|| !isset($_GET['punctualityValue'])|| !isset($_GET['presenceValue'])|| !isset($_GET['paceValue'])|| !isset($_GET['step']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId");            
			$precisionValue   = $this -> input -> get("precisionValue");
            $perfectionValue   = $this -> input -> get("perfectionValue");
            $punctualityValue   = $this -> input -> get("punctualityValue");<commit_msg>bug fix on leaderboard when user has no registered games<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Game extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this -> load -> model("usermodel");
        $this -> load -> model("Gamemodel");
    }
    public function getPlayHistory(){
        if(!isset($_GET['loginId'])|| !isset($_GET['plays']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId");
            $plays   = $this -> input -> get("plays");
            $uid = $this->usermodel->getUserIdFromLogin($loginId);
            echo $this->Gamemodel->addHistoryFields($plays,$uid);
        }
    }
    public function getLeaderboard(){
        if(!isset($_GET['loginId']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId");
            $uid = $this->usermodel->getUserIdFromLogin($loginId);
            $leaderboard = $this->Gamemodel->getLeaderboard();
            $resultString ="";
            foreach ($leaderboard as $user) {
                foreach ($user as $item) {
                    $resultString.=$item.",";
                }
                $resultString.=$item.";";
            }

            $meAndUp = $this->Gamemodel->getMyRankAndScore($uid);
            if(count($meAndUp)==0){
                echo "-,0;";
            }
            foreach ($meAndUp as $mup) {
                if($mup['userid']==$uid)
                    $myPoint = $mup['sum(score)'];
                echo count($meAndUp).",".$myPoint.";";
            }
            echo $resultString;
        }
    }
    public function sendEndLevelStats(){
        if(!isset($_GET['loginId']) || !isset($_GET['precisionValue'])|| !isset($_GET['perfectionValue'])|| !isset($_GET['punctualityValue'])|| !isset($_GET['presenceValue'])|| !isset($_GET['paceValue'])|| !isset($_GET['step']))
        {
            echo json_encode("0Invalid parameters. there is at least one missing parameter. please check the API");
        }
        else
        {
            $loginId   = $this -> input -> get("loginId"); 
			$precisionValue   = $this -> input -> get("precisionValue");
            $perfectionValue   = $this -> input -> get("perfectionValue");
            $punctualityValue   = $this -> input -> get("punctualityValue");
{'fraction_non_alphanumeric': 0.15924557651176358, 'fraction_numerical': 0.0015555123468792534, 'mean_word_length': 2.0473933649289098, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '1188125', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1382, 'n_words': 303}