<commit_before><?php
namespace Youkok\Processors\PopularListing;

use Youkok\Enums\MostPopularElement;
use Youkok\Helpers\CacheHelper;
use Youkok\Helpers\SessionHandler;
use Youkok\Models\Element;

class PopularElementsProcessor extends AbstractPopularListingProcessor
{
    public static function fromDelta($delta, $cache, $limit)
    {
        $ids = CacheHelper::getMostPopularElementsFromDelta($cache, $delta, $limit);
        if (empty($ids)) {
            return [];
        }

        return static::idListToElements($ids);
    }

    public static function fromSessionHandler(SessionHandler $sessionHandler)
    {
        return new PopularElementsProcessor($sessionHandler, 'most_popular_element');
    }

    private static function idListToElements(array $ids)
    {
        $elements = [];
        foreach ($ids as $id => $downloads) {
            $element = Element::fromId($id, ['id', 'name', 'slug', 'uri', 'link', 'empty', 'parent']);
            $element->_downloads = (string) $downloads;

            $elements[] = $element;
        }
        return $elements;<commit_msg>Fix links to popular elements<commit_after><?php
namespace Youkok\Processors\PopularListing;

use Youkok\Enums\MostPopularElement;
use Youkok\Helpers\CacheHelper;
use Youkok\Helpers\SessionHandler;
use Youkok\Models\Element;

class PopularElementsProcessor extends AbstractPopularListingProcessor
{
    public static function fromDelta($delta, $cache, $limit)
    {
        $ids = CacheHelper::getMostPopularElementsFromDelta($cache, $delta, $limit);
        if (empty($ids)) {
            return [];
        }

        return static::idListToElements($ids);
    }

    public static function fromSessionHandler(SessionHandler $sessionHandler)
    {
        return new PopularElementsProcessor($sessionHandler, 'most_popular_element');
    }

    private static function idListToElements(array $ids)
    {
        $elements = [];
        foreach ($ids as $id => $downloads) {
            $element = Element::fromId($id, ['id', 'name', 'slug', 'uri', 'link', 'empty', 'parent', 'checksum']);
            $element->_downloads = (string) $downloads;

            $elements[] = $element;
        }
        return $elements;
{'fraction_non_alphanumeric': 0.12352941176470589, 'fraction_numerical': 0.0, 'mean_word_length': 3.335294117647059, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4940307', 'n_tokens_mistral': 621, 'n_tokens_neox': 607, 'n_words': 136}