<commit_before><?php

namespace Eduity\EloquentOnet\Models;

use Illuminate\Database\Eloquent\Model;

class OnetOccupation extends Model
{
    protected $table = 'onet_occupation_data';
    protected $primaryKey = 'onetsoc_code';
    public $incrementing = false;

    /** RELATIONSHIPS */
    public function abilities()
    {
        return $this->abilities_by_importance(3);
    }

    public function abilities_by_importance($atLeast = null)
    {
        return $this->abilities_by_scale('IM', $atLeast);
    }

    public function abilities_by_level($atLeast = null)
    {
        return $this->abilities_by_scale('LV', $atLeast);
    }

    protected function abilities_by_scale($scale, $atLeast = null)
    {
        $query = $this
            ->belongsToMany(\Eduity\EloquentOnet\Models\OnetAbility::class, 'onet_abilities', 'onetsoc_code', 'element_id');

        if($atLeast !== null) {
            // "Important" only, to avoid duplicate records
            $query->where('scale_id', 'IM');
        }
            
            // O*NET itself seems to only show >3 on their sites
        $query->where('data_value' , '>=', $atLeast)
            
            // If they recommend it be suppressed, let it.
            ->where('recommend_suppress', 'N')

            // Include extra data from `onet_abilities`
            ->withPivot([
                'data_value',
                'n',
                'standard_error',
                'lower_ci_bound',<commit_msg>Update scale values to avoid errors<commit_after><?php

namespace Eduity\EloquentOnet\Models;

use Illuminate\Database\Eloquent\Model;

class OnetOccupation extends Model
{
    protected $table = 'onet_occupation_data';
    protected $primaryKey = 'onetsoc_code';
    public $incrementing = false;

    /** RELATIONSHIPS */
    public function abilities()
    {
        return $this->abilities_by_importance(3);
    }

    public function abilities_by_importance($atLeast = 0)
    {
        return $this->abilities_by_scale('IM', $atLeast);
    }

    public function abilities_by_level($atLeast = 0)
    {
        return $this->abilities_by_scale('LV', $atLeast);
    }

    protected function abilities_by_scale($scale, $atLeast = null)
    {
        $query = $this
            ->belongsToMany(\Eduity\EloquentOnet\Models\OnetAbility::class, 'onet_abilities', 'onetsoc_code', 'element_id');

        if($atLeast !== null) {
            // "Important" only, to avoid duplicate records
            $query->where('scale_id', 'IM');
        }
            
            // O*NET itself seems to only show >3 on their sites
        $query->where('data_value' , '>=', $atLeast)
            
            // If they recommend it be suppressed, let it.
            ->where('recommend_suppress', 'N')

            // Include extra data from `onet_abilities`
            ->withPivot([
                'data_value',
                'n',
                'standard_error',
                'lower_ci_bound',
{'fraction_non_alphanumeric': 0.11994609164420485, 'fraction_numerical': 0.0020215633423180594, 'mean_word_length': 2.2412663755458517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '4414360', 'n_tokens_mistral': 914, 'n_tokens_neox': 885, 'n_words': 186}