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
8 changes: 4 additions & 4 deletions src/api/endpoints/annotate/_shared/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from src.api.endpoints.annotate._shared.queries.get_annotation_batch_info import GetAnnotationBatchInfoQueryBuilder
from src.api.endpoints.annotate.all.get.models.agency import AgencyAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.location import LocationAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.name import NameAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.name import NameAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse, \
GetNextURLForAllAnnotationInnerResponse
from src.api.endpoints.annotate.all.get.models.url_type import URLTypeAnnotationSuggestion
Expand Down Expand Up @@ -32,15 +32,15 @@ async def extract_and_format_get_annotation_result(
convert_user_url_type_suggestion_to_url_type_annotation_suggestion(
url.user_relevant_suggestions
)
record_type_suggestions: list[RecordTypeAnnotationSuggestion] = \
record_type_suggestions: RecordTypeAnnotationResponseOuterInfo = \
convert_user_record_type_suggestion_to_record_type_annotation_suggestion(
url.user_record_type_suggestions
)
agency_suggestions: AgencyAnnotationResponseOuterInfo = \
await GetAgencySuggestionsQueryBuilder(url_id=url.id).run(session)
location_suggestions: LocationAnnotationResponseOuterInfo = \
await GetLocationSuggestionsQueryBuilder(url_id=url.id).run(session)
name_suggestions: list[NameAnnotationSuggestion] = \
name_suggestions: NameAnnotationResponseOuterInfo = \
await GetNameSuggestionsQueryBuilder(url_id=url.id).run(session)
return GetNextURLForAllAnnotationResponse(
next_annotation=GetNextURLForAllAnnotationInnerResponse(
Expand Down
11 changes: 7 additions & 4 deletions src/api/endpoints/annotate/all/get/models/name.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pydantic import BaseModel


class NameAnnotationSuggestion(BaseModel):
name: str
suggestion_id: int
endorsement_count: int
id: int
display_name: str
user_count: int
robo_count: int

class NameAnnotationResponseOuterInfo(BaseModel):

Check warning on line 9 in src/api/endpoints/annotate/all/get/models/name.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/models/name.py#L9 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/all/get/models/name.py:9:1: D101 Missing docstring in public class
suggestions: list[NameAnnotationSuggestion]

Check warning on line 10 in src/api/endpoints/annotate/all/get/models/name.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/models/name.py#L10 <292>

no newline at end of file
Raw output
./src/api/endpoints/annotate/all/get/models/name.py:10:48: W292 no newline at end of file
16 changes: 11 additions & 5 deletions src/api/endpoints/annotate/all/get/models/record_type.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from pydantic import BaseModel
from pydantic import BaseModel, Field

Check warning on line 1 in src/api/endpoints/annotate/all/get/models/record_type.py

View workflow job for this annotation

GitHub Actions / flake8

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

Missing docstring in public module
Raw output
./src/api/endpoints/annotate/all/get/models/record_type.py:1:1: D100 Missing docstring in public module

from src.api.endpoints.annotate.all.get.models.suggestion import SuggestionModel

Check warning on line 3 in src/api/endpoints/annotate/all/get/models/record_type.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/models/record_type.py#L3 <401>

'src.api.endpoints.annotate.all.get.models.suggestion.SuggestionModel' imported but unused
Raw output
./src/api/endpoints/annotate/all/get/models/record_type.py:3:1: F401 'src.api.endpoints.annotate.all.get.models.suggestion.SuggestionModel' imported but unused
from src.core.enums import RecordType



class RecordTypeAnnotationSuggestion(BaseModel):
class RecordTypeSuggestionModel(BaseModel):

Check warning on line 6 in src/api/endpoints/annotate/all/get/models/record_type.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/models/record_type.py#L6 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/all/get/models/record_type.py:6:1: D101 Missing docstring in public class
record_type: RecordType
endorsement_count: int
user_count: int
robo_confidence: int | None = Field(
description="The robo labeler's given confidence for its suggestion. Null if no robo-label occurred.",
ge=0,
le=100,
)

class RecordTypeAnnotationResponseOuterInfo(BaseModel):

Check warning on line 15 in src/api/endpoints/annotate/all/get/models/record_type.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/models/record_type.py#L15 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/all/get/models/record_type.py:15:1: D101 Missing docstring in public class
suggestions: list[RecordTypeSuggestionModel]

13 changes: 4 additions & 9 deletions src/api/endpoints/annotate/all/get/models/response.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from typing import Optional

from pydantic import Field, BaseModel

from src.api.endpoints.annotate.agency.get.dto import GetNextURLForAgencyAgencyInfo
from src.api.endpoints.annotate.all.get.models.agency import AgencyAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.location import LocationAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.name import NameAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.name import NameAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.url_type import URLTypeAnnotationSuggestion
from src.api.endpoints.annotate.dtos.shared.base.response import AnnotationInnerResponseInfoBase
from src.api.endpoints.annotate.relevance.get.dto import RelevanceAnnotationResponseInfo
from src.core.enums import RecordType


class GetNextURLForAllAnnotationInnerResponse(AnnotationInnerResponseInfoBase):
Expand All @@ -23,10 +18,10 @@ class GetNextURLForAllAnnotationInnerResponse(AnnotationInnerResponseInfoBase):
url_type_suggestions: list[URLTypeAnnotationSuggestion] = Field(
title="Whether the auto-labeler identified the URL as relevant or not"
)
record_type_suggestions: list[RecordTypeAnnotationSuggestion] = Field(
record_type_suggestions: RecordTypeAnnotationResponseOuterInfo = Field(
title="What record type, if any, user and the auto-labeler identified the URL as"
)
name_suggestions: list[NameAnnotationSuggestion] | None = Field(
name_suggestions: NameAnnotationResponseOuterInfo = Field(
title="User and Auto-Suggestions for names"
)

Expand Down
19 changes: 11 additions & 8 deletions src/api/endpoints/annotate/all/get/queries/convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import Counter

from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.record_type import RecordTypeAnnotationResponseOuterInfo, \
RecordTypeSuggestionModel
from src.api.endpoints.annotate.all.get.models.url_type import URLTypeAnnotationSuggestion
from src.core.enums import RecordType
from src.db.models.impl.flag.url_validated.enums import URLType
Expand All @@ -26,18 +27,20 @@ def convert_user_url_type_suggestion_to_url_type_annotation_suggestion(

def convert_user_record_type_suggestion_to_record_type_annotation_suggestion(
db_suggestions: list[UserRecordTypeSuggestion]
) -> list[RecordTypeAnnotationSuggestion]:
) -> RecordTypeAnnotationResponseOuterInfo:
counter: Counter[RecordType] = Counter()
for suggestion in db_suggestions:
counter[suggestion.record_type] += 1

anno_suggestions: list[RecordTypeAnnotationSuggestion] = []
suggestions: list[RecordTypeSuggestionModel] = []
for record_type, endorsement_count in counter.most_common(3):
anno_suggestions.append(
RecordTypeAnnotationSuggestion(
suggestions.append(
RecordTypeSuggestionModel(
record_type=record_type,
endorsement_count=endorsement_count,
user_count=endorsement_count,
robo_confidence=0,
)
)

return anno_suggestions
return RecordTypeAnnotationResponseOuterInfo(
suggestions=suggestions
)
22 changes: 15 additions & 7 deletions src/api/endpoints/annotate/all/get/queries/name/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Sequence

from sqlalchemy import select, func, RowMapping
from sqlalchemy import select, func, RowMapping, case
from sqlalchemy.ext.asyncio import AsyncSession

from src.api.endpoints.annotate.all.get.models.name import NameAnnotationSuggestion
from src.api.endpoints.annotate.all.get.models.name import NameAnnotationSuggestion, NameAnnotationResponseOuterInfo
from src.db.helpers.session import session_helper as sh
from src.db.models.impl.link.user_name_suggestion.sqlalchemy import LinkUserNameSuggestion
from src.db.models.impl.url.suggestion.name.enums import NameSuggestionSource
from src.db.models.impl.url.suggestion.name.sqlalchemy import URLNameSuggestion
from src.db.queries.base.builder import QueryBuilderBase

Expand All @@ -19,14 +20,18 @@
super().__init__()
self.url_id = url_id

async def run(self, session: AsyncSession) -> list[NameAnnotationSuggestion]:
async def run(self, session: AsyncSession) -> NameAnnotationResponseOuterInfo:

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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/queries/name/core.py#L23 <102>

Missing docstring in public method
Raw output
./src/api/endpoints/annotate/all/get/queries/name/core.py:23:1: D102 Missing docstring in public method
query = (
select(
URLNameSuggestion.id.label('suggestion_id'),
URLNameSuggestion.suggestion.label('name'),
URLNameSuggestion.id.label('id'),
URLNameSuggestion.suggestion.label('display_name'),
func.count(
LinkUserNameSuggestion.user_id
).label('endorsement_count'),
).label('user_count'),
case(
(URLNameSuggestion.source == NameSuggestionSource.HTML_METADATA_TITLE, 1),
else_=0
).label("robo_count")
)
.outerjoin(
LinkUserNameSuggestion,
Expand All @@ -47,12 +52,15 @@
)

mappings: Sequence[RowMapping] = await sh.mappings(session, query=query)
return [
suggestions = [
NameAnnotationSuggestion(
**mapping
)
for mapping in mappings
]
return NameAnnotationResponseOuterInfo(
suggestions=suggestions
)



Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ async def test_annotate_all(
# Get a valid URL to annotate
get_response_1 = await ath.request_validator.get_next_url_for_all_annotations()
assert get_response_1.next_annotation is not None
assert len(get_response_1.next_annotation.name_suggestions) == 1
name_suggestion = get_response_1.next_annotation.name_suggestions[0]
assert name_suggestion.name is not None
assert name_suggestion.endorsement_count == 0
assert len(get_response_1.next_annotation.name_suggestions.suggestions) == 1
name_suggestion = get_response_1.next_annotation.name_suggestions.suggestions[0]
assert name_suggestion.display_name is not None
assert name_suggestion.user_count == 0

# Apply the second batch id as a filter and see that a different URL is returned
get_response_2 = await ath.request_validator.get_next_url_for_all_annotations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ async def test_annotate_anonymous(
session_id: UUID = get_response_1.session_id
assert session_id is not None
assert get_response_1.next_annotation is not None
assert len(get_response_1.next_annotation.name_suggestions) == 1
name_suggestion: NameAnnotationSuggestion = get_response_1.next_annotation.name_suggestions[0]
assert name_suggestion.name is not None
assert name_suggestion.endorsement_count == 0
assert len(get_response_1.next_annotation.name_suggestions.suggestions) == 1
name_suggestion: NameAnnotationSuggestion = get_response_1.next_annotation.name_suggestions.suggestions[0]
assert name_suggestion.display_name is not None
assert name_suggestion.user_count == 0

agency_id: int = await ddc.agency()

Expand Down