You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting this error when following the python method, the problem lies on line 203 - casting the "value" variable into int, when I changed the line from float to int the error did not occur but I had very strange numbers on my ram readings.
This is the error description:
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\scheduler.py", line 135, in MemoryStats
stats.Memory.stats()
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\stats.py", line 612, in stats
display_themed_percent_radial_bar(memory_stats_theme_data['SWAP']['RADIAL'], swap_percent)
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\stats.py", line 203, in display_themed_percent_radial_bar
value=int(value),
^^^^^^^^^^
ValueError: cannot convert float NaN to integer
if HW_SENSORS == "PYTHON":
if platform.system() == 'Windows':
logger.warning("It is recommended to use LibreHardwareMonitor integration for Windows instead of Python "
"libraries (require admin. rights)")
import library.sensors.sensors_python as sensors
elif HW_SENSORS == "LHM":
if platform.system() == 'Windows':
import library.sensors.sensors_librehardwaremonitor as sensors
else:
logger.error("LibreHardwareMonitor integration is only available on Windows")
try:
sys.exit(0)
except:
os._exit(0)
elif HW_SENSORS == "STUB":
logger.warning("Stub sensors, not real HW sensors")
import library.sensors.sensors_stub_random as sensors
elif HW_SENSORS == "STATIC":
logger.warning("Stub sensors, not real HW sensors")
import library.sensors.sensors_stub_static as sensors
elif HW_SENSORS == "AUTO":
if platform.system() == 'Windows':
import library.sensors.sensors_librehardwaremonitor as sensors
else:
import library.sensors.sensors_python as sensors
else:
logger.error("Unsupported HW_SENSORS value in config.yaml")
try:
sys.exit(0)
except:
os._exit(0)
import library.sensors.sensors_custom as sensors_custom
def get_theme_file_path(name):
if name:
return os.path.join(config.THEME_DATA['PATH'], name)
else:
return None
def display_themed_value(theme_data, value, min_size=0, unit=''):
if not theme_data.get("SHOW", False):
return
if value is None:
return
# overridable MIN_SIZE from theme with backward compatibility
min_size = theme_data.get("MIN_SIZE", min_size)
text = f"{{:>{min_size}}}".format(value)
if theme_data.get("SHOW_UNIT", True) and unit:
text += str(unit)
display.lcd.DisplayText(
text=text,
x=theme_data.get("X", 0),
y=theme_data.get("Y", 0),
width=theme_data.get("WIDTH", 0),
height=theme_data.get("HEIGHT", 0),
font=config.FONTS_DIR + theme_data.get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
font_size=theme_data.get("FONT_SIZE", 10),
font_color=theme_data.get("FONT_COLOR", (0, 0, 0)),
background_color=theme_data.get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
align=theme_data.get("ALIGN", "left"),
anchor=theme_data.get("ANCHOR", "lt"),
)
def display_themed_line_graph(theme_data, values):
if not theme_data.get("SHOW", False):
return
line_color = theme_data.get("LINE_COLOR", (0, 0, 0))
display.lcd.DisplayLineGraph(
x=theme_data.get("X", 0),
y=theme_data.get("Y", 0),
width=theme_data.get("WIDTH", 1),
height=theme_data.get("HEIGHT", 1),
values=values,
min_value=theme_data.get("MIN_VALUE", 0),
max_value=theme_data.get("MAX_VALUE", 100),
autoscale=theme_data.get("AUTOSCALE", False),
line_color=line_color,
line_width=theme_data.get("LINE_WIDTH", 2),
graph_axis=theme_data.get("AXIS", False),
axis_color=theme_data.get("AXIS_COLOR", line_color), # If no color specified, use line color for axis
axis_font=config.FONTS_DIR + theme_data.get("AXIS_FONT", "roboto/Roboto-Black.ttf"),
axis_font_size=theme_data.get("AXIS_FONT_SIZE", 10),
background_color=theme_data.get("BACKGROUND_COLOR", (0, 0, 0)),
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None))
)
def save_last_value(value: float, last_values: List[float], history_size: int):
# Initialize last values list the first time with given size
if len(last_values) != history_size:
last_values[:] = last_values_list(size=history_size)
# Store the value to the list that can then be used for line graph
last_values.append(value)
# Also remove the oldest value from list
last_values.pop(0)
class Custom: @staticmethod
def stats():
for custom_stat in config.THEME_DATA['STATS']['CUSTOM']:
if custom_stat != "INTERVAL":
# Load the custom sensor class from sensors_custom.py based on the class name
try:
custom_stat_class = getattr(sensors_custom, str(custom_stat))()
numeric_value = custom_stat_class.as_numeric()
string_value = custom_stat_class.as_string()
last_values = custom_stat_class.last_values()
except Exception as e:
logger.error(
"Error loading custom sensor class " + str(custom_stat) + " from sensors_custom.py : " + str(e))
return
if string_value is None:
string_value = str(numeric_value)
# Display text
theme_data = config.THEME_DATA['STATS']['CUSTOM'][custom_stat].get("TEXT", None)
if theme_data is not None and string_value is not None:
display_themed_value(theme_data=theme_data, value=string_value)
# Display graph from numeric value
theme_data = config.THEME_DATA['STATS']['CUSTOM'][custom_stat].get("GRAPH", None)
if theme_data is not None and numeric_value is not None and not math.isnan(numeric_value):
display_themed_progress_bar(theme_data=theme_data, value=numeric_value)
# Display radial from numeric and text value
theme_data = config.THEME_DATA['STATS']['CUSTOM'][custom_stat].get("RADIAL", None)
if theme_data is not None and numeric_value is not None and not math.isnan(
numeric_value) and string_value is not None:
display_themed_radial_bar(
theme_data=theme_data,
value=numeric_value,
custom_text=string_value
)
# Display plot graph from histo values
theme_data = config.THEME_DATA['STATS']['CUSTOM'][custom_stat].get("LINE_GRAPH", None)
if theme_data is not None and last_values is not None:
display_themed_line_graph(theme_data=theme_data, values=last_values)
I am getting this error when following the python method, the problem lies on line 203 - casting the "value" variable into int, when I changed the line from float to int the error did not occur but I had very strange numbers on my ram readings.
This is the error description:
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\scheduler.py", line 135, in MemoryStats
stats.Memory.stats()
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\stats.py", line 612, in stats
display_themed_percent_radial_bar(memory_stats_theme_data['SWAP']['RADIAL'], swap_percent)
File "D:\Downloads\turing-smart-screen-python-3.9.1\library\stats.py", line 203, in display_themed_percent_radial_bar
value=int(value),
^^^^^^^^^^
ValueError: cannot convert float NaN to integer
This is my main.py:
def display_themed_percent_radial_bar(theme_data, value):
display_themed_radial_bar(
theme_data=theme_data,
value=int(value),
unit="%",
min_size=3
)
`# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
https://github.com/mathoudebine/turing-smart-screen-python/
Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine)
Copyright (C) 2022-2023 Rollbacke
Copyright (C) 2022-2023 Ebag333
Copyright (C) 2022-2023 w1ld3r
Copyright (C) 2022-2023 Charles Ferguson (gerph)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
import datetime
import locale
import math
import os
import platform
import sys
from typing import List
import babel.dates
import requests
from ping3 import ping
from psutil._common import bytes2human
from uptime import uptime
import library.config as config
from library.display import display
from library.log import logger
DEFAULT_HISTORY_SIZE = 10
ETH_CARD = config.CONFIG_DATA["config"].get("ETH", "")
WLO_CARD = config.CONFIG_DATA["config"].get("WLO", "")
HW_SENSORS = config.CONFIG_DATA["config"].get("HW_SENSORS", "AUTO")
CPU_FAN = config.CONFIG_DATA["config"].get("CPU_FAN", "AUTO")
PING_DEST = config.CONFIG_DATA["config"].get("PING", "127.0.0.1")
if HW_SENSORS == "PYTHON":
if platform.system() == 'Windows':
logger.warning("It is recommended to use LibreHardwareMonitor integration for Windows instead of Python "
"libraries (require admin. rights)")
import library.sensors.sensors_python as sensors
elif HW_SENSORS == "LHM":
if platform.system() == 'Windows':
import library.sensors.sensors_librehardwaremonitor as sensors
else:
logger.error("LibreHardwareMonitor integration is only available on Windows")
try:
sys.exit(0)
except:
os._exit(0)
elif HW_SENSORS == "STUB":
logger.warning("Stub sensors, not real HW sensors")
import library.sensors.sensors_stub_random as sensors
elif HW_SENSORS == "STATIC":
logger.warning("Stub sensors, not real HW sensors")
import library.sensors.sensors_stub_static as sensors
elif HW_SENSORS == "AUTO":
if platform.system() == 'Windows':
import library.sensors.sensors_librehardwaremonitor as sensors
else:
import library.sensors.sensors_python as sensors
else:
logger.error("Unsupported HW_SENSORS value in config.yaml")
try:
sys.exit(0)
except:
os._exit(0)
import library.sensors.sensors_custom as sensors_custom
def get_theme_file_path(name):
if name:
return os.path.join(config.THEME_DATA['PATH'], name)
else:
return None
def display_themed_value(theme_data, value, min_size=0, unit=''):
if not theme_data.get("SHOW", False):
return
def display_themed_percent_value(theme_data, value):
display_themed_value(
theme_data=theme_data,
value=int(value),
min_size=3,
unit="%"
)
def display_themed_temperature_value(theme_data, value):
display_themed_value(
theme_data=theme_data,
value=int(value),
min_size=3,
unit="°C"
)
def display_themed_progress_bar(theme_data, value):
if not theme_data.get("SHOW", False):
return
def display_themed_radial_bar(theme_data, value, min_size=0, unit='', custom_text=None):
if not theme_data.get("SHOW", False):
return
def display_themed_percent_radial_bar(theme_data, value):
display_themed_radial_bar(
theme_data=theme_data,
value=int(value),
unit="%",
min_size=3
)
def display_themed_temperature_radial_bar(theme_data, value):
display_themed_radial_bar(
theme_data=theme_data,
value=int(value),
min_size=3,
unit="°C"
)
def display_themed_line_graph(theme_data, values):
if not theme_data.get("SHOW", False):
return
def save_last_value(value: float, last_values: List[float], history_size: int):
# Initialize last values list the first time with given size
if len(last_values) != history_size:
last_values[:] = last_values_list(size=history_size)
# Store the value to the list that can then be used for line graph
last_values.append(value)
# Also remove the oldest value from list
last_values.pop(0)
def last_values_list(size: int) -> List[float]:
return [math.nan] * size
class CPU:
last_values_cpu_percentage = []
last_values_cpu_temperature = []
last_values_cpu_fan_speed = []
last_values_cpu_frequency = []
class Gpu:
last_values_gpu_percentage = []
last_values_gpu_mem_percentage = []
last_values_gpu_temperature = []
last_values_gpu_fps = []
last_values_gpu_fan_speed = []
last_values_gpu_frequency = []
class Memory:
last_values_memory_swap = []
last_values_memory_virtual = []
class Disk:
last_values_disk_usage = []
class Net:
last_values_wlo_upload = []
last_values_wlo_download = []
last_values_eth_upload = []
last_values_eth_download = []
class Date:
@staticmethod
def stats():
if HW_SENSORS == "STATIC":
# For static sensors, use predefined date/time
date_now = datetime.datetime.fromtimestamp(1694014609)
else:
date_now = datetime.datetime.now()
class SystemUptime:
@staticmethod
def stats():
if HW_SENSORS == "STATIC":
# For static sensors, use predefined uptime
uptimesec = 4294036
else:
uptimesec = int(uptime())
class Custom:
@staticmethod
def stats():
for custom_stat in config.THEME_DATA['STATS']['CUSTOM']:
if custom_stat != "INTERVAL":
class Weather:
@staticmethod
def stats():
WEATHER_UNITS = {'metric': '°C', 'imperial': '°F', 'standard': '°K'}
class Ping:
last_values_ping = []
`
The text was updated successfully, but these errors were encountered: