Skip to content

Commit

Permalink
Merge pull request #921 from Deltares/920-unreliable-data-in-a-time-s…
Browse files Browse the repository at this point in the history
…eries-table-must-not-be-used-in-scaling-the-y-axis

Filter unreliable flagged data from charts
  • Loading branch information
hvangeffen authored Jun 19, 2024
2 parents 1dd4299 + c0b2510 commit 18fcbe9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/components/charts/ElevationChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ import { Series } from '../../lib/timeseries/timeSeries.js'
import uniq from 'lodash-es/uniq'
import { VChipGroup } from 'vuetify/components'
import { difference } from 'lodash-es'
import {
dataFromResources,
removeUnreliableData,
} from '@/lib/charts/dataFromResources'
const LEGEND_HEIGHT = 76
Expand Down Expand Up @@ -163,8 +167,10 @@ const setChartConfigValues = (axisOptions: CartesianAxesOptions) => {
const addToChart = (chartSeries: ChartSeries) => {
const id = chartSeries.id
const seriesData = props.series[chartSeries.dataResources[0]]
const data = seriesData?.data !== undefined ? seriesData.data : []
const rawData = dataFromResources(chartSeries.dataResources, props.series)
const data = removeUnreliableData(rawData)
const line = new ChartLine(data, {
tooltip: {
toolTipFormatter: () => {
Expand Down
8 changes: 6 additions & 2 deletions src/components/charts/TimeSeriesChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ import type { ChartConfig } from '../../lib/charts/types/ChartConfig.js'
import type { ChartSeries } from '../../lib/charts/types/ChartSeries.js'
import type { ThresholdLine } from '../../lib/charts/types/ThresholdLine.js'
import { Series } from '../../lib/timeseries/timeSeries.js'
import { dataFromResources } from '../../lib/charts/dataFromResources'
import {
dataFromResources,
removeUnreliableData,
} from '@/lib/charts/dataFromResources'
import uniq from 'lodash-es/uniq'
import { extent } from 'd3'
import { VChipGroup } from 'vuetify/components'
Expand Down Expand Up @@ -186,7 +189,8 @@ watch(
const addToChart = (chartSeries: ChartSeries) => {
const id = chartSeries.id
const data = dataFromResources(chartSeries.dataResources, props.series)
const rawData = dataFromResources(chartSeries.dataResources, props.series)
const data = removeUnreliableData(rawData)
const tooltip: TooltipOptions = {
toolTipFormatter: (d) => {
Expand Down
36 changes: 29 additions & 7 deletions src/lib/charts/dataFromResources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { createDateTimes } from '../table/tableData'
import { Series } from '../timeseries/timeSeries'
import { SeriesArrayData, TimeSeriesData } from '../timeseries/types/SeriesData'
import type { Series } from '../timeseries/timeSeries'
import type {
SeriesArrayData,
SeriesData,
TimeSeriesData,
} from '@/lib/timeseries/types/SeriesData'

/**
* Determines if the specified data is reliable.
* @param data - A SeriesData or SeriesArrayData object.
* @returns True if the data is reliable, false otherwise.
*/
export function isReliableData(data: SeriesArrayData | SeriesData) {
// Hardcoded unreliable flags since backend does not provide this information
const unreliableFlags = ['6', '7', '8']
return !unreliableFlags.includes(data.flag)
}

/**
* Retrieves a single array from the specified data resources. When multiple data resources are specified, the data is combined into a single array.
Expand All @@ -12,8 +27,8 @@ export function dataFromResources(
dataResourceIds: string[],
series: Record<string, Series>,
) {
let data: (SeriesData | SeriesArrayData)[] = []
if (dataResourceIds.length > 1) {
let data: SeriesArrayData[] = []
let allFound = true
for (const resourceId of dataResourceIds) {
if (series[resourceId] === undefined) {
Expand Down Expand Up @@ -45,10 +60,17 @@ export function dataFromResources(
return result
})
}
return data
} else {
const seriesData = series[dataResourceIds[0]]
if (seriesData?.data !== undefined) return seriesData.data
else return []
data = series[dataResourceIds[0]]?.data ?? []
}
return data
}

/**
* Filters out unreliable data from a list of SeriesData or SeriesArrayData objects.
* @param data - An array of SeriesData or SeriesArrayData objects.
* @returns An array of SeriesData or SeriesArrayData objects with unreliable data removed.
*/
export function removeUnreliableData(data: (SeriesArrayData | SeriesData)[]) {
return data.filter(isReliableData)
}

0 comments on commit 18fcbe9

Please sign in to comment.