feat(labeling): ratios reset for labeling implemeneted
This commit is contained in:
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user