<commit_before>from datetime import timedelta
from sqlalchemy.sql import func

from zeus.config import db
from zeus.constants import Result, Status
from zeus.models import Repository, TestCase, Job
from zeus.utils import timezone

from .base_repository import BaseRepositoryResource
from ..schemas import TestCaseStatisticsSchema

testcases_schema = TestCaseStatisticsSchema(many=True)


class RepositoryTestsResource(BaseRepositoryResource):
    def get(self, repo: Repository):
        """
        Return a list of testcases for the given repository.
        """
        runs_failed = (
            func.count(TestCase.result)
            .filter(TestCase.result == Result.failed)
            .label("runs_failed")
        )

        query = (
            db.session.query(
                TestCase.hash,
                TestCase.name,
                func.count(TestCase.hash).label("runs_total"),
                runs_failed,
                func.avg(TestCase.duration).label("avg_duration"),
            )
            .filter(
                TestCase.job_id.in_(
                    db.session.query(Job.id)
                    .filter(
                        Job.repository_id == repo.id,
                        Job.date_finished >= timezone.now() - timedelta(days=14),
                        Job.status == Status.finished,
                    )
                    .limit(1000)
                    .subquery()
                )
            )
            .group_by(TestCase.hash, TestCase.name)
            .order_by(runs_failed.desc())
        )

        return self.paginate_with_schema(testcases_schema, query)
<commit_msg>fix: Jobs should be 10k, not 1k<commit_after>from datetime import timedelta
from sqlalchemy.sql import func

from zeus.config import db
from zeus.constants import Result, Status
from zeus.models import Repository, TestCase, Job
from zeus.utils import timezone

from .base_repository import BaseRepositoryResource
from ..schemas import TestCaseStatisticsSchema

testcases_schema = TestCaseStatisticsSchema(many=True)


class RepositoryTestsResource(BaseRepositoryResource):
    def get(self, repo: Repository):
        """
        Return a list of testcases for the given repository.
        """
        runs_failed = (
            func.count(TestCase.result)
            .filter(TestCase.result == Result.failed)
            .label("runs_failed")
        )

        query = (
            db.session.query(
                TestCase.hash,
                TestCase.name,
                func.count(TestCase.hash).label("runs_total"),
                runs_failed,
                func.avg(TestCase.duration).label("avg_duration"),
            )
            .filter(
                TestCase.job_id.in_(
                    db.session.query(Job.id)
                    .filter(
                        Job.repository_id == repo.id,
                        Job.date_finished >= timezone.now() - timedelta(days=14),
                        Job.status == Status.finished,
                    )
                    .limit(10000)
                    .subquery()
                )
            )
            .group_by(TestCase.hash, TestCase.name)
            .order_by(runs_failed.desc())
        )

        return self.paginate_with_schema(testcases_schema, query)

{'fraction_non_alphanumeric': 0.08690367669401398, 'fraction_numerical': 0.004861744150714068, 'mean_word_length': 1.6612772837510106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1772944', 'n_tokens_mistral': 880, 'n_tokens_neox': 822, 'n_words': 172}