add time taken to interrogate

This commit is contained in:
Luna 2023-06-10 01:40:58 -03:00
parent 7c94afb01e
commit 4ab35b285e
1 changed files with 12 additions and 5 deletions

17
main.py
View File

@ -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)
);
"""