Skip to content

Commit c1c40f1

Browse files
authored
Merge pull request #146 from mathoudebine/feature/add-static-stub-data
Feature/add static stub data
2 parents 15e18f6 + f01169a commit c1c40f1

File tree

6 files changed

+117
-14
lines changed

6 files changed

+117
-14
lines changed

.github/workflows/system-monitor-windows.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ jobs:
4040
echo "Using theme ${{ matrix.theme }}"
4141
(Get-Content config.yaml) -replace "^ THEME.*$"," THEME: ${{ matrix.theme }}" | Set-Content config.yaml
4242
43-
# For tests do not use LibreHardwareMonitor as it needs admin rights
44-
(Get-Content config.yaml) -replace "^ HW_SENSORS.*$"," HW_SENSORS: PYTHON" | Set-Content config.yaml
45-
4643
- name: Run system monitor for 20 seconds
4744
run: |
4845
Start-Process -NoNewWindow python3 main.py -RedirectStandardOutput output.log -RedirectStandardError error.log

config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ config:
2222

2323
# Hardware sensors reading
2424
# Choose the appropriate method for reading your hardware sensors:
25-
# - PYTHON use Python libraries (psutils, GPUtil...) to read hardware sensors (supports all OS but not all HW)
26-
# - LHM use LibreHardwareMonitor library to read hardware sensors (Windows only - NEEDS ADMIN RIGHTS)
27-
# - STUB use fake random data instead of real hardware sensors
28-
# - AUTO use the best method based on your OS: Windows OS will use LHM, other OS will use Python libraries
25+
# - PYTHON use Python libraries (psutils, GPUtil...) to read hardware sensors (supports all OS but not all HW)
26+
# - LHM use LibreHardwareMonitor library to read hardware sensors (Windows only - NEEDS ADMIN RIGHTS)
27+
# - STUB / STATIC use random/static data instead of real hardware sensors
28+
# - AUTO use the best method based on your OS: Windows OS will use LHM, other OS will use Python libraries
2929
HW_SENSORS: AUTO
3030

3131
# Network interfaces

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@ def frequency() -> float:
124124
if sensor.SensorType == Hardware.SensorType.Clock:
125125
# Keep only real core clocks, ignore effective core clocks
126126
if "Core #" in str(sensor.Name) and "Effective" not in str(sensor.Name):
127-
frequencies.append(float(sensor.Value))
128-
# Take mean of all core clock as "CPU clock"
129-
return mean(frequencies)
127+
if sensor.Value:
128+
frequencies.append(float(sensor.Value))
129+
130+
if frequencies:
131+
# Take mean of all core clock as "CPU clock" (as it is done in Windows Task Manager Performance tab)
132+
return mean(frequencies)
133+
else:
134+
# Frequencies reading is not supported on this CPU
135+
return math.nan
130136

131137
@staticmethod
132138
def load() -> Tuple[float, float, float]: # 1 / 5 / 15min avg:
@@ -201,8 +207,8 @@ def is_available() -> bool:
201207
found_nvidia = (get_hw_and_update(Hardware.HardwareType.GpuNvidia) is not None)
202208
found_intel = (get_hw_and_update(Hardware.HardwareType.GpuIntel) is not None)
203209

204-
if found_amd and (found_nvidia or found_intel) or (found_nvidia and found_intel):
205-
logger.warning(
210+
if (found_amd and (found_nvidia or found_intel)) or (found_nvidia and found_intel):
211+
logger.info(
206212
"Found multiple GPUs on your system. Will use dedicated GPU (AMD/Nvidia) for stats if possible.")
207213

208214
return found_amd or found_nvidia or found_intel
File renamed without changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# turing-smart-screen-python - a Python system monitor and library for 3.5" USB-C displays like Turing Smart Screen or XuanFang
2+
# https://github.com/mathoudebine/turing-smart-screen-python/
3+
4+
# Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine)
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
# This file will use static data instead of real hardware sensors
20+
# Used for screenshots and tests
21+
# For all platforms (Linux, Windows, macOS)
22+
23+
from typing import Tuple
24+
25+
import library.sensors.sensors as sensors
26+
27+
28+
class Cpu(sensors.Cpu):
29+
@staticmethod
30+
def percentage(interval: float) -> float:
31+
return 18.3
32+
33+
@staticmethod
34+
def frequency() -> float:
35+
return 2400.0
36+
37+
@staticmethod
38+
def load() -> Tuple[float, float, float]: # 1 / 5 / 15min avg:
39+
return 25.0, 37.8, 75.6
40+
41+
@staticmethod
42+
def is_temperature_available() -> bool:
43+
return True
44+
45+
@staticmethod
46+
def temperature() -> float:
47+
return 68.9
48+
49+
50+
class Gpu(sensors.Gpu):
51+
@staticmethod
52+
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
53+
return 75.8, 22.7, 1480, 52.3
54+
55+
@staticmethod
56+
def is_available() -> bool:
57+
return True
58+
59+
60+
class Memory(sensors.Memory):
61+
@staticmethod
62+
def swap_percent() -> float:
63+
return 12.4
64+
65+
@staticmethod
66+
def virtual_percent() -> float:
67+
return 37.0
68+
69+
@staticmethod
70+
def virtual_used() -> int: # In bytes
71+
return 5920000000
72+
73+
@staticmethod
74+
def virtual_free() -> int: # In bytes
75+
return 10080000000
76+
77+
78+
class Disk(sensors.Disk):
79+
@staticmethod
80+
def disk_usage_percent() -> float:
81+
return 59.0
82+
83+
@staticmethod
84+
def disk_used() -> int: # In bytes
85+
return 1180000000000
86+
87+
@staticmethod
88+
def disk_free() -> int: # In bytes
89+
return 820000000000
90+
91+
92+
class Net(sensors.Net):
93+
@staticmethod
94+
def stats(if_name, interval) -> Tuple[
95+
int, int, int, int]: # up rate (B/s), uploaded (B), dl rate (B/s), downloaded (B)
96+
return 2000000, 4857000, 839000000, 5623000000

library/stats.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
except:
5151
os._exit(0)
5252
elif HW_SENSORS == "STUB":
53-
import library.sensors.sensors_stub as sensors
53+
logger.warning("Stub sensors, not real HW sensors")
54+
import library.sensors.sensors_stub_random as sensors
55+
elif HW_SENSORS == "STATIC":
56+
logger.warning("Stub sensors, not real HW sensors")
57+
import library.sensors.sensors_stub_static as sensors
5458
elif HW_SENSORS == "AUTO":
5559
if platform.system() == 'Windows':
5660
import library.sensors.sensors_librehardwaremonitor as sensors
@@ -119,7 +123,7 @@ def percentage():
119123
def frequency():
120124
if THEME_DATA['STATS']['CPU']['FREQUENCY']['TEXT'].get("SHOW", False):
121125

122-
cpu_freq = f'{int(sensors.Cpu.frequency()) / 1000:.2f}'
126+
cpu_freq = f'{sensors.Cpu.frequency() / 1000:.2f}'
123127
if THEME_DATA['STATS']['CPU']['FREQUENCY']['TEXT'].get("SHOW_UNIT", True):
124128
cpu_freq += " GHz"
125129

0 commit comments

Comments
 (0)