• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15"""Generate the lineage event which conform to proto format."""
16import time
17
18from ..lineage_pb2 import LineageEvent
19
20
21def serialize_to_lineage_event(name, value):
22    """Serialize value to lineage event."""
23    event = LineageEvent()
24    event.wall_time = time.time()
25    content = _get_lineage_content(name, event)
26    content.ParseFromString(value)
27    return event.SerializeToString()
28
29
30def _get_lineage_content(name, event):
31    if name == 'dataset_graph':
32        return event.dataset_graph
33    if name == 'eval_lineage':
34        return event.evaluation_lineage
35    if name == 'train_lineage':
36        return event.train_lineage
37    if name == 'custom_lineage_data':
38        return event.user_defined_info
39    raise KeyError(f'No such field in LineageEvent')
40