Skip to content
Snippets Groups Projects
Commit 971ba374 authored by VulcanixFR's avatar VulcanixFR
Browse files

Fix DB indexing

parent 36042633
Branches
No related merge requests found
......@@ -317,7 +317,7 @@ class Database:
# Adds the file description to the database
try:
md = pd.read_sql_query(f"SELECT `index` FROM {_DB_METADATA_TABLE}")
md = pd.read_sql_query(f"SELECT `index` FROM {_DB_METADATA_TABLE}", self.db)
index = md["index"].to_numpy()[-1] + 1
except:
index = 0
......
......@@ -16,11 +16,13 @@ from time import time
# %% - Constants
QUERY_DROP_TABLE = lambda r: f"drop table if exists Robot{r}_indicators;"
QUERY_RUNS = lambda r: f'SELECT `index`, `Name` FROM DataFiles WHERE `Robot` = "Robot_{r}";'
QUERY_RUNS = lambda r: f'SELECT `index`, `Name`, `Year`, `Month`, `Day` FROM DataFiles WHERE `Robot` = "Robot_{r}";'
COMPUTED_COLUMS = [
"Time",
"RunTime",
"Speed",
"Class",
"Date",
"Axis",
"RMS", "KMeans", "PeakFactor", "MeanTemperature"
]
......@@ -30,7 +32,7 @@ COMPUTED_COLUMS = [
QUERY_INDICATORS = lambda r: f"SELECT * FROM Robot{r}_indicators;"
# %% - Computation for one run
def compute_run (DB: Database, robot: int, run: int, t0: int):
def compute_run (DB: Database, robot: int, run: int, t0: int, date: str):
out = []
......@@ -49,7 +51,7 @@ def compute_run (DB: Database, robot: int, run: int, t0: int):
temp = sub[f"Temperature_A{m}"].to_numpy()
line = [
# *line,
t0, t0, 0,
t0, t0, 0, data["Class"][0], date,
f"A{m}", RMS(c), kmeans(c), peak_factor(c), np.mean(temp)
]
out.append(line)
......@@ -72,8 +74,8 @@ def compute_run (DB: Database, robot: int, run: int, t0: int):
temp = sub[f"Temperature_A{m}"].to_numpy()
line = [
# *line,
time, t0, s, f"A{m}",
RMS(c), kmeans(c), peak_factor(c), np.mean(temp)
time, t0, s, data["Class"][0], date,
f"A{m}", RMS(c), kmeans(c), peak_factor(c), np.mean(temp)
]
out.append(line)
# out.append(line)
......@@ -96,12 +98,13 @@ def compute_indicators (DB: Database, robot: int):
times = [ name.split(" ")[0] for name in files["Name"] ]
times = [ t.split("h") for t in times ]
times = [ 3600 * int(t[0]) + 60 * int(t[1]) for t in times ]
dates = (files["Year"].astype(str) + "-" + files["Month"].astype(str) + "-" + files["Day"].astype(str)).to_numpy()
# Compute
out = []
for i, run in enumerate(runs):
print("Robot", robot, "run n°", run)
out = [ *out, *compute_run(DB, robot, run, times[i]) ]
out = [ *out, *compute_run(DB, robot, run, times[i], dates[i]) ]
# Save
df = pd.DataFrame(out, columns=COMPUTED_COLUMS)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment