adding timeinfo
This commit is contained in:
parent
2018745d52
commit
046aef031f
18
src/time_info.py
Normal file
18
src/time_info.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from datetime import timedelta, datetime
|
||||
|
||||
class TimeInfo:
|
||||
def __init__(self, to_go):
|
||||
self.times = []
|
||||
self.to_go = to_go
|
||||
|
||||
def add_measurement(self, time_measurement):
|
||||
if time_measurement > 0:
|
||||
self.times.append(time_measurement)
|
||||
self.to_go -= 1
|
||||
|
||||
def info(self):
|
||||
seconds = sum(self.times) / len(self.times)
|
||||
td = timedelta(seconds = int(seconds * self.to_go))
|
||||
ft = datetime.now() + td
|
||||
print("Going to finish in {}".format(ft.strftime("%d/%m @ %H:%M")))
|
||||
|
|
@ -18,6 +18,7 @@ from word_stats import WordStats
|
|||
from writer import Writer
|
||||
from loader import load_files
|
||||
from database import Database
|
||||
from time_info import TimeInfo
|
||||
|
||||
|
||||
def match_file(words, structures):
|
||||
|
@ -38,6 +39,7 @@ def match_file(words, structures):
|
|||
|
||||
def main(args):
|
||||
structures, lemma_msds, max_num_components = build_structures(args)
|
||||
timeinfo = TimeInfo(len(args.input))
|
||||
|
||||
database = Database(args)
|
||||
match_store = MatchStore(args, database)
|
||||
|
@ -45,8 +47,10 @@ def main(args):
|
|||
|
||||
for words in load_files(args, database):
|
||||
if words is None:
|
||||
timeinfo.add_measurement(-1)
|
||||
continue
|
||||
|
||||
start_time = time.time()
|
||||
matches = match_file(words, structures)
|
||||
match_store.add_matches(matches)
|
||||
word_stats.add_words(words)
|
||||
|
@ -57,6 +61,9 @@ def main(args):
|
|||
del matches
|
||||
gc.collect()
|
||||
|
||||
timeinfo.add_measurement(time.time() - start_time)
|
||||
timeinfo.info()
|
||||
|
||||
# if no output files, just exit
|
||||
if all([x == None for x in [args.out, args.out_no_stat, args.all, args.stats]]):
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user