-
Notifications
You must be signed in to change notification settings - Fork 61
/
generic_attribute_mapper.py
65 lines (55 loc) 路 2.24 KB
/
generic_attribute_mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Copyright (c) 2022, Neptune Labs Sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from neptune.new.internal.backends.api_model import AttributeType
class NoValue:
pass
VALUE = "value"
LAST_VALUE = "last"
VALUES = "values"
atomic_attribute_types_map = {
AttributeType.FLOAT.value: "floatProperties",
AttributeType.INT.value: "intProperties",
AttributeType.BOOL.value: "boolProperties",
AttributeType.STRING.value: "stringProperties",
AttributeType.DATETIME.value: "datetimeProperties",
AttributeType.RUN_STATE.value: "experimentStateProperties",
AttributeType.NOTEBOOK_REF.value: "notebookRefProperties",
}
value_series_attribute_types_map = {
AttributeType.FLOAT_SERIES.value: "floatSeriesProperties",
AttributeType.STRING_SERIES.value: "stringSeriesProperties",
}
value_set_attribute_types_map = {
AttributeType.STRING_SET.value: "stringSetProperties",
}
# TODO: nicer mapping?
_unmapped_attribute_types_map = {
AttributeType.FILE_SET.value: "fileSetProperties", # TODO: return size?
AttributeType.FILE.value: "fileProperties", # TODO: name? size?
AttributeType.IMAGE_SERIES.value: "imageSeriesProperties", # TODO: return last step?
AttributeType.GIT_REF.value: "gitRefProperties", # TODO: commit? branch?
}
def map_attribute_result_to_value(attribute):
for attribute_map, value_key in [
(atomic_attribute_types_map, VALUE),
(value_series_attribute_types_map, LAST_VALUE),
(value_set_attribute_types_map, VALUES),
]:
source_property = attribute_map.get(attribute.type)
if source_property is not None:
mapped_attribute_entry = getattr(attribute, source_property)
return getattr(mapped_attribute_entry, value_key)
return NoValue