Skip to content

Commit

Permalink
report vercel test
Browse files Browse the repository at this point in the history
  • Loading branch information
CropWatchDevelopment committed Oct 22, 2024
1 parent 64dfe76 commit c2513bf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"@supabase/ssr": "^0.4.0",
"@supabase/supabase-js": "^2.45.0",
"bufferutil": "^4.0.8",
"canvas": "^2.11.2",
"chart.js": "4",
"chartjs-node-canvas": "^4.1.6",
"d3-node": "^3.0.0",
"highcharts-export-server": "^4.0.2",
"leaflet": "^1.9.4",
Expand Down
32 changes: 23 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// Import necessary modules
import { error, redirect, type RequestHandler } from "@sveltejs/kit";
import PdfPrinter from 'pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
import fs from 'fs';
import path from 'path';
import moment from "moment";
import D3Node from 'd3-node';
import * as d3 from 'd3';
import sharp from 'sharp';

// Define the GET handler
export const GET: RequestHandler = async ({ params, fetch, locals: { supabase, safeGetSession } }) => {
export const GET: RequestHandler = async ({ params, fetch, url, locals: { supabase, safeGetSession } }) => {
const session = await safeGetSession();

if (!session?.user) {
throw redirect(303, '/auth/unauthorized');
}

const month = url.searchParams.get('month');
if (!month) {
throw error(400, 'You must include a month');
}
if (moment(month).isAfter(new Date())) {
throw error(400, 'month must be in the past');
}

const devEui = params.dev_eui;

if (!devEui) {
Expand All @@ -25,7 +26,7 @@ export const GET: RequestHandler = async ({ params, fetch, locals: { supabase, s

// Fetch the data for the device
const response = await fetch(
`/api/v1/devices/${params.dev_eui}/data?firstDataDate=${moment().startOf('month').toISOString()}&lastDataDate=${moment().endOf('month').toISOString()}&timezone=asia/tokyo`
`/api/v1/devices/${params.dev_eui}/data?firstDataDate=${moment(month).startOf('month').toISOString()}&lastDataDate=${moment(month).endOf('month').toISOString()}&timezone=asia/tokyo`
);

if (!response.ok) {
Expand Down Expand Up @@ -83,7 +84,7 @@ export const GET: RequestHandler = async ({ params, fetch, locals: { supabase, s
['部署:', 'ペットフード事業部'],
['使用場所:', location.name],
['センサー名:', data.device.name],
['測定期間', `${moment().startOf('month').format('YYYY/MM/DD')} - ${moment().endOf('month').format('YYYY/MM/DD')}`],
['測定期間', `${moment(month).startOf('month').format('YYYY/MM/DD')} - ${moment(month).endOf('month').format('YYYY/MM/DD')}`],
['DevEUI', devEui]
];
const sensorDetails = [
Expand Down
16 changes: 8 additions & 8 deletions src/routes/app/devices/[dev_eui]/reports/co2-report-01.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
const sampleCount = combinedArray.length;

const sensorDetails = [
['Data Type', 'Temperature'],
['データタイプ', '温度'],
['サンプリング数', sampleCount.toString()],
['最大値', `${maxTemperature}℃`],
['最小値', `${minTemperature}℃`],
Expand All @@ -85,7 +85,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
) / sampleCount;

const humidityDetails = [
['Data Type', 'Humidity'],
['データタイプ', '湿度'],
['サンプリング数', sampleCount.toString()],
['最大湿度', `${maxHumidity}%`],
['最小湿度', `${minHumidity}%`],
Expand All @@ -100,7 +100,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
) / sampleCount;

const co2Details = [
['Data Type', 'CO2'],
['データタイプ', 'CO2'],
['サンプリング数', sampleCount.toString()],
['最大CO2濃度', `${maxCO2}ppm`],
['最小CO2濃度', `${minCO2}ppm`],
Expand Down Expand Up @@ -139,7 +139,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
const docDefinition = {
content: [
{
text: '週次 (or 月次) 温度データレポート',
text: '月次データレポート',
style: 'header',
alignment: 'center',
margin: [0, 0, 0, 10],
Expand All @@ -150,7 +150,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
width: '25%',
stack: [
{
text: 'Report Details',
text: 'レポート詳細',
style: 'subheader',
margin: [0, 0, 0, 3],
},
Expand All @@ -167,7 +167,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
width: '25%',
stack: [
{
text: 'Temperature Details',
text: '温度詳細',
style: 'subheader',
margin: [0, 0, 0, 3],
},
Expand All @@ -184,7 +184,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
width: '25%',
stack: [
{
text: 'Humidity Details',
text: '湿度詳細',
style: 'subheader',
margin: [0, 0, 0, 3],
},
Expand All @@ -201,7 +201,7 @@ export function buildPdfDefinition(data: any, chartImageBase64: string) {
width: '25%',
stack: [
{
text: 'CO2 Details',
text: 'Co2 詳細',
style: 'subheader',
margin: [0, 0, 0, 3],
},
Expand Down

0 comments on commit c2513bf

Please sign in to comment.