init
This commit is contained in:
56
scripts/create_mulog.py
Normal file
56
scripts/create_mulog.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
from scripts import utils
|
||||
from directive.munet.log_record import identify, parse, full_parse
|
||||
|
||||
# from .settings import conf
|
||||
|
||||
LOGGER = logging.LoggerAdapter(
|
||||
logging.getLogger("swmu"), {"unitid": "unassigned"})
|
||||
|
||||
|
||||
def load_log(import_dir, sim_time_check):
|
||||
with open(import_dir) as fin:
|
||||
# take only message even when row is f"{log_address}: {message}"
|
||||
fin_data = [row.split(":")[-1].strip() for row in fin]
|
||||
index = 0
|
||||
list_ts = []
|
||||
list_ts_warning = []
|
||||
five_year = time.time() - 157784630
|
||||
|
||||
for message in fin_data:
|
||||
message_ts = utils.get_timestamp_of_message(
|
||||
bytes.fromhex(message))
|
||||
if sim_time_check == "max_y" and message_ts is not None:
|
||||
if message_ts < five_year:
|
||||
list_ts_warning.append(
|
||||
(index, message, message_ts))
|
||||
continue
|
||||
message_type = identify(bytes.fromhex(message))
|
||||
try:
|
||||
message_type_parse = parse(bytes.fromhex(message))
|
||||
message_type_full_parse = full_parse(bytes.fromhex(message))
|
||||
except Exception:
|
||||
# except Exception as e:
|
||||
# logging.warning(e)
|
||||
continue
|
||||
if message_ts is not None and message_ts <= 423792000:
|
||||
list_ts_warning.append(
|
||||
(index, message, message_ts))
|
||||
list_ts.append(
|
||||
(index, message, message_ts, message_type, message_type_parse,
|
||||
message_type_full_parse, list_ts_warning))
|
||||
index += 1
|
||||
"""
|
||||
if list_ts_warning:
|
||||
LOGGER.warning(
|
||||
f"timestamp in mulog is suspicious ([row in mulog]"
|
||||
f", [message], [timestamp]): {list_ts_warning}")
|
||||
"""
|
||||
return list_ts
|
||||
|
||||
|
||||
def dir_mulog(import_dir, sim_time_check):
|
||||
mulog_data = load_log(import_dir, sim_time_check)
|
||||
return mulog_data
|
||||
Reference in New Issue
Block a user