From 7059338ede40ca22ad98407d597d701e485ddbb0 Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Mon, 19 Feb 2024 20:21:18 +0100 Subject: [PATCH] updated models --- src/model_experiential/classes.py | 67 +++++++++++++++++------------- src/model_interpersonal/classes.py | 31 +------------- src/model_textual/classes.py | 2 +- 3 files changed, 39 insertions(+), 61 deletions(-) diff --git a/src/model_experiential/classes.py b/src/model_experiential/classes.py index 9d9bdcd..29f550e 100644 --- a/src/model_experiential/classes.py +++ b/src/model_experiential/classes.py @@ -1,10 +1,45 @@ -from __future__ import annotations from pydantic import BaseModel from typing import List import random -class ExperientialModelOutput(BaseModel): +class ModelOutput(BaseModel): + + @classmethod + def classname(cls) -> str: + """Return classname.""" + return cls.__name__ + + @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): + """Instantiate with random numbers.""" + kwargs = {field: random.random() for field in cls.list_fields()} + return cls(**kwargs) + + def __repr__(self) -> str: + model_dict = self.model_dump() + model_repr_str = f"{self.classname()}(" + model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) + model_repr_str += ")" + return model_repr_str + + def highest_score_field(self) -> str: + """Return name of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict, key=lambda k: model_dict[k]) + + def highest_score_value(self) -> float: + """Return value of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict.values()) + + +class ExperientialModelOutput(ModelOutput): non_transactional_action: float non_transactional_reaction: float unidirectional_transactional_action: float @@ -24,34 +59,6 @@ class ExperientialModelOutput(BaseModel): symbolic_suggestive: float symbolic_attributive: float - @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) -> ExperientialModelOutput: - """Instantiate with random numbers.""" - kwargs = {field: random.random() for field in cls.list_fields()} - return ExperientialModelOutput(**kwargs) - - def __repr__(self) -> str: - model_dict = self.model_dump() - model_repr_str = "ExperientialModelOutput(" - model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) - model_repr_str += ")" - return model_repr_str - - def highest_score_field(self) -> str: - """Return name of field with highest score.""" - model_dict = self.model_dump() - return max(model_dict, key=lambda k: model_dict[k]) - - def highest_score_value(self) -> float: - """Return value of field with highest score.""" - model_dict = self.model_dump() - return max(model_dict.values()) - if __name__ == '__main__': m = ExperientialModelOutput.from_random() diff --git a/src/model_interpersonal/classes.py b/src/model_interpersonal/classes.py index 60c16ad..d57717d 100644 --- a/src/model_interpersonal/classes.py +++ b/src/model_interpersonal/classes.py @@ -1,5 +1,5 @@ from pydantic import BaseModel -from typing import List, Dict +from typing import List import random @@ -88,35 +88,6 @@ class ModalityDepthModelOutput(ModelOutput): # modality_color: ModalityColorModelOutput # modality_depth: ModalityDepthModelOutput -# @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) -> InterpersonalModelOutput: -# """Instantiate with random numbers.""" -# print(cls.model_fields) -# kwargs = {field: info.annotation.from_random() for field, info in cls.model_fields.items()} -# return InterpersonalModelOutput(**kwargs) - -# def __repr__(self) -> str: -# model_dict = self.model_dump() -# model_repr_str = "ExperientialModelOutput(" -# model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) -# model_repr_str += ")" -# return model_repr_str - -# def highest_score_field(self) -> str: -# """Return name of field with highest score.""" -# model_dict = self.model_dump() -# return max(model_dict, key=lambda k: model_dict[k]) - -# def highest_score_value(self) -> float: -# """Return value of field with highest score.""" -# model_dict = self.model_dump() -# return max(model_dict.values()) - if __name__ == '__main__': m = ContactModelOutput.from_random() diff --git a/src/model_textual/classes.py b/src/model_textual/classes.py index 8b135f5..a9bc4d1 100644 --- a/src/model_textual/classes.py +++ b/src/model_textual/classes.py @@ -1,5 +1,5 @@ from pydantic import BaseModel -from typing import List, Dict +from typing import List import random