Don't store duration in db

This commit is contained in:
George Lacey 2021-05-03 18:14:34 +01:00
parent 20218372d5
commit 7a8b027716
2 changed files with 5 additions and 5 deletions

View File

@ -20,7 +20,6 @@ class Database(object):
fingerprint text NOT NULL, fingerprint text NOT NULL,
start text NOT NULL, start text NOT NULL,
end text NOT NULL, end text NOT NULL,
duration long NOT NULL,
filecount long NOT NULL);""" filecount long NOT NULL);"""
self.conn.execute(query) self.conn.execute(query)
self.commit() self.commit()
@ -28,5 +27,5 @@ class Database(object):
def insert(self, log_entry: LogEntry): def insert(self, log_entry: LogEntry):
query = f"INSERT INTO {self.table_name} (name, fingerprint, start, end, duration, filecount) VALUES(?,?,?,?,?)" query = f"INSERT INTO {self.table_name} (name, fingerprint, start, end, duration, filecount) VALUES(?,?,?,?,?)"
self.conn.execute(query, (log_entry.name, log_entry.fingerprint, log_entry.start_time, log_entry.end_time, self.conn.execute(query, (log_entry.name, log_entry.fingerprint, log_entry.start_time, log_entry.end_time,
log_entry.duration, log_entry.file_count)) log_entry.file_count))
self.commit() self.commit()

View File

@ -1,4 +1,5 @@
from datetime import * from datetime import datetime
from math import floor
import re import re
@ -23,12 +24,12 @@ class LogEntry(object):
f"file_count: {self.file_count}"]) f"file_count: {self.file_count}"])
def get_duration(self, duration_string): def get_duration(self, duration_string):
total_seconds = 0.0 total_seconds = 0
time_strings = [('second', 1), ('minute', 60), ('hour', 3600), ('day', 86400)] time_strings = [('second', 1), ('minute', 60), ('hour', 3600), ('day', 86400)]
for ts, mult in time_strings: for ts, mult in time_strings:
total_seconds += self.get_time_unit_string(duration_string, ts, mult) total_seconds += self.get_time_unit_string(duration_string, ts, mult)
return total_seconds return floor(total_seconds)
@staticmethod @staticmethod
def get_time_unit_string(text: str, time_text: str, multiplier: int = 1): def get_time_unit_string(text: str, time_text: str, multiplier: int = 1):