1- # Copyright (c) 2021, INRIA
1+ # Copyright (c) 2021, Inria
22# Copyright (c) 2021, University of Lille
33# All rights reserved.
44#
3535from typing import NewType , Any
3636from zlib import crc32
3737
38- from powerapi .exception import PowerAPIExceptionWithMessage , PowerAPIException
38+ from powerapi .exception import PowerAPIExceptionWithMessage
3939from powerapi .message import Message
4040
4141TIMESTAMP_KEY = 'timestamp'
@@ -60,59 +60,32 @@ def __init__(self, msg, input_data):
6060 self .input_data = input_data
6161
6262
63- class DeserializationFail (PowerAPIException ):
64- """
65- Exception raised when the
66- in the good format
67- """
68-
69-
7063class Report (Message ):
7164 """
72- Report abtract class.
65+ Report abstract class.
7366 """
7467
75- def __init__ (self , timestamp : datetime , sensor : str , target : str , metadata : dict [str , Any ] = {} ):
68+ def __init__ (self , timestamp : datetime , sensor : str , target : str , metadata : dict [str , Any ] | None = None ):
7669 """
77- Initialize a report using the given parameters.
78- :param datetime timestamp: Timestamp
79- :param str sensor: Sensor name.
80- :param str target: Target name.
70+ :param timestamp: Timestamp of the measurements.
71+ :param sensor: Name of the sensor from which the measurements were taken.
72+ :param target: Name of the target that the measurements refer to.
8173 """
82- Message .__init__ (self , None )
8374 self .timestamp = timestamp
8475 self .sensor = sensor
8576 self .target = target
86- self .metadata = dict (metadata )
87-
88- #: id given by the dispatcher actor in order manage report order
89- self .dispatcher_report_id = None
90-
91- def __str__ (self ):
92- return f'{ self .__class__ .__name__ } ({ self .timestamp } , { self .sensor } , { self .target } , { self .metadata } )'
77+ self .metadata = metadata if metadata is not None else {}
9378
94- def __repr__ (self ):
95- return f'{ self .__class__ .__name__ } ({ self .timestamp } , { self .sensor } , { self .target } , { self . metadata } )'
79+ def __repr__ (self ) -> str :
80+ return f'{ self .__class__ .__name__ } ({ self .timestamp } , { self .sensor } , { self .target } )'
9681
97- def __eq__ (self , other ):
82+ def __eq__ (self , other ) -> bool :
9883 return (isinstance (other , type (self )) and
9984 self .timestamp == other .timestamp and
10085 self .sensor == other .sensor and
10186 self .target == other .target and
10287 self .metadata == other .metadata )
10388
104- @staticmethod
105- def to_json (report : Report ) -> dict :
106- """
107- :return: a json dictionary, that can be converted into json format, from a given Report
108- """
109- json = report .__dict__
110- # sender_name and dispatcher_report_id are not used
111- json .pop ('sender_name' )
112- json .pop ('dispatcher_report_id' )
113-
114- return json
115-
11689 @staticmethod
11790 def _extract_timestamp (ts ):
11891 # Unix timestamp format (in milliseconds)
0 commit comments