-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06cfdc4
commit 523d134
Showing
4 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |