From 64246bd2fdb6673064009cb0479a11b0bf5b8423 Mon Sep 17 00:00:00 2001 From: goodmice Date: Thu, 4 Aug 2022 01:32:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B0=D0=B3=D0=B3=D1=80=D0=B5=D0=B3=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BA=D0=B5=D1=82=D0=BE=D0=B2=20sig?= =?UTF-8?q?nalr=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D1=82=D0=B5=D0=BB=D0=B5=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Telemetry/TelemetryView/index.jsx | 38 +++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/pages/Telemetry/TelemetryView/index.jsx b/src/pages/Telemetry/TelemetryView/index.jsx index 67967f5..5f28e42 100755 --- a/src/pages/Telemetry/TelemetryView/index.jsx +++ b/src/pages/Telemetry/TelemetryView/index.jsx @@ -1,4 +1,5 @@ import { Select } from 'antd' +import { BehaviorSubject, buffer, throttleTime } from 'rxjs' import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { useIdWell } from '@asb/context' @@ -73,7 +74,7 @@ export const makeChartGroups = (flowChart) => { maxYAccessor: accessor + 'Max', bindDomainFrom: accessor, }) - console.log(flowChart) + return [ [ makeDataset('Высота блока', 'Высота ТБ','#303030', 'blockPosition', 'м'), @@ -151,6 +152,9 @@ const TelemetryView = memo(() => { const idWell = useIdWell() + const saubSubject$ = useMemo(() => new BehaviorSubject(), []) + const spinSubject$ = useMemo(() => new BehaviorSubject(), []) + const handleDataSaub = useCallback((data) => { if (data) { const dataSaub = normalizeData(data) @@ -165,11 +169,22 @@ const TelemetryView = memo(() => { const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), []) useEffect(() => { - const unsubscribe = Subscribe( - 'hubs/telemetry', `well_${idWell}`, - { methodName: 'ReceiveDataSaub', handler: handleDataSaub }, - { methodName: 'ReceiveDataSpin', handler: handleDataSpin } - ) + const subscribtion = saubSubject$.pipe( + buffer(saubSubject$.pipe(throttleTime(700))) + ).subscribe((data) => handleDataSaub(data.flat())) + + 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( async () => { const flowChart = await DrillFlowChartService.getByIdWell(idWell) @@ -183,9 +198,18 @@ const TelemetryView = memo(() => { `Не удалось получить данные по скважине "${idWell}"`, 'Получение данных по скважине' ) - return unsubscribe }, [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(() => { invokeWebApiWrapperAsync( async () => {