Merged in feature/hyo-dashboard (pull request #1)

Feature/hyo dashboard
This commit is contained in:
hyojin kim 2023-09-13 04:41:35 +00:00
commit 2096a56164
22 changed files with 5640 additions and 139 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
NEXT_PUBLIC_BASE_API_URL="http://13.209.39.139:32171"

View File

@ -1,34 +1,26 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# GSEPS Control Center
## Getting Started
## 프로젝트 소개
First, run the development server:
- 카메라에서 수집된 사진 이미지를 inference 한 결과 이미지와 결과 데이터를 히스토그램 차트로 보여주는 Control Center 화면
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```
### 배포 주소
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
- [GSEPS Control Center](http://13.209.39.139:31985/dashboard)
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
### 기술 스택
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
- react
- next.js
- typescript
- tailwindCSS
- nivo chart
## Learn More
### 화면 구성
To learn more about Next.js, take a look at the following resources:
<img src="./public/readmeImage.png">
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
### 주요 기능
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
- 카메라에서 수집된 사진 원본 이미지, inference 결과 이미지 제공
- inference 결과 데이터에 따른 히스토그램 차트 제공

54
dockerfile Normal file
View File

@ -0,0 +1,54 @@
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager (Yarn 2)
COPY package.json yarn.lock* ./
RUN yarn install --immutable
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
# RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
# ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]

View File

@ -1,5 +1,17 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'standalone',
images: {
remotePatterns: [
{
protocol: 'http',
hostname: '13.209.39.139',
port: '31192',
pathname: '/api/**',
},
],
},
compiler: {
styledComponents: true,
},

74
package-lock.json generated
View File

@ -8,11 +8,19 @@
"name": "front-boilerplate",
"version": "0.0.1",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@nivo/bar": "^0.83.0",
"@nivo/core": "^0.83.0",
"@nivo/line": "^0.83.0",
"@sdt/sdt-ui-kit": "^0.1.20",
"@tanstack/react-query": "^4.33.0",
"autoprefixer": "10.4.15",
"axios": "^1.4.0",
"cookies-next": "^3.0.0",
"date-fns": "^2.30.0",
"eslint": "8.47.0",
"eslint-config-next": "13.4.19",
"lodash": "^4.17.21",
@ -2817,6 +2825,29 @@
"react": ">= 16.14.0 < 19.0.0"
}
},
"node_modules/@nivo/bar": {
"version": "0.83.0",
"resolved": "https://registry.npmjs.org/@nivo/bar/-/bar-0.83.0.tgz",
"integrity": "sha512-QXN6BcT1PiT/YViyoDU4G5mytbOUP1jYbuQmJhDDxKPMLNcZ/pHfThedRGVfDoD1poHBRJtV6mbgeCpAVmlTtw==",
"dependencies": {
"@nivo/annotations": "0.83.0",
"@nivo/axes": "0.83.0",
"@nivo/colors": "0.83.0",
"@nivo/core": "0.83.0",
"@nivo/legends": "0.83.0",
"@nivo/scales": "0.83.0",
"@nivo/tooltip": "0.83.0",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-scale": "^3.2.3",
"@types/d3-shape": "^2.0.0",
"d3-scale": "^3.2.3",
"d3-shape": "^1.3.5",
"lodash": "^4.17.21"
},
"peerDependencies": {
"react": ">= 16.14.0 < 19.0.0"
}
},
"node_modules/@nivo/colors": {
"version": "0.83.0",
"resolved": "https://registry.npmjs.org/@nivo/colors/-/colors-0.83.0.tgz",
@ -4503,6 +4534,21 @@
"integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==",
"dev": true
},
"node_modules/date-fns": {
"version": "2.30.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
"integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
"dependencies": {
"@babel/runtime": "^7.21.0"
},
"engines": {
"node": ">=0.11"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/date-fns"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -10500,6 +10546,26 @@
"prop-types": "^15.7.2"
}
},
"@nivo/bar": {
"version": "0.83.0",
"resolved": "https://registry.npmjs.org/@nivo/bar/-/bar-0.83.0.tgz",
"integrity": "sha512-QXN6BcT1PiT/YViyoDU4G5mytbOUP1jYbuQmJhDDxKPMLNcZ/pHfThedRGVfDoD1poHBRJtV6mbgeCpAVmlTtw==",
"requires": {
"@nivo/annotations": "0.83.0",
"@nivo/axes": "0.83.0",
"@nivo/colors": "0.83.0",
"@nivo/core": "0.83.0",
"@nivo/legends": "0.83.0",
"@nivo/scales": "0.83.0",
"@nivo/tooltip": "0.83.0",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-scale": "^3.2.3",
"@types/d3-shape": "^2.0.0",
"d3-scale": "^3.2.3",
"d3-shape": "^1.3.5",
"lodash": "^4.17.21"
}
},
"@nivo/colors": {
"version": "0.83.0",
"resolved": "https://registry.npmjs.org/@nivo/colors/-/colors-0.83.0.tgz",
@ -11761,6 +11827,14 @@
"integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==",
"dev": true
},
"date-fns": {
"version": "2.30.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
"integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
"requires": {
"@babel/runtime": "^7.21.0"
}
},
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",

View File

@ -1,5 +1,5 @@
{
"name": "front-boilerplate",
"name": "gesps-front",
"version": "0.0.1",
"private": true,
"scripts": {
@ -9,11 +9,19 @@
"lint": "next lint"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@nivo/bar": "^0.83.0",
"@nivo/core": "^0.83.0",
"@nivo/line": "^0.83.0",
"@sdt/sdt-ui-kit": "^0.1.20",
"@tanstack/react-query": "^4.33.0",
"autoprefixer": "10.4.15",
"axios": "^1.4.0",
"cookies-next": "^3.0.0",
"date-fns": "^2.30.0",
"eslint": "8.47.0",
"eslint-config-next": "13.4.19",
"lodash": "^4.17.21",

BIN
public/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
public/readmeImage.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

View File

@ -0,0 +1,12 @@
import { ResultDataType } from '@/app/dashboard/types';
import { afterAxios, fetchApi } from '../config';
export interface GetResultApiRequestType {}
export type GetResultApiResponseType = ResultDataType;
export const getResultApi = (): Promise<GetResultApiResponseType> =>
fetchApi({
url: 'blokworks/v1/transport/inference/results',
method: 'GET',
}).then(afterAxios);

View File

@ -0,0 +1,49 @@
import React from 'react';
import { ResponsiveBar } from '@nivo/bar';
function BarChart({ data }: any) {
return (
<div className="w-full h-[calc(100vh-300px)]">
<ResponsiveBar
data={data}
keys={['count']}
indexBy="range"
margin={{ top: 50, right: 20, bottom: 50, left: 60 }}
padding={0.3}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
colors={{ scheme: 'nivo' }}
borderColor={{
from: 'color',
modifiers: [['darker', 1.6]],
}}
// maxValue={10}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
}}
enableLabel={false}
labelTextColor={{
from: 'color',
modifiers: [['darker', 1.6]],
}}
legends={[]}
role="application"
ariaLabel="Nivo bar chart demo"
barAriaLabel={(e) =>
e.id + ': ' + e.formattedValue + ' in country: ' + e.indexValue
}
/>
</div>
);
}
export default BarChart;

View File

@ -0,0 +1,77 @@
/* eslint-disable @next/next/no-img-element */
'use client';
import React from 'react';
import BarChart from './BarChart';
import { format } from 'date-fns';
import Image from 'next/image';
import useDashboard from '../hooks/useDashboard';
import { Button } from '@sdt/sdt-ui-kit';
import { useQueryClient } from '@tanstack/react-query';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faArrowsRotate } from '@fortawesome/free-solid-svg-icons';
function Dashboard() {
const { getResult, convertChartData } = useDashboard();
const queryClient = useQueryClient();
return (
<div>
<div className=" flex items-center h-[80px] px-12 bg-white border-b border-gray-300">
<Image src={'/logo.png'} alt="logo" width={100} height={50} />
</div>
<div className="grid grid-cols-8 p-12 h-[calc(100vh-150px)]">
{getResult.data && (
<>
<div className="mt-20 col-span-2">
<h2 className="text-lg font-semibold text-center">Input Image</h2>
<div className="relative w-full h-[calc(50vh-250px)] mt-2 mb-12">
<img
src={getResult.data?.origin.imageUrl}
alt="origin image"
className="w-full h-full"
/>
</div>
<h2 className="text-lg font-semibold text-center">
Inference Result Image
</h2>
<div className="relative w-full h-[calc(50vh-250px)] mt-2">
<img
src={getResult.data?.latest.imageUrl}
alt="inference image"
className="w-full h-full"
/>
</div>
</div>
<div className="col-span-6">
<div className="text-right text-lg font-semibold">
:{' '}
{format(
getResult.data?.latest.timestamp,
'yyyy-MM-dd HH:mm:ss',
)}
<Button
onClick={() => queryClient.invalidateQueries(['result'])}
backgroundColor="#fafafa"
className="ml-2"
>
<FontAwesomeIcon
icon={faArrowsRotate}
style={{ color: '#7a7a7a' }}
/>
</Button>
</div>
<BarChart data={convertChartData} />
</div>
</>
)}
</div>
<div className="text-center text-[#7a7a7a]">
Copyright 2023 SDT Inc. All rights reserved.
</div>
</div>
);
}
export default Dashboard;

View File

@ -0,0 +1,29 @@
export const DUMMY_DATA = {
latest: {
imageUrl:
'http://13.209.39.139:31192/api/v1/buckets/gseps-test-a/objects/download?prefix=MjAyMzA5MDctMTEyNzU2LmpwZw==&version_id=null',
timestamp: 1694073245526,
particleSizeRatio: [
{
range: 186,
count: 1,
},
{
range: 102.5,
count: 1,
},
{
range: 79.5,
count: 8,
},
{
range: 313.5,
count: 1,
},
{
range: 146.5,
count: 1,
},
],
},
};

View File

@ -0,0 +1,27 @@
import React, { useMemo } from 'react';
import { getResultApi } from '@/api/dashboard/resultApi';
import { useQuery } from '@tanstack/react-query';
function useDashboard() {
const getResult = useQuery(['result'], () => getResultApi(), {
refetchOnWindowFocus: false,
});
/**
* bar chart convert data
*/
const convertChartData = useMemo(() => {
const data = getResult.data?.latest.particleSizeRatio?.map((result, i) => {
return {
range: Number(result.range).toFixed(2),
count: result.count,
};
});
return data;
}, [getResult.data]);
return { getResult, convertChartData };
}
export default useDashboard;

View File

@ -0,0 +1,7 @@
export default function LoginLayout({
children,
}: {
children: React.ReactNode;
}) {
return <>{children}</>;
}

View File

@ -0,0 +1,8 @@
import React from 'react';
import Dashboard from './components/Dashboard';
function LoginPage() {
return <Dashboard />;
}
export default LoginPage;

View File

@ -0,0 +1,12 @@
import { StaticImageData } from 'next/image';
export interface ResultDataType {
origin: {
imageUrl: string;
};
latest: {
imageUrl: string;
timestamp: number;
particleSizeRatio: { range: string; count: number }[];
};
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@ -8,8 +8,8 @@ import { defaultInstance } from '@/api/config';
import { cookies } from 'next/headers';
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
title: 'GSEPS',
description: 'GSEPS Control Center',
};
export default function RootLayout({

View File

@ -1,113 +1,15 @@
import Image from 'next/image';
'use client';
import React, { useEffect } from 'react';
import { useRouter } from 'next/navigation';
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">src/app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>
const router = useRouter();
const targetRoutePath = '/dashboard';
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
useEffect(() => {
router.push(targetRoutePath);
}, [router]);
<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore the Next.js 13 playground.
</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
return <main></main>;
}

View File

@ -9,9 +9,9 @@ export default function Layout({ children }: { children: React.ReactNode }) {
useSilentAuth();
return (
<div className="w-full overflow-hidden">
<div className="flex pt-14">
<main className={`w-full p-12`}>{children}</main>
<div className="w-full overflow-hidden bg-[#fafafa]">
<div className="flex">
<main className={`w-full h-screen`}>{children}</main>
</div>
<Alert

View File

@ -35,7 +35,7 @@ function useSilentAuth() {
!SDT_AT &&
!(pathname.includes('login') || pathname.includes('reset-password'))
) {
router.push(`/login`);
// router.push(`/login`);
handleLogout();
}
}, [SDT_AT, handleLogout, loggedIn, pathname, router, setSignOut]);

5237
yarn.lock Normal file

File diff suppressed because it is too large Load Diff