TimberVis Flexiboard: Visualization and Exploration Flexiboard for Timber Buildings IoT data sensors. The pulse of the wood Monitoring of Wooden houses: Time series of sensors data measuring humidity, temperatures, vibrations and weather conditions. https://lnu.se/forskning/forskningsprojekt/projekt-flexiboard-for-visualisering-och-utforskning-av-trabyggnader/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
infravis-trahust/py/import.py

56 lines
1.3 KiB

import csv, sqlite3, os
BASEDIR = '../Data/Charlie-1-2023'
ALL_FILES = os.listdir(BASEDIR)
GROUPS = [1]
DB_FILE = 'charlie.db'
try:
print(f"Deleting and recreating '{DB_FILE}'...")
os.remove(DB_FILE)
except:
pass
con = sqlite3.connect('charlie.db')
cur = con.cursor()
for g in GROUPS:
table_name = f'Hus_Charlie_g{g}'
first = True
for f in ALL_FILES:
if f[0] == str(g):
print(g, f)
with open(f'{BASEDIR}/{f}', 'r') as fin:
reader = csv.reader(fin)
data = []
for line in reader:
#print(line)
if line[0][:9] == 'Connected':
header1 = next(reader)
header2 = next(reader)
if (first):
first = False
col_names = [f"{header1[i]}_{header2[i]}" for i in range(len(header1))]
#print(f"CREATE TABLE charlie{*col_names,}")
cur.execute(f"CREATE TABLE {table_name}{*col_names,}")
con.commit()
else:
data.append(tuple(line))
#print(data)
#exit()
placeholder = f"({','.join('?' for _ in range(len(data[0])))})"
q = f"INSERT INTO {table_name} VALUES {placeholder};"
#print(q)
#exit()
cur.executemany(q, data)
con.commit()
#res = cur.execute("SELECT name FROM sqlite_master")
res = cur.execute(f'SELECT * FROM "{table_name}";')
print(res.fetchall())