Добавлена аггрегация пакетов signalr на странице телеметрии

This commit is contained in:
goodmice 2022-08-04 01:32:15 +05:00
parent 53c99a5f42
commit 64246bd2fd

View File

@ -1,4 +1,5 @@
import { Select } from 'antd' import { Select } from 'antd'
import { BehaviorSubject, buffer, throttleTime } from 'rxjs'
import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { useState, useEffect, useCallback, memo, useMemo } from 'react'
import { useIdWell } from '@asb/context' import { useIdWell } from '@asb/context'
@ -73,7 +74,7 @@ export const makeChartGroups = (flowChart) => {
maxYAccessor: accessor + 'Max', maxYAccessor: accessor + 'Max',
bindDomainFrom: accessor, bindDomainFrom: accessor,
}) })
console.log(flowChart)
return [ return [
[ [
makeDataset('Высота блока', 'Высота ТБ','#303030', 'blockPosition', 'м'), makeDataset('Высота блока', 'Высота ТБ','#303030', 'blockPosition', 'м'),
@ -151,6 +152,9 @@ const TelemetryView = memo(() => {
const idWell = useIdWell() const idWell = useIdWell()
const saubSubject$ = useMemo(() => new BehaviorSubject(), [])
const spinSubject$ = useMemo(() => new BehaviorSubject(), [])
const handleDataSaub = useCallback((data) => { const handleDataSaub = useCallback((data) => {
if (data) { if (data) {
const dataSaub = normalizeData(data) const dataSaub = normalizeData(data)
@ -165,11 +169,22 @@ const TelemetryView = memo(() => {
const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), []) const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), [])
useEffect(() => { useEffect(() => {
const unsubscribe = Subscribe( const subscribtion = saubSubject$.pipe(
'hubs/telemetry', `well_${idWell}`, buffer(saubSubject$.pipe(throttleTime(700)))
{ methodName: 'ReceiveDataSaub', handler: handleDataSaub }, ).subscribe((data) => handleDataSaub(data.flat()))
{ methodName: 'ReceiveDataSpin', handler: handleDataSpin }
) return () => subscribtion.unsubscribe()
}, [saubSubject$])
useEffect(() => {
const subscribtion = spinSubject$.pipe(
buffer(spinSubject$.pipe(throttleTime(700)))
).subscribe((data) => handleDataSpin(data.flat()))
return () => subscribtion.unsubscribe()
}, [spinSubject$])
useEffect(() => {
invokeWebApiWrapperAsync( invokeWebApiWrapperAsync(
async () => { async () => {
const flowChart = await DrillFlowChartService.getByIdWell(idWell) const flowChart = await DrillFlowChartService.getByIdWell(idWell)
@ -183,9 +198,18 @@ const TelemetryView = memo(() => {
`Не удалось получить данные по скважине "${idWell}"`, `Не удалось получить данные по скважине "${idWell}"`,
'Получение данных по скважине' 'Получение данных по скважине'
) )
return unsubscribe
}, [idWell, chartInterval, handleDataSpin, handleDataSaub]) }, [idWell, chartInterval, handleDataSpin, handleDataSaub])
useEffect(() => {
const unsubscribe = Subscribe(
'hubs/telemetry', `well_${idWell}`,
{ methodName: 'ReceiveDataSaub', handler: (data) => saubSubject$.next(data) },
{ methodName: 'ReceiveDataSpin', handler: (data) => spinSubject$.next(data) }
)
return () => unsubscribe()
}, [idWell, saubSubject$, spinSubject$])
useEffect(() => { useEffect(() => {
invokeWebApiWrapperAsync( invokeWebApiWrapperAsync(
async () => { async () => {