ruvector_memopt/core/
patterns.rs1use chrono::{Datelike, Timelike};
4use crate::windows::memory::MemoryStatus;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct MemoryPattern {
10 pub load: f32,
12 pub consumption_rate: f32,
14 pub available_ratio: f32,
16 pub page_file_ratio: f32,
18 pub process_count: u32,
20 pub hour: u8,
22 pub day_of_week: u8,
24 pub time_since_last_opt: f32,
26}
27
28impl MemoryPattern {
29 pub fn from_status(status: &MemoryStatus) -> Self {
31 let now = chrono::Local::now();
32
33 Self {
34 load: status.memory_load_percent as f32 / 100.0,
35 consumption_rate: 0.0, available_ratio: (status.available_physical_mb / status.total_physical_mb) as f32,
37 page_file_ratio: 1.0 - (status.available_page_file_mb / status.total_page_file_mb) as f32,
38 process_count: 0, hour: now.hour() as u8,
40 day_of_week: now.weekday().num_days_from_monday() as u8,
41 time_since_last_opt: 0.0,
42 }
43 }
44
45 pub fn to_vector(&self) -> Vec<f32> {
47 vec![
48 self.load,
49 self.consumption_rate,
50 self.available_ratio,
51 self.page_file_ratio,
52 self.process_count as f32 / 1000.0, self.hour as f32 / 24.0,
54 self.day_of_week as f32 / 7.0,
55 self.time_since_last_opt / 3600.0, ]
57 }
58
59 pub const DIM: usize = 8;
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct LabeledPattern {
66 pub pattern: MemoryPattern,
67 pub optimized: bool,
69 pub aggressive: bool,
71 pub freed_mb: f32,
73 pub success: bool,
75}