diff --git a/scripts/data.py b/scripts/data.py new file mode 100644 index 0000000000000000000000000000000000000000..112273dadff8547268c8d3584fb5cd6bd17f7b3c --- /dev/null +++ b/scripts/data.py @@ -0,0 +1,67 @@ +## This file is part of the execution-time evaluation for the qronos observer abstractions. +## Copyright (C) 2022-2023 Tim Rheinfels <tim.rheinfels@fau.de> +## See https://gitlab.cs.fau.de/qronos-state-abstractions/execution-time +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see <https://www.gnu.org/licenses/>. + +### +### @file data.py +### +### @brief Provides functionality for handling the evaluation data +### +### @author Tim Rheinfels <tim.rheinfels@fau.de> +### + +import numpy as np +import ujson as json +import logging +import struct + +### +### @brief Reads the evaluation JSON data from @p path, performs +### some checks and returns it as dictionary. +### +### @param path Path to the JSON file +### +### @returns Dictionary containing the evaluation data +### +def load_json_data(path): + with open(path, 'r') as f: + data = f.read() + + # Now we can parse it as json + data = json.loads(data) + + # Check if git revision is dirty + if data['version']['git_revision'].endswith('-dirty'): + logging.warning('Data stored under "%s" has dirty git revision: %s' % (path, data['version']['git_revision'])) + + # Check if unit tests succeeded + if not data['unit_tests']['success']: + logging.error('Unit tests did not succeed for data stored under "%s": %s' % (path, data['unit_tests']['output'])) + + # Done. + return data + +### +### @brief Decodes a single-precision float @p data encoded as integer +### +### @param data Single-precision float encoded as 32-bit integer +### +### @returns Decoded single-precision float represented by @p data +### +def decode(data): + if isinstance(data, list): + return np.array([decode(x) for x in data], dtype=np.float32) + return struct.unpack('<f', struct.pack('<I', data))[0]