Архив:

* Исправлена ошибка при переключении периода
* Подкорректирована работа интерполяционного поиска
This commit is contained in:
goodmice 2022-07-19 15:01:20 +05:00
parent 547baa6289
commit c9f28a45af

View File

@ -86,8 +86,8 @@ const interpolationSearch = (data, begin, end, accessor) => {
} }
return x return x
} }
let x0 = findIdx(begin, 0, 5) let x0 = findIdx(begin, 0, 100)
let x1 = findIdx(end, x0, 3) let x1 = findIdx(end, x0, 100)
return { start: x0, end: x1, count: x1 - x0 } return { start: x0, end: x1, count: x1 - x0 }
} }
@ -109,12 +109,12 @@ const Archive = memo(() => {
const idWell = useIdWell() const idWell = useIdWell()
const [search, setSearchParams] = useSearchParams() const [search, setSearchParams] = useSearchParams()
const getInitialRange = useCallback(() => parseInt(search.get('range') ?? defaultPeriod) * 1000, [search]) const getInitialRange = useCallback(() => parseInt(search.get('range') ?? defaultPeriod) * 1000, [search])
const getInitialDate = useCallback(() => new Date(search.get('start') ?? (Date.now() - chartInterval)), [search])
const [scrollPercent, setScrollPercent] = useState(0.15) const [scrollPercent, setScrollPercent] = useState(0.15)
const [chartInterval, setChartInterval] = useState(getInitialRange) const [chartInterval, setChartInterval] = useState(getInitialRange)
const getInitialDate = useCallback(() => new Date(search.get('start') ?? (Date.now() - chartInterval)), [search, chartInterval])
const [startDate, setStartDate] = useState(getInitialDate) const [startDate, setStartDate] = useState(getInitialDate)
const onGraphWheel = useCallback((e) => { const onGraphWheel = useCallback((e) => {
@ -133,7 +133,7 @@ const Archive = memo(() => {
if (!date) return false if (!date) return false
const dt = new Date(date).setHours(0, 0, 0, 0) const dt = new Date(date).setHours(0, 0, 0, 0)
return dt < dateLimit.from || dt > +dateLimit.to - chartInterval return dt < dateLimit.from || dt > +dateLimit.to - chartInterval
}, [dateLimit]) }, [dateLimit, chartInterval])
const isDateTimeDisabled = useCallback((date) => ({ const isDateTimeDisabled = useCallback((date) => ({
disabledHours: () => range(24).filter(h => { disabledHours: () => range(24).filter(h => {
@ -151,7 +151,7 @@ const Archive = memo(() => {
const dt = +new Date(date).setSeconds(s) const dt = +new Date(date).setSeconds(s)
return dt < dateLimit.from || dt > +dateLimit.to - chartInterval return dt < dateLimit.from || dt > +dateLimit.to - chartInterval
}) })
}), [dateLimit]) }), [dateLimit, chartInterval])
useEffect(() => { useEffect(() => {
const params = {} const params = {}
@ -189,11 +189,11 @@ const Archive = memo(() => {
invokeWebApiWrapperAsync( invokeWebApiWrapperAsync(
async () => { async () => {
const data = await TelemetryDataSaubService.getData(idWell, loadingStartDate.toISOString(), loadingInterval, DATA_COUNT) const data = await TelemetryDataSaubService.getData(idWell, loadingStartDate.toISOString(), loadingInterval, DATA_COUNT)
const loadedStartDate = new Date(Math.max(+newLoaded.start, +startDate - chartInterval * ADDITIVE_PAGES)) const loadedStartDate = new Date(Math.max(+newLoaded.start, +startDate - chartInterval * ADDITIVE_PAGES))
const loadedEndDate = new Date(Math.min(+newLoaded.end, +startDate + chartInterval * (ADDITIVE_PAGES + 1))) const loadedEndDate = new Date(Math.min(+newLoaded.end, +startDate + chartInterval * (ADDITIVE_PAGES + 1)))
setLoaded({ start: loadedStartDate, end: loadedEndDate }) setLoaded({ start: loadedStartDate, end: loadedEndDate })
if (data) { if (data) {
data.forEach(elm => elm.date = new Date(elm.date)) data.forEach(elm => elm.date = new Date(elm.date))
setDataSaub((prevDataSaub) => { setDataSaub((prevDataSaub) => {
@ -202,7 +202,7 @@ const Archive = memo(() => {
return cutData(newData, loadedStartDate, loadedEndDate) return cutData(newData, loadedStartDate, loadedEndDate)
}) })
} }
}, },
setShowLoader, setShowLoader,
`Не удалось загрузить данные по скважине "${idWell}" c ${startDate.toISOString()} по ${new Date(+startDate + chartInterval).toISOString()}`, `Не удалось загрузить данные по скважине "${idWell}" c ${startDate.toISOString()} по ${new Date(+startDate + chartInterval).toISOString()}`,
@ -213,6 +213,7 @@ const Archive = memo(() => {
const onRangeChange = useCallback((value) => { const onRangeChange = useCallback((value) => {
setChartInterval(value * 1000) setChartInterval(value * 1000)
setDataSaub([]) setDataSaub([])
setLoaded(null)
}, []) }, [])
const domain = useMemo(() => ({ min: startDate, max: new Date(+startDate + chartInterval)}), [startDate, chartInterval]) const domain = useMemo(() => ({ min: startDate, max: new Date(+startDate + chartInterval)}), [startDate, chartInterval])