Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/endpoints/annotate/relevance/get/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RelevanceAnnotationResponseInfo(BaseModel):
)

class GetNextRelevanceAnnotationResponseInfo(AnnotationInnerResponseInfoBase):
annotation: RelevanceAnnotationInfo | None = Field(
annotation: RelevanceAnnotationResponseInfo | None = Field(
title="The auto-labeler's annotation for relevance"
)

Expand Down
11 changes: 6 additions & 5 deletions src/api/endpoints/annotate/relevance/get/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from src.api.endpoints.annotate._shared.queries.get_annotation_batch_info import GetAnnotationBatchInfoQueryBuilder
from src.api.endpoints.annotate._shared.queries.get_next_url_for_user_annotation import \
GetNextURLForUserAnnotationQueryBuilder
from src.api.endpoints.annotate.relevance.get.dto import GetNextRelevanceAnnotationResponseInfo
from src.api.endpoints.annotate.relevance.get.dto import GetNextRelevanceAnnotationResponseInfo, \
RelevanceAnnotationResponseInfo
from src.core.tasks.url.operators.auto_relevant.models.annotation import RelevanceAnnotationInfo
from src.db.dto_converter import DTOConverter
from src.db.dtos.url.mapping import URLMapping
Expand Down Expand Up @@ -40,7 +41,7 @@ async def run(
)

if url.auto_relevant_suggestion is not None:
suggestion = url.auto_relevant_suggestion.relevant
suggestion = url.auto_relevant_suggestion
else:
suggestion = None

Expand All @@ -49,11 +50,11 @@ async def run(
url=url.url,
url_id=url.id
),
annotation=RelevanceAnnotationInfo(
is_relevant=suggestion.is_relevant,
annotation=RelevanceAnnotationResponseInfo(
is_relevant=suggestion.relevant,
confidence=suggestion.confidence,
model_name=suggestion.model_name
),
) if suggestion else None,
html_info=html_response_info,
batch_info=await GetAnnotationBatchInfoQueryBuilder(
batch_id=self.batch_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Sequence
from typing import Sequence

Check warning on line 1 in src/core/tasks/url/operators/auto_relevant/queries/get_tdos.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/url/operators/auto_relevant/queries/get_tdos.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/url/operators/auto_relevant/queries/get_tdos.py:1:1: D100 Missing docstring in public module

from sqlalchemy import select, Row
from sqlalchemy.ext.asyncio import AsyncSession
Expand Down Expand Up @@ -27,13 +27,9 @@
.options(
selectinload(URL.compressed_html)
)
.outerjoin(
URLCompressedHTML,
URL.id == URLCompressedHTML.url_id
)
.join(URLCompressedHTML)
.where(
URL.outcome == URLStatus.PENDING.value,
URLCompressedHTML.compressed_html.is_not(None)
)
)
query = StatementComposer.exclude_urls_with_extant_model(
Expand Down
50 changes: 7 additions & 43 deletions src/db/client/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from src.api.endpoints.annotate.all.get.query import GetNextURLForAllAnnotationQueryBuilder
from src.api.endpoints.annotate.all.post.dto import AllAnnotationPostInfo
from src.api.endpoints.annotate.dtos.record_type.response import GetNextRecordTypeAnnotationResponseInfo
from src.api.endpoints.annotate.relevance.get.dto import GetNextRelevanceAnnotationResponseInfo
from src.api.endpoints.annotate.relevance.get.dto import GetNextRelevanceAnnotationResponseInfo, \

Check warning on line 25 in src/db/client/async_.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/client/async_.py#L25 <401>

'src.api.endpoints.annotate.relevance.get.dto.RelevanceAnnotationResponseInfo' imported but unused
Raw output
./src/db/client/async_.py:25:1: F401 'src.api.endpoints.annotate.relevance.get.dto.RelevanceAnnotationResponseInfo' imported but unused
RelevanceAnnotationResponseInfo
from src.api.endpoints.annotate.relevance.get.query import GetNextUrlForRelevanceAnnotationQueryBuilder
from src.api.endpoints.batch.dtos.get.summaries.response import GetBatchSummariesResponse
from src.api.endpoints.batch.dtos.get.summaries.summary import BatchSummary
from src.api.endpoints.collector.dtos.manual_batch.post import ManualBatchInputDTO
Expand Down Expand Up @@ -311,50 +313,12 @@
)
session.add(suggestion)

@session_manager
async def get_next_url_for_relevance_annotation(
self,
session: AsyncSession,
user_id: int,
batch_id: Optional[int]
batch_id: int | None,
user_id: int | None = None,

Check warning on line 319 in src/db/client/async_.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/client/async_.py#L319 <100>

Unused argument 'user_id'
Raw output
./src/db/client/async_.py:319:9: U100 Unused argument 'user_id'
) -> GetNextRelevanceAnnotationResponseInfo | None:

url = await GetNextURLForUserAnnotationQueryBuilder(
user_suggestion_model_to_exclude=UserRelevantSuggestion,
auto_suggestion_relationship=URL.auto_relevant_suggestion,
batch_id=batch_id
).run(session)
if url is None:
return None

# Next, get all HTML content for the URL
html_response_info = DTOConverter.html_content_list_to_html_response_info(
url.html_content
)

if url.auto_relevant_suggestion is not None:
suggestion = url.auto_relevant_suggestion
else:
suggestion = None

return GetNextRelevanceAnnotationResponseInfo(
url_info=URLMapping(
url=url.url,
url_id=url.id
),
annotation=RelevanceAnnotationInfo(
is_relevant=suggestion.relevant,
confidence=suggestion.confidence,
model_name=suggestion.model_name
) if suggestion is not None else None,
html_info=html_response_info,
batch_info=await GetAnnotationBatchInfoQueryBuilder(
batch_id=batch_id,
models=[
UserUrlAgencySuggestion,
]
).run(session)
)
return await self.run_query_builder(GetNextUrlForRelevanceAnnotationQueryBuilder(batch_id))

# endregion relevant

Expand Down Expand Up @@ -609,7 +573,7 @@
model: Type[Base]
) -> bool:
statement = (select(URL)
.join(URLHTMLContent)
.join(URLCompressedHTML)
.where(URL.outcome == URLStatus.PENDING.value))
# Exclude URLs with auto suggested record types
statement = self.statement_composer.exclude_urls_with_extant_model(
Expand Down
4 changes: 4 additions & 0 deletions tests/automated/integration/tasks/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
meets_prereqs = await operator.meets_task_prerequisites()
assert not meets_prereqs

async def assert_prereqs_met(operator):

Check warning on line 8 in tests/automated/integration/tasks/asserts.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/tasks/asserts.py#L8 <103>

Missing docstring in public function
Raw output
./tests/automated/integration/tasks/asserts.py:8:1: D103 Missing docstring in public function
meets_prereqs = await operator.meets_task_prerequisites()
assert meets_prereqs


def assert_task_has_expected_run_info(run_info, url_ids: list[int]):
assert run_info.outcome == TaskOperatorOutcome.SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from src.db.models.instantiations.url.core import URL
from src.db.models.instantiations.url.error_info import URLErrorInfo
from src.db.models.instantiations.url.suggestion.relevant.auto import AutoRelevantSuggestion
from tests.automated.integration.tasks.asserts import assert_prereqs_not_met, assert_task_has_expected_run_info
from tests.automated.integration.tasks.asserts import assert_prereqs_not_met, assert_task_has_expected_run_info, \
assert_prereqs_met
from tests.automated.integration.tasks.url.auto_relevant.setup import setup_operator, setup_urls


Expand All @@ -15,6 +16,7 @@ async def test_url_auto_relevant_task(db_data_creator):
await assert_prereqs_not_met(operator)

url_ids = await setup_urls(db_data_creator)
await assert_prereqs_met(operator)

task_id = await db_data_creator.adb_client.initiate_task(task_type=TaskType.RELEVANCY)

Expand Down