sysnexa 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sysnexa/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("sysnexa")
5
+ except PackageNotFoundError:
6
+ __version__ = "0.1.0"
File without changes
@@ -0,0 +1,38 @@
1
+
2
+ """Hardware analysis utilities for Sysnexa."""
3
+
4
+ import platform
5
+ from dataclasses import dataclass
6
+
7
+ import psutil
8
+
9
+
10
+ @dataclass
11
+ class HardwareInfo:
12
+ operating_system: str
13
+ os_release: str
14
+ os_version: str
15
+ architecture: str
16
+ processor: str
17
+ physical_cores: int | None
18
+ logical_cores: int | None
19
+ total_ram_gb: float
20
+
21
+
22
+ class HardwareAnalyzer:
23
+ """Collect hardware and operating system information."""
24
+
25
+ @staticmethod
26
+ def get_info() -> HardwareInfo:
27
+ memory = psutil.virtual_memory()
28
+
29
+ return HardwareInfo(
30
+ operating_system=platform.system() or "Unknown",
31
+ os_release=platform.release() or "Unknown",
32
+ os_version=platform.version() or "Unknown",
33
+ architecture=platform.machine() or "Unknown",
34
+ processor=platform.processor() or "Unknown",
35
+ physical_cores=psutil.cpu_count(logical=False),
36
+ logical_cores=psutil.cpu_count(logical=True),
37
+ total_ram_gb=round(memory.total / (1024 ** 3), 2),
38
+ )
@@ -0,0 +1,104 @@
1
+
2
+ """System performance scoring engine for Sysnexa."""
3
+
4
+ from dataclasses import dataclass, field
5
+
6
+ from sysnexa.monitor.cpu import CPUMonitor
7
+ from sysnexa.monitor.disk import DiskMonitor
8
+ from sysnexa.monitor.ram import RAMMonitor
9
+
10
+
11
+ @dataclass
12
+ class PerformanceScore:
13
+ total_score: float
14
+ grade: str
15
+ cpu_score: float
16
+ ram_score: float
17
+ disk_score: float
18
+ recommendations: list[str] = field(default_factory=list)
19
+
20
+
21
+ class PerformanceAnalyzer:
22
+ """Analyze system performance and calculate a health score."""
23
+
24
+ @staticmethod
25
+ def _calculate_component_score(usage: float) -> float:
26
+ """Convert resource usage into a score from 0 to 100."""
27
+ usage = max(0.0, min(100.0, usage))
28
+
29
+ if usage <= 50:
30
+ return 100.0
31
+
32
+ if usage <= 70:
33
+ return 100.0 - (usage - 50) * 1.0
34
+
35
+ if usage <= 90:
36
+ return 80.0 - (usage - 70) * 2.0
37
+
38
+ return max(0.0, 40.0 - (usage - 90) * 4.0)
39
+
40
+ @staticmethod
41
+ def _get_grade(score: float) -> str:
42
+ if score >= 90:
43
+ return "Excellent"
44
+ if score >= 75:
45
+ return "Good"
46
+ if score >= 60:
47
+ return "Fair"
48
+ return "Poor"
49
+
50
+ @classmethod
51
+ def analyze(cls) -> PerformanceScore:
52
+ """Calculate the overall system performance score."""
53
+ cpu = CPUMonitor.get_info()
54
+ ram = RAMMonitor.get_info()
55
+ disks = DiskMonitor.get_info()
56
+
57
+ cpu_score = cls._calculate_component_score(cpu.usage_percent)
58
+ ram_score = cls._calculate_component_score(ram.usage_percent)
59
+
60
+ if disks:
61
+ disk_score = sum(
62
+ cls._calculate_component_score(disk.usage_percent)
63
+ for disk in disks
64
+ ) / len(disks)
65
+ else:
66
+ disk_score = 100.0
67
+
68
+ total_score = round(
69
+ cpu_score * 0.35
70
+ + ram_score * 0.35
71
+ + disk_score * 0.30,
72
+ 2,
73
+ )
74
+
75
+ recommendations = []
76
+
77
+ if cpu.usage_percent >= 80:
78
+ recommendations.append(
79
+ "High CPU usage detected. Consider closing unnecessary processes."
80
+ )
81
+
82
+ if ram.usage_percent >= 80:
83
+ recommendations.append(
84
+ "High RAM usage detected. Close unused applications."
85
+ )
86
+
87
+ if any(disk.usage_percent >= 85 for disk in disks):
88
+ recommendations.append(
89
+ "Disk space is running low. Consider freeing up storage."
90
+ )
91
+
92
+ if not recommendations:
93
+ recommendations.append(
94
+ "Your system performance is looking good. Keep it up!"
95
+ )
96
+
97
+ return PerformanceScore(
98
+ total_score=total_score,
99
+ grade=cls._get_grade(total_score),
100
+ cpu_score=round(cpu_score, 2),
101
+ ram_score=round(ram_score, 2),
102
+ disk_score=round(disk_score, 2),
103
+ recommendations=recommendations,
104
+ )
@@ -0,0 +1,108 @@
1
+
2
+ from __future__ import annotations
3
+
4
+ from dataclasses import dataclass
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ import matplotlib
10
+
11
+ matplotlib.use("Agg")
12
+
13
+ import matplotlib.dates as mdates
14
+ import matplotlib.pyplot as plt
15
+
16
+
17
+ @dataclass
18
+ class TrendSummary:
19
+ total_records: int
20
+ average_score: float
21
+ highest_score: float
22
+ lowest_score: float
23
+ latest_score: float
24
+ trend: str
25
+
26
+
27
+ class PerformanceTrend:
28
+ """Analyze and visualize historical system performance."""
29
+
30
+ COMPONENTS = ("cpu_score", "ram_score", "disk_score")
31
+
32
+ def analyze(
33
+ self,
34
+ records: list[dict[str, Any]],
35
+ ) -> TrendSummary:
36
+ if not records:
37
+ raise ValueError("No performance history available.")
38
+
39
+ scores = [float(record["total_score"]) for record in records]
40
+
41
+ difference = scores[-1] - scores[0]
42
+
43
+ if difference > 0:
44
+ trend = "Improving"
45
+ elif difference < 0:
46
+ trend = "Declining"
47
+ else:
48
+ trend = "Stable"
49
+
50
+ return TrendSummary(
51
+ total_records=len(records),
52
+ average_score=round(sum(scores) / len(scores), 2),
53
+ highest_score=round(max(scores), 2),
54
+ lowest_score=round(min(scores), 2),
55
+ latest_score=round(scores[-1], 2),
56
+ trend=trend,
57
+ )
58
+
59
+ def generate_chart(
60
+ self,
61
+ records: list[dict[str, Any]],
62
+ output: Path | str = "performance-trend.png",
63
+ ) -> Path:
64
+ if not records:
65
+ raise ValueError("Cannot generate chart without history.")
66
+
67
+ chronological_records = list(reversed(records))
68
+
69
+ timestamps = [
70
+ datetime.fromisoformat(record["timestamp"])
71
+ for record in chronological_records
72
+ ]
73
+
74
+ scores = [
75
+ float(record["total_score"])
76
+ for record in chronological_records
77
+ ]
78
+
79
+ output_path = Path(output)
80
+ output_path.parent.mkdir(parents=True, exist_ok=True)
81
+
82
+ figure, axis = plt.subplots(figsize=(11, 6))
83
+
84
+ axis.plot(
85
+ mdates.date2num(timestamps), # type: ignore[no-untyped-call]
86
+ scores,
87
+ marker="o",
88
+ linewidth=2,
89
+ label="Overall Performance",
90
+ )
91
+
92
+ axis.set_title("Sysnexa Performance Trend")
93
+ axis.set_xlabel("Date")
94
+ axis.set_ylabel("Performance Score")
95
+ axis.set_ylim(0, 100)
96
+ axis.grid(True, alpha=0.3)
97
+ axis.legend()
98
+
99
+ axis.xaxis.set_major_formatter(
100
+ mdates.DateFormatter("%Y-%m-%d") # type: ignore[no-untyped-call]
101
+ )
102
+ figure.autofmt_xdate()
103
+ figure.tight_layout()
104
+
105
+ figure.savefig(output_path, dpi=150)
106
+ plt.close(figure)
107
+
108
+ return output_path
File without changes