Skip to content

Commit

Permalink
ProgressStats
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Sep 29, 2023
1 parent 06cfdc4 commit 523d134
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/mapfile_parser/mapfile_parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ class MapsComparisonInfo:
def __init__(self): ...


class ProgressStats:
undecompedSize: int
decompedSize: int

def __init__(self): ...

@property
def total(self) -> int: ...

def getAsFrogressEntry(self, name: str) -> dict[str, int]: ...

@staticmethod
def printHeader() -> None: ...

def print(self, category: str, totalStats: ProgressStats) -> None: ...


class Symbol:
name: str
vram: int
Expand Down
2 changes: 2 additions & 0 deletions src/rs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod symbol;
mod found_symbol_info;
mod symbol_comparison_info;
mod maps_comparison_info;
mod progress_stats;
pub mod utils;

pub use mapfile::MapFile;
Expand All @@ -17,6 +18,7 @@ pub use symbol::Symbol;
pub use found_symbol_info::FoundSymbolInfo;
pub use symbol_comparison_info::SymbolComparisonInfo;
pub use maps_comparison_info::MapsComparisonInfo;
pub use progress_stats::ProgressStats;

#[pyo3::prelude::pymodule]
fn mapfile_parser(_py: pyo3::prelude::Python<'_>, m: &pyo3::prelude::PyModule) -> pyo3::prelude::PyResult<()> {
Expand Down
16 changes: 10 additions & 6 deletions src/rs/mapfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl MapFile {
}

#[pyo3(name = "toCsvSymbols")]
pub fn to_ssv_symbols(&self) -> String {
pub fn to_csv_symbols(&self) -> String {
let mut ret = String::new();

write!(ret, "File,{}\n", symbol::Symbol::to_csv_header()).unwrap();
Expand All @@ -468,13 +468,17 @@ impl MapFile {
}


/*
def printAsCsv(self, printVram: bool=True, skipWithoutSymbols: bool=True):
print(self.toCsv(printVram=printVram, skipWithoutSymbols=skipWithoutSymbols), end="")
#[pyo3(name = "printAsCsv", signature=(print_vram=true, skip_without_symbols=true))]
pub fn print_as_csv(&self, print_vram: bool, skip_without_symbols: bool) {
print!("{}", self.to_csv(print_vram, skip_without_symbols));
}

def printSymbolsCsv(self):
print(self.toCsvSymbols(), end="")
#[pyo3(name = "printSymbolsCsv")]
pub fn print_symbols_csv(&self) {
print!("{}", self.to_csv_symbols());
}

/*
def toJson(self, humanReadable: bool=True) -> dict[str, Any]:
segmentsList = []
for segment in self._segmentsList:
Expand Down
52 changes: 52 additions & 0 deletions src/rs/progress_stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* SPDX-FileCopyrightText: © 2023 Decompollaborate */
/* SPDX-License-Identifier: MIT */

use std::collections::HashMap;

use pyo3::prelude::*;

#[derive(Debug, Clone)]
#[pyclass(module = "mapfile_parser", unsendable, sequence)]
pub struct ProgressStats {
#[pyo3(get, set, name = "undecompedSize")]
pub undecomped_size: u32,

#[pyo3(get, set, name = "decompedSize")]
pub decomped_size: u32,
}

#[pymethods]
impl ProgressStats {
#[new]
pub fn new() -> Self {
Self {
undecomped_size: 0,
decomped_size: 0,
}
}

#[getter]
pub fn total(&self) -> u32 {
self.undecomped_size + self.decomped_size
}

#[pyo3(name = "getAsFrogressEntry")]
pub fn get_as_frogress_entry(&self, name: &str) -> HashMap<String, u32> {
let mut categories: HashMap<String, u32> = HashMap::new();

categories.insert(name.to_string(), self.decomped_size);
categories.insert(format!("{}/total", name), self.total());

categories
}

#[staticmethod]
#[pyo3(name = "printHeader")]
pub fn print_header() {
println!("{:<28}: {:>12} / {:>8} {:>10}% ({:>20}%)", "Category", "DecompedSize", "Total", "OfFolder", "OfTotal");
}

pub fn print(&self, category: &str, totalStats: &ProgressStats) {
println!("{:<28}: {:>12} / {:>8} {:>10.4}% ({:>8.4}% / {:>8.4}%)", category, self.decomped_size, self.total(), self.decomped_size / self.total() * 100, self.decomped_size / totalStats.total() * 100, self.total() / totalStats.total() * 100);
}
}

0 comments on commit 523d134

Please sign in to comment.