Skip to content

Commit

Permalink
Merge pull request #30 from shm11C3/fix/processes-data
Browse files Browse the repository at this point in the history
Fix: Corrected bugs in the processes list, including display errors a…
  • Loading branch information
shm11C3 authored Nov 23, 2024
2 parents f0ca688 + b0042ff commit 679baf4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lto = true

[package]
name = "hardware_visualizer"
version = "0.1.1"
version = "0.1.2"
description = "A real-time hardware monitoring tool for Windows"
authors = ["@shm11C3"]
license = ""
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/commands/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ pub fn get_process_list(state: tauri::State<'_, AppState>) -> Vec<ProcessInfo> {
let memory_usage = if let Some(history) = process_memory_histories.get(&pid) {
let len = history.len().min(5); // 最大5秒分のデータ
let sum: f32 = history.iter().rev().take(len).sum();
let avg = sum / len as f32;
let avg = (sum as f32 / 1024.0) / len as f32;

(avg * 10.0).round() / 10.0
(avg * 10.0).round() / 10.0 // 小数点1桁で丸める
} else {
process.memory() as f32 / 1024.0 // 履歴がなければ現在のメモリ使用量を返す
process.memory() as f32 / 1024.0 // KB → MBに変換
};

ProcessInfo {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"productName": "HardwareVisualizer",
"mainBinaryName": "hardware-visualizer",
"version": "0.1.1",
"version": "0.1.2",
"identifier": "HardwareVisualizer",
"plugins": {},
"app": {
Expand Down
31 changes: 27 additions & 4 deletions src/components/charts/ProcessTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,35 @@ const ProcessesTable = ({
const sortedProcesses = [...processes];
if (sortConfig !== null) {
sortedProcesses.sort((a, b) => {
if (a[sortConfig.key] < b[sortConfig.key]) {
return sortConfig.direction === "ascending" ? -1 : 1;
const aValue = a[sortConfig.key];
const bValue = b[sortConfig.key];

// 数値の場合はそのまま比較
if (typeof aValue === "number" && typeof bValue === "number") {
return sortConfig.direction === "ascending"
? aValue - bValue
: bValue - aValue;
}
if (a[sortConfig.key] > b[sortConfig.key]) {
return sortConfig.direction === "ascending" ? 1 : -1;

// 数値を文字列として保持している場合は数値に変換
if (typeof aValue === "string" && typeof bValue === "string") {
const aNumber = Number.parseFloat(aValue);
const bNumber = Number.parseFloat(bValue);

// 小数が文字列として比較されてしまうため、NaNでない場合は数値として比較
if (!Number.isNaN(aNumber) && !Number.isNaN(bNumber)) {
return sortConfig.direction === "ascending"
? aNumber - bNumber
: bNumber - aNumber;
}

// 数値でない場合は文字列として比較
return sortConfig.direction === "ascending"
? aValue.localeCompare(bValue)
: bValue.localeCompare(aValue);
}

// 型が異なる場合は順序を変更しない
return 0;
});
}
Expand Down

0 comments on commit 679baf4

Please sign in to comment.