Exemple #1
0
    def to_csvdb(self, serialized_report) -> Tuple[List[str], Dict]:
        """
        Return raw data from serialized report
        :return: Header, Dict(str, List(Dict))
        """
        basic_csv_row = {
            key: serialized_report[key]
            for key in CSV_HEADER_COMMON
        }
        # timestamp
        basic_csv_row['timestamp'] = datetime_to_timestamp(
            basic_csv_row['timestamp'])

        final_dict = {}

        try:
            for group_name, sockets in serialized_report['groups'].items():
                new_csv_row = basic_csv_row.copy()
                for socket_name, cpus in sockets.items():
                    new_csv_row['socket'] = socket_name
                    for cpu_name, events in cpus.items():
                        new_csv_row['cpu'] = cpu_name
                        for event_name, value in events.items():
                            new_csv_row[event_name] = value

                        # add in final dict
                        if group_name in final_dict:
                            final_dict[group_name].append(new_csv_row.copy())
                        else:
                            final_dict[group_name] = [new_csv_row.copy()]
        except KeyError:
            raise BadInputData()

        return CSV_HEADER_HWPC, final_dict
Exemple #2
0
    def to_csvdb(self, serialized_report) -> Tuple[List[str], Dict]:
        """
        Return raw data from serialized report

        {
            'PowerReport' : [{
                'timestamp': ...
                'sensor': ...
                'target': ...
                'power': ...
                'metadata': {
                    ...
                }
            }]
        }
        """
        final_dict = {}
        try:
            for field in CSV_HEADER_POWER:
                final_dict[field] = serialized_report[field]

            final_dict['timestamp'] = datetime_to_timestamp(
                serialized_report['timestamp'])

            for key, val in serialized_report['metadata'].items():
                final_dict[key] = val

        except KeyError:
            raise BadInputData()

        final_dict = {self.get_type().__name__: [final_dict]}
        return CSV_HEADER_POWER, final_dict