def from_csvdb(self, file_name, row) -> Dict: """ Get the csvdb report { 'timestamp': ... 'sensor': ... 'target': ... 'power': ... 'metadata': { ... } } """ final_dict: Dict = {} try: final_dict = {key: row[key] for key in CSV_HEADER_POWER} final_dict['timestamp'] = timestamp_to_datetime( int(row['timestamp'])) final_dict['power'] = float(row['power']) final_dict['metadata'] = {} for key in row.keys(): if key not in CSV_HEADER_POWER: final_dict['metadata'][key] = row[key] except KeyError: raise BadInputData() return final_dict
def power_report(): return PowerReport(timestamp_to_datetime(1), SENSOR_NAME, TARGET_NAME, 0.11, { 'socket': 1, 'metadata1': 'azerty', 'metadata2': 'qwerty' })
def gen_power_report(): global CPT CPT += 1 return PowerReport(timestamp_to_datetime(CPT), SENSOR, TARGET, -1, 0.11, { "metadata1": "truc", "metadata2": "oui" })
def test_csvdb_second_primary_missing(self, hwpc_csvdb): """ Create one full HWPCReport (the first), then return None """ hwpc_csvdb.add_files(SECOND_PRIMARY_MISSING) hwpc_csvdb.connect() group_name = [path.split('/')[-1][:-4] for path in SECOND_PRIMARY_MISSING] csvdb_iter = hwpc_csvdb.iter(False) report = next(csvdb_iter) for group in group_name: assert group in report.groups assert report.timestamp == timestamp_to_datetime(1539260664189) with pytest.raises(StopIteration) as pytest_wrapped: next(csvdb_iter)
def test_csvdb_first_primary_missing(self, csvdb): """ Create one full HWPCReport (the second), then return None """ csvdb.add_files(FIRST_PRIMARY_MISSING) csvdb.connect() group_name = [path.split('/')[-1][:-4] for path in FIRST_PRIMARY_MISSING] csvdb_iter = csvdb.iter(HWPCModel(), False) report = next(csvdb_iter) for group in group_name: assert group in report.groups assert report.timestamp == timestamp_to_datetime(1539260665189) with pytest.raises(StopIteration) as pytest_wrapped: next(csvdb_iter) assert pytest_wrapped.type == StopIteration
def from_csvdb(self, file_name, row) -> Dict: """ Get HWPCReport from a few csv files. """ final_dict = {} try: group_name = file_name[:-4] if file_name[ len(file_name) - 4:] == '.csv' else file_name final_dict = {key: row[key] for key in CSV_HEADER_COMMON} final_dict['timestamp'] = timestamp_to_datetime( int(row['timestamp'])) final_dict['groups'] = {} # If group doesn't exist, create it if group_name not in final_dict: final_dict['groups'][group_name] = {} # If socket doesn't exist, create it if row['socket'] not in final_dict['groups'][group_name]: final_dict['groups'][group_name][row['socket']] = {} # If cpu doesn't exist, create it if row['cpu'] not in final_dict['groups'][group_name][ row['socket']]: final_dict['groups'][group_name][row['socket']][ row['cpu']] = {} # Add events for key, value in row.items(): if key not in CSV_HEADER_HWPC: final_dict['groups'][group_name][row['socket']][ row['cpu']][key] = int(value) except KeyError: raise BadInputData() return final_dict
def gen_power_report(): global CPT CPT += 1 return PowerReport(timestamp_to_datetime(CPT), SENSOR, TARGET, 0.11, {'mdt_socket': '-1', 'metadata1': 'truc', 'metadata2': 'oui'})
def power_report(): return PowerReport(timestamp_to_datetime(1), SENSOR_NAME, TARGET_NAME, 1, 0.11, {"metadata1": "azerty", "metadata2": "qwerty"})