From 43a01bd57fe5417776b5478e9cb88adc0d3e603e Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 29 Nov 2021 15:15:58 +0500 Subject: [PATCH] =?UTF-8?q?WellOperationStatService=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/WellTreeSelector.tsx | 2 +- src/pages/Cluster/functions.jsx | 40 ++++++------ src/pages/Cluster/index.jsx | 4 +- .../WellCompositeEditor/WellCompositeInfo.jsx | 16 ++--- .../WellCompositeEditor/index.jsx | 20 +++--- src/pages/WellOperations/WellSectionsStat.jsx | 65 ++++++++++--------- 6 files changed, 74 insertions(+), 73 deletions(-) diff --git a/src/components/WellTreeSelector.tsx b/src/components/WellTreeSelector.tsx index 3d4a421..00011e5 100644 --- a/src/components/WellTreeSelector.tsx +++ b/src/components/WellTreeSelector.tsx @@ -25,7 +25,7 @@ interface TreeNodeData { children?: TreeNodeData[] } -export const WellTreeSelector = (): React.ReactNode => { +export const WellTreeSelector = () => { const [wellsTree, setWellsTree] = useState([]) const [showLoader, setShowLoader] = useState(false) const history = useHistory() diff --git a/src/pages/Cluster/functions.jsx b/src/pages/Cluster/functions.jsx index 49aa6da..a817859 100644 --- a/src/pages/Cluster/functions.jsx +++ b/src/pages/Cluster/functions.jsx @@ -1,21 +1,20 @@ -import { WellOperationStatService } from '../../services/api'; +import { OperationStatService } from '../../services/api' -const maxPrefix = "isMax" -const minPrefix = "isMin" +const maxPrefix = 'isMax' +const minPrefix = 'isMin' export const getPrecision = (number) => Number.isNaN(number ?? NaN) ? '-' : number.toFixed(2) export const getOperations = async (idWell) => { - const ops = await WellOperationStatService.getTvd(idWell); + const ops = await OperationStatService.getTvd(idWell) - if (!ops) return []; + if (!ops) return [] - const convert = wellOperationDto => - ({ - key: wellOperationDto?.id, - depth: wellOperationDto?.depthStart, - date: wellOperationDto?.dateStart - }) + const convert = wellOperationDto => ({ + key: wellOperationDto?.id, + depth: wellOperationDto?.depthStart, + date: wellOperationDto?.dateStart + }) const planData = ops .map(item => convert(item.plan)) @@ -26,23 +25,23 @@ export const getOperations = async (idWell) => { .filter(el => el.key) const predictData = ops - .map(item => convert(item.predict)) - .filter(el => el.key) + .map(item => convert(item.predict)) + .filter(el => el.key) return { operations: ops, plan: planData, fact: factData, predict: predictData } -} +} -export const makeFilterMinMaxFunction = (key) => (filterValue, +export const makeFilterMinMaxFunction = (key) => (filterValue, dataItem) => - filterValue === "max" + filterValue === 'max' ? dataItem[maxPrefix + key] - : filterValue === "min" + : filterValue === 'min' ? dataItem[minPrefix + key] : false export const calcAndUpdateStats = (data, keys) => { - let mins = {} - let maxs = {} + const mins = {} + const maxs = {} keys.forEach((key) => { maxs[key] = Number.MIN_VALUE @@ -52,7 +51,6 @@ export const calcAndUpdateStats = (data, keys) => { data.forEach((item) => { keys.forEach((key) => { if (mins[key] > item[key]) mins[key] = item[key] - if (maxs[key] < item[key]) maxs[key] = item[key] }) }) @@ -64,7 +62,7 @@ export const calcAndUpdateStats = (data, keys) => { }) } } - + export const calcAndUpdateStatsBySections = (data, keys) => { const sectionTypes = new Set() data.forEach((item) => sectionTypes.add(item.sectionType)) diff --git a/src/pages/Cluster/index.jsx b/src/pages/Cluster/index.jsx index ea2a8a6..e3f04b9 100644 --- a/src/pages/Cluster/index.jsx +++ b/src/pages/Cluster/index.jsx @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react' import ClusterWells from './ClusterWells' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' -import { WellOperationStatService } from '../../services/api' +import { OperationStatService } from '../../services/api' export const Cluster = () => { @@ -13,7 +13,7 @@ export const Cluster = () => { useEffect(() => invokeWebApiWrapperAsync( async () => { - const clusterData = await WellOperationStatService.getStatCluster(idClaster) + const clusterData = await OperationStatService.getStatCluster(idClaster) setData(clusterData?.statsWells ?? []) }, setShowLoader, diff --git a/src/pages/WellOperations/WellCompositeEditor/WellCompositeInfo.jsx b/src/pages/WellOperations/WellCompositeEditor/WellCompositeInfo.jsx index e35e227..99a9136 100644 --- a/src/pages/WellOperations/WellCompositeEditor/WellCompositeInfo.jsx +++ b/src/pages/WellOperations/WellCompositeEditor/WellCompositeInfo.jsx @@ -1,16 +1,16 @@ -import { useEffect, useState } from "react" -import { invokeWebApiWrapperAsync } from "../../../components/factory" -import LoaderPortal from "../../../components/LoaderPortal"; -import { WellOperationStatService } from "../../../services/api"; -import ClusterWells from "../../Cluster/ClusterWells"; +import { useEffect, useState } from 'react' +import { invokeWebApiWrapperAsync } from '../../../components/factory' +import LoaderPortal from '../../../components/LoaderPortal' +import { OperationStatService } from '../../../services/api' +import ClusterWells from '../../Cluster/ClusterWells' export const WellCompositeInfo = ({idWell, selectedIdWells}) => { - const [showLoader, setShowLoader] = useState(false); - const [statsWells, setStatsWells] = useState([]); + const [showLoader, setShowLoader] = useState(false) + const [statsWells, setStatsWells] = useState([]) useEffect(() => invokeWebApiWrapperAsync( async () => { - const operations = await WellOperationStatService.getWellsStat(selectedIdWells) + const operations = await OperationStatService.getWellsStat(selectedIdWells) setStatsWells(operations) }, setShowLoader, diff --git a/src/pages/WellOperations/WellCompositeEditor/index.jsx b/src/pages/WellOperations/WellCompositeEditor/index.jsx index 2b35175..0b210d6 100644 --- a/src/pages/WellOperations/WellCompositeEditor/index.jsx +++ b/src/pages/WellOperations/WellCompositeEditor/index.jsx @@ -5,14 +5,14 @@ import { DepositService, WellCompositeService } from '../../../services/api' import { invokeWebApiWrapperAsync } from '../../../components/factory' import LoaderPortal from '../../../components/LoaderPortal' import { WellCompositeSections } from './WellCompositeSections' -import { WellOperationStatService } from '../../../services/api' +import { OperationStatService } from '../../../services/api' import ClusterWells from '../../Cluster/ClusterWells' const { Content } = Layout export const WellCompositeEditor = ({idWell}) => { const { tab } = useParams() - const rootPath = `/well/${idWell}/operations/composite`; + const rootPath = `/well/${idWell}/operations/composite` const [wellsTree, setWellsTree] = useState([]) const [showLoader, setShowLoader] = useState(false) @@ -68,7 +68,7 @@ export const WellCompositeEditor = ({idWell}) => { useEffect(() => invokeWebApiWrapperAsync( async () => { - const stats = await WellOperationStatService.getWellsStat(selectedIdWells) + const stats = await OperationStatService.getWellsStat(selectedIdWells) setStatsWells(Array.isArray(stats) ? stats : []) }, setShowTabLoader, @@ -98,24 +98,24 @@ export const WellCompositeEditor = ({idWell}) => { - + Статистика по скважинам - + Статистика по секциям - + - + @@ -135,4 +135,4 @@ export const WellCompositeEditor = ({idWell}) => { ) -} \ No newline at end of file +} diff --git a/src/pages/WellOperations/WellSectionsStat.jsx b/src/pages/WellOperations/WellSectionsStat.jsx index 8c89d18..ae288f5 100644 --- a/src/pages/WellOperations/WellSectionsStat.jsx +++ b/src/pages/WellOperations/WellSectionsStat.jsx @@ -2,28 +2,28 @@ import { useState, useEffect } from 'react' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' import { Table, makeColumn, makeColumnsPlanFact } from '../../components/Table' -import { WellOperationStatService } from '../../services/api' +import { OperationStatService } from '../../services/api' -const makeNumberRender = format => value => { +const makeNumberRender = value => { const v = +value if(Number.isFinite(v)) - return v.toFixed(format) + return v.toFixed(2) return '-' } const columns = [ - makeColumn('Тип секции','sectionType'), - makeColumnsPlanFact('Глубина' ,'wellDepth', {render:makeNumberRender(2)}), - makeColumnsPlanFact('Часы' ,'duration', {render:makeNumberRender(2)}), - makeColumnsPlanFact('МСП' ,'rop', {render:makeNumberRender(2)}), - makeColumnsPlanFact('Рейсовая скорость' ,'routeSpeed', {render:makeNumberRender(2)}), - makeColumnsPlanFact('Подъем КНБК' ,'bhaUpSpeed', {render:makeNumberRender(2)}), - makeColumnsPlanFact('Спуск КНБК' ,'bhaDownSpeed', {render:makeNumberRender(2)}), - makeColumnsPlanFact('Спуск ОК' ,'casingDownSpeed', {render:makeNumberRender(2)}), + makeColumn('Тип секции', 'sectionType'), + makeColumnsPlanFact('Глубина' ,'wellDepth', {render:makeNumberRender}), + makeColumnsPlanFact('Часы' ,'duration', {render:makeNumberRender}), + makeColumnsPlanFact('МСП' ,'rop', {render:makeNumberRender}), + makeColumnsPlanFact('Рейсовая скорость' ,'routeSpeed', {render:makeNumberRender}), + makeColumnsPlanFact('Подъем КНБК' ,'bhaUpSpeed', {render:makeNumberRender}), + makeColumnsPlanFact('Спуск КНБК' ,'bhaDownSpeed', {render:makeNumberRender}), + makeColumnsPlanFact('Спуск ОК' ,'casingDownSpeed', {render:makeNumberRender}), ] -const calcDuration = (start, end) => { - const msInDay = 1000*60*60*24 +const calcDuration = (start, end) => { + const msInDay = 1000 * 60 * 60 * 24 const startD = new Date(start) const endD = new Date(end) const ms = endD - startD @@ -36,11 +36,11 @@ export const WellSectionsStat = ({idWell}) => { useEffect(() => invokeWebApiWrapperAsync( async () => { - const sectionsResponse = await WellOperationStatService.getStatWell(idWell) + const sectionsResponse = await OperationStatService.getStatWell(idWell) if(sectionsResponse?.sections){ const sections = sectionsResponse.sections - .map(s=>({ + .map(s => ({ key: s.id, sectionType: s.caption, wellDepthPlan: s.plan?.wellDepthEnd, @@ -51,26 +51,29 @@ export const WellSectionsStat = ({idWell}) => { bhaDownSpeedPlan: s.plan?.bhaDownSpeed, casingDownSpeedPlan: s.plan?.casingDownSpeed, - wellDepthFact : s.fact?.wellDepthEnd, - durationFact : calcDuration(s.fact?.start, s.fact?.end), - ropFact : s.fact?.rop, - routeSpeedFact : s.fact?.routeSpeed, - bhaUpSpeedFact : s.fact?.bhaUpSpeed, - bhaDownSpeedFact : s.fact?.bhaDownSpeed, - casingDownSpeedFact : s.fact?.casingDownSpeed, + wellDepthFact: s.fact?.wellDepthEnd, + durationFact: calcDuration(s.fact?.start, s.fact?.end), + ropFact: s.fact?.rop, + routeSpeedFact: s.fact?.routeSpeed, + bhaUpSpeedFact: s.fact?.bhaUpSpeed, + bhaDownSpeedFact: s.fact?.bhaDownSpeed, + casingDownSpeedFact: s.fact?.casingDownSpeed, })) .sort((a,b) => a.wellDepthPlan - b.wellDepthPlan) setSections(sections) } }, setShowLoader - ),[idWell]) + ), [idWell]) - return - - -} \ No newline at end of file + return ( + +
+ + ) +}