Skip to content

Commit

Permalink
Filter unrelaibleFlagged data from charts
Browse files Browse the repository at this point in the history
  • Loading branch information
hvangeffen committed Jun 13, 2024
1 parent 729f685 commit ee3bc89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/charts/ElevationChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ 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 } from '@/lib/charts/dataFromResources.js'
const LEGEND_HEIGHT = 76
Expand Down Expand Up @@ -163,8 +164,7 @@ 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 data = dataFromResources([chartSeries.dataResources[0]], props.series)
const line = new ChartLine(data, {
tooltip: {
toolTipFormatter: () => {
Expand Down
21 changes: 14 additions & 7 deletions src/lib/charts/dataFromResources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
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 '../timeseries/types/SeriesData'

export function filterUnreliableFlags(data: SeriesArrayData | SeriesData) {
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 +21,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 +54,8 @@ 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.filter(filterUnreliableFlags) ?? []
}

0 comments on commit ee3bc89

Please sign in to comment.