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

Large diffs are not rendered by default.

This file was deleted.

11 changes: 3 additions & 8 deletions src/api/endpoints/annotate/agency/get/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
county: str | None = None
locality: str | None = None

class GetNextURLForAgencyAnnotationInnerResponse(AnnotationInnerResponseInfoBase):
agency_suggestions: list[
GetNextURLForAgencyAgencyInfo
]

class GetNextURLForAgencyAnnotationResponse(BaseModel):
next_annotation: GetNextURLForAgencyAnnotationInnerResponse | None

class AgencySuggestionAndUserCount(BaseModel):

Check warning on line 16 in src/api/endpoints/annotate/agency/get/dto.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/agency/get/dto.py#L16 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/agency/get/dto.py:16:1: D101 Missing docstring in public class
suggestion: GetNextURLForAgencyAgencyInfo
user_count: int

Check warning on line 18 in src/api/endpoints/annotate/agency/get/dto.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/agency/get/dto.py#L18 <292>

no newline at end of file
Raw output
./src/api/endpoints/annotate/agency/get/dto.py:18:20: W292 no newline at end of file
118 changes: 0 additions & 118 deletions src/api/endpoints/annotate/agency/get/queries/next_for_annotation.py

This file was deleted.

31 changes: 19 additions & 12 deletions src/api/endpoints/annotate/all/get/queries/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Select, and_, or_
from sqlalchemy import Select, exists, select

Check warning on line 1 in src/api/endpoints/annotate/all/get/queries/core.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/queries/core.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/annotate/all/get/queries/core.py:1:1: D100 Missing docstring in public module
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import joinedload

Expand All @@ -9,8 +9,6 @@
from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse, \
GetNextURLForAllAnnotationInnerResponse
from src.api.endpoints.annotate.all.get.queries.location_.core import GetLocationSuggestionsQueryBuilder
from src.api.endpoints.annotate.all.get.queries.previously_annotated.core import \
URLPreviouslyAnnotatedByUserCTEContainer
from src.api.endpoints.annotate.relevance.get.dto import RelevanceAnnotationResponseInfo
from src.collectors.enums import URLStatus
from src.db.dto_converter import DTOConverter
Expand All @@ -20,7 +18,9 @@
from src.db.models.impl.url.suggestion.agency.user import UserUrlAgencySuggestion
from src.db.models.impl.url.suggestion.record_type.auto import AutoRecordTypeSuggestion
from src.db.models.impl.url.suggestion.relevant.auto.sqlalchemy import AutoRelevantSuggestion
from src.db.models.impl.url.suggestion.relevant.user import UserURLTypeSuggestion
from src.db.models.views.unvalidated_url import UnvalidatedURL
from src.db.models.views.url_anno_count import URLAnnotationCount
from src.db.models.views.url_annotations_flags import URLAnnotationFlagsView
from src.db.queries.base.builder import QueryBuilderBase

Expand All @@ -40,31 +40,36 @@
self,
session: AsyncSession
) -> GetNextURLForAllAnnotationResponse:
prev_annotated_cte = URLPreviouslyAnnotatedByUserCTEContainer(user_id=self.user_id)
query = (
Select(URL)
# URL Must be unvalidated
.join(
UnvalidatedURL,
UnvalidatedURL.url_id == URL.id
)
# Must not have been previously annotated by user
# TODO (SM422): Remove where conditional on whether it already has user suggestions
.join(
prev_annotated_cte.cte,
prev_annotated_cte.url_id == URL.id
)
.join(
URLAnnotationFlagsView,
URLAnnotationFlagsView.url_id == URL.id
)
.join(
URLAnnotationCount,
URLAnnotationCount.url_id == URL.id
)
)
if self.batch_id is not None:
query = query.join(LinkBatchURL).where(LinkBatchURL.batch_id == self.batch_id)
query = (
query
.where(
URL.status == URLStatus.OK.value,
# Must not have been previously annotated by user
~exists(
select(UserURLTypeSuggestion.id)
.where(
UserURLTypeSuggestion.url_id == URL.id,
UserURLTypeSuggestion.user_id == self.user_id,
)
)
)
)
# Add load options
Expand All @@ -74,8 +79,10 @@
joinedload(URL.auto_record_type_suggestion),
)

# TODO (SM422): Add order by highest number of suggestions (auto or user), desc
query = query.order_by(URL.id.asc()).limit(1)
query = query.order_by(
URLAnnotationCount.total_anno_count.desc(),
URL.id.asc()
).limit(1)
raw_results = (await session.execute(query)).unique()
url: URL | None = raw_results.scalars().one_or_none()
if url is None:
Expand Down

This file was deleted.

This file was deleted.

Loading