in progress: send data to pgutil from formatresult
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json, os, shutil
|
import json, os, shutil
|
||||||
|
from pgutil import PGUTIL
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
def format_result(app_config: Config, json_path):
|
def format_result(app_config: Config, json_path):
|
||||||
@@ -8,7 +9,7 @@ def format_result(app_config: Config, json_path):
|
|||||||
data_path = app_config['data_path']
|
data_path = app_config['data_path']
|
||||||
|
|
||||||
# if pg_config is not None, run the postgres prediction[0] of this code
|
# if pg_config is not None, run the postgres prediction[0] of this code
|
||||||
pg_config = app_config['pg_config']
|
pgutil = PGUTIL(app_config, json_path)
|
||||||
|
|
||||||
# if this is True, run the prediction[0] "for line in contents:" below
|
# if this is True, run the prediction[0] "for line in contents:" below
|
||||||
sort_by_match_strength = app_config['sort_by_match_strength']
|
sort_by_match_strength = app_config['sort_by_match_strength']
|
||||||
@@ -34,14 +35,22 @@ def format_result(app_config: Config, json_path):
|
|||||||
# handles data for first prediction for a given photo
|
# handles data for first prediction for a given photo
|
||||||
total_count += 1
|
total_count += 1
|
||||||
guess_label = prediction[0][0][1]
|
guess_label = prediction[0][0][1]
|
||||||
|
match_accuracy = prediction[0][0][2]
|
||||||
match_strength = 'weak'
|
match_strength = 'weak'
|
||||||
|
|
||||||
|
# container for data to ship to pg
|
||||||
|
pgutil.insert_data({
|
||||||
|
"filename": img_path,
|
||||||
|
"topprediction": guess_label,
|
||||||
|
"matchaccuracy": match_accuracy
|
||||||
|
})
|
||||||
|
|
||||||
# assign value for match strength
|
# assign value for match strength
|
||||||
if float(prediction[0][0][2]) > 0.9:
|
if float(match_accuracy) > 0.9:
|
||||||
match_strength = 'strong'
|
match_strength = 'strong'
|
||||||
elif float(prediction[0][0][2]) > 0.7:
|
elif float(match_accuracy) > 0.7:
|
||||||
match_strength = 'moderate'
|
match_strength = 'moderate'
|
||||||
elif float(prediction[0][0][2]) > 0.4:
|
elif float(match_accuracy) > 0.4:
|
||||||
match_strength = 'fair'
|
match_strength = 'fair'
|
||||||
elif match_strength == 'weak':
|
elif match_strength == 'weak':
|
||||||
weak_results += 1
|
weak_results += 1
|
||||||
|
|||||||
16
pgutil.py
16
pgutil.py
@@ -2,7 +2,7 @@ import psycopg2, json
|
|||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
class PGUTIL:
|
class PGUTIL:
|
||||||
def __init__(self, config_file: Config = None):
|
def __init__(self, config_file: Config = None, json_path: str = None):
|
||||||
if config_file is None:
|
if config_file is None:
|
||||||
load_config = Config()
|
load_config = Config()
|
||||||
config_file = load_config.run()
|
config_file = load_config.run()
|
||||||
@@ -11,7 +11,8 @@ class PGUTIL:
|
|||||||
|
|
||||||
if pg_dsn is None:
|
if pg_dsn is None:
|
||||||
raise Exception("Insufficient data to establish PostgreSQL connection.")
|
raise Exception("Insufficient data to establish PostgreSQL connection.")
|
||||||
|
if json_path:
|
||||||
|
self.json_path = json_path
|
||||||
self.config_file = config_file
|
self.config_file = config_file
|
||||||
|
|
||||||
def create_tables(self):
|
def create_tables(self):
|
||||||
@@ -59,5 +60,12 @@ class PGUTIL:
|
|||||||
|
|
||||||
print("Connection closed.")
|
print("Connection closed.")
|
||||||
|
|
||||||
def insert_data(self):
|
def insert_data(self, analysis):
|
||||||
pass
|
# if self.json_path is None:
|
||||||
|
# return
|
||||||
|
|
||||||
|
# establish pg connection
|
||||||
|
conn = psycopg2.connect(self['config_file']['dsn'])
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user