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 writer import Writer
|
||||||
from loader import load_files
|
from loader import load_files
|
||||||
from database import Database
|
from database import Database
|
||||||
|
from time_info import TimeInfo
|
||||||
|
|
||||||
|
|
||||||
def match_file(words, structures):
|
def match_file(words, structures):
|
||||||
|
@ -38,6 +39,7 @@ def match_file(words, structures):
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
structures, lemma_msds, max_num_components = build_structures(args)
|
structures, lemma_msds, max_num_components = build_structures(args)
|
||||||
|
timeinfo = TimeInfo(len(args.input))
|
||||||
|
|
||||||
database = Database(args)
|
database = Database(args)
|
||||||
match_store = MatchStore(args, database)
|
match_store = MatchStore(args, database)
|
||||||
|
@ -45,8 +47,10 @@ def main(args):
|
||||||
|
|
||||||
for words in load_files(args, database):
|
for words in load_files(args, database):
|
||||||
if words is None:
|
if words is None:
|
||||||
|
timeinfo.add_measurement(-1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
matches = match_file(words, structures)
|
matches = match_file(words, structures)
|
||||||
match_store.add_matches(matches)
|
match_store.add_matches(matches)
|
||||||
word_stats.add_words(words)
|
word_stats.add_words(words)
|
||||||
|
@ -57,6 +61,9 @@ def main(args):
|
||||||
del matches
|
del matches
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
timeinfo.add_measurement(time.time() - start_time)
|
||||||
|
timeinfo.info()
|
||||||
|
|
||||||
# if no output files, just exit
|
# if no output files, just exit
|
||||||
if all([x == None for x in [args.out, args.out_no_stat, args.all, args.stats]]):
|
if all([x == None for x in [args.out, args.out_no_stat, args.all, args.stats]]):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user