diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts index 46cb2fc..c5d6c4c 100644 --- a/src/components/Table/index.ts +++ b/src/components/Table/index.ts @@ -65,7 +65,101 @@ export const makeColumnsPlanFact = (title:string, key:string|string[], columsOth ] } } + +const maxPrefix = "isMax" +const minPrefix = "isMin" + +export const makeFilterMinMaxFunction = (key: string | number) => (filterValue: string | number, + dataItem: any) => + filterValue === "max" + ? dataItem[maxPrefix + key] + : filterValue === "min" + ? dataItem[minPrefix + key] + : false + +export const makeFilterTextMatch = (key: string | number) => (filterValue: string | number, dataItem: any) => + dataItem[key] === filterValue + +export const makeNumericSorter = (key: any) => (a: any, b: any) => a[key] - b[key] + +export const makeStringSorter = (key: any) => (a: any, b: any) => +{ +for (let i = 0; i < a.length; i++) { + if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) + return 1 + + if (a.charCodeAt(i) > b.charCodeAt(i)) + return -1 +} +return 0 +} + +export const makeGroupColumn = (title: any, children: any) => ({ + title: title, + children: children, +}) + +export const makeTextColumn = (title: any, dataIndex: any, filters: any, sorter: any, render: any, other: any) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: filters ? makeFilterTextMatch(dataIndex) : null, + sorter: sorter ? makeStringSorter(dataIndex) : null, + render: render, + ...other +}) + +export const makeNumericColumn = (title: any, dataIndex: any, filters: any, width: string) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: makeFilterMinMaxFunction(dataIndex), + sorter: makeNumericSorter(dataIndex), + width: width +}) + +export const makeNumericColumnPlanFact = (title: any, dataIndex: any, filters: any) => + makeGroupColumn( title, [ + makeNumericColumn('п', dataIndex + 'Plan', filters, ''), + makeNumericColumn('ф', dataIndex + 'Fact', filters, ''), + ]) + +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/pages/ClusterSections.jsx b/src/pages/ClusterSections.jsx index 5164b0e..63079ed 100644 --- a/src/pages/ClusterSections.jsx +++ b/src/pages/ClusterSections.jsx @@ -1,9 +1,8 @@ import { Table, Tag, Button, Badge, Divider, Modal} from "antd" import { LineChartOutlined, ProfileOutlined } from '@ant-design/icons' import { useState } from "react" +import { makeTextColumn, makeGroupColumn, makeNumericColumn, makeNumericColumnPlanFact, calcAndUpdateStatsBySections } from '../components/Table/index' -const isMaxPrefix = "isMax" -const isMinPrefix = "isMin" const filtersMinMax = [ { @@ -35,61 +34,6 @@ const filtersSectionsType = [ }, ] -const makeFilterMinMaxFunction = (key) => (filterValue, dataItem) => - filterValue === "max" - ? dataItem[isMaxPrefix + key] - : filterValue === "min" - ? dataItem[isMinPrefix + key] - : false - -const makeFilterTextMatch = (key) => (filterValue, dataItem) => - dataItem[key] === filterValue - -const makeNumericSorter = (key) => (a, b) => a[key] - b[key] - -const makeStringSorter = (key) => (a, b) => -{ - for (let i = 0; i < a.length; i++) { - if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) - return 1 - - if (a.charCodeAt(i) > b.charCodeAt(i)) - return -1 - } - return 0 -} - -const makeGroupColumn = (title, children) => ({ - title: title, - children: children, -}) - -const makeTextColumn = (title, dataIndex, filters, sorter, render, other) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filters ? makeFilterTextMatch(dataIndex) : null, - sorter: sorter ? makeStringSorter(dataIndex) : null, - render: render, - ...other -}) - -const makeNumericColumn = (title, dataIndex, filters) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: makeFilterMinMaxFunction(dataIndex), - sorter: makeNumericSorter(dataIndex) -}) - -const makeNumericColumnPlanFact = (title, dataIndex, filters) => - makeGroupColumn( title, [ - makeNumericColumn('п', dataIndex + 'Plan', filters), - makeNumericColumn('ф', dataIndex + 'Fact', filters), - ]) - const ModalWindowButton = ({buttonIcon, buttonText, modalTitle, modalContent}) =>{ const [isModalVisible, setIsModalVisible] = useState(false) @@ -129,7 +73,7 @@ const columns = [ makeNumericColumnPlanFact('Подъем КНБК', 'sectionBhaUpSpeed', filtersMinMax),//Скорость подъема КНБК makeNumericColumnPlanFact('Скорость спуска ОК', 'sectionCasingDownSpeed', filtersMinMax), ]), - makeNumericColumn('НПВ, сут', 'notProductiveTime', filtersMinMax), + makeNumericColumn('НПВ, сут', 'notProductiveTime', filtersMinMax, '80px'), { title: "TVD", render: (_, record) => { - 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][isMaxPrefix + key] = data[i][key] === maxs[key] - data[i][isMinPrefix + key] = data[i][key] === mins[key] - }) - } -} - -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) - }) -} - calcAndUpdateStatsBySections(wellsStat, [ "sectionWellDepthPlan", "sectionWellDepthFact", @@ -220,6 +130,7 @@ calcAndUpdateStatsBySections(wellsStat, [ "sectionBhaUpSpeedFact", "sectionCasingDownSpeedPlan", "sectionCasingDownSpeedFact", + "notProductiveTime" ]) export default function ClusterStat() { @@ -236,7 +147,6 @@ export default function ClusterStat() { return ( <> -

Статистика по секциям

diff --git a/src/pages/ClusterWells.jsx b/src/pages/ClusterWells.jsx index 4b72493..9d3f1ae 100644 --- a/src/pages/ClusterWells.jsx +++ b/src/pages/ClusterWells.jsx @@ -5,9 +5,8 @@ import { useState, useEffect } from "react"; import { ClusterService } from '../services/api' import { notify } from "../components/factory" import { Table, Tag, Button } from 'antd'; +import { makeTextColumn, makeGroupColumn, makeNumericColumn, makeNumericColumnPlanFact, calcAndUpdateStatsBySections } from '../components/Table/index' -const isMaxPrefix = "isMax" -const isMinPrefix = "isMin" const filtersMinMax = [ { @@ -23,72 +22,48 @@ const filtersMinMax = [ const filtersWellsType = [ { text: "Наклонно-направленная", - value: "sidelong", + value: "Наклонно-направленная", }, { text: "Горизонтальная", - value: "horizontal", + value: "Горизонтальная", } ] -const makeFilterMinMaxFunction = (key) => (filterValue, dataItem) => - filterValue === "max" - ? dataItem[isMaxPrefix + key] - : filterValue === "min" - ? dataItem[isMinPrefix + key] - : false +const contractors = [ + { type: "Буровой подрядчик", caption: 'ООО "НГ-Бурение"' }, + // { type: "ННБ", caption: 'ООО НПП "Буринтех"' }, + // { type: "Растворный сревис", caption: 'ООО НПП "Буринтех"' }, + // { type: "Цементирование", caption: "Норд-Сервис" }, +] -const makeFilterTextMatch = (key) => (filterValue, dataItem) => - dataItem[key] === filterValue +const wellsStatDefault = [ + { key:1, caption :'42669', wellType :'Наклонно-направленная', factStart: 5, factEnd: 12, periodPlan :80.0, periodFact :79.0, rateOfPenetrationPlan :19.0, rateOfPenetrationFact :10.3, routeSpeedPlan :60.0, routeSpeedFact :158.0, notProductiveTime: 10, companies :contractors }, + { key:2, caption :'42669', wellType :'Горизонтальная', factStart: 7, factEnd: 11, periodPlan :1280.0, periodFact :1284.0, rateOfPenetrationPlan :90.0, rateOfPenetrationFact :138.3, routeSpeedPlan :60.0, routeSpeedFact :85.5, notProductiveTime: 11, companies :contractors }, + { key:3, caption :'42669', wellType :'Наклонно-направленная', factStart: 8, factEnd: 13, periodPlan :3615.9, periodFact :3616.0, rateOfPenetrationPlan :406.1, rateOfPenetrationFact :391.0, routeSpeedPlan :60.0, routeSpeedFact :57.7, notProductiveTime: 12, companies :contractors }, + { key:4, caption :'16311', wellType :'Наклонно-направленная', factStart: 9, factEnd: 17, periodPlan :80.0, periodFact :81.0, rateOfPenetrationPlan :10.8, rateOfPenetrationFact :11.0, routeSpeedPlan :60.0, routeSpeedFact :81.0, notProductiveTime: 13, companies :contractors }, + { key:5, caption :'16314', wellType :'Горизонтальная', factStart: 15, factEnd: 15, periodPlan :1411.0, periodFact :1412.0, rateOfPenetrationPlan :107.8, rateOfPenetrationFact :99.0, routeSpeedPlan :60.0, routeSpeedFact :96.4, notProductiveTime: 14, companies :contractors }, + { key:6, caption :'16311', wellType :'Наклонно-направленная', factStart: 14, factEnd: 20, periodPlan :3181.0, periodFact :3181.0, rateOfPenetrationPlan :171.6, rateOfPenetrationFact :171.0, routeSpeedPlan :35.0, routeSpeedFact :80.9, notProductiveTime: 15, companies :contractors }, + { key:7, caption :'16311', wellType :'Горизонтальная', factStart: 12, factEnd: 21, periodPlan :4181.0, periodFact :4187.0, rateOfPenetrationPlan :271.9, rateOfPenetrationFact :220.0, routeSpeedPlan :20.0, routeSpeedFact :32.9, notProductiveTime: 16, companies :contractors }, + { key:8, caption :'16315', wellType :'Наклонно-направленная', factStart: 13, factEnd: 22, periodPlan :80.0, periodFact :80.0, rateOfPenetrationPlan :21.1, rateOfPenetrationFact :23.0, routeSpeedPlan :60.0, routeSpeedFact :53.3, notProductiveTime: 17, companies :contractors }, + { key:9, caption :'16315', wellType :'Горизонтальная', factStart: 11, factEnd: 23, periodPlan :1500.0, periodFact :1505.0, rateOfPenetrationPlan :130.3, rateOfPenetrationFact :150.5, routeSpeedPlan :60.0, routeSpeedFact :58.2, notProductiveTime: 18, companies :contractors } +] -const makeNumericSorter = (key) => (a, b) => a[key] - b[key] - -const makeStringSorter = (key) => (a, b) => -{ - for (let i = 0; i < a.length; i++) { - if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) - return 1 - - if (a.charCodeAt(i) > b.charCodeAt(i)) - return -1 - } - return 0 -} - -const makeGroupColumn = (title, children) => ({ - title: title, - children: children, -}) - -const makeTextColumn = (title, dataIndex, filters, sorter, render, other) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filters ? makeFilterTextMatch(dataIndex) : null, - sorter: sorter ? makeStringSorter(dataIndex) : null, - render: render, - ...other -}) - -const makeNumericColumn = (title, dataIndex, filters) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: makeFilterMinMaxFunction(dataIndex), - sorter: makeNumericSorter(dataIndex) -}) - -const makeNumericColumnPlanFact = (title, dataIndex, filters) => - makeGroupColumn( title, [ - makeNumericColumn('п', dataIndex + 'Plan', filters), - makeNumericColumn('ф', dataIndex + 'Fact', filters), - ]) +calcAndUpdateStatsBySections(wellsStatDefault, [ + "factStart", + "factEnd", + "periodPlan", + "periodFact", + "rateOfPenetrationPlan", + "rateOfPenetrationFact", + "routeSpeedPlan", + "routeSpeedFact", + "notProductiveTime" +]) export default function Cluster() { let { id } = useParams() - const [wellsStat, setWellsStat] = useState(null) + const [wellsStat, setWellsStat] = useState(wellsStatDefault) const [showLoader, setShowLoader] = useState(false) useEffect(() => { @@ -143,7 +118,6 @@ export default function Cluster() { return ( -

Статистика по скважинам

record.id} + className={'mt-20px'} /> ) } \ No newline at end of file