@@ -138,9 +138,8 @@ func calcPercentile(data []float64, p float64) float64 {
138138 c := math .Ceil (k )
139139 if f == c {
140140 return data [int (k )]
141- } else {
142- return data [int (f )]* (c - k ) + data [int (c )]* (k - f )
143141 }
142+ return data [int (f )]* (c - k ) + data [int (c )]* (k - f )
144143}
145144
146145const queryLimit = 10000
@@ -273,19 +272,19 @@ func (mongo *mongoHandler) getHeatMap(dbname, collection, metric string) (*heatM
273272
274273 iter := _collection .Find (bson.M {"m" : metric }).Sort ("ts" ).Iter ()
275274 for iter .Next (& doc ) {
276- if tsInt , err := strconv .ParseInt (doc ["ts" ].(string ), 10 , 64 ); err != nil {
275+ tsInt , err := strconv .ParseInt (doc ["ts" ].(string ), 10 , 64 )
276+ if err != nil {
277277 return nil , err
278- } else {
279- x := math .Floor (width * float64 (tsInt - hm .MinTS ) / float64 (hm .MaxTS - hm .MinTS ))
280- y := math .Floor (height * doc ["v" ].(float64 ) / hm .MaxValue )
281- if x == width {
282- x --
283- }
284- if y == height {
285- y --
286- }
287- hm .Map [int (y )][int (x )]++
288278 }
279+ x := math .Floor (width * float64 (tsInt - hm .MinTS ) / float64 (hm .MaxTS - hm .MinTS ))
280+ y := math .Floor (height * doc ["v" ].(float64 ) / hm .MaxValue )
281+ if x == width {
282+ x --
283+ }
284+ if y == height {
285+ y --
286+ }
287+ hm .Map [int (y )][int (x )]++
289288 }
290289 if err := iter .Close (); err != nil {
291290 return nil , err
@@ -301,15 +300,14 @@ func (mongo *mongoHandler) getHistogram(dbname, collection, metric string) (map[
301300 defer session .Close ()
302301 _collection := session .DB (dbPrefix + dbname ).C (collection )
303302
304- var skip int
305- if count , err := _collection . Find (bson. M { "m" : metric }). Count (); err != nil {
303+ count , err := _collection . Find (bson. M { "m" : metric }). Count ()
304+ if err != nil {
306305 return nil , err
307- } else {
308- skip = int (float64 (count )* 0.99 ) - 1
309306 }
310- if skip == - 1 {
307+ if count <= 1 {
311308 return nil , errors .New ("not enough data points" )
312309 }
310+ skip := int (float64 (count )* 0.99 ) - 1
313311
314312 var doc map [string ]interface {}
315313 if err := _collection .Find (bson.M {"m" : metric }).Sort ("v" ).Skip (skip ).One (& doc ); err != nil {
@@ -330,11 +328,11 @@ func (mongo *mongoHandler) getHistogram(dbname, collection, metric string) (map[
330328 lr := minValue + float64 (i )* delta
331329 rr := lr + delta
332330 rname := fmt .Sprintf ("%f - %f" , lr , rr )
333- if count , err := _collection .Find (bson.M {"m" : metric , "v" : bson.M {"$gte" : lr , "$lt" : rr }}).Count (); err != nil {
331+ count , err := _collection .Find (bson.M {"m" : metric , "v" : bson.M {"$gte" : lr , "$lt" : rr }}).Count ()
332+ if err != nil {
334333 return nil , err
335- } else {
336- histogram [rname ] = 100.0 * float64 (count ) / float64 (skip )
337334 }
335+ histogram [rname ] = 100.0 * float64 (count ) / float64 (skip )
338336 }
339337
340338 return histogram , nil
0 commit comments