<commit_before><?php

namespace App\Model;

final class SeriesModel extends BaseEntityModel
{
    /** @var string */
    public $tableName = 'series';

    /** @var string */
    protected $ratingTableName = 'rating_series_season';

    public function getTop($limit)
    {
        return $this->query("
        SELECT
        {$this->tableName}.*
        FROM {$this->tableName}
        LEFT JOIN series_season ON {$this->tableName}.id = series_season.{$this->tableName}_id
        LEFT JOIN {$this->ratingTableName} ON series_season.id = {$this->ratingTableName}.series_season_id
        GROUP BY {$this->tableName}.id
        ORDER BY sum({$this->ratingTableName}.rating) / count({$this->ratingTableName}.id) DESC
        LIMIT {$limit}");
    }

    public function getNotRated($userId, $limit = false)
    {
        return $this->getTable()->limit($limit);
    }
}
<commit_msg>replaced query with nette database<commit_after><?php

namespace App\Model;

final class SeriesModel extends BaseEntityModel
{
    /** @var string */
    public $tableName = 'series';

    /** @var string */
    protected $ratingTableName = 'rating_series_season';

    public function getTop($limit)
    {
        return $this
            ->findAll()
            ->group('id')
            ->order("sum(:series_season:{$this->ratingTableName}.rating)/count(*) DESC")
            ->limit($limit);
    }

    public function getNotRated($userId, $limit = false)
    {
        return $this->getTable()->limit($limit);
    }
}

{'fraction_non_alphanumeric': 0.14551495016611296, 'fraction_numerical': 0.0, 'mean_word_length': 2.774436090225564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '905397', 'n_tokens_mistral': 446, 'n_tokens_neox': 435, 'n_words': 95}