clearml-server/apiserver/database/model/model.py

108 lines
3.6 KiB
Python
Raw Normal View History

from mongoengine import (
StringField,
DateTimeField,
BooleanField,
EmbeddedDocumentField,
2023-05-25 16:17:40 +00:00
IntField,
ListField,
)
2019-06-10 21:24:35 +00:00
2021-01-05 14:28:49 +00:00
from apiserver.database import Database, strict
from apiserver.database.fields import (
StrippedStringField,
SafeDictField,
SafeSortedListField,
SafeMapField,
)
from apiserver.database.model import AttributedDocument
2021-01-05 14:28:49 +00:00
from apiserver.database.model.base import GetMixin
from apiserver.database.model.metadata import MetadataItem
2021-01-05 14:28:49 +00:00
from apiserver.database.model.model_labels import ModelLabels
from apiserver.database.model.project import Project
2023-05-25 16:17:40 +00:00
from apiserver.database.model.task.metrics import MetricEvent
2021-01-05 14:28:49 +00:00
from apiserver.database.model.task.task import Task
2019-06-10 21:24:35 +00:00
class Model(AttributedDocument):
_field_collation_overrides = {
"metadata.": AttributedDocument._numeric_locale,
2023-05-25 16:17:40 +00:00
"last_metrics.": AttributedDocument._numeric_locale,
}
2019-06-10 21:24:35 +00:00
meta = {
2020-04-01 16:20:53 +00:00
"db_alias": Database.backend,
"strict": strict,
"indexes": [
"parent",
"project",
"task",
2021-05-03 15:02:25 +00:00
"last_update",
2020-07-06 18:50:43 +00:00
("company", "framework"),
2020-04-01 16:20:53 +00:00
("company", "name"),
("company", "user"),
2022-09-29 16:40:05 +00:00
("company", "uri"),
2019-06-10 21:24:35 +00:00
{
2020-04-01 16:20:53 +00:00
"name": "%s.model.main_text_index" % Database.backend,
"fields": ["$name", "$id", "$comment", "$parent", "$task", "$project"],
"default_language": "english",
"weights": {
"name": 10,
"id": 10,
"comment": 10,
"parent": 5,
"task": 3,
"project": 3,
},
},
2019-06-10 21:24:35 +00:00
],
}
get_all_query_options = GetMixin.QueryParameterOptions(
pattern_fields=("name", "comment"),
fields=("ready",),
list_fields=(
"tags",
"system_tags",
"framework",
"uri",
"id",
"user",
"project",
"task",
"parent",
"metadata.*",
),
2023-05-25 16:17:40 +00:00
range_fields=("last_metrics.*", "last_iteration"),
2021-05-03 15:02:25 +00:00
datetime_fields=("last_update",),
)
2019-06-10 21:24:35 +00:00
id = StringField(primary_key=True)
name = StrippedStringField(user_set_allowed=True, min_length=3)
2020-04-01 16:20:53 +00:00
parent = StringField(reference_field="Model", required=False)
2019-06-10 21:24:35 +00:00
project = StringField(reference_field=Project, user_set_allowed=True)
created = DateTimeField(required=True, user_set_allowed=True)
task = StringField(reference_field=Task)
comment = StringField(user_set_allowed=True)
tags = SafeSortedListField(StringField(required=True), user_set_allowed=True)
system_tags = SafeSortedListField(StringField(required=True), user_set_allowed=True)
2020-04-01 16:20:53 +00:00
uri = StrippedStringField(default="", user_set_allowed=True)
2019-06-10 21:24:35 +00:00
framework = StringField()
design = SafeDictField()
labels = ModelLabels()
ready = BooleanField(required=True)
2021-05-03 15:02:25 +00:00
last_update = DateTimeField()
last_change = DateTimeField()
last_changed_by = StringField()
2020-04-01 16:20:53 +00:00
ui_cache = SafeDictField(
default=dict, user_set_allowed=True, exclude_by_default=True
)
company_origin = StringField(exclude_by_default=True)
metadata = SafeMapField(
field=EmbeddedDocumentField(MetadataItem), user_set_allowed=True
)
2023-05-25 16:17:40 +00:00
last_iteration = IntField(default=0)
last_metrics = SafeMapField(field=SafeMapField(EmbeddedDocumentField(MetricEvent)))
unique_metrics = ListField(StringField(required=True), exclude_by_default=True)
2022-11-29 15:34:06 +00:00
def get_index_company(self) -> str:
return self.company or self.company_origin or ""