Skip to content

Commit

Permalink
Fix db conn
Browse files Browse the repository at this point in the history
  • Loading branch information
sacconazzo authored Aug 30, 2024
1 parent 1b9225b commit 8a0f3f1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/calibrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const ai = require("./ai");

const calibrate = async ({ force = true, tentative = 1, absorption } = {}) => {
if (force) {
const [[spread]] = await conn.raw(
const [[spread]] = await db.raw(
`select\
min(b.b1_current) as A1_MIN,\
min(b.b2_current) as A2_MIN,\
Expand Down Expand Up @@ -33,7 +33,7 @@ const calibrate = async ({ force = true, tentative = 1, absorption } = {}) => {
}
}

const [[data]] = await conn.raw(
const [[data]] = await db.raw(
`select\
count(*) as snaps,
truncate(avg(a.ch5), 4) as OFFSET_A1,\
Expand Down Expand Up @@ -71,14 +71,14 @@ const calibrate = async ({ force = true, tentative = 1, absorption } = {}) => {
data.OFFSET_A1 = (data.OFFSET_A1 + offsetBaseA1).toFixed(4);
data.OFFSET_A2 = (data.OFFSET_A2 + offsetBaseA2).toFixed(4);

await conn("settings")
await db("settings")
.update({ value: data.OFFSET_A1 })
.where({ key: "OFFSET_A1" });
await conn("settings")
await db("settings")
.update({ value: data.OFFSET_A2 })
.where({ key: "OFFSET_A2" });

await conn("calibrate-snaps").insert({
await db("calibrate-snaps").insert({
temperature: data.TEMPERATURE,
a1: data.OFFSET_A1,
a2: data.OFFSET_A2,
Expand All @@ -96,14 +96,14 @@ const calibrateAI = async () => {
console.log(`Current sensor recalibrate from AI: ${JSON.stringify(data)}`);

if (data && data.OFFSET_A1 > 0.2 && data.OFFSET_A2 > 0.2) {
await conn("settings")
await db("settings")
.update({ value: data.OFFSET_A1 })
.where({ key: "OFFSET_A1" });
await conn("settings")
await db("settings")
.update({ value: data.OFFSET_A2 })
.where({ key: "OFFSET_A2" });

await conn("calibrate-snaps").insert({
await db("calibrate-snaps").insert({
temperature: data.TEMPERATURE,
a1: data.OFFSET_A1,
a2: data.OFFSET_A2,
Expand Down

0 comments on commit 8a0f3f1

Please sign in to comment.