import FormControl from '@mui/material/FormControl'; import InputLabel from '@mui/material/InputLabel'; import MenuItem from '@mui/material/MenuItem'; import Select, { SelectChangeEvent } from '@mui/material/Select'; import { GetServerSideProps } from 'next'; import Head from 'next/head'; import Link from 'next/link'; import { useRouter } from 'next/router' import { parseCookies } from 'nookies'; import React, { useEffect, useState } from 'react' import BasicButton from '../../components/buttons/basicButton/BasicButton'; import { BasicButtonView } from '../../components/buttons/basicButton/BasicButtonView'; import { LineBarChart } from '../../components/graph/LineBarChart'; import LineChart from '../../components/graph/LineChart'; import Header from '../../components/header/Header' import PageTitle from '../../components/pageTitle/PageTitle'; import { api } from '../../services/api'; import { EconomiaAcumulada } from '../../services/economiaAcumulada'; import { EvolucaoPld } from '../../services/evolucaoPld'; import getAPIClient from '../../services/ssrApi'; import { GoBack, PldGraphView, PldTableView } from '../../styles/layouts/pld/PldView' import RenderIf from '../../utils/renderIf' interface pldInterface { tableData: any, graphByHourData: any, graphByMonthData: any userName: string, clientMonth: any } export default function pld({tableData, graphByHourData, graphByMonthData, userName, clientMonth}: pldInterface) { const router = useRouter() const { region } = router.query const [date, setDate] = useState(''); const [select, setSelect] = useState('NORDESTE'); const [page, setPage] = useState('table') const [day, setDay] = useState(null) const [dataByDay, setDataByDay] = useState([]) const [sul, setSul] = useState([]) const [norte, setNorte] = useState([]) const [sudeste, setSudeste] = useState([]) const [nordeste, setNordeste] = useState([]) const handleChange = (event: SelectChangeEvent) => { setSelect(event.target.value); }; const handleChangeDay = (event: SelectChangeEvent) => { setDay(event.target.value); }; function getDataByDay() { api.post('/pld/daily', { "limit": 20, "offset": 0, "filters": [ {"type" : "=", "field" : "mes_ref", "value": `${day}/2022`, "row": true}, {"type" : "=", "field" : "pld.submercado", "value": select} ], "order": [{ "field": "day_calc", "direction": "asc" }] }).then(res => { setDataByDay(res.data.data) }).catch(exception => console.log(exception)) } function getDataByHour() { api.post('/pld/schedule', { "limit": 20, "offset": 0, "filters": [ {"type" : "=", "field" : "dia_num", "value": date, "row": true}, {"type" : "=", "field" : "submercado", "value": "SUL"} ], "order": [{ "field": "hour", "direction": "asc" }] }).then(res => { setSul(res.data.data) }).catch(exception => console.log(exception)) api.post('/pld/schedule', { "limit": 20, "offset": 0, "filters": [ {"type" : "=", "field" : "dia_num", "value": date, "row": true}, {"type" : "=", "field" : "submercado", "value": "SUDESTE"} ], "order": [{ "field": "hour", "direction": "asc" }] }).then(res => { setSudeste(res.data.data) }).catch(exception => console.log(exception)) api.post('/pld/schedule', { "limit": 20, "offset": 0, "filters": [ {"type" : "=", "field" : "dia_num", "value": date, "row": true}, {"type" : "=", "field" : "submercado", "value": "NORTE"} ], "order": [{ "field": "hour", "direction": "asc" }] }).then(res => { setNorte(res.data.data) }).catch(exception => console.log(exception)) api.post('/pld/schedule', { "limit": 20, "offset": 0, "filters": [ {"type" : "=", "field" : "dia_num", "value": date, "row": true}, {"type" : "=", "field" : "submercado", "value": "NORDESTE"} ], "order": [{ "field": "hour", "direction": "asc" }] }).then(res => { setNordeste(res.data.data) }).catch(exception => console.log(exception)) } function handleColorNorte(value, region) { if (value <= tableData.result[1].norte_min) return 'green' else if (value >= tableData.result[0][`${region}_max`]) return 'red' else if (tableData.result[0][`${region}_max`] - value > tableData.result[0][`${region}_max`]/2) return 'dullGreen' else if (tableData.result[1][`${region}_min`] - value <= tableData.result[1][`${region}_min`]) return 'dullRed' } const dateFormated = new Date() useEffect(() => { getDataByHour() getDataByDay() console.log(dataByDay) }, [date, day, select]) return (
Smart Energia - PLD
{'< Voltar para Visão Geral'} { tableData.data.map(data => { return <> }) } { tableData.result.map((data, index) => { if (index === 0) { return <> } else if (index===1) { return <> } else if (index===2) { return <> } }) }
Mês Nordeste Norte Sudeste Sul
{data.year_month_formatted} {parseFloat(data.nordeste).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sul).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}
Máximo {parseFloat(data.nordeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sul_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}
Mínimo {parseFloat(data.nordeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sul_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}
Desv. Padrão {parseFloat(data.nordeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sul_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}
setPage('perMouth')}>

Valores Diários

setPage('perDate')}>

Valores Horários

setPage('table')}>{'< Voltar para tabela PLD'}
Região
Mês
setPage('table')}>{'< Voltar para tabela PLD'}
setDate(value.target.value)}/> {/* console.log()}/> */}
) } export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) let tableData = []; let clientMonth = []; await apiClient.post('/pld/list').then(res => { tableData = res.data }).catch(res => { console.log(res) }) await apiClient.post('/pld', { "filters": [], "fields": ["mes_ref"], "distinct": true }).then(res => { clientMonth = res.data.data }).catch(res => { console.log(res) }) if (!token) { return { redirect: { destination: '/', permanent: false } } } return { props: { tableData, userName, clientMonth } } }