removed unused object

This commit is contained in:
Brian Bjarke Jensen
2024-03-17 18:19:29 +01:00
parent a7f2f67d05
commit 6fec85adfe
2 changed files with 7 additions and 90 deletions
+4 -87
View File
@@ -11,101 +11,18 @@ from pydantic import BaseModel
from pydantic import field_serializer from pydantic import field_serializer
from pydantic import field_validator from pydantic import field_validator
from src.model_experiential import ( from core.dto import ModelData
VisualSyntaxModelOutput,
)
from src.model_interpersonal import AngleModelOutput
from src.model_interpersonal import ContactModelOutput
from src.model_interpersonal import DistanceModelOutput
from src.model_interpersonal import ModalityColorModelOutput
from src.model_interpersonal import ModalityDepthModelOutput
from src.model_interpersonal import ModalityLightingModelOutput
from src.model_interpersonal import PointOfViewModelOutput
from src.model_textual import FramingModelOutput
from src.model_textual import InformationValueModelOutput
from src.model_textual import SalienceModelOutput
class NoDocumentFoundException(Exception): class NoDocumentFoundException(Exception):
pass pass
class ModelOutputs(BaseModel):
visual_syntax: VisualSyntaxModelOutput
contact: ContactModelOutput
angle: AngleModelOutput
point_of_view: PointOfViewModelOutput
distance: DistanceModelOutput
modality_lighting: ModalityLightingModelOutput
modality_color: ModalityColorModelOutput
modality_depth: ModalityDepthModelOutput
information_value: InformationValueModelOutput
framing: FramingModelOutput
salience: SalienceModelOutput
@classmethod
def list_fields(cls) -> list[str]:
"""List options that are stored as attributes."""
return list(cls.model_fields.keys())
@classmethod
def from_random(cls) -> ModelOutputs:
"""Instantiate with random numbers."""
kwargs = {
field: field_info.annotation.from_random() # type: ignore
for field, field_info
in cls.model_fields.items()
}
return cls(**kwargs)
@classmethod
def from_annotations(
cls,
visual_syntax: str,
contact: str,
angle: str,
point_of_view: str,
distance: str,
modality_lighting: str,
modality_color: str,
modality_depth: str,
information_value: str,
framing: str,
salience: str,
) -> ModelOutputs:
"""Instantiate from annotation."""
kwargs = {
'visual_syntax': VisualSyntaxModelOutput
.from_choice(visual_syntax),
'contact': ContactModelOutput
.from_choice(contact),
'angle': AngleModelOutput
.from_choice(angle),
'point_of_view': PointOfViewModelOutput
.from_choice(point_of_view),
'distance': DistanceModelOutput
.from_choice(distance),
'modality_lighting': ModalityLightingModelOutput
.from_choice(modality_lighting),
'modality_color': ModalityColorModelOutput
.from_choice(modality_color),
'modality_depth': ModalityDepthModelOutput
.from_choice(modality_depth),
'information_value': InformationValueModelOutput
.from_choice(information_value),
'framing': FramingModelOutput
.from_choice(framing),
'salience': SalienceModelOutput
.from_choice(salience),
}
return cls(**kwargs)
class VisualCommunication(BaseModel): class VisualCommunication(BaseModel):
name: str name: str
image: Image.Image image: Image.Image
annotation: ModelOutputs | None = None annotation: ModelData | None = None
prediction: ModelOutputs | None = None prediction: ModelData | None = None
class Config: class Config:
arbitrary_types_allowed = True arbitrary_types_allowed = True
@@ -162,4 +79,4 @@ class VisualCommunication(BaseModel):
"""Generate random prediction values.""" """Generate random prediction values."""
if not force and self.prediction is not None: if not force and self.prediction is not None:
logging.warning('set force=True to overwrite existing values.') logging.warning('set force=True to overwrite existing values.')
self.prediction = ModelOutputs.from_random() self.prediction = ModelData.from_random()
+3 -3
View File
@@ -4,9 +4,9 @@ import logging
from pymongo.collection import Collection from pymongo.collection import Collection
from .classes import ModelOutputs
from .classes import NoDocumentFoundException from .classes import NoDocumentFoundException
from .classes import VisualCommunication from .classes import VisualCommunication
from core.dto import ModelData
def count_documents( def count_documents(
@@ -97,7 +97,7 @@ def get_visual_communication(
def upsert_predictions( def upsert_predictions(
collection: Collection, collection: Collection,
vis_com_name: str, vis_com_name: str,
predictions: ModelOutputs, predictions: ModelData,
) -> None: ) -> None:
"""Upsert prediction data in the database.""" """Upsert prediction data in the database."""
query = { query = {
@@ -120,7 +120,7 @@ def upsert_predictions(
def upsert_annotations( def upsert_annotations(
collection: Collection, collection: Collection,
vis_com_name: str, vis_com_name: str,
annotations: ModelOutputs, annotations: ModelData,
) -> None: ) -> None:
"""Upserts annotation data in the database.""" """Upserts annotation data in the database."""
query = { query = {