asb_cloud_front/src/pages/TelemetryView/index.jsx

211 lines
6.4 KiB
React
Raw Normal View History

import {useState, useEffect} from 'react'
import {Row, Col, Select} from 'antd'
2021-08-12 17:47:16 +05:00
import {Column} from './Column'
import {CustomColumn} from './CustomColumn'
import ActiveMessagesOnline from './ActiveMessagesOnline'
import LoaderPortal from '../../components/LoaderPortal'
import {UserOfWells} from './UserOfWells'
import {Subscribe} from '../../services/signalr'
import {DataService} from '../../services/api'
import {ModeDisplay} from "../../components/ModeDisplay"
import notify from "../../components/notify"
import '../../styles/message.css'
const {Option} = Select
const dash = [7, 3]
2021-04-16 15:50:01 +05:00
const blockHeightGroup = {
label: "Высота блока",
2021-04-16 15:50:01 +05:00
yDisplay: false,
linePv: {label: "blockPosition", units: 'м', xAccessorName: "blockPosition", yAccessorName: "date", color: '#333'},
lineOther: {
label: "wellDepth",
units: 'м',
xAccessorName: "wellDepth",
yAccessorName: "date",
color: '#333',
showLine: false,
xConstValue: 30
},
2021-04-16 15:50:01 +05:00
}
const blockSpeedGroup = {
label: "Скорость блока",
2021-04-16 15:50:01 +05:00
yDisplay: false,
linePv: {label: "blockSpeed", units: 'м/ч', xAccessorName: "blockSpeed", yAccessorName: "date", color: '#0a0'},
lineSp: {label: "blockSpeedSp", units: 'м/ч', xAccessorName: "blockSpeedSp", yAccessorName: "date", color: '#0a0'},
2021-04-16 15:50:01 +05:00
}
const pressureGroup = {
label: "Давление",
yDisplay: false,
linePv: {label: "pressure", units: 'атм', xAccessorName: "pressure", yAccessorName: "date", color: '#c00'},
lineSp: {label: "pressureSp", units: 'атм', xAccessorName: "pressureSp", yAccessorName: "date", color: '#c00'},
lineIdle: {label: "pressureIdle", units: 'атм', xAccessorName: "pressureIdle", yAccessorName: "date", color: '#c00'},
2021-04-16 15:50:01 +05:00
linesOther: [
{
label: "мекс. перепад",
units: 'атм',
xAccessorName: "pressureDeltaLimitMax",
yAccessorName: "date",
color: '#c00'
},
2021-04-16 15:50:01 +05:00
],
}
const axialLoadGroup = {
label: "Осевая нагрузка",
2021-04-16 15:50:01 +05:00
yDisplay: false,
linePv: {label: "axialLoad", units: 'т', xAccessorName: "axialLoad", yAccessorName: "date", color: '#00a'},
lineSp: {label: "axialLoadSp", units: 'т', xAccessorName: "axialLoadSp", yAccessorName: "date", color: '#00a', dash},
2021-04-16 15:50:01 +05:00
linesOther: [
{label: "axialLoadLimitMax", units: 'т', xAccessorName: "axialLoadLimitMax", yAccessorName: "date", color: '#00a'},
2021-04-16 15:50:01 +05:00
],
}
const hookWeightGroup = {
label: "Вес на крюке",
2021-04-16 15:50:01 +05:00
yDisplay: false,
linePv: {label: "hookWeight", units: 'т', xAccessorName: "hookWeight", yAccessorName: "date", color: '#0aa'},
lineIdle: {
label: "hookWeightIdle",
units: 'т',
xAccessorName: "hookWeightIdle",
yAccessorName: "date",
color: '#0aa',
dash
},
2021-04-16 15:50:01 +05:00
linesOther: [
{
label: "hookWeightLimitMin",
units: 'т',
xAccessorName: "hookWeightLimitMin",
yAccessorName: "date",
color: '#0aa'
},
{
label: "hookWeightLimitMax",
units: 'т',
xAccessorName: "hookWeightLimitMax",
yAccessorName: "date",
color: '#0aa'
},
2021-04-16 15:50:01 +05:00
],
}
const rotorTorqueGroup = {
label: "Момент на роторе",
2021-04-16 15:50:01 +05:00
yDisplay: false,
linePv: {label: "rotorTorque", units: 'кН·м', xAccessorName: "rotorTorque", yAccessorName: "date", color: '#a0a'},
lineSp: {label: "rotorTorqueSp", units: 'кН·м', xAccessorName: "rotorTorqueSp", yAccessorName: "date", color: '#a0a'},
lineIdle: {
label: "rotorTorqueIdle",
units: 'кН·м',
xAccessorName: "rotorTorqueIdle",
yAccessorName: "date",
color: '#a0a'
},
2021-04-16 15:50:01 +05:00
linesOther: [
{
label: "rotorTorqueLimitMax",
units: 'кН·м',
xAccessorName: "rotorTorqueLimitMax",
yAccessorName: "date",
color: '#a0a'
},
2021-04-16 15:50:01 +05:00
],
}
const paramsGroups = [blockHeightGroup, blockSpeedGroup, pressureGroup, axialLoadGroup, hookWeightGroup, rotorTorqueGroup]
const timePeriodCollection = [
{value: '60', label: '1 минута'},
{value: '300', label: '5 минут'},
{value: '600', label: '10 минут'},
{value: '1800', label: '30 минут'},
{value: '3600', label: '1 час'},
{value: '21600', label: '6 часов'},
{value: '43200', label: '12 часов'},
{value: '86400', label: '24 часа'}
]
2021-07-27 12:08:11 +05:00
const defaultChartInterval = '600'
2021-08-12 17:47:16 +05:00
export default function TelemetryView({idWell}) {
2021-04-16 15:50:01 +05:00
const [saubData, setSaubData] = useState([])
2021-07-27 12:08:11 +05:00
const [chartInterval, setChartInterval] = useState(defaultChartInterval)
const [loader, setLoader] = useState(false)
2021-07-27 12:08:11 +05:00
const options = timePeriodCollection.map((line) => <Option key={line.value}>{line.label}</Option>)
const handleReceiveDataSaub = (data) => {
if (data) {
2021-04-16 15:50:01 +05:00
setSaubData(data)
}
2021-04-16 15:50:01 +05:00
}
useEffect(() => {
const update = async () => {
setLoader(true)
try {
2021-08-12 17:47:16 +05:00
const data = await DataService.getData(idWell)
handleReceiveDataSaub(data)
} catch (ex) {
2021-08-12 17:47:16 +05:00
notify(`Не удалось получить данные по скважине "${idWell}"`, 'error')
console.log(ex)
}
setLoader(false)
2021-08-12 17:47:16 +05:00
return Subscribe('hubs/telemetry', 'ReceiveDataSaub', `well_${idWell}`, handleReceiveDataSaub)
}
update()
2021-08-12 17:47:16 +05:00
}, [idWell])
useEffect(() => {
setLoader(true)
2021-08-12 17:47:16 +05:00
DataService.getData(idWell, null, chartInterval)
.then(handleReceiveDataSaub)
.catch(error => console.error(error))
.finally(() => setLoader(false))
2021-08-12 17:47:16 +05:00
}, [idWell, chartInterval])
const colSpan = 24 / (paramsGroups.length)
return (<LoaderPortal show={loader}>
<Row style={{marginBottom: '1rem'}}>
<Col>
<ModeDisplay data={saubData}/>
</Col>
<span style={{flexGrow: 0.1}}>&nbsp;</span>
2021-04-16 15:50:01 +05:00
<Col>
Интервал:&nbsp;
2021-07-27 12:08:11 +05:00
<Select defaultValue={defaultChartInterval} onChange={setChartInterval}>
{options}
</Select>
2021-04-16 15:50:01 +05:00
</Col>
<span style={{flexGrow: 1}}>&nbsp;</span>
2021-04-16 15:50:01 +05:00
<Col>
<UserOfWells data={saubData}/>
2021-04-16 15:50:01 +05:00
</Col>
</Row>
<Row>
<Col span={3}>
<CustomColumn data={saubData}/>
2021-04-16 15:50:01 +05:00
</Col>
<Col span={24 - 3}>
2021-04-16 15:50:01 +05:00
<Row>
{paramsGroups.map((group, index) =>
<Col span={colSpan} className='border_small' key={group.label}>
<Column data={saubData} lineGroup={group} interval={chartInterval}
showBorder={saubData[saubData.length - 1]?.drillingBy === index}/>
</Col>)}
2021-04-16 15:50:01 +05:00
</Row>
</Col>
</Row>
2021-08-12 17:47:16 +05:00
<ActiveMessagesOnline idWell={idWell}/>
</LoaderPortal>)
2021-04-16 15:50:01 +05:00
}