mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
console/graph: also invert unit direction on bidirectional
This commit is contained in:
@@ -100,8 +100,9 @@ func (input graphHandlerInput) previousPeriod() graphHandlerInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type toSQL1Options struct {
|
type toSQL1Options struct {
|
||||||
skipWithClause bool
|
skipWithClause bool
|
||||||
offsetedStart time.Time
|
reverseDirection bool
|
||||||
|
offsetedStart time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (input graphHandlerInput) toSQL1(axis int, options toSQL1Options) string {
|
func (input graphHandlerInput) toSQL1(axis int, options toSQL1Options) string {
|
||||||
@@ -155,6 +156,17 @@ func (input graphHandlerInput) toSQL1(axis int, options toSQL1Options) string {
|
|||||||
withStr = fmt.Sprintf("\nWITH\n %s", strings.Join(with, ",\n "))
|
withStr = fmt.Sprintf("\nWITH\n %s", strings.Join(with, ",\n "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Units
|
||||||
|
units := input.Units
|
||||||
|
if options.reverseDirection {
|
||||||
|
switch units {
|
||||||
|
case "inl2%":
|
||||||
|
units = "outl2%"
|
||||||
|
case "outl2%":
|
||||||
|
units = "inl2%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sqlQuery := fmt.Sprintf(`
|
sqlQuery := fmt.Sprintf(`
|
||||||
{{ with %s }}%s
|
{{ with %s }}%s
|
||||||
SELECT %d AS axis, * FROM (
|
SELECT %d AS axis, * FROM (
|
||||||
@@ -175,7 +187,7 @@ ORDER BY time WITH FILL
|
|||||||
StartForInterval: startForInterval,
|
StartForInterval: startForInterval,
|
||||||
MainTableRequired: requireMainTable(input.schema, input.Dimensions, input.Filter),
|
MainTableRequired: requireMainTable(input.schema, input.Dimensions, input.Filter),
|
||||||
Points: input.Points,
|
Points: input.Points,
|
||||||
Units: input.Units,
|
Units: units,
|
||||||
}),
|
}),
|
||||||
withStr, axis, strings.Join(fields, ",\n "), where, offsetShift, offsetShift,
|
withStr, axis, strings.Join(fields, ",\n "), where, offsetShift, offsetShift,
|
||||||
dimensionsInterpolate,
|
dimensionsInterpolate,
|
||||||
@@ -189,7 +201,10 @@ func (input graphHandlerInput) toSQL() string {
|
|||||||
// Handle specific options. We have to align time periods in
|
// Handle specific options. We have to align time periods in
|
||||||
// case the previous period does not use the same offsets.
|
// case the previous period does not use the same offsets.
|
||||||
if input.Bidirectional {
|
if input.Bidirectional {
|
||||||
parts = append(parts, input.reverseDirection().toSQL1(2, toSQL1Options{skipWithClause: true}))
|
parts = append(parts, input.reverseDirection().toSQL1(2, toSQL1Options{
|
||||||
|
skipWithClause: true,
|
||||||
|
reverseDirection: true,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
if input.PreviousPeriod {
|
if input.PreviousPeriod {
|
||||||
parts = append(parts, input.previousPeriod().toSQL1(3, toSQL1Options{
|
parts = append(parts, input.previousPeriod().toSQL1(3, toSQL1Options{
|
||||||
@@ -199,8 +214,9 @@ func (input graphHandlerInput) toSQL() string {
|
|||||||
}
|
}
|
||||||
if input.Bidirectional && input.PreviousPeriod {
|
if input.Bidirectional && input.PreviousPeriod {
|
||||||
parts = append(parts, input.reverseDirection().previousPeriod().toSQL1(4, toSQL1Options{
|
parts = append(parts, input.reverseDirection().previousPeriod().toSQL1(4, toSQL1Options{
|
||||||
skipWithClause: true,
|
skipWithClause: true,
|
||||||
offsetedStart: input.Start,
|
reverseDirection: true,
|
||||||
|
offsetedStart: input.Start,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
return strings.Join(parts, "\nUNION ALL\n")
|
return strings.Join(parts, "\nUNION ALL\n")
|
||||||
|
|||||||
@@ -312,6 +312,49 @@ SELECT
|
|||||||
FROM {{ .Table }}
|
FROM {{ .Table }}
|
||||||
WHERE {{ .Timefilter }} AND (SrcCountry = 'FR' AND DstCountry = 'US')
|
WHERE {{ .Timefilter }} AND (SrcCountry = 'FR' AND DstCountry = 'US')
|
||||||
GROUP BY time, dimensions
|
GROUP BY time, dimensions
|
||||||
|
ORDER BY time WITH FILL
|
||||||
|
FROM {{ .TimefilterStart }}
|
||||||
|
TO {{ .TimefilterEnd }} + INTERVAL 1 second
|
||||||
|
STEP {{ .Interval }}
|
||||||
|
INTERPOLATE (dimensions AS emptyArrayString()))
|
||||||
|
{{ end }}`,
|
||||||
|
}, {
|
||||||
|
Description: "no dimensions, reverse direction, inl2%",
|
||||||
|
Input: graphHandlerInput{
|
||||||
|
Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC),
|
||||||
|
End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC),
|
||||||
|
Points: 100,
|
||||||
|
Dimensions: []query.Column{},
|
||||||
|
Filter: query.NewFilter("DstCountry = 'FR' AND SrcCountry = 'US'"),
|
||||||
|
Units: "inl2%",
|
||||||
|
Bidirectional: true,
|
||||||
|
},
|
||||||
|
Expected: `
|
||||||
|
{{ with context @@{"start":"2022-04-10T15:45:10Z","end":"2022-04-11T15:45:10Z","points":100,"units":"inl2%"}@@ }}
|
||||||
|
SELECT 1 AS axis, * FROM (
|
||||||
|
SELECT
|
||||||
|
{{ call .ToStartOfInterval "TimeReceived" }} AS time,
|
||||||
|
{{ .Units }}/{{ .Interval }} AS xps,
|
||||||
|
emptyArrayString() AS dimensions
|
||||||
|
FROM {{ .Table }}
|
||||||
|
WHERE {{ .Timefilter }} AND (DstCountry = 'FR' AND SrcCountry = 'US')
|
||||||
|
GROUP BY time, dimensions
|
||||||
|
ORDER BY time WITH FILL
|
||||||
|
FROM {{ .TimefilterStart }}
|
||||||
|
TO {{ .TimefilterEnd }} + INTERVAL 1 second
|
||||||
|
STEP {{ .Interval }}
|
||||||
|
INTERPOLATE (dimensions AS emptyArrayString()))
|
||||||
|
{{ end }}
|
||||||
|
UNION ALL
|
||||||
|
{{ with context @@{"start":"2022-04-10T15:45:10Z","end":"2022-04-11T15:45:10Z","points":100,"units":"outl2%"}@@ }}
|
||||||
|
SELECT 2 AS axis, * FROM (
|
||||||
|
SELECT
|
||||||
|
{{ call .ToStartOfInterval "TimeReceived" }} AS time,
|
||||||
|
{{ .Units }}/{{ .Interval }} AS xps,
|
||||||
|
emptyArrayString() AS dimensions
|
||||||
|
FROM {{ .Table }}
|
||||||
|
WHERE {{ .Timefilter }} AND (SrcCountry = 'FR' AND DstCountry = 'US')
|
||||||
|
GROUP BY time, dimensions
|
||||||
ORDER BY time WITH FILL
|
ORDER BY time WITH FILL
|
||||||
FROM {{ .TimefilterStart }}
|
FROM {{ .TimefilterStart }}
|
||||||
TO {{ .TimefilterEnd }} + INTERVAL 1 second
|
TO {{ .TimefilterEnd }} + INTERVAL 1 second
|
||||||
|
|||||||
Reference in New Issue
Block a user