<commit_before>package Artemis::MCP::Scheduler::Schema::TestrunDB::Result::TestrunScheduling;

use MooseX::Method::Signatures;

        use aliased 'Artemis::MCP::Scheduler::Host';
        use aliased 'Artemis::MCP::Scheduler::Queue';

        method match_host (ArrayRef $free_hosts)
        {
                foreach my $host ($self->requested_hosts->all)
                {
                        for (my $i = 0; $i <=  $#$free_hosts; $i++) {
                                if ($free_hosts->[$i]->{name} eq $host->hostname) {
                                        my $chosen_host = $free_hosts->[$i];
                                        my @free_hosts = @$free_hosts[0..$i-1, $i+1..$#$free_hosts];
                                        $free_hosts = \@free_hosts;
                                        return $chosen_host;
                                }
                        }
                }
                return;
        }

        # mem(4096);
        # mem > 4000;
        # TODO:
        sub _helper {
                my ($available, $subkey, $given) = @_;

                if ($given)
                {
                        # available
                        return
                            grep
                            {
                                    $given ~~ ($subkey ? $_->{$subkey} : $_)
                            } @{ $available };
                }
                else
                {
                        $subkey ? $available->[0]->{$subkey} : $available->[0];
                }
        }

        # vendor("AMD");        # with optional argument the value is checked against available features and returns the matching features
        # vendor eq "AMD";      # without argument returns the value
        # @_ means this optional param
        # $_ is some lines later the current context inside the for-loop where the eval happens
        sub mem(;$)      { _helper($_->features->{mem},      undef,      @_) }
        sub vendor(;$)   { _helper($_->features->{cpu},      'vendors',  @_) }
        sub family(;$)   { _helper($_->features->{cpu},      'family',   @_) }
        sub model(;$)    { _helper($_->features->{cpu},      'model',    @_) }
        sub stepping(;$) { _helper($_->features->{cpu},      'stepping', @_) }
        sub revision(;$) { _helper($_->features->{cpu},      'revision', @_) }
        sub socket(;$)   { _helper($_->features->{cpu},      'socket',   @_) }
        sub cores(;$)    { _helper($_->features->{cpu},      'cores',    @_) }
        sub clock(;$)    { _helper($_->features->{cpu},      'clock',    @_) }
        sub l2cache(;$)  { _helper($_->features->{cpu},      'l2cache',  @_) }
        sub l3cache(;$)  { _helper($_->features->{cpu},      'l3cache',  @_) }

        method match_feature($free_hosts)
        {
        HOST:
                foreach my $host (@$free_hosts)
                {
                        $_ = $host;
                        foreach my $this_feature (@{$self->requested_features->all})
                        {
                                my $success = eval $this_feature->feature;
                                print STDERR "TestRequest.fits: ", $@ if $@;
                                next HOST if not $success;
                        }
                        return $host;
                }
                return;
        }

        method fits (ArrayRef $free_hosts)
        {
                if (not $free_hosts)
                {
                        return;
                }
                elsif ($self->hostnames)
                {
                        my $host = $self->match_host($free_hosts);
                        if ($host)
                        {
                                return $host;
                        }
                        elsif ($self->requested_features)
                        {
                                $host = $self->match_feature($free_hosts);
                                return $host if $host;
                        }
                        return;
                }
                elsif ($self->requested_features) # but no wanted hostnames
                {
                        my $host = $self->match_feature($free_hosts);
                        return $host if $host;
                        return;
                }
                else # free_hosts but no wanted hostnames and no requested_features
                {
                        return shift @$free_hosts;
                }
        }

<commit_msg>Scheduler: move extended schema functions back into original schema<commit_after>package Artemis::MCP::Scheduler::Schema::TestrunDB::Result::TestrunScheduling;



{'fraction_non_alphanumeric': 0.1230572705982542, 'fraction_numerical': 0.0038322333404300617, 'mean_word_length': 1.0461672473867596, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2277824', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1134, 'n_words': 240}