add pcs to graph & turn off buzzer with timer

This commit is contained in:
Muhammad Izza Alfiansyah 2024-07-08 18:03:21 +07:00
parent 1364b1b5a3
commit 6dda8c69c1
2 changed files with 48 additions and 16 deletions

View File

@ -279,7 +279,7 @@ export default function () {
? lastHistori()?.berhasil ? lastHistori()?.berhasil
? "bg-green-500" ? "bg-green-500"
: "bg-red-500" : "bg-red-500"
: "bg-orange-500") + " rounded shadow text-white p-10" : "bg-orange-500") + " rounded shadow text-white p-8"
} }
> >
<div class="text-3xl"> <div class="text-3xl">

View File

@ -8,18 +8,25 @@ import { Chart, registerables } from "chart.js";
export default function () { export default function () {
let canvas: any; let canvas: any;
const [items, setItems] = createSignal<KondisiTapai[]>([]); const [items, setItems] = createSignal<KondisiTapai[]>([]);
const [labels, setLabels] = createSignal<any>([]);
const getData = async () => { const getData = async () => {
const { data } = await supabase const { data } = await supabase
.from("kondisi_tapai") .from("kondisi_tapai")
.select("*") .select("*")
// .eq("pengujian", true) // .eq("pengujian", true)
.order("created_time", { ascending: false }); .order("created_time", { ascending: true });
setItems(data as KondisiTapai[]); setItems(data as KondisiTapai[]);
}; };
const getLamaJam = (created_time: number) => {
const epochTimeAwal = items()[0].created_time;
let lamaJam = created_time - epochTimeAwal;
lamaJam = Math.round(lamaJam / 3600);
return lamaJam;
};
const renderChart = async () => { const renderChart = async () => {
let labels = []; let labels = [];
let kadarRegresi = []; let kadarRegresi = [];
@ -27,15 +34,14 @@ export default function () {
let jam: any[] = []; let jam: any[] = [];
let i = 0; let i = 0;
let j = 0; let j = 0;
items().forEach((item) => {
const lamaJam = getLamaJam(item.created_time);
const epochTimeAwal = items()[items().length - 1].created_time; if (lamaJam % 6 == 0) {
items() jam.push(lamaJam);
.reverse()
.forEach((item) => {
const lamaJam = item.created_time - epochTimeAwal;
jam.push(Math.round(lamaJam / 3600));
kadarAktual.push(item.kadar_gas); kadarAktual.push(item.kadar_gas);
}); }
});
while (i <= 72) { while (i <= 72) {
const jamPengujian = jam[j]; const jamPengujian = jam[j];
@ -56,8 +62,6 @@ export default function () {
j += 1; j += 1;
} }
setLabels(labels);
new Chart(canvas, { new Chart(canvas, {
type: "line", type: "line",
data: { data: {
@ -80,6 +84,10 @@ export default function () {
], ],
}, },
options: { options: {
interaction: {
intersect: false,
mode: "index",
},
responsive: true, responsive: true,
scales: { scales: {
x: { x: {
@ -96,6 +104,28 @@ export default function () {
}, },
min: 0, min: 0,
max: 10, max: 10,
ticks: {
callback: (val) => {
return val + "%";
},
},
},
},
plugins: {
tooltip: {
callbacks: {
title(_) {
return "";
},
label(tooltipItem) {
return (
tooltipItem.dataset.label +
": " +
tooltipItem.parsed.y.toFixed(2) +
"%"
);
},
},
}, },
}, },
}, },
@ -124,8 +154,10 @@ export default function () {
class="bg-white rounded shadow p-5" class="bg-white rounded shadow p-5"
classList={{ hidden: items().length < 1 }} classList={{ hidden: items().length < 1 }}
> >
<canvas ref={canvas} style={{ "max-height": "300px" }}></canvas> <canvas ref={canvas} style={{ "max-height": "400px" }}></canvas>
<div class="text-sm text-center">Jam Ke-</div> <div class="text-sm text-center" style={{ "font-family": "Arial" }}>
Jam Ke-
</div>
</div> </div>
<div class="bg-white rounded shadow p-5"> <div class="bg-white rounded shadow p-5">
<Table <Table
@ -138,10 +170,10 @@ export default function () {
"Suhu", "Suhu",
"Kelembaban", "Kelembaban",
]} ]}
items={items().map((item, i) => [ items={items().map((item) => [
getDates(item.created_time), getDates(item.created_time),
getTimes(item.created_time).slice(0, 5), getTimes(item.created_time).slice(0, 5),
labels()[i], getLamaJam(item.created_time),
item.kadar_gas.toString().slice(0, 4) + " %", item.kadar_gas.toString().slice(0, 4) + " %",
item.suhu.toString().slice(0, 4) + " C", item.suhu.toString().slice(0, 4) + " C",
item.kelembaban.toString().slice(0, 4) + " %", item.kelembaban.toString().slice(0, 4) + " %",