utils/parse_fmle_log.py
author cavaliet
Tue, 28 Oct 2014 11:32:45 +0100
changeset 74 bdcc964b3c01
parent 29 5007c248fbad
permissions -rwxr-xr-x
good optimisation for piano roll
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import codecs
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import sys
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import dateutil.parser
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from datetime import date, datetime, time
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
from dateutil.tz import tzlocal
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import pytz
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
if __name__ == "__main__":
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    file_log = codecs.open(sys.argv[1], 'r', "UTF-16LE")
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    start_time = ""
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    duration = None
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    start_stat = False
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    for line in file_log:
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        if "Session Started" in line:
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
             start_time = dateutil.parser.parse(":".join(line.split(":")[:-1]).strip()).replace(tzinfo=tzlocal())
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
             start_time_utc = start_time.astimezone(pytz.utc)
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        if "Encoding Statistics" in line:
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
            start_stat = True
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        if start_stat and line.startswith("Video"):
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
            duration = dateutil.parser.parse(line.split()[2]) - datetime.combine(date.today(), time())
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        if start_stat and duration:
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
            print("Start time local: " + start_time.isoformat())
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
            print("Start time UTC  : " + start_time_utc.isoformat())
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
            if duration:
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
                print("Duration  : " + str(duration) + " - " + str(int(duration.total_seconds())) + " s - " + str(int(duration.total_seconds())*1000) + " ms")
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
            duration = None
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
            start_stat = False
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
5007c248fbad add utility to parse fmle log file
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33