diff --git a/cnceye/edge/find.py b/cnceye/edge/find.py index e505a6c..7a7f5c3 100644 --- a/cnceye/edge/find.py +++ b/cnceye/edge/find.py @@ -22,17 +22,19 @@ def find_edge(filepath: str, minimal_diff: float = 5.0): previous_distance = distance -def find_edges(mysql_config: dict = MYSQL_CONFIG, minimal_diff: float = 5.0): +def find_edges( + process_id: int, mysql_config: dict = MYSQL_CONFIG, minimal_diff: float = 5.0 +): cnx = mysql.connector.connect(**mysql_config, database="coord") cursor = cnx.cursor() - query = "SELECT * FROM sensor" - cursor.execute(query) + query = "SELECT * FROM sensor WHERE process_id = %s" + cursor.execute(query, (process_id,)) rows = cursor.fetchall() previous_distance = "" edges = [] for row in rows: # x, y, z, distance - distance = row[4] + distance = row[5] if check_if_edge_is_found(distance, previous_distance, minimal_diff): edges.append(row) previous_distance = distance diff --git a/mysql/init.sql b/mysql/init.sql index 5c5c2c1..d199970 100644 --- a/mysql/init.sql +++ b/mysql/init.sql @@ -75,6 +75,7 @@ CREATE TABLE IF NOT EXISTS `sensor` ( `x` FLOAT NOT NULL, `y` FLOAT NOT NULL, `z` FLOAT NOT NULL, + `process_id` int(11) unsigned NOT NULL, `distance` FLOAT NOT NULL, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) diff --git a/pyproject.toml b/pyproject.toml index e488ec1..3f3630e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cnceye" -version = "0.4.1" +version = "0.4.2" description = "CMM python library" license = "MIT" authors = ["yuichiroaoki <45054071+yuichiroaoki@users.noreply.github.com>"] diff --git a/tests/test_find.py b/tests/test_find.py index b76dbd5..bb7625c 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -3,6 +3,8 @@ import mysql.connector import sqlite3 +process_id = 100 + def copy_sqlite_db_to_mysql(): db_path = "tests/fixtures/db/listener.db" @@ -11,6 +13,7 @@ def copy_sqlite_db_to_mysql(): query = "SELECT x,y,z,distance FROM coord" data = [] for row in cur.execute(query): + row = (*row, process_id) data.append(row) cur.close() conn.close() @@ -18,7 +21,8 @@ def copy_sqlite_db_to_mysql(): mysql_conn = mysql.connector.connect(**MYSQL_CONFIG, database="coord") mysql_cur = mysql_conn.cursor() mysql_cur.executemany( - "INSERT INTO sensor(x, y, z, distance) VALUES (%s, %s, %s, %s)", data + "INSERT INTO sensor(x, y, z, distance, process_id) VALUES (%s,%s,%s, %s, %s)", + data, ) mysql_conn.commit() mysql_cur.close() @@ -27,7 +31,7 @@ def copy_sqlite_db_to_mysql(): def test_find_edges(): copy_sqlite_db_to_mysql() - measured_edges = find.find_edges() + measured_edges = find.find_edges(process_id) assert len(measured_edges) > 32 @@ -45,7 +49,7 @@ def test_find_edge_from_sqlite(): def test_add_measured_edge_coord(): - measured_edges = find.find_edges() + measured_edges = find.find_edges(process_id) edge_data = [ (1, -50.0, -21.667, 10.0), (2, -50.0, 21.667, 10.0),