From 78197ac3ac7c3845d84a5567e78b5491c3cb4dee Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 04:26:52 +0200 Subject: [PATCH 1/7] include requirement files for lib management --- requirements.in | 3 +++ requirements.txt | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 requirements.in create mode 100644 requirements.txt diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..af010ed --- /dev/null +++ b/requirements.in @@ -0,0 +1,3 @@ +psycopg2-binary +python-dotenv +opencv-python diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..687f469 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile +# +numpy==2.0.1 + # via opencv-python +opencv-python==4.10.0.84 + # via -r requirements.in +psycopg2-binary==2.9.9 + # via -r requirements.in +python-dotenv==1.0.1 + # via -r requirements.in From acb7c73e3e180db8354bcce95417c3ff1354a761 Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 04:27:09 +0200 Subject: [PATCH 2/7] include ignore files --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fab3812 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +venv/ +.venv/ +.idea/ +.env +**.db \ No newline at end of file From 77a75ed27bb2b6f64ac298ac8fdd79c93e0e46c4 Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 04:27:21 +0200 Subject: [PATCH 3/7] include example environment --- src/.env.example | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/.env.example diff --git a/src/.env.example b/src/.env.example new file mode 100644 index 0000000..e1824db --- /dev/null +++ b/src/.env.example @@ -0,0 +1,6 @@ +DB_TYPE=sqlite3 +DB_HOST= +DB_PORT=5432 +DB_NAME= +DB_USERNAME= +DB_PASSWORD= From 9395f12c7f72e824548f7bdee7cbfae0ada4c3f5 Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 04:28:03 +0200 Subject: [PATCH 4/7] initialized database logic to handle dev or prod data storing --- src/db.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/db.py diff --git a/src/db.py b/src/db.py new file mode 100644 index 0000000..82749e7 --- /dev/null +++ b/src/db.py @@ -0,0 +1,120 @@ +import os +import sys +import time +import sqlite3 +import argparse +import psycopg2 +from dotenv import load_dotenv +from psycopg2.extras import execute_values + +load_dotenv() + +SQLITE3_DB = 'spectrometer_data.db' +DB_TYPE = os.getenv('DB_TYPE', 'sqlite3') + +if DB_TYPE != 'sqlite3': + DB_HOST = os.environ.get('DB_HOST', 'localhost') + DB_PORT = os.environ.get('DB_PORT', '5432') + DB_NAME = os.environ.get('DB_NAME', 'postgres') + DB_USERNAME = os.environ.get('DB_USERNAME', 'postgres') + DB_PASSWORD = os.environ.get('DB_PASSWORD', 'postgres') + + +def parse_arguments() -> argparse.Namespace: + parser = argparse.ArgumentParser() + parser.add_argument( + '-i', '--initialize', action='store_true', help='Initialize SQLite3 database', + ) + parser.add_argument( + '-t', '--test', action='store_true', help='Test SQLite3 database measurements insertion.', + ) + return parser.parse_args() + + +def snapshot_database(timestamp, wavelengths, intensities): + data_to_insert = prepare_snapshot_db_data(timestamp, wavelengths, intensities) + + if DB_TYPE == "postgresql": + save_measurements_to_postgresql( + ''' + INSERT INTO measurements (timestamp, wavelength, intensity) + VALUES %s + ''' % data_to_insert, + data_to_insert, + ) + else: + save_measurements_to_sqlite3( + '''INSERT INTO measurements (timestamp, wavelength, intensity) VALUES (?, ?, ?)''', + data_to_insert, + ) + + +def prepare_snapshot_db_data(timestamp, wavelengths, intensities): + return [(timestamp, wl, inten) for wl, inten in zip(wavelengths, intensities)] + + +def connect_to_sqlite3() -> sqlite3.Connection: + return sqlite3.connect(SQLITE3_DB) + + +def connect_to_postgresql() -> psycopg2.connect: + return psycopg2.connect( + host=DB_HOST, + database=DB_NAME, + user=DB_USERNAME, + password=DB_PASSWORD, + port=DB_PORT, + ) + + +def save_measurements_to_sqlite3(query, data_to_insert): + conn = connect_to_sqlite3() + cursor = conn.cursor() + cursor.executemany(query, data_to_insert) + conn.commit() + conn.close() + + +def save_measurements_to_postgresql(query, data_to_insert): + conn = connect_to_postgresql() + cursor = conn.cursor() + execute_values(cursor, query, data_to_insert) + conn.commit() + cursor.close() + conn.close() + + +def create_sqlite3_db(): + conn = connect_to_sqlite3() + cursor = conn.cursor() + + cursor.execute(''' + CREATE TABLE IF NOT EXISTS measurements ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + timestamp TEXT, + wavelength REAL, + intensity REAL + ) + ''') + + conn.commit() + conn.close() + + +if __name__ == '__main__': + args = parse_arguments() + if args.initialize: + create_sqlite3_db() + elif args.test: + test_data = prepare_snapshot_db_data( + time.strftime("%Y%m%d--%H%M%S"), # <- timestamp + [395.6, 396.1], # <- wavelengths + [2, 1] # <- intensities + ) + + save_measurements_to_sqlite3( + '''INSERT INTO measurements (timestamp, wavelength, intensity) VALUES (?, ?, ?)''', + test_data, + ) + + sys.exit(0) From c608a4c32eec2204775b3e6f07f3f7c91e5bd328 Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 04:32:01 +0200 Subject: [PATCH 5/7] calling new db module to also push measurements into database --- src/PySpectrometer2-Picam2-v1.0.py | 12 +++++++++--- src/PySpectrometer2-USB-v1.0.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/PySpectrometer2-Picam2-v1.0.py b/src/PySpectrometer2-Picam2-v1.0.py index c0965ef..7b31f64 100644 --- a/src/PySpectrometer2-Picam2-v1.0.py +++ b/src/PySpectrometer2-Picam2-v1.0.py @@ -32,6 +32,8 @@ import base64 import argparse from picamera2 import Picamera2 +from src.db import snapshot_database + parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() @@ -149,7 +151,8 @@ def snapshot(savedata): now = time.strftime("%Y%m%d--%H%M%S") timenow = time.strftime("%H:%M:%S") imdata1 = savedata[0] - graphdata = savedata[1] + wavelengths = savedata[1][0] + intensities = savedata[1][1] if dispWaterfall == True: imdata2 = savedata[2] cv2.imwrite("waterfall-" + now + ".png",imdata2) @@ -158,11 +161,14 @@ def snapshot(savedata): #print(graphdata[1]) #intensities f = open("Spectrum-"+now+'.csv','w') f.write('Wavelength,Intensity\r\n') - for x in zip(graphdata[0],graphdata[1]): + for x in zip(wavelengths, intensities): f.write(str(x[0])+','+str(x[1])+'\r\n') f.close() + + snapshot_database(now, wavelengths, intensities) + message = "Last Save: "+timenow - return(message) + return message while True: diff --git a/src/PySpectrometer2-USB-v1.0.py b/src/PySpectrometer2-USB-v1.0.py index 8bb6adc..1b4fa2f 100644 --- a/src/PySpectrometer2-USB-v1.0.py +++ b/src/PySpectrometer2-USB-v1.0.py @@ -33,6 +33,8 @@ import base64 import argparse +from src.db import snapshot_database + parser = argparse.ArgumentParser() parser.add_argument("--device", type=int, default=0, help="Video Device number e.g. 0, use v4l2-ctl --list-devices") parser.add_argument("--fps", type=int, default=30, help="Frame Rate e.g. 30") @@ -153,7 +155,8 @@ def snapshot(savedata): now = time.strftime("%Y%m%d--%H%M%S") timenow = time.strftime("%H:%M:%S") imdata1 = savedata[0] - graphdata = savedata[1] + wavelengths = savedata[1][0] + intensities = savedata[1][1] if dispWaterfall == True: imdata2 = savedata[2] cv2.imwrite("waterfall-" + now + ".png",imdata2) @@ -162,11 +165,14 @@ def snapshot(savedata): #print(graphdata[1]) #intensities f = open("Spectrum-"+now+'.csv','w') f.write('Wavelength,Intensity\r\n') - for x in zip(graphdata[0],graphdata[1]): + for x in zip(wavelengths, intensities): f.write(str(x[0])+','+str(x[1])+'\r\n') f.close() + + snapshot_database(now, wavelengths, intensities) + message = "Last Save: "+timenow - return(message) + return message while(cap.isOpened()): # Capture frame-by-frame From e83923b046dc00914dc4deadd86f67eb3ce158f6 Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 05:30:42 +0200 Subject: [PATCH 6/7] initialized documentation about how to use the new db.py module --- USE_DB.md | 49 ++++++++++++++++++++++++++++++++++++++ media/db_file.png | Bin 0 -> 2040 bytes media/db_test_entries.png | Bin 0 -> 7401 bytes 3 files changed, 49 insertions(+) create mode 100644 USE_DB.md create mode 100644 media/db_file.png create mode 100644 media/db_test_entries.png diff --git a/USE_DB.md b/USE_DB.md new file mode 100644 index 0000000..a694a69 --- /dev/null +++ b/USE_DB.md @@ -0,0 +1,49 @@ +# How to use the PySpectrometer DB module + ## Requirements: + 1. Update, install and upgrade pip + ```shell + sudo apt update + sudo apt install python3-pip + pip3 --version + sudo pip3 install --upgrade pip + ``` + 2. Set up the .env file + ```shell + sudo cp src/.env.example src/.env + ``` + + ## Installation: + 1. Create a new virtual environment + ```shell + python3 -m venv .venv + ``` + 2. Activating the .venv + ```shell + source .venv/bin/activate + ``` + 3. Install requirements on the .venv + ```shell + pip3 install -r requirements.txt + ``` + + ## Initialize database: + ### Local / Development Environment: + 1. Run the `db.py` module with the initialize argument: + ```shell + python3 src/db.py --initialize + ``` + > This creates a new local SQLite3 database in the root folder of this project. + ![db_file.png](media/db_file.png) + 2. Run the `db.py` module again with the test argument: + ```shell + python3 src/db.py --test + ``` + > This will create two test entries into the new created database at `measurements` table. + You can delete them after verifying that it works. + ![db_test_entries.png](media/db_test_entries.png) + ### Production Environment: + > Following soon... + +Now, if you run any of the PySpectrometer2 scripts, it should, based on the DB_TYPE (`sqlite3`, `postgresql`) from the .env +file, pick the correct database and write the data to the database whenever a new .csv file is generated. + diff --git a/media/db_file.png b/media/db_file.png new file mode 100644 index 0000000000000000000000000000000000000000..0fdcbb2f23d3d0dbaaa019c1552df1dee33ce8f5 GIT binary patch literal 2040 zcmV000NSNklrtt2@=CSdKe|`S-4~5d+;}-yEKo^WKq~zD|*Mhq6@4h#B_uk&b^jxr~ z&*5y)VBUV(bbI@IHEAa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LaW&ZKqQyG=&YIh`$7&#_ITorbZ?KaiN3zFY4!T{XuT1^Ml0ow+Oe*F!^gv}v_NV~Ll%Z9;plLNo z>i5FiLNq4GT0+|qyKuJ?^*{$q)Wm^V%qhN zZZm&XHs8alK5aTM4xA>1H5EN#Pr;7y(po=eu$^thIMSEr!~FDN_h@0cY`*{++3&6I z7U?_4TK!$aeSUi(nFx?P%0sIheq*+Ddj`{nT>n2j6j?pm(SnZxI*E`{J`>`0AM=MGiFN`ybtVs}l`A-W28-cW_7Q zJUWm}Sfex74?3;m+R*D_%d4#3ey2340u8{1$v;z+Q_a<(@#TFegT41EuGnW3M)S&t zYlAdi!xJ|w+eyo1lDG!UnCa)MyqndSs+_VUH_r@`$`>awqof2~2K~RmkPgX*zES@c zLrxd45&Fim)>n=>PIAq}3Na)jVt0A#c!#?1LOci?{)UkH{Yb#0gKzeaS6i}&<*hP!c% zNLkN69Cvk-zNvPl<7zSufAqHHqjrT8ysY~yNA~{!A*12TqsLKCc1{NAHEZ3ZQ(U$) zYuUPusNw$+2+2{rr}wqmUk7cM@z&Fx_gldd;C~9AN<=WV_JjZWVcS1JggZ+kwEo`T w2tr2j{2wQS0C($F@ZUr3&cVpPgI`l;P)*M`=S^9p$)5o=6)oj5MT^k?0XcI&$p8QV literal 0 HcmV?d00001 From 37ac3823e9e54dfca91d7742497ae99e5db07aac Mon Sep 17 00:00:00 2001 From: schuggermi Date: Wed, 31 Jul 2024 05:34:43 +0200 Subject: [PATCH 7/7] optimized grammar --- USE_DB.md | 90 +++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/USE_DB.md b/USE_DB.md index a694a69..51c6c64 100644 --- a/USE_DB.md +++ b/USE_DB.md @@ -1,49 +1,49 @@ -# How to use the PySpectrometer DB module - ## Requirements: - 1. Update, install and upgrade pip - ```shell - sudo apt update - sudo apt install python3-pip - pip3 --version - sudo pip3 install --upgrade pip - ``` - 2. Set up the .env file - ```shell - sudo cp src/.env.example src/.env - ``` +# How to Use the PySpectrometer DB Module - ## Installation: - 1. Create a new virtual environment - ```shell - python3 -m venv .venv - ``` - 2. Activating the .venv - ```shell - source .venv/bin/activate - ``` - 3. Install requirements on the .venv - ```shell - pip3 install -r requirements.txt - ``` +## Requirements: +1. Update, install, and upgrade pip: + ```shell + sudo apt update + sudo apt install python3-pip + pip3 --version + sudo pip3 install --upgrade pip + ``` +2. Set up the .env file: + ```shell + sudo cp src/.env.example src/.env + ``` - ## Initialize database: - ### Local / Development Environment: - 1. Run the `db.py` module with the initialize argument: - ```shell - python3 src/db.py --initialize - ``` - > This creates a new local SQLite3 database in the root folder of this project. - ![db_file.png](media/db_file.png) - 2. Run the `db.py` module again with the test argument: - ```shell - python3 src/db.py --test - ``` - > This will create two test entries into the new created database at `measurements` table. - You can delete them after verifying that it works. - ![db_test_entries.png](media/db_test_entries.png) - ### Production Environment: - > Following soon... +## Installation: +1. Create a new virtual environment: + ```shell + python3 -m venv .venv + ``` +2. Activate the virtual environment: + ```shell + source .venv/bin/activate + ``` +3. Install requirements in the virtual environment: + ```shell + pip3 install -r requirements.txt + ``` -Now, if you run any of the PySpectrometer2 scripts, it should, based on the DB_TYPE (`sqlite3`, `postgresql`) from the .env -file, pick the correct database and write the data to the database whenever a new .csv file is generated. +## Initialize Database: +### Local / Development Environment: +1. Run the `db.py` module with the initialize argument: + ```shell + python3 src/db.py --initialize + ``` + > This creates a new local SQLite3 database in the root folder of this project. + ![db_file.png](media/db_file.png) +2. Run the `db.py` module again with the test argument: + ```shell + python3 src/db.py --test + ``` + > This will create two test entries in the newly created database in the `measurements` table. + You can delete them after verifying that it works. + ![db_test_entries.png](media/db_test_entries.png) +### Production Environment: +> Coming soon... + +Now, if you run any of the PySpectrometer2 scripts, it should, based on the DB_TYPE (`sqlite3`, `postgresql`) from the .env file, select the correct database and write data to the database whenever a new .csv file is generated.