hastic-zzz / hastic-server

Hastic data management server for analyzing patterns and anomalies from Grafana
GNU General Public License v3.0
330 stars 23 forks source link

WIP: Utils.spans.cutSpanWithSpans more tests #755

Closed jonyrock closed 5 years ago

jonyrock commented 5 years ago

Just to be sure that the function Utils.spans.cutSpanWithSpans works as it should, few more tests added: It will help in future if we want to improve the performance.

This PR changes the behavior of cutSpanWithSpans and renames it to cutSegmentWithSegments

New tests:

One-point cut

If we cut [1, 10] with [5, 5] , we should get spans [1, 4] and [6, 10]

Infinite spans

If we cut [0, Infinity] with [5, 10], we should get [0, 4] and [11, Infinity]

If we cut [1, 6] with [0, Infinity], we should get []

If we cut [0, 6] with [1, Infinity], we should get [0, 0]

If we cut [-Infinity, Infinity] with [-Infinity, Infinity] we should get []

Overlapping cuts

There are many combinations where cuts include each other or could be sorted wrong. Many new combinations added. Including infinite case.

jonyrock commented 5 years ago

@amper43 @rozetko

In first version of this PR, I said:

One-point cut

If we cut [1, 10] with [5, 5] , we should get spans [1, 5] and [5, 10]

but is truly correct behavior? In theory we can get such case when we run detector for one point for threshold.

We should better define what Span(x,y) is. Possible options are: (x, y), (x, y], [x, y) and [x, y]

jonyrock commented 5 years ago

I believe that Span should represent a discrete structure, which is a countable set, integer segment , subset of Z

So when we want to get cut [x, x] from [a, b] where a < x < b, then we should return split [a, x - 1] and [x + 1, b]

jonyrock commented 5 years ago

Also, I propose to stop using word "Span" without clear math definition. So I an going to rename Utils.spans.cutSpanWithSpans accordingly.

jonyrock commented 5 years ago

image

If [a, b] is the segment we are cutting from and [z, z] and [x, y] are cutting segments, we should get [[a, a], [a, x - 1]] in result

jonyrock commented 5 years ago

All thread compiled to https://github.com/hastic/hastic-server/pull/756