@@ -91,9 +91,7 @@ def __init__(
9191 else :
9292 self .graphsymbol = graphsymbol
9393 if self ._len_noansi (self .graphsymbol ) != 1 :
94- raise Exception (
95- "Bad graphsymbol length, must be 1" , self ._len_noansi (self .graphsymbol )
96- )
94+ raise Exception ("Bad graphsymbol length, must be 1" , self ._len_noansi (self .graphsymbol ))
9795 self .multivalue = multivalue
9896 self .hsymbols = [
9997 self ._u ("" ),
@@ -181,9 +179,7 @@ def _get_thresholds(self, data):
181179 if self .multivalue :
182180 totalvalue_len += len ("," + self ._trans_hr (ivalue ))
183181 else :
184- totalvalue_len = max (
185- totalvalue_len , len (self ._trans_hr (ivalue ))
186- )
182+ totalvalue_len = max (totalvalue_len , len (self ._trans_hr (ivalue )))
187183
188184 if self .multivalue :
189185 # remove one comma if multivalues
@@ -214,17 +210,13 @@ def _gen_graph_string(
214210 ):
215211 """Generate the bar + its paddings (left and right)"""
216212
217- def _gen_graph_string_part (
218- value , max_value , min_neg_value , graph_length , color
219- ):
213+ def _gen_graph_string_part (value , max_value , min_neg_value , graph_length , color ):
220214 all_width = max_value + abs (min_neg_value )
221215
222216 if all_width == 0 :
223217 bar_width = 0
224218 else :
225- bar_width = int (
226- abs (float (value )) * float (graph_length ) / float (all_width )
227- )
219+ bar_width = int (abs (float (value )) * float (graph_length ) / float (all_width ))
228220
229221 return (
230222 Pyasciigraph ._color_string (self .graphsymbol * bar_width , color ),
@@ -236,9 +228,7 @@ def _gen_graph_string_part(
236228 if all_width == 0 :
237229 neg_width = 0
238230 else :
239- neg_width = int (
240- abs (float (min_neg_value )) * float (graph_length ) / float (all_width )
241- )
231+ neg_width = int (abs (float (min_neg_value )) * float (graph_length ) / float (all_width ))
242232 int (abs (max_value ) * graph_length / all_width )
243233
244234 if isinstance (value , Iterable ):
@@ -264,9 +254,7 @@ def _gen_graph_string_part(
264254 accuvalue += scaled_value
265255
266256 # left padding
267- totalstring = (
268- Pyasciigraph ._u (" " ) * (neg_width - abs (totalsquares )) + totalstring
269- )
257+ totalstring = Pyasciigraph ._u (" " ) * (neg_width - abs (totalsquares )) + totalstring
270258
271259 # reset some counters
272260 accuvalue = 0
@@ -285,9 +273,7 @@ def _gen_graph_string_part(
285273 accuvalue += scaled_value
286274
287275 # right padding
288- totalstring += Pyasciigraph ._u (" " ) * (
289- start_value_pos - neg_width - abs (totalsquares )
290- )
276+ totalstring += Pyasciigraph ._u (" " ) * (start_value_pos - neg_width - abs (totalsquares ))
291277 return totalstring
292278 else :
293279 # handling for single value item
@@ -312,9 +298,7 @@ def _gen_info_string(self, info, start_info_pos, line_length):
312298 number_of_space = line_length - start_info_pos - self ._len_noansi (info )
313299 return info + Pyasciigraph ._u (" " ) * number_of_space
314300
315- def _gen_value_string (
316- self , value , min_neg_value , color , start_value_pos , start_info_pos
317- ):
301+ def _gen_value_string (self , value , min_neg_value , color , start_value_pos , start_info_pos ):
318302 """Generate the value string + padding"""
319303 icount = 0
320304 if isinstance (value , Iterable ) and self .multivalue :
@@ -324,14 +308,10 @@ def _gen_value_string(
324308 # with the len() function even when they are not printed to
325309 # the screen.
326310 totalvalue_len = len (self ._trans_hr (ivalue ))
327- totalvalue = Pyasciigraph ._color_string (
328- self ._trans_hr (ivalue ), icolor
329- )
311+ totalvalue = Pyasciigraph ._color_string (self ._trans_hr (ivalue ), icolor )
330312 else :
331313 totalvalue_len += len ("," + self ._trans_hr (ivalue ))
332- totalvalue += "," + Pyasciigraph ._color_string (
333- self ._trans_hr (ivalue ), icolor
334- )
314+ totalvalue += "," + Pyasciigraph ._color_string (self ._trans_hr (ivalue ), icolor )
335315 icount += 1
336316 elif isinstance (value , Iterable ):
337317 max_value = min_neg_value
@@ -347,9 +327,7 @@ def _gen_value_string(
347327 totalvalue_len = len (self ._trans_hr (value ))
348328 totalvalue = Pyasciigraph ._color_string (self ._trans_hr (value ), color )
349329
350- number_space = (
351- start_info_pos - start_value_pos - totalvalue_len - self .separator_length
352- )
330+ number_space = start_info_pos - start_value_pos - totalvalue_len - self .separator_length
353331
354332 # This must not be negitive, this happens when the string length is
355333 # larger than the separator length
@@ -457,18 +435,14 @@ def graph(self, label=None, data=[]):
457435 # calcul of where to start info
458436 start_info_pos = self .line_length - all_thre ["info_max_length" ]
459437 # calcul of where to start value
460- start_value_pos = (
461- start_info_pos - self .separator_length - all_thre ["value_max_length" ]
462- )
438+ start_value_pos = start_info_pos - self .separator_length - all_thre ["value_max_length" ]
463439 # calcul of where to end graph
464440 graph_length = start_value_pos - self .separator_length
465441 else :
466442 # calcul of where to start value
467443 start_value_pos = self .min_graph_length + self .separator_length
468444 # calcul of where to start info
469- start_info_pos = (
470- start_value_pos + all_thre ["value_max_length" ] + self .separator_length
471- )
445+ start_info_pos = start_value_pos + all_thre ["value_max_length" ] + self .separator_length
472446 # calcul of where to end graph
473447 graph_length = start_value_pos - self .separator_length
474448 # calcul of the real line length
@@ -514,32 +488,18 @@ def make_alert_message(
514488 score_col = "metric_score_smooth" ,
515489 ascii_graph = False ,
516490):
517- df_alert_metric = df_alert_metric .sort_values (
518- by = "metric_timestamp" , ascending = False
519- ).dropna ()
520- df_alert_metric ["metric_timestamp" ] = pd .to_datetime (
521- df_alert_metric ["metric_timestamp" ]
522- )
491+ df_alert_metric = df_alert_metric .sort_values (by = "metric_timestamp" , ascending = False ).dropna ()
492+ df_alert_metric ["metric_timestamp" ] = pd .to_datetime (df_alert_metric ["metric_timestamp" ])
523493 x = df_alert_metric ["metric_value" ].round (2 ).values .tolist ()
524494 metric_name = df_alert_metric ["metric_name" ].unique ()[0 ]
525- metric_timestamp_from = (
526- df_alert_metric ["metric_timestamp" ].min ().strftime ("%Y-%m-%d %H:%M" )
527- )
528- metric_timestamp_to = (
529- df_alert_metric ["metric_timestamp" ].max ().strftime ("%Y-%m-%d %H:%M" )
530- )
495+ metric_timestamp_from = df_alert_metric ["metric_timestamp" ].min ().strftime ("%Y-%m-%d %H:%M" )
496+ metric_timestamp_to = df_alert_metric ["metric_timestamp" ].max ().strftime ("%Y-%m-%d %H:%M" )
531497 graph_title = f"{ metric_name } ({ metric_timestamp_from } to { metric_timestamp_to } )"
532498 message = ""
533499 if ascii_graph :
534500 labels = (
535- np .where (
536- df_alert_metric ["metric_alert" ] == 1 ,
537- anomaly_symbol ,
538- normal_symbol
539- )
540- + (df_alert_metric [score_col ].round (2 ) * 100 )
541- .astype ("int" )
542- .astype ("str" )
501+ np .where (df_alert_metric ["metric_alert" ] == 1 , anomaly_symbol , normal_symbol )
502+ + (df_alert_metric [score_col ].round (2 ) * 100 ).astype ("int" ).astype ("str" )
543503 + "% "
544504 )
545505 data = zip (labels , x )
0 commit comments