3535from library .display import display
3636from library .log import logger
3737
38+ DEFAULT_HISTORY_SIZE = 10
39+
3840ETH_CARD = config .CONFIG_DATA ["config" ]["ETH" ]
3941WLO_CARD = config .CONFIG_DATA ["config" ]["WLO" ]
4042HW_SENSORS = config .CONFIG_DATA ["config" ]["HW_SENSORS" ]
@@ -220,10 +222,13 @@ def display_themed_line_graph(theme_data, values):
220222 )
221223
222224
223- def save_last_value (value , last_values : List [float ]):
224- # Store the value to the history list that can be used for line graph
225+ def save_last_value (value : float , last_values : List [float ], history_size : int ):
226+ # Initialize last values list the first time with given size
227+ if len (last_values ) != history_size :
228+ last_values [:] = last_values_list (size = history_size )
229+ # Store the value to the list that can then be used for line graph
225230 last_values .append (value )
226- # Also remove the oldest value from history list
231+ # Also remove the oldest value from list
227232 last_values .pop (0 )
228233
229234
@@ -232,17 +237,18 @@ def last_values_list(size: int) -> List[float]:
232237
233238
234239class CPU :
235- last_values_cpu_percentage = last_values_list ( size = 10 )
236- last_values_cpu_temperature = last_values_list ( size = 10 )
237- last_values_cpu_fan_speed = last_values_list ( size = 10 )
240+ last_values_cpu_percentage = []
241+ last_values_cpu_temperature = []
242+ last_values_cpu_fan_speed = []
238243
239244 @classmethod
240245 def percentage (cls ):
241246 theme_data = config .THEME_DATA ['STATS' ]['CPU' ]['PERCENTAGE' ]
242247 cpu_percentage = sensors .Cpu .percentage (
243248 interval = theme_data .get ("INTERVAL" , None )
244249 )
245- save_last_value (cpu_percentage , cls .last_values_cpu_percentage )
250+ save_last_value (cpu_percentage , cls .last_values_cpu_percentage ,
251+ theme_data ['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
246252 # logger.debug(f"CPU Percentage: {cpu_percentage}")
247253
248254 display_themed_progress_bar (theme_data ['GRAPH' ], cpu_percentage )
@@ -272,7 +278,9 @@ def load(cls):
272278 @classmethod
273279 def temperature (cls ):
274280 temperature = sensors .Cpu .temperature ()
275- save_last_value (temperature , cls .last_values_cpu_temperature )
281+ save_last_value (temperature , cls .last_values_cpu_temperature ,
282+ config .THEME_DATA ['STATS' ]['CPU' ]['TEMPERATURE' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" ,
283+ DEFAULT_HISTORY_SIZE ))
276284
277285 cpu_temp_text_data = config .THEME_DATA ['STATS' ]['CPU' ]['TEMPERATURE' ]['TEXT' ]
278286 cpu_temp_radial_data = config .THEME_DATA ['STATS' ]['CPU' ]['TEMPERATURE' ]['RADIAL' ]
@@ -297,7 +305,9 @@ def temperature(cls):
297305 @classmethod
298306 def fan_speed (cls ):
299307 fan_percent = sensors .Cpu .fan_percent ()
300- save_last_value (fan_percent , cls .last_values_cpu_fan_speed )
308+ save_last_value (fan_percent , cls .last_values_cpu_fan_speed ,
309+ config .THEME_DATA ['STATS' ]['CPU' ]['FAN_SPEED' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" ,
310+ DEFAULT_HISTORY_SIZE ))
301311
302312 cpu_fan_text_data = config .THEME_DATA ['STATS' ]['CPU' ]['FAN_SPEED' ]['TEXT' ]
303313 cpu_fan_radial_data = config .THEME_DATA ['STATS' ]['CPU' ]['FAN_SPEED' ]['RADIAL' ]
@@ -321,26 +331,31 @@ def fan_speed(cls):
321331
322332
323333class Gpu :
324- last_values_gpu_percentage = last_values_list ( size = 10 )
325- last_values_gpu_mem_percentage = last_values_list ( size = 10 )
326- last_values_gpu_temperature = last_values_list ( size = 10 )
327- last_values_gpu_fps = last_values_list ( size = 10 )
328- last_values_gpu_fan_speed = last_values_list ( size = 10 )
334+ last_values_gpu_percentage = []
335+ last_values_gpu_mem_percentage = []
336+ last_values_gpu_temperature = []
337+ last_values_gpu_fps = []
338+ last_values_gpu_fan_speed = []
329339
330340 @classmethod
331341 def stats (cls ):
332342 load , memory_percentage , memory_used_mb , temperature = sensors .Gpu .stats ()
333343 fps = sensors .Gpu .fps ()
334344 fan_percent = sensors .Gpu .fan_percent ()
335345
336- save_last_value (load , cls .last_values_gpu_percentage )
337- save_last_value (memory_percentage , cls .last_values_gpu_mem_percentage )
338- save_last_value (temperature , cls .last_values_gpu_temperature )
339- save_last_value (fps , cls .last_values_gpu_fps )
340- save_last_value (fan_percent , cls .last_values_gpu_fan_speed )
341-
342346 theme_gpu_data = config .THEME_DATA ['STATS' ]['GPU' ]
343347
348+ save_last_value (load , cls .last_values_gpu_percentage ,
349+ theme_gpu_data ['PERCENTAGE' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
350+ save_last_value (memory_percentage , cls .last_values_gpu_mem_percentage ,
351+ theme_gpu_data ['MEMORY_PERCENT' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
352+ save_last_value (temperature , cls .last_values_gpu_temperature ,
353+ theme_gpu_data ['TEMPERATURE' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
354+ save_last_value (fps , cls .last_values_gpu_fps ,
355+ theme_gpu_data ['FPS' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
356+ save_last_value (fan_percent , cls .last_values_gpu_fan_speed ,
357+ theme_gpu_data ['FAN_SPEED' ]['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
358+
344359 ################################ for backward compatibility only
345360 gpu_mem_graph_data = theme_gpu_data ['MEMORY' ]['GRAPH' ]
346361 gpu_mem_radial_data = theme_gpu_data ['MEMORY' ]['RADIAL' ]
@@ -518,19 +533,19 @@ def stats():
518533
519534 display_themed_value (
520535 theme_data = memory_stats_theme_data ['VIRTUAL' ]['USED' ],
521- value = int (sensors .Memory .virtual_used () / 1024 ** 2 ),
536+ value = int (sensors .Memory .virtual_used () / 1024 ** 2 ),
522537 min_size = 5 ,
523538 unit = " M"
524539 )
525540 display_themed_value (
526541 theme_data = memory_stats_theme_data ['VIRTUAL' ]['FREE' ],
527- value = int (sensors .Memory .virtual_free () / 1024 ** 2 ),
542+ value = int (sensors .Memory .virtual_free () / 1024 ** 2 ),
528543 min_size = 5 ,
529544 unit = " M"
530545 )
531546 display_themed_value (
532547 theme_data = memory_stats_theme_data ['VIRTUAL' ]['TOTAL' ],
533- value = int ((sensors .Memory .virtual_free () + sensors .Memory .virtual_used ()) / 1024 ** 2 ),
548+ value = int ((sensors .Memory .virtual_free () + sensors .Memory .virtual_used ()) / 1024 ** 2 ),
534549 min_size = 5 ,
535550 unit = " M"
536551 )
0 commit comments