Skip to content

Commit

Permalink
pass process_id (#17)
Browse files Browse the repository at this point in the history
* pass process_id

* fmt

* add process id
  • Loading branch information
yuichiroaoki authored Oct 23, 2023
1 parent c2ad2df commit 2e2294f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cnceye/edge/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mysql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cnceye"
version = "0.4.1"
version = "0.4.2"
description = "CMM python library"
license = "MIT"
authors = ["yuichiroaoki <[email protected]>"]
Expand Down
10 changes: 7 additions & 3 deletions tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -11,14 +13,16 @@ 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()

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()
Expand All @@ -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


Expand All @@ -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),
Expand Down

0 comments on commit 2e2294f

Please sign in to comment.