Skip to content

Commit bfe9575

Browse files
authored
Merge pull request #429 from Police-Data-Accessibility-Project/mc_422_auto_validate
Complete pre-auto validate draft
2 parents 768b1d6 + 9a69a9a commit bfe9575

File tree

130 files changed

+1181
-2026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1181
-2026
lines changed

alembic/versions/2025_09_21_0940-8d7208843b76_update_for_human_agreement_logic.py

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.

src/api/endpoints/annotate/_shared/queries/get_next_url_for_user_annotation.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/api/endpoints/annotate/agency/get/dto.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ class GetNextURLForAgencyAgencyInfo(BaseModel):
1313
county: str | None = None
1414
locality: str | None = None
1515

16-
class GetNextURLForAgencyAnnotationInnerResponse(AnnotationInnerResponseInfoBase):
17-
agency_suggestions: list[
18-
GetNextURLForAgencyAgencyInfo
19-
]
20-
21-
class GetNextURLForAgencyAnnotationResponse(BaseModel):
22-
next_annotation: GetNextURLForAgencyAnnotationInnerResponse | None
23-
16+
class AgencySuggestionAndUserCount(BaseModel):
17+
suggestion: GetNextURLForAgencyAgencyInfo
18+
user_count: int

src/api/endpoints/annotate/agency/get/queries/next_for_annotation.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

src/api/endpoints/annotate/all/get/queries/core.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sqlalchemy import Select, and_, or_
1+
from sqlalchemy import Select, exists, select
22
from sqlalchemy.ext.asyncio import AsyncSession
33
from sqlalchemy.orm import joinedload
44

@@ -9,8 +9,6 @@
99
from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse, \
1010
GetNextURLForAllAnnotationInnerResponse
1111
from src.api.endpoints.annotate.all.get.queries.location_.core import GetLocationSuggestionsQueryBuilder
12-
from src.api.endpoints.annotate.all.get.queries.previously_annotated.core import \
13-
URLPreviouslyAnnotatedByUserCTEContainer
1412
from src.api.endpoints.annotate.relevance.get.dto import RelevanceAnnotationResponseInfo
1513
from src.collectors.enums import URLStatus
1614
from src.db.dto_converter import DTOConverter
@@ -20,7 +18,9 @@
2018
from src.db.models.impl.url.suggestion.agency.user import UserUrlAgencySuggestion
2119
from src.db.models.impl.url.suggestion.record_type.auto import AutoRecordTypeSuggestion
2220
from src.db.models.impl.url.suggestion.relevant.auto.sqlalchemy import AutoRelevantSuggestion
21+
from src.db.models.impl.url.suggestion.relevant.user import UserURLTypeSuggestion
2322
from src.db.models.views.unvalidated_url import UnvalidatedURL
23+
from src.db.models.views.url_anno_count import URLAnnotationCount
2424
from src.db.models.views.url_annotations_flags import URLAnnotationFlagsView
2525
from src.db.queries.base.builder import QueryBuilderBase
2626

@@ -40,31 +40,36 @@ async def run(
4040
self,
4141
session: AsyncSession
4242
) -> GetNextURLForAllAnnotationResponse:
43-
prev_annotated_cte = URLPreviouslyAnnotatedByUserCTEContainer(user_id=self.user_id)
4443
query = (
4544
Select(URL)
4645
# URL Must be unvalidated
4746
.join(
4847
UnvalidatedURL,
4948
UnvalidatedURL.url_id == URL.id
5049
)
51-
# Must not have been previously annotated by user
52-
# TODO (SM422): Remove where conditional on whether it already has user suggestions
53-
.join(
54-
prev_annotated_cte.cte,
55-
prev_annotated_cte.url_id == URL.id
56-
)
5750
.join(
5851
URLAnnotationFlagsView,
5952
URLAnnotationFlagsView.url_id == URL.id
6053
)
54+
.join(
55+
URLAnnotationCount,
56+
URLAnnotationCount.url_id == URL.id
57+
)
6158
)
6259
if self.batch_id is not None:
6360
query = query.join(LinkBatchURL).where(LinkBatchURL.batch_id == self.batch_id)
6461
query = (
6562
query
6663
.where(
6764
URL.status == URLStatus.OK.value,
65+
# Must not have been previously annotated by user
66+
~exists(
67+
select(UserURLTypeSuggestion.id)
68+
.where(
69+
UserURLTypeSuggestion.url_id == URL.id,
70+
UserURLTypeSuggestion.user_id == self.user_id,
71+
)
72+
)
6873
)
6974
)
7075
# Add load options
@@ -74,8 +79,10 @@ async def run(
7479
joinedload(URL.auto_record_type_suggestion),
7580
)
7681

77-
# TODO (SM422): Add order by highest number of suggestions (auto or user), desc
78-
query = query.order_by(URL.id.asc()).limit(1)
82+
query = query.order_by(
83+
URLAnnotationCount.total_anno_count.desc(),
84+
URL.id.asc()
85+
).limit(1)
7986
raw_results = (await session.execute(query)).unique()
8087
url: URL | None = raw_results.scalars().one_or_none()
8188
if url is None:

src/api/endpoints/annotate/all/get/queries/previously_annotated/build.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/api/endpoints/annotate/all/get/queries/previously_annotated/core.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)