Compare commits
16 Commits
f7b4de8130
...
61f0b7f06b
| Author | SHA1 | Date | |
|---|---|---|---|
| 61f0b7f06b | |||
| a7f8e39bac | |||
| 4923b3c698 | |||
| 28f34a6a31 | |||
| b81675e445 | |||
| c6d80dbc8a | |||
| bc54b365ea | |||
| 41308788fd | |||
| d6232cb358 | |||
| d89a336fb1 | |||
| e84ae42c83 | |||
| 6ec8f0863b | |||
| 4f231b343c | |||
| 454039e60c | |||
| c7c148fede | |||
| e30adc6612 |
32
database/schema/ratios.ts
Normal file
32
database/schema/ratios.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import {
|
||||||
|
integer,
|
||||||
|
jsonb,
|
||||||
|
pgTable,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
uniqueIndex,
|
||||||
|
uuid,
|
||||||
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createSelectSchema } from "drizzle-zod";
|
||||||
|
|
||||||
|
export const labelRatio = pgTable(
|
||||||
|
"labelRatio",
|
||||||
|
{
|
||||||
|
ratio_id: uuid(" ratio_id").defaultRandom().primaryKey(),
|
||||||
|
name: text("name").default("labels"),
|
||||||
|
autoLabel: integer("autoLabel").default(0),
|
||||||
|
manualLabel: integer("manualLabel").default(0),
|
||||||
|
lastReset: timestamp().defaultNow(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
|
||||||
|
uniqueIndex("labelname").on(table.name),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Schema for inserting a user - can be used to validate API requests
|
||||||
|
// export const insertRolesSchema = createInsertSchema(roles, {
|
||||||
|
// name: z.string().min(3, {message: "Role name must be more than 3 letters"}),
|
||||||
|
// });
|
||||||
|
// Schema for selecting a Expenses - can be used to validate API responses
|
||||||
|
export const selectRolesSchema = createSelectSchema(labelRatio);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Printer } from "lucide-react";
|
import { Printer, Tag } from "lucide-react";
|
||||||
import {
|
import {
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupContent,
|
SidebarGroupContent,
|
||||||
@@ -10,7 +10,15 @@ import {
|
|||||||
import { hasPageAccess } from "@/utils/userAccess";
|
import { hasPageAccess } from "@/utils/userAccess";
|
||||||
import { User } from "@/types/users";
|
import { User } from "@/types/users";
|
||||||
|
|
||||||
const items = [
|
export function ProductionSideBar({
|
||||||
|
user,
|
||||||
|
moduleID,
|
||||||
|
}: {
|
||||||
|
user: User | null;
|
||||||
|
moduleID: string;
|
||||||
|
}) {
|
||||||
|
const url: string = window.location.host.split(":")[0];
|
||||||
|
const items = [
|
||||||
{
|
{
|
||||||
title: "One Click Print",
|
title: "One Click Print",
|
||||||
url: "/ocp",
|
url: "/ocp",
|
||||||
@@ -20,31 +28,15 @@ const items = [
|
|||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "RFID",
|
title: "Rfid Readers",
|
||||||
moduleName: "prodcution",
|
|
||||||
description: "RFID stuff",
|
|
||||||
url: "/rfid",
|
url: "/rfid",
|
||||||
icon: "Tags",
|
icon: Tag,
|
||||||
active: true,
|
role: ["viewer"],
|
||||||
roles: [
|
module: "production",
|
||||||
"viewer",
|
active:
|
||||||
"technician",
|
url === "usday1vms006" || url === "localhost" ? true : false,
|
||||||
"supervisor",
|
|
||||||
"manager",
|
|
||||||
"admin",
|
|
||||||
"systemAdmin",
|
|
||||||
],
|
|
||||||
subSubModule: [],
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function ProductionSideBar({
|
|
||||||
user,
|
|
||||||
moduleID,
|
|
||||||
}: {
|
|
||||||
user: User | null;
|
|
||||||
moduleID: string;
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel>Production</SidebarGroupLabel>
|
<SidebarGroupLabel>Production</SidebarGroupLabel>
|
||||||
|
|||||||
27
frontend/src/components/production/ocp/LabelRatio.tsx
Normal file
27
frontend/src/components/production/ocp/LabelRatio.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { getlabelRatio } from "@/utils/querys/production/labelRatio";
|
||||||
|
import { labelRatioColumns } from "@/utils/tableData/production/labelRatio/labelRatioColumns";
|
||||||
|
import { LabelRatioTable } from "@/utils/tableData/production/labelRatio/labelRatioData";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export default function LabelRatio() {
|
||||||
|
const { data, isError, isLoading } = useQuery(getlabelRatio());
|
||||||
|
|
||||||
|
const ratioData = data ? data : [];
|
||||||
|
if (isError) {
|
||||||
|
return <div>Error</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <div>Loading</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="m-2">
|
||||||
|
<LabelRatioTable
|
||||||
|
columns={labelRatioColumns}
|
||||||
|
data={ratioData}
|
||||||
|
//style={style}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
ResizablePanel,
|
ResizablePanel,
|
||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "@/components/ui/resizable-panels";
|
} from "@/components/ui/resizable-panels";
|
||||||
|
import LabelRatio from "./LabelRatio";
|
||||||
|
|
||||||
export default function OCPPage() {
|
export default function OCPPage() {
|
||||||
const { settings } = useSettingStore();
|
const { settings } = useSettingStore();
|
||||||
@@ -97,6 +98,7 @@ export default function OCPPage() {
|
|||||||
<ResizableHandle />
|
<ResizableHandle />
|
||||||
<ResizablePanel>
|
<ResizablePanel>
|
||||||
<PrinterStatus />
|
<PrinterStatus />
|
||||||
|
<LabelRatio />
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
</ResizablePanelGroup>
|
</ResizablePanelGroup>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
|
|||||||
20
frontend/src/utils/querys/production/labelRatio.tsx
Normal file
20
frontend/src/utils/querys/production/labelRatio.tsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { queryOptions } from "@tanstack/react-query";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export function getlabelRatio() {
|
||||||
|
return queryOptions({
|
||||||
|
queryKey: ["labelRatio"],
|
||||||
|
queryFn: () => fetchSettings(),
|
||||||
|
|
||||||
|
//staleTime: 1000,
|
||||||
|
refetchInterval: 2 * 2000,
|
||||||
|
refetchOnWindowFocus: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchSettings = async () => {
|
||||||
|
const { data } = await axios.get(`/api/ocp/labelratio`);
|
||||||
|
// if we are not localhost ignore the devDir setting.
|
||||||
|
//const url: string = window.location.host.split(":")[0];
|
||||||
|
return data.data ?? [];
|
||||||
|
};
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
//import { fixTime } from "@/utils/fixTime";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { getReaders } from "@/utils/querys/rfid/getReaders";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import axios from "axios";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
// This type is used to define the shape of our data.
|
||||||
|
// You can use a Zod schema here if you want.
|
||||||
|
export type Adjustmnets = {
|
||||||
|
ratio_id: string;
|
||||||
|
name: string;
|
||||||
|
autoLabel: number;
|
||||||
|
manualLabel: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const labelRatioColumns: ColumnDef<Adjustmnets>[] = [
|
||||||
|
// {
|
||||||
|
// accessorKey: "line",
|
||||||
|
// header: () => <div className="text-left">Line</div>,
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
accessorKey: "autoLabel",
|
||||||
|
header: "Auto Labels",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "manualLabel",
|
||||||
|
header: "Manual Labels",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "goodRatio",
|
||||||
|
header: "Ratio",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const goodRatio =
|
||||||
|
(parseInt(row.getValue("autoLabel")) /
|
||||||
|
(parseInt(row.getValue("autoLabel")) +
|
||||||
|
parseInt(row.getValue("manualLabel")))) *
|
||||||
|
100;
|
||||||
|
return (
|
||||||
|
<div className="text-center font-medium">
|
||||||
|
{isNaN(goodRatio) ? 0 : goodRatio.toFixed(2)}%
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "reset",
|
||||||
|
header: "Reset Reads",
|
||||||
|
cell: () => {
|
||||||
|
const { refetch } = useQuery(getReaders());
|
||||||
|
const [readerReset, setReaderReset] = useState(false);
|
||||||
|
const resetReads = async () => {
|
||||||
|
setReaderReset(true);
|
||||||
|
try {
|
||||||
|
const res = await axios.post("/api/ocp/resetlabelratio", {
|
||||||
|
reader: name,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
toast.success(res.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
} else {
|
||||||
|
toast.error(res.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(error.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
}
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="text-left font-medium">
|
||||||
|
<Button
|
||||||
|
className="h-4"
|
||||||
|
onClick={resetReads}
|
||||||
|
disabled={readerReset}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
useReactTable,
|
||||||
|
getPaginationRowModel,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
|
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[];
|
||||||
|
data: TData[];
|
||||||
|
//style: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LabelRatioTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
//style,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageIndex: 0, //initial page index
|
||||||
|
pageSize: 5, //default page size
|
||||||
|
});
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
onPaginationChange: setPagination,
|
||||||
|
state: {
|
||||||
|
//...
|
||||||
|
pagination,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(parseInt(style.height.replace("px", "")) - 50);
|
||||||
|
return (
|
||||||
|
<LstCard>
|
||||||
|
<div>
|
||||||
|
<div className="flex flex-row justify-between">
|
||||||
|
{data.length === 0 ? (
|
||||||
|
<span className="text-center">
|
||||||
|
No labels printed since last reset.
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span>Label Ratio</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<ScrollArea className="max-h-32 rounded-md border m-2">
|
||||||
|
<Table
|
||||||
|
// style={{
|
||||||
|
// width: `${parseInt(style.width.replace("px", "")) - 50}px`,
|
||||||
|
// height: `${parseInt(style.height.replace("px", "")) - 200}px`,
|
||||||
|
// cursor: "move",
|
||||||
|
// }}
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column
|
||||||
|
.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={
|
||||||
|
row.getIsSelected() && "selected"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext()
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="h-24 text-center"
|
||||||
|
>
|
||||||
|
No labels.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</ScrollArea>
|
||||||
|
</div>
|
||||||
|
</LstCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
//import { fixTime } from "@/utils/fixTime";
|
//import { fixTime } from "@/utils/fixTime";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { getReaders } from "@/utils/querys/rfid/getReaders";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import axios from "axios";
|
||||||
import { format } from "date-fns-tz";
|
import { format } from "date-fns-tz";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
// This type is used to define the shape of our data.
|
// This type is used to define the shape of our data.
|
||||||
// You can use a Zod schema here if you want.
|
// You can use a Zod schema here if you want.
|
||||||
@@ -89,7 +95,52 @@ export const readerColumns: ColumnDef<Readers>[] = [
|
|||||||
100;
|
100;
|
||||||
return (
|
return (
|
||||||
<div className="text-left font-medium">
|
<div className="text-left font-medium">
|
||||||
{isNaN(goodRatio) ? 0 : goodRatio}%
|
{isNaN(goodRatio) ? 0 : goodRatio.toFixed(2)}%
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "reset",
|
||||||
|
header: "Reset Reads",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const { refetch } = useQuery(getReaders());
|
||||||
|
const [readerReset, setReaderReset] = useState(false);
|
||||||
|
// const goodRatio =
|
||||||
|
// (parseInt(row.getValue("goodReads")) /
|
||||||
|
// (parseInt(row.getValue("goodReads")) +
|
||||||
|
// parseInt(row.getValue("badReads")))) *
|
||||||
|
// 100;
|
||||||
|
const name = row.getValue("reader");
|
||||||
|
const resetReads = async () => {
|
||||||
|
setReaderReset(true);
|
||||||
|
try {
|
||||||
|
const res = await axios.post("/api/rfid/resetRatio", {
|
||||||
|
reader: name,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
toast.success(res.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
} else {
|
||||||
|
toast.error(res.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(error.data.message);
|
||||||
|
setReaderReset(false);
|
||||||
|
}
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="text-left font-medium">
|
||||||
|
<Button
|
||||||
|
className="h-4"
|
||||||
|
onClick={resetReads}
|
||||||
|
disabled={readerReset}
|
||||||
|
>
|
||||||
|
Reset Reads
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admConfig": {
|
"admConfig": {
|
||||||
"build": 454,
|
"build": 465,
|
||||||
"oldBuild": "backend-0.1.3.zip"
|
"oldBuild": "backend-0.1.3.zip"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
|||||||
try {
|
try {
|
||||||
const results = await axios.post(url, consumeSomething, {
|
const results = await axios.post(url, consumeSomething, {
|
||||||
headers: {
|
headers: {
|
||||||
|
"X-API-Key": process.env.TEC_API_KEY || "",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Basic ${prod.user.prod}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
//console.log(results);
|
//console.log(results);
|
||||||
|
|||||||
23
server/services/ocp/controller/labeling/getLabelRatio.ts
Normal file
23
server/services/ocp/controller/labeling/getLabelRatio.ts
Normal file
@@ -0,0 +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).where(eq(labelRatio.name, "label"))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the labelratio",
|
||||||
|
data: [labelError],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Current labelratio.",
|
||||||
|
data: labelInfo,
|
||||||
|
};
|
||||||
|
};
|
||||||
84
server/services/ocp/controller/labeling/labelRatio.ts
Normal file
84
server/services/ocp/controller/labeling/labelRatio.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
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";
|
||||||
|
import { createLog } from "../../../logger/logger.js";
|
||||||
|
|
||||||
|
export const autoLabelCreated = async () => {
|
||||||
|
const { error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.insert(labelRatio)
|
||||||
|
.values({
|
||||||
|
name: "label",
|
||||||
|
autoLabel: 1,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: labelRatio.name,
|
||||||
|
set: { autoLabel: sql`${labelRatio.autoLabel} + 1` },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"labeling",
|
||||||
|
"ocp",
|
||||||
|
"There was an error updating auto label ratio"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const manualLabelCreated = async () => {
|
||||||
|
const { error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.insert(labelRatio)
|
||||||
|
.values({
|
||||||
|
name: "label",
|
||||||
|
manualLabel: 1,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: labelRatio.name,
|
||||||
|
set: { manualLabel: sql`${labelRatio.manualLabel} + 1` },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"labeling",
|
||||||
|
"ocp",
|
||||||
|
"There was an error updating manual Label Ratio"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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.",
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@ import { unPausePrinter } from "../../utils/unpausePrinter.js";
|
|||||||
|
|
||||||
import { labelingProcess } from "../labeling/labelProcess.js";
|
import { labelingProcess } from "../labeling/labelProcess.js";
|
||||||
import { timeZoneFix } from "../../../../globalUtils/timeZoneFix.js";
|
import { timeZoneFix } from "../../../../globalUtils/timeZoneFix.js";
|
||||||
|
import { autoLabelCreated } from "../labeling/labelRatio.js";
|
||||||
|
|
||||||
let logLevel: string = process.env.LOG_LEVEL || "info";
|
let logLevel: string = process.env.LOG_LEVEL || "info";
|
||||||
let errorCheck = false;
|
let errorCheck = false;
|
||||||
@@ -132,6 +133,7 @@ export const printerStatus = async (p: any) => {
|
|||||||
|
|
||||||
// sending over for labeling.
|
// sending over for labeling.
|
||||||
labelingProcess({ printer: p });
|
labelingProcess({ printer: p });
|
||||||
|
autoLabelCreated();
|
||||||
} else if (tmp[2] === "0") {
|
} else if (tmp[2] === "0") {
|
||||||
// printer was unpaused for the first time or made it here
|
// printer was unpaused for the first time or made it here
|
||||||
createLog(
|
createLog(
|
||||||
@@ -146,6 +148,7 @@ export const printerStatus = async (p: any) => {
|
|||||||
|
|
||||||
// sending over for labeling.
|
// sending over for labeling.
|
||||||
labelingProcess({ printer: p });
|
labelingProcess({ printer: p });
|
||||||
|
autoLabelCreated();
|
||||||
} else if (tmp[2] === "1") {
|
} else if (tmp[2] === "1") {
|
||||||
// printer is paused and waiting
|
// printer is paused and waiting
|
||||||
createLog(
|
createLog(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
|
|||||||
import { createLog } from "../../../../../logger/logger.js";
|
import { createLog } from "../../../../../logger/logger.js";
|
||||||
import { readTags } from "../../../../../rfid/controller/readTags.js";
|
import { readTags } from "../../../../../rfid/controller/readTags.js";
|
||||||
import { labelingProcess } from "../../../labeling/labelProcess.js";
|
import { labelingProcess } from "../../../labeling/labelProcess.js";
|
||||||
|
import { autoLabelCreated } from "../../../labeling/labelRatio.js";
|
||||||
import { stapperFaulted, strapperFaults } from "./strapperFault.js";
|
import { stapperFaulted, strapperFaults } from "./strapperFault.js";
|
||||||
|
|
||||||
export let cameraPalletCheck = 20;
|
export let cameraPalletCheck = 20;
|
||||||
@@ -85,6 +86,7 @@ export const labelerTagRead = async (tagData: any) => {
|
|||||||
cameraPalletCheck - currentPalletCheck
|
cameraPalletCheck - currentPalletCheck
|
||||||
}.`
|
}.`
|
||||||
);
|
);
|
||||||
|
autoLabelCreated();
|
||||||
} else {
|
} else {
|
||||||
currentPalletCheck = 0;
|
currentPalletCheck = 0;
|
||||||
createLog(
|
createLog(
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import AutostartPrinterCycle from "./routes/printers/autoLabelerStart.js";
|
|||||||
import AutostopPrinterCycle from "./routes/printers/autoLabelerStop.js";
|
import AutostopPrinterCycle from "./routes/printers/autoLabelerStop.js";
|
||||||
import { deleteLabels } from "../../globalUtils/dbCleanUp/labelCleanUp.js";
|
import { deleteLabels } from "../../globalUtils/dbCleanUp/labelCleanUp.js";
|
||||||
import bookInLabel from "./routes/labeling/bookIn.js";
|
import bookInLabel from "./routes/labeling/bookIn.js";
|
||||||
|
import labelRatio from "./routes/labeling/getLabelRatio.js";
|
||||||
|
import resetRatio from "./routes/labeling/resetLabelRatio.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -40,6 +42,8 @@ const routes = [
|
|||||||
getLabels,
|
getLabels,
|
||||||
manualprint,
|
manualprint,
|
||||||
bookInLabel,
|
bookInLabel,
|
||||||
|
labelRatio,
|
||||||
|
resetRatio,
|
||||||
//dyco
|
//dyco
|
||||||
dycoCon,
|
dycoCon,
|
||||||
dycoClose,
|
dycoClose,
|
||||||
|
|||||||
38
server/services/ocp/routes/labeling/getLabelRatio.ts
Normal file
38
server/services/ocp/routes/labeling/getLabelRatio.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
import { getLabelRatio } from "../../controller/labeling/getLabelRatio.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Returns current active lots that are tech released",
|
||||||
|
method: "get",
|
||||||
|
path: "/labelratio",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const { data: labelData, error: labelError } = await tryCatch(
|
||||||
|
getLabelRatio()
|
||||||
|
);
|
||||||
|
apiHit(c, { endpoint: "/labelratio" });
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the printers",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: labelData.success,
|
||||||
|
message: labelData.message,
|
||||||
|
data: labelData.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
import { manualLabelCreated } from "../../controller/labeling/labelRatio.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ app.openapi(
|
|||||||
const { data: createLabel, error: labelError } = await tryCatch(
|
const { data: createLabel, error: labelError } = await tryCatch(
|
||||||
labelingProcess({ line: bodyData.line })
|
labelingProcess({ line: bodyData.line })
|
||||||
);
|
);
|
||||||
|
manualLabelCreated();
|
||||||
if (labelError) {
|
if (labelError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
38
server/services/ocp/routes/labeling/resetLabelRatio.ts
Normal file
38
server/services/ocp/routes/labeling/resetLabelRatio.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
import { getLabelRatio } from "../../controller/labeling/getLabelRatio.js";
|
||||||
|
import { resetLabelRatio } from "../../controller/labeling/labelRatio.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Resets the label Ratio",
|
||||||
|
method: "post",
|
||||||
|
path: "/resetlabelratio",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const { data: labelData, error: labelError } = await tryCatch(
|
||||||
|
resetLabelRatio()
|
||||||
|
);
|
||||||
|
apiHit(c, { endpoint: "/labelratio" });
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the printers",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: labelData.success,
|
||||||
|
message: labelData.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
@@ -6,6 +6,7 @@ import { eq, sql } from "drizzle-orm";
|
|||||||
import { db } from "../../../../database/dbclient.js";
|
import { db } from "../../../../database/dbclient.js";
|
||||||
import { rfidReaders } from "../../../../database/schema/rfidReaders.js";
|
import { rfidReaders } from "../../../../database/schema/rfidReaders.js";
|
||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
export const newHeartBeat = async (reader: string) => {
|
export const newHeartBeat = async (reader: string) => {
|
||||||
/**
|
/**
|
||||||
@@ -79,6 +80,36 @@ export const badRead = async (reader: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resetRatios = async (reader: string) => {
|
||||||
|
const { error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.update(rfidReaders)
|
||||||
|
.set({
|
||||||
|
goodReads: 0,
|
||||||
|
badReads: 0,
|
||||||
|
})
|
||||||
|
.where(eq(rfidReaders.reader, reader))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"rfid",
|
||||||
|
"rfid",
|
||||||
|
`${reader} encountered an error resetting the data.`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `${reader} encountered an error resetting the data.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
createLog("info", "rfid", "rfid", `${reader} just had the tag data reset.`);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `${reader} just had the tag data reset.`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const goodRead = async (reader: string) => {
|
export const goodRead = async (reader: string) => {
|
||||||
/**
|
/**
|
||||||
* When we have a bad read we want to make sure the reader shows this was well.
|
* When we have a bad read we want to make sure the reader shows this was well.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { rfidTags } from "../../../../../database/schema/rfidTags.js";
|
|||||||
import { and, eq, gte, ne, sql } from "drizzle-orm";
|
import { and, eq, gte, ne, sql } from "drizzle-orm";
|
||||||
import { rfidReaders } from "../../../../../database/schema/rfidReaders.js";
|
import { rfidReaders } from "../../../../../database/schema/rfidReaders.js";
|
||||||
import { shouldSkipByCooldown } from "../../utils/rateLimit.js";
|
import { shouldSkipByCooldown } from "../../utils/rateLimit.js";
|
||||||
|
import { autoLabelCreated } from "../../../ocp/controller/labeling/labelRatio.js";
|
||||||
|
|
||||||
export const wrapperStuff = async (tagData: any) => {
|
export const wrapperStuff = async (tagData: any) => {
|
||||||
console.log("WrapperTag", tagData[0].tag);
|
console.log("WrapperTag", tagData[0].tag);
|
||||||
@@ -152,7 +153,7 @@ export const wrapperStuff = async (tagData: any) => {
|
|||||||
const genlabel = await labelingProcess({
|
const genlabel = await labelingProcess({
|
||||||
line: lineNum.toString(),
|
line: lineNum.toString(),
|
||||||
});
|
});
|
||||||
|
autoLabelCreated();
|
||||||
console.log(genlabel);
|
console.log(genlabel);
|
||||||
if (genlabel?.success) {
|
if (genlabel?.success) {
|
||||||
const createPrintData = {
|
const createPrintData = {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import addReader from "./route/addReader.js";
|
|||||||
import updateReader from "./route/updateReader.js";
|
import updateReader from "./route/updateReader.js";
|
||||||
import manualTrigger from "./route/manualTagRead.js";
|
import manualTrigger from "./route/manualTagRead.js";
|
||||||
import getReaders from "./route/getReaders.js";
|
import getReaders from "./route/getReaders.js";
|
||||||
|
import resetRatio from "./route/resetRatio.js";
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
@@ -15,6 +16,7 @@ const routes = [
|
|||||||
updateReader,
|
updateReader,
|
||||||
manualTrigger,
|
manualTrigger,
|
||||||
getReaders,
|
getReaders,
|
||||||
|
resetRatio,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
|
|||||||
54
server/services/rfid/route/resetRatio.ts
Normal file
54
server/services/rfid/route/resetRatio.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
|
import { addReader } from "../controller/addReader.js";
|
||||||
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import type { User } from "../../../types/users.js";
|
||||||
|
import { verify } from "hono/jwt";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
import { resetRatios } from "../controller/readerControl.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
export const ReaderBody = z.object({
|
||||||
|
reader: z.string().openapi({ example: "wrapper1" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["rfid"],
|
||||||
|
summary: "Resets the ratio on the reader",
|
||||||
|
method: "post",
|
||||||
|
path: "/resetRatio",
|
||||||
|
//middleware: authMiddleware,
|
||||||
|
//description: "Adding in a new reader to add to the network.",
|
||||||
|
request: {
|
||||||
|
body: { content: { "application/json": { schema: ReaderBody } } },
|
||||||
|
},
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const body = await c.req.json();
|
||||||
|
apiHit(c, { endpoint: "/resetRatio", lastBody: body });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const reset = await resetRatios(body.reader);
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: reset.success,
|
||||||
|
message: reset.message,
|
||||||
|
},
|
||||||
|
200
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: `${body.name} encountered an error while trying to reset the readers ratio`,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user