Skip to content

Commit

Permalink
Partly fixes - only applies for diff_last - #912
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Krivonog boris.krivonog@inova.si

Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
  • Loading branch information
crnjan committed Jan 11, 2023
1 parent c8c3b8c commit fff6b6d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default {
return Promise.resolve(getter([]))
}

let boundary = seriesComponents[component.component].includeBoundary?.(component)
const itemPromises = neededItems.map((neededItem) => {
if (this.items[neededItem]) return Promise.resolve(this.items[neededItem])
return this.$oh.api.get(`/rest/items/${neededItem}`).then((item) => {
Expand All @@ -154,7 +155,8 @@ export default {
let query = {
serviceId: component.config.service || undefined,
starttime: seriesStartTime.toISOString(),
endtime: seriesEndTime.subtract(1, 'millisecond').toISOString()
endtime: seriesEndTime.subtract(1, 'millisecond').toISOString(),
boundary: boundary
}

return Promise.all([itemPromises[neededItem], this.$oh.api.get(url, query)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default (aggregationFunction, arr, idx, values) => {
aggregate = idx < 1 ? NaN : arr[1][0] - values[idx - 1][1][0]
break
case 'diff_last':
aggregate = idx < 1 ? NaN : arr[1][arr[1].length - 1] - values[idx - 1][1][values[idx - 1][1].length - 1]
if (idx < 1) {
aggregate = arr[1][arr[1].length - 1] - arr[1][0]
} else {
aggregate = arr[1][arr[1].length - 1] - values[idx - 1][1][values[idx - 1][1].length - 1]
}
break
case 'average':
aggregate = arr[1].reduce((sum, state) => sum + parseFloat(state), 0) / arr[1].length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,38 @@ function dimensionFromDate (d, dimension, invert) {
}
}

function includeBoundaryFor (component) {
return (!component || !component.config || component.config.aggregationFunction !== 'diff_last') ? undefined : true
}

export default {
neededItems (component) {
if (!component || !component.config || !component.config.item) return []
return [component.config.item]
},
includeBoundary (component) {
return includeBoundaryFor(component)
},
get (component, points, startTime, endTime, chart) {
let dimension1 = component.config.dimension1
let dimension2 = component.config.dimension2
let boundary = includeBoundaryFor(component)

const itemPoints = points.find(p => p.name === component.config.item).data
const groups = itemPoints.reduce((acc, p) => {
// we'll suppose dimension2 always more granular than dimension1
// e.g. if dimension1=day, dimension2 can be hour but not month
let groupStart = dimension2 || dimension1
if (groupStart === 'weekday' || groupStart === 'isoWeekday') groupStart = 'day'
let start = dayjs(p.time).startOf(groupStart)
let pTime = dayjs(p.time)
let start = pTime.startOf(groupStart)
if (acc.length && acc[acc.length - 1][0].isSame(start)) {
acc[acc.length - 1][1].push(p.state)
} else {
acc.push([start, [p.state]])
if (acc.length === 1 && boundary && !pTime.isSame(start)) {
acc[0][1].unshift(NaN)
}
}
return acc
}, [])
Expand Down

0 comments on commit fff6b6d

Please sign in to comment.