Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
TakanoTaiga committed Mar 14, 2024
1 parent 18b6d62 commit cd3bcb2
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 2 deletions.
149 changes: 149 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
csv = "1.1"
serde = { version = "1.0", features = ["derive"] }
walkdir = "2.3"
3 changes: 1 addition & 2 deletions src/bin/auto_ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn main() {
if *user == "taiga" {
let rss_str = columns.get(5).unwrap_or(&"0");
let rss_value: i32 = rss_str.parse().unwrap_or(0);
let cpu = columns.get(2).unwrap_or(&"");

let file_name = format!("./data/{}.csv",pid);
let path = Path::new(&file_name);
Expand All @@ -35,7 +34,7 @@ fn main() {
.open(path)
.expect("Failed to open file");

writeln!(file, "{},{}", cpu, rss_value)
writeln!(file, "{}", rss_value)
.expect("Failed to write to file");
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/bin/csvcheck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use csv::StringRecord;
use std::fs::{self};
use std::io::{self};
use walkdir::WalkDir;

fn main() -> io::Result<()> {
let data_dir = "./data";
let optimized_dir = "./optimized";

// optimizedディレクトリがない場合は作成
fs::create_dir_all(optimized_dir)?;

for entry in WalkDir::new(data_dir).into_iter().filter_map(|e| e.ok()) {
let path = entry.path();
if path.is_file() && path.extension().and_then(|s| s.to_str()) == Some("csv") {
let mut rdr = csv::Reader::from_path(&path)?;
let mut prev_record: Option<StringRecord> = None;
let mut is_varying = false;

for result in rdr.records() {
let record = result?;
if let Some(prev) = prev_record {
if prev != record {
is_varying = true;
break;
}
}
prev_record = Some(record);
}

if is_varying {
let file_name = path.file_name().unwrap();
let dest_path = format!("{}/{}", optimized_dir, file_name.to_str().unwrap());
fs::copy(path, dest_path)?;
}
}
}

Ok(())
}

0 comments on commit cd3bcb2

Please sign in to comment.