Скорл ограничен до текущего времени

filter заменён на интерполяционный поиск
This commit is contained in:
goodmice 2021-11-12 18:08:22 +05:00
parent e803a9172b
commit a9c148d891

View File

@ -6,12 +6,12 @@ import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { Flex } from '../../components/Grid' import { Flex } from '../../components/Grid'
import { PeriodPicker, defaultPeriod } from '../../components/PeriodPicker' import { PeriodPicker, defaultPeriod } from '../../components/PeriodPicker'
import { ArchiveDisplay } from './ArchiveDisplay' import { ArchiveDisplay, cutData } from './ArchiveDisplay'
const DATA_COUNT = 2048 // Колличество точек на подгрузку графика const DATA_COUNT = 2048 // Колличество точек на подгрузку графика
const ADDITIVE_PAGES = 2 // Дополнительные данные для графиков const ADDITIVE_PAGES = 2 // Дополнительные данные для графиков
const LOADING_TRIGGER = 0.5 const LOADING_TRIGGER = 0.5
const MOUSE_SENSITIVITY = 1 / 530 const WHEEL_SENSITIVITY = 1 / 530
const getLoadingInterval = (loaded, startDate, interval) => { const getLoadingInterval = (loaded, startDate, interval) => {
// Если данные загружены и дата не заходит за тригер дозагрузка не требуется // Если данные загружены и дата не заходит за тригер дозагрузка не требуется
@ -22,8 +22,8 @@ const getLoadingInterval = (loaded, startDate, interval) => {
) )
return { loadingStartDate: startDate, newLoaded: loaded, loadingInterval: 0 } return { loadingStartDate: startDate, newLoaded: loaded, loadingInterval: 0 }
let loadingStartDate = new Date(+startDate - interval * ADDITIVE_PAGES) let loadingStartDate = +startDate - interval * ADDITIVE_PAGES
let loadingEndDate = new Date(+startDate + interval * (ADDITIVE_PAGES + 1)) let loadingEndDate = +startDate + interval * (ADDITIVE_PAGES + 1)
const newLoaded = { const newLoaded = {
start: loadingStartDate, start: loadingStartDate,
@ -32,18 +32,21 @@ const getLoadingInterval = (loaded, startDate, interval) => {
if (loaded) { if (loaded) {
if (loadingStartDate >= loaded.start) if (loadingStartDate >= loaded.start)
loadingStartDate = new Date(loaded.end) loadingStartDate = loaded.end
if (loadingEndDate <= loaded.end) if (loadingEndDate <= loaded.end)
loadingEndDate = new Date(loaded.start) loadingEndDate = loaded.start
newLoaded.start = new Date(Math.min(loaded.start, loadingStartDate)) newLoaded.start = Math.min(loaded.start, loadingStartDate)
newLoaded.end = new Date(Math.max(loaded.end, loadingEndDate)) newLoaded.end = Math.max(loaded.end, loadingEndDate)
} }
const loadingInterval = Math.trunc((loadingEndDate - loadingStartDate) / 1000) const loadingInterval = Math.trunc((loadingEndDate - loadingStartDate) / 1000)
return { return {
loadingStartDate, loadingStartDate: new Date(loadingStartDate),
newLoaded, newLoaded: {
start: new Date(newLoaded.start),
end: new Date(newLoaded.end)
},
loadingInterval loadingInterval
} }
} }
@ -54,14 +57,14 @@ export default function Archive({idWell}) {
const [startDate, setStartDate] = useState(new Date(+new Date() - chartInterval)) const [startDate, setStartDate] = useState(new Date(+new Date() - chartInterval))
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [loaded, setLoaded] = useState(null) const [loaded, setLoaded] = useState(null)
const [dateMinLimit, setDateMinLimit] = useState(0)
const onGraphWheel = (e) => { const onGraphWheel = (e) => {
if (loaded) { if (loaded) {
setStartDate((prevStartDate) => { setStartDate((prevStartDate) => {
const offset = e.deltaY * chartInterval * MOUSE_SENSITIVITY const offset = e.deltaY * chartInterval * WHEEL_SENSITIVITY
const nextStartDate = new Date(+prevStartDate + offset) const nextStartDate = new Date(+prevStartDate + offset)
return new Date(Math.max(loaded.start, Math.min(nextStartDate, +loaded.end - chartInterval))) const lastPossibleDate = new Date(Math.min(loaded.end, new Date()) - chartInterval)
return new Date(Math.max(loaded.start, Math.min(nextStartDate, lastPossibleDate)))
}) })
} }
} }
@ -69,8 +72,12 @@ export default function Archive({idWell}) {
useEffect(() => invokeWebApiWrapperAsync( useEffect(() => invokeWebApiWrapperAsync(
async () => { async () => {
const dates = await TelemetryDataSaubService.getDataDatesRange(idWell) const dates = await TelemetryDataSaubService.getDataDatesRange(idWell)
setDateMinLimit(new Date(dates?.from ?? 0)) let startDate
setStartDate(new Date(+new Date(dates?.to ?? new Date()) - chartInterval)) if (dates?.from && dates?.to)
startDate = Math.max(new Date(dates.from), +new Date(dates.to) - chartInterval)
else
startDate = +new Date() - chartInterval
setStartDate(new Date(startDate))
}, },
setShowLoader, setShowLoader,
`Не удалось загрузить диапозон телеметрии для скважины "${idWell}"` `Не удалось загрузить диапозон телеметрии для скважины "${idWell}"`
@ -78,6 +85,7 @@ export default function Archive({idWell}) {
useEffect(() => { useEffect(() => {
setStartDate((startDate) => new Date(Math.min(+new Date() - chartInterval, startDate))) setStartDate((startDate) => new Date(Math.min(+new Date() - chartInterval, startDate)))
setDataSaub([])
}, [chartInterval]) }, [chartInterval])
useEffect(() => { useEffect(() => {
@ -97,10 +105,7 @@ export default function Archive({idWell}) {
setDataSaub((prevDataSaub) => { setDataSaub((prevDataSaub) => {
const newData = [...prevDataSaub, ...data] const newData = [...prevDataSaub, ...data]
newData.sort((a, b) => a.date > b.date ? 1 : -1) newData.sort((a, b) => a.date > b.date ? 1 : -1)
return newData.filter(val => { return cutData(newData, loadedStartDate, loadedEndDate)
const date = new Date(val.date)
return loadedStartDate < date && date < loadedEndDate
})
}) })
} }