feat(labeling): ratios reset for labeling implemeneted

This commit is contained in:
2025-07-14 12:37:38 -05:00
parent a7f8e39bac
commit 61f0b7f06b
11 changed files with 340 additions and 8 deletions

View File

@@ -1,23 +1,23 @@
import { eq } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { labelRatio } from "../../../../../database/schema/ratios.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
export const getLabelRatio = async () => {
const { data: labelInfo, error: labelError } = await tryCatch(
db.select().from(labelRatio)
db.select().from(labelRatio).where(eq(labelRatio.name, "label"))
);
if (labelError) {
return {
success: false,
message: "There was an error getting the labels",
message: "There was an error getting the labelratio",
data: [labelError],
};
}
return {
success: true,
message: "Current labels order by upd_Date.",
count: labelInfo.length,
message: "Current labelratio.",
data: labelInfo,
};
};

View File

@@ -1,4 +1,4 @@
import { sql } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { labelRatio } from "../../../../../database/schema/ratios.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
@@ -51,3 +51,34 @@ export const manualLabelCreated = async () => {
);
}
};
export const resetLabelRatio = async () => {
const { error } = await tryCatch(
db
.update(labelRatio)
.set({
name: sql`'label-' || (SELECT count(*) FROM ${labelRatio})`,
lastReset: sql`NOW()`,
})
.where(eq(labelRatio.name, "label"))
);
if (error) {
console.log(error);
createLog(
"error",
"labeling",
"ocp",
"There was an error resetting Label Ratio"
);
return {
success: false,
message: "There was an issue resetting the label data.",
};
}
return {
success: true,
message: "Label Ratio has been reset.",
};
};