Last active
September 8, 2018 15:44
-
-
Save AlexanderFabisch/3516db2804687877a258e294cda82eca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import msgpack | |
def summarize_logfile(filename): | |
n_samples = {} | |
typenames = {} | |
with open(filename, "r") as f: | |
unpacker = msgpack.Unpacker(file_like=f) | |
n_keys = unpacker.read_map_header() | |
stream_names = [] | |
for i in range(n_keys): | |
key = unpacker.unpack() | |
if key.endswith(".meta"): | |
stream_name = key[:-5] | |
n_meta_keys = unpacker.read_map_header() | |
for j in range(n_meta_keys): | |
meta_key = unpacker.unpack() | |
if meta_key == "type": | |
typenames[stream_name] = unpacker.unpack() | |
elif meta_key == "timestamps": | |
n_samples[stream_name] = unpacker.read_array_header() | |
for k in range(n_samples[stream_name]): | |
unpacker.skip() | |
else: | |
unpacker.skip() | |
else: | |
unpacker.skip() | |
return n_samples, typenames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment