Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
114431be
Commit
114431be
authored
Mar 30, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
heatmap: add tests for heatmap_data_converter
parent
84b15fc7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
176 additions
and
1 deletions
+176
-1
public/app/plugins/panel/heatmap/heatmap_data_converter.ts
+51
-1
public/app/plugins/panel/heatmap/specs/heatmap_data_converter_specs.ts
+125
-0
No files found.
public/app/plugins/panel/heatmap/heatmap_data_converter.ts
View file @
114431be
...
...
@@ -5,6 +5,16 @@ import _ from 'lodash';
let
VALUE_INDEX
=
0
;
let
TIME_INDEX
=
1
;
interface
XBucket
{
x
:
number
;
buckets
:
any
;
}
interface
YBucket
{
y
:
number
;
values
:
number
[];
}
/**
* Convert set of time series into heatmap buckets
* @return {Object} Heatmap object:
...
...
@@ -347,11 +357,51 @@ function logp(value, base) {
return
Math
.
log
(
value
)
/
Math
.
log
(
base
);
}
/**
* Compare two heatmap data objects
* @param objA
* @param objB
*/
function
isHeatmapDataEqual
(
objA
:
any
,
objB
:
any
):
boolean
{
let
is_eql
=
true
;
_
.
forEach
(
objA
,
(
xBucket
:
XBucket
,
x
)
=>
{
if
(
objB
[
x
])
{
_
.
forEach
(
xBucket
.
buckets
,
(
yBucket
:
YBucket
,
y
)
=>
{
if
(
objB
[
x
].
buckets
&&
objB
[
x
].
buckets
[
y
])
{
if
(
objB
[
x
].
buckets
[
y
].
values
)
{
is_eql
=
_
.
isEqual
(
yBucket
.
values
.
sort
(),
objB
[
x
].
buckets
[
y
].
values
.
sort
());
if
(
!
is_eql
)
{
return
false
;
}
}
else
{
is_eql
=
false
;
return
false
;
}
}
else
{
is_eql
=
false
;
return
false
;
}
});
if
(
!
is_eql
)
{
return
false
;
}
}
else
{
is_eql
=
false
;
return
false
;
}
});
return
is_eql
;
}
export
{
convertToHeatMap
,
convertToCards
,
removeZeroBuckets
,
mergeZeroBuckets
,
getMinLog
,
getValueBucketBound
getValueBucketBound
,
isHeatmapDataEqual
};
public/app/plugins/panel/heatmap/specs/heatmap_data_converter_specs.ts
0 → 100644
View file @
114431be
///<reference path="../../../../headers/common.d.ts" />
import
_
from
'lodash'
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'../../../../../test/lib/common'
;
import
TimeSeries
from
'app/core/time_series2'
;
import
{
convertToHeatMap
,
isHeatmapDataEqual
}
from
'../heatmap_data_converter'
;
describe
(
'isHeatmapDataEqual'
,
()
=>
{
let
ctx
:
any
=
{};
beforeEach
(()
=>
{
ctx
.
heatmapA
=
{
'1422774000000'
:
{
x
:
1422774000000
,
buckets
:
{
'1'
:
{
y
:
1
,
values
:
[
1
,
1.5
]
},
'2'
:
{
y
:
2
,
values
:
[
1
]
}
}
}
};
ctx
.
heatmapB
=
{
'1422774000000'
:
{
x
:
1422774000000
,
buckets
:
{
'1'
:
{
y
:
1
,
values
:
[
1.5
,
1
]
},
'2'
:
{
y
:
2
,
values
:
[
1
]
}
}
}
};
});
it
(
'should proper compare objects'
,
()
=>
{
let
heatmapC
=
_
.
cloneDeep
(
ctx
.
heatmapA
);
heatmapC
[
'1422774000000'
].
buckets
[
'1'
].
values
=
[
1
,
1.5
];
let
heatmapD
=
_
.
cloneDeep
(
ctx
.
heatmapA
);
heatmapD
[
'1422774000000'
].
buckets
[
'1'
].
values
=
[
1.5
,
1
,
1.6
];
let
heatmapE
=
_
.
cloneDeep
(
ctx
.
heatmapA
);
heatmapE
[
'1422774000000'
].
buckets
[
'1'
].
values
=
[
1
,
1.6
];
expect
(
isHeatmapDataEqual
(
ctx
.
heatmapA
,
ctx
.
heatmapB
)).
to
.
be
(
true
);
expect
(
isHeatmapDataEqual
(
ctx
.
heatmapA
,
heatmapC
)).
to
.
be
(
true
);
expect
(
isHeatmapDataEqual
(
ctx
.
heatmapA
,
heatmapD
)).
to
.
be
(
false
);
expect
(
isHeatmapDataEqual
(
ctx
.
heatmapA
,
heatmapE
)).
to
.
be
(
false
);
});
});
describe
(
'HeatmapDataConverter'
,
()
=>
{
let
ctx
:
any
=
{};
beforeEach
(()
=>
{
ctx
.
series
=
[];
ctx
.
series
.
push
(
new
TimeSeries
({
datapoints
:
[[
1
,
1422774000000
],
[
2
,
1422774060000
]],
alias
:
'series1'
}));
ctx
.
series
.
push
(
new
TimeSeries
({
datapoints
:
[[
2
,
1422774000000
],
[
3
,
1422774060000
]],
alias
:
'series2'
}));
ctx
.
xBucketSize
=
60000
;
// 60s
ctx
.
yBucketSize
=
1
;
ctx
.
logBase
=
1
;
});
describe
(
'when logBase is 1 (linear scale)'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
logBase
=
1
;
});
it
(
'should build proper heatmap data'
,
()
=>
{
let
expectedHeatmap
=
{
'1422774000000'
:
{
x
:
1422774000000
,
buckets
:
{
'1'
:
{
y
:
1
,
values
:
[
1
]
},
'2'
:
{
y
:
2
,
values
:
[
2
]
}
}
},
'1422774060000'
:
{
x
:
1422774060000
,
buckets
:
{
'2'
:
{
y
:
2
,
values
:
[
2
]
},
'3'
:
{
y
:
3
,
values
:
[
3
]
}
}
},
};
let
heatmap
=
convertToHeatMap
(
ctx
.
series
,
ctx
.
yBucketSize
,
ctx
.
xBucketSize
,
ctx
.
logBase
);
expect
(
isHeatmapDataEqual
(
heatmap
,
expectedHeatmap
)).
to
.
be
(
true
);
});
});
describe
(
'when logBase is 2'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
logBase
=
2
;
});
it
(
'should build proper heatmap data'
,
()
=>
{
let
expectedHeatmap
=
{
'1422774000000'
:
{
x
:
1422774000000
,
buckets
:
{
'1'
:
{
y
:
1
,
values
:
[
1
]
},
'2'
:
{
y
:
2
,
values
:
[
2
]
}
}
},
'1422774060000'
:
{
x
:
1422774060000
,
buckets
:
{
'2'
:
{
y
:
2
,
values
:
[
2
,
3
]
}
}
},
};
let
heatmap
=
convertToHeatMap
(
ctx
.
series
,
ctx
.
yBucketSize
,
ctx
.
xBucketSize
,
ctx
.
logBase
);
expect
(
isHeatmapDataEqual
(
heatmap
,
expectedHeatmap
)).
to
.
be
(
true
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment