OperationTime. Adapt Dto.

This commit is contained in:
ngfrolov 2022-09-28 18:04:55 +05:00
parent 564ea43a80
commit 1f8bf12821

View File

@ -2,7 +2,7 @@ import React, { ReactNode, useEffect, useState } from 'react'
import { Col, Row, Select } from 'antd' import { Col, Row, Select } from 'antd'
import { Moment } from 'moment' import { Moment } from 'moment'
import { DateRangeWrapper, makeColumn, Table } from '@components/Table' import { DateRangeWrapper, makeColumn, makeNumericRender, Table } from '@components/Table'
import LoaderPortal from '@components/LoaderPortal' import LoaderPortal from '@components/LoaderPortal'
import { arrayOrDefault, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import D3HorizontalChart from '@components/d3/D3HorizontalChart' import D3HorizontalChart from '@components/d3/D3HorizontalChart'
@ -17,68 +17,10 @@ type DataType = {
subsystemName: string subsystemName: string
usedTimeHours: number usedTimeHours: number
kUsage: number kUsage: number
k2: number sumDepthInterval: number
operationCount: number
} }
const _data: DataType[] = [
{
"idSubsystem": 1,
"subsystemName": "Keруррурk",
"usedTimeHours": 2,
"kUsage": 0.45,
"k2": 1
},
{
"idSubsystem": 2,
"subsystemName": "Lol",
"usedTimeHours": 0,
"kUsage": 0.24,
"k2": 0
},
{
"idSubsystem": 3,
"subsystemName": "kek",
"usedTimeHours": 0,
"kUsage": 0.37,
"k2": 0
},
{
"idSubsystem": 4,
"subsystemName": "keklol",
"usedTimeHours": 0,
"kUsage": 0.73,
"k2": 0
},
{
"idSubsystem": 5,
"subsystemName": "Keруррурk1",
"usedTimeHours": 2,
"kUsage": 0.45,
"k2": 1
},
{
"idSubsystem": 6,
"subsystemName": "Lol2",
"usedTimeHours": 0,
"kUsage": 0.24,
"k2": 0
},
{
"idSubsystem": 7,
"subsystemName": "kek3",
"usedTimeHours": 0,
"kUsage": 0.37,
"k2": 0
},
{
"idSubsystem": 8,
"subsystemName": "keklol4",
"usedTimeHours": 0,
"kUsage": 0.73,
"k2": 0
},
]
const subsystemColors = [ const subsystemColors = [
'#1abc9c', '#1abc9c',
'#16a085', '#16a085',
@ -107,14 +49,15 @@ const tableColumns = [
<div style={{ backgroundColor: color, padding: '5px 0' }} /> <div style={{ backgroundColor: color, padding: '5px 0' }} />
) }), ) }),
makeColumn('Подсистема', 'subsystemName'), makeColumn('Подсистема', 'subsystemName'),
makeColumn('Время работы, ч', 'usedTimeHours'), makeColumn('% использования', 'kUsage', { render: val => (+val * 100).toFixed(2) }),
makeColumn('Активность, %', 'kUsage', { render: (d) => d * 100 }) makeColumn('Проходка, м', 'sumDepthInterval', {render: makeNumericRender(2)}),
makeColumn('Время работы, ч', 'usedTimeHours', {render: makeNumericRender(2)}),
makeColumn('Кол-во запусков', 'operationCount'),
] ]
const OperationTime = () => { const OperationTime = () => {
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [data1, setData1] = useState([]) const [data, setData] = useState<DataType[]>([])
const [data, setData] = useState(_data)
const [dateRange, setDateRange] = useState<Moment[]>([]) const [dateRange, setDateRange] = useState<Moment[]>([])
const [childrenData, setChildrenData] = useState<ReactNode[]>([]) const [childrenData, setChildrenData] = useState<ReactNode[]>([])
const [well] = useWell() const [well] = useWell()
@ -127,14 +70,14 @@ const OperationTime = () => {
async () => { async () => {
if (!well.id) return if (!well.id) return
try { try {
setData1(arrayOrDefault(await SubsystemOperationTimeService.getStat( setData(arrayOrDefault(await SubsystemOperationTimeService.getStat(
well.id, well.id,
undefined, undefined,
dateRange[1] ? dateRange[0]?.toISOString() : undefined, dateRange[1] ? dateRange[0]?.toISOString() : undefined,
dateRange[1]?.toISOString(), dateRange[1]?.toISOString(),
))) )))
} catch(e) { } catch(e) {
setData1([]) setData([])
throw e throw e
} }
}, },
@ -145,7 +88,7 @@ const OperationTime = () => {
}, [dateRange]) }, [dateRange])
useEffect(() => { useEffect(() => {
setChildrenData(_data.map((item) => ( setChildrenData(data.map((item) => (
<Option key={item.subsystemName}> <Option key={item.subsystemName}>
{item.subsystemName} {item.subsystemName}
</Option> </Option>
@ -154,7 +97,7 @@ const OperationTime = () => {
const selectChange = (value: string[]) => { const selectChange = (value: string[]) => {
setData(_data.reduce((previousValue: DataType[], currentValue) => { setData(data.reduce((previousValue: DataType[], currentValue) => {
if (value.includes(currentValue.subsystemName)) { if (value.includes(currentValue.subsystemName)) {
previousValue.push(currentValue) previousValue.push(currentValue)
} }