From 4ab35b285ee1922eca2d729165882b0759cd5694 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 10 Jun 2023 01:40:58 -0300 Subject: [PATCH] add time taken to interrogate --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 258cb70..1d817ed 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import time import os import json import aiohttp @@ -250,11 +251,11 @@ async def insert_post(ctx, post): async def insert_interrogated_result( - ctx, interrogator: Interrogator, md5: str, tag_string: str + ctx, interrogator: Interrogator, md5: str, tag_string: str, time_taken: float ): await ctx.db.execute_insert( - "insert into interrogated_posts (md5, model_name, output_tag_string) values (?,?,?)", - (md5, interrogator.model_id, tag_string), + "insert into interrogated_posts (md5, model_name, output_tag_string, time_taken) values (?,?,?,?)", + (md5, interrogator.model_id, tag_string, time_taken), ) await ctx.db.commit() @@ -282,10 +283,15 @@ async def fight(ctx): "interrogating %r (%d/%d)", missing_hash, index, len(missing_hashes) ) post_filepath = next(DOWNLOADS.glob(f"{missing_hash}*")) + + start_ts = time.monotonic() tag_string = await interrogator.interrogate(ctx.session, post_filepath) - log.info("got %r", tag_string) + end_ts = time.monotonic() + time_taken = round(end_ts - start_ts, 10) + + log.info("took %.5fsec, got %r", time_taken, tag_string) await insert_interrogated_result( - ctx, interrogator, missing_hash, tag_string + ctx, interrogator, missing_hash, tag_string, time_taken ) @@ -385,6 +391,7 @@ async def realmain(ctx): md5 text, model_name text not null, output_tag_string text not null, + time_taken real not null, primary key (md5, model_name) ); """