From e063fac9ada5b8afa73941d83a0153990158fa26 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 30 Aug 2021 11:26:00 +0500 Subject: [PATCH] Removed 'Cluster' tables functions from 'Table' folder to Cluster index --- src/components/Table/index.ts | 34 --------- .../{DepthToDay.jsx => ChartDepthToDay.jsx} | 6 +- src/pages/Cluster/ClusterSections.jsx | 4 +- src/pages/Cluster/ClusterWells.jsx | 76 +++++++++---------- src/pages/Cluster/index.jsx | 37 +++++++++ src/pages/WellOperations/Tvd.jsx | 4 +- 6 files changed, 81 insertions(+), 80 deletions(-) rename src/components/charts/{DepthToDay.jsx => ChartDepthToDay.jsx} (96%) diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts index f080b59..a520422 100644 --- a/src/components/Table/index.ts +++ b/src/components/Table/index.ts @@ -134,40 +134,6 @@ export const makeNumericColumnPlanFact = (title: any, dataIndex: any, filters: a makeNumericColumn('ф', dataIndex + 'Fact', filters, width), ]) -export const calcAndUpdateStats = (data: any, keys: any) => { - let mins: any = {} - let maxs: any = {} - - keys.forEach((key: any) => { - maxs[key] = Number.MIN_VALUE - mins[key] = Number.MAX_VALUE - }) - - data.forEach((item: any) => { - keys.forEach((key: any) => { - if (mins[key] > item[key]) mins[key] = item[key] - - if (maxs[key] < item[key]) maxs[key] = item[key] - }) - }) - - for (let i = 0; i < data.length; i++) { - keys.forEach((key: any) => { - data[i][maxPrefix + key] = data[i][key] === maxs[key] - data[i][minPrefix + key] = data[i][key] === mins[key] - }) - } -} - -export const calcAndUpdateStatsBySections = (data: any, keys: any) => { - const sectionTypes = new Set() - data.forEach((item: any) => sectionTypes.add(item.sectionType)) - sectionTypes.forEach(sectionType => { - const filteredBySectionData = data.filter((item: any) => item.sectionType === sectionType) - calcAndUpdateStats(filteredBySectionData, keys) - }) -} - type PaginationContainer = { skip?: number; take?: number; diff --git a/src/components/charts/DepthToDay.jsx b/src/components/charts/ChartDepthToDay.jsx similarity index 96% rename from src/components/charts/DepthToDay.jsx rename to src/components/charts/ChartDepthToDay.jsx index 694df1a..18b7217 100644 --- a/src/components/charts/DepthToDay.jsx +++ b/src/components/charts/ChartDepthToDay.jsx @@ -68,8 +68,8 @@ const defaultOptions = { reverse:true, display: true, title: { - display: true, - text: 'Value' + display: false, + text: '' }, } }, @@ -111,7 +111,7 @@ const makeDataset = (data, label, color, width=1.5, dash) => ({ borderDash: dash, }) -export default function DepthToDay({dataPlan, dataFact, dataForecast}) { +export default function ChartDepthToDay({dataPlan, dataFact, dataForecast}) { const chartRef = useRef(null) const [chart, setChart] = useState() diff --git a/src/pages/Cluster/ClusterSections.jsx b/src/pages/Cluster/ClusterSections.jsx index 194a774..6db2605 100644 --- a/src/pages/Cluster/ClusterSections.jsx +++ b/src/pages/Cluster/ClusterSections.jsx @@ -4,9 +4,9 @@ import { LineChartOutlined, ProfileOutlined } from "@ant-design/icons"; import { useState, useEffect } from "react"; import { makeTextColumn, - makeNumericColumnPlanFact, - calcAndUpdateStatsBySections, + makeNumericColumnPlanFact } from "../../components/Table"; +import { calcAndUpdateStatsBySections } from "./index"; const filtersMinMax = [ { diff --git a/src/pages/Cluster/ClusterWells.jsx b/src/pages/Cluster/ClusterWells.jsx index 088ebe5..cf300e5 100644 --- a/src/pages/Cluster/ClusterWells.jsx +++ b/src/pages/Cluster/ClusterWells.jsx @@ -6,12 +6,12 @@ import { makeTextColumn, makeGroupColumn, makeNumericColumn, - makeNumericColumnPlanFact, - calcAndUpdateStatsBySections, + makeNumericColumnPlanFact } from "../../components/Table"; +import { calcAndUpdateStatsBySections } from "./index"; import { invokeWebApiWrapperAsync } from '../../components/factory'; import { WellOperationStatService } from '../../services/api'; -import DepthToDay from '../../components/charts/DepthToDay'; +import ChartDepthToDay from '../../components/charts/ChartDepthToDay'; const filtersMinMax = [ { @@ -45,31 +45,33 @@ export default function ClusterWells({ clusterData }) { const [dataForecast, setDataForecast] = useState([]); useEffect(() => { - invokeWebApiWrapperAsync( - async () => { - const operations = await WellOperationStatService.getTvd(selectedWellId); - - const planData = operations.map(el => { - return {key: el.plan?.id, depth: el.plan?.wellDepth, date: el.plan?.startDate} - }).filter(el => el.key) - - setDataPlan(planData) - - const factData = operations.map(el => { - return {key: el.fact?.id, depth: el.fact?.wellDepth, date: el.fact?.startDate} - }).filter(el => el.key) - - setDataFact(factData) - - const predictData = operations.map(el => { - return {key: el.predict?.id, depth: el.predict?.wellDepth, date: el.predict?.startDate} - }).filter(el => el.key) - - setDataForecast(predictData) - }, - null, - `Не удалось загрузить операции по скважине "${selectedWellId}"`, - ); + if (selectedWellId > 0) { + invokeWebApiWrapperAsync( + async () => { + const operations = await WellOperationStatService.getTvd(selectedWellId); + + const planData = operations.map(el => { + return {key: el.plan?.id, depth: el.plan?.wellDepth, date: el.plan?.startDate} + }).filter(el => el.key) + + setDataPlan(planData) + + const factData = operations.map(el => { + return {key: el.fact?.id, depth: el.fact?.wellDepth, date: el.fact?.startDate} + }).filter(el => el.key) + + setDataFact(factData) + + const predictData = operations.map(el => { + return {key: el.predict?.id, depth: el.predict?.wellDepth, date: el.predict?.startDate} + }).filter(el => el.key) + + setDataForecast(predictData) + }, + null, + `Не удалось загрузить операции по скважине "${selectedWellId}"`, + ); + } }, [selectedWellId]); const closeModal = () => { @@ -98,16 +100,12 @@ export default function ClusterWells({ clusterData }) { factStart: new Date(el.total.fact.start).toLocaleString(), factEnd: new Date(el.total.fact.end).toLocaleString(), periodPlan: ( - Math.abs( - new Date(el.total.plan.start) - new Date(el.total.plan.end) - ) / - (1000 * 60 * 60 * 24) + new Date(el.total.plan.start) - new Date(el.total.plan.end) / + (1000 * 60 * 60 * 24) ).toFixed(2), periodFact: ( - Math.abs( - new Date(el.total.fact.start) - new Date(el.total.fact.end) - ) / - (1000 * 60 * 60 * 24) + new Date(el.total.fact.start) - new Date(el.total.fact.end) / + (1000 * 60 * 60 * 24) ).toFixed(2), rateOfPenetrationPlan: el.total.plan.rop.toFixed(2), rateOfPenetrationFact: el.total.fact.rop.toFixed(2), @@ -167,14 +165,14 @@ export default function ClusterWells({ clusterData }) { /> - diff --git a/src/pages/Cluster/index.jsx b/src/pages/Cluster/index.jsx index 93ff7a8..3cef4f5 100644 --- a/src/pages/Cluster/index.jsx +++ b/src/pages/Cluster/index.jsx @@ -9,6 +9,43 @@ import { WellOperationStatService } from "../../services/api"; const { Content } = Layout; +const maxPrefix = "isMax" +const minPrefix = "isMin" + +export const calcAndUpdateStats = (data, keys) => { + let mins = {} + let maxs = {} + + keys.forEach((key) => { + maxs[key] = Number.MIN_VALUE + mins[key] = Number.MAX_VALUE + }) + + data.forEach((item) => { + keys.forEach((key) => { + if (mins[key] > item[key]) mins[key] = item[key] + + if (maxs[key] < item[key]) maxs[key] = item[key] + }) + }) + + for (let i = 0; i < data.length; i++) { + keys.forEach((key) => { + data[i][maxPrefix + key] = data[i][key] === maxs[key] + data[i][minPrefix + key] = data[i][key] === mins[key] + }) + } +} + +export const calcAndUpdateStatsBySections = (data, keys) => { + const sectionTypes = new Set() + data.forEach((item) => sectionTypes.add(item.sectionType)) + sectionTypes.forEach(sectionType => { + const filteredBySectionData = data.filter((item) => item.sectionType === sectionType) + calcAndUpdateStats(filteredBySectionData, keys) + }) +} + export default function Cluster() { let { idClaster, tab } = useParams(); const [data, setData] = useState([]); diff --git a/src/pages/WellOperations/Tvd.jsx b/src/pages/WellOperations/Tvd.jsx index b7b1f5d..c286ed1 100644 --- a/src/pages/WellOperations/Tvd.jsx +++ b/src/pages/WellOperations/Tvd.jsx @@ -1,4 +1,4 @@ -import DepthToDay from '../../components/charts/DepthToDay'; +import ChartDepthToDay from '../../components/charts/ChartDepthToDay'; import { useState, useEffect } from 'react'; import { invokeWebApiWrapperAsync } from '../../components/factory'; import { WellOperationStatService } from '../../services/api'; @@ -39,7 +39,7 @@ export const Tvd = ({ idWell }) => {

График Глубина-день

-