]> Humopery - polarsbop.git/commitdiff
three partitions not two
authorErik Mackdanz <erikmack@gmail.com>
Sat, 25 Nov 2023 03:40:15 +0000 (21:40 -0600)
committerErik Mackdanz <erikmack@gmail.com>
Sat, 25 Nov 2023 03:40:15 +0000 (21:40 -0600)
scripts/paraexport
src/main.rs

index 972e7cf6104b55cb59991d474774df7fa62ba2e9..be33a5dc7b3eba3d85043f90497d1401f61023c0 100755 (executable)
@@ -3,7 +3,8 @@
 # start multiple jobs in parallel
 target/debug/polarsbop 0 &
 target/debug/polarsbop 1 &
+target/debug/polarsbop 2 &
 
-wait %1 %2
+wait %1 %2 %3
 
 echo done
index 0182cc640581740ef0cf62921449b5bff81d6f48..eb31d5e6b1b2ec30f2f5472cfbc3cbb1b985d3d6 100644 (file)
@@ -4,16 +4,16 @@ use std::fs::{create_dir_all,File};
 
 fn main() -> Result<(),PolarsError> {
 
-    // expect first arg to be a file suffix = 0, 1
+    // expect first arg to be a file partition = 0, 1, 2
     let mut argsiter = args();
     let _ = argsiter.next();
-    let suffix = argsiter.next()
-       .expect("single argument required, 0 or 1");
+    let partition = argsiter.next()
+       .expect("single argument required, 0 or 1 or 2");
 
     // prep output file
     create_dir_all("out")
        .expect("couldn't create out dir");
-    let outfilename = format!("out/output-{}.json",suffix);
+    let outfilename = format!("out/output-{}.json",partition);
     // println!("{}",outfilename);
     let mut file = File::create(outfilename)
        .expect("couldn't create output file");
@@ -38,18 +38,30 @@ fn main() -> Result<(),PolarsError> {
        )));
 
     // read and parse from disk
-    let df = CsvReader::from_path("data/bop.csv")?
+    let mut df = CsvReader::from_path("data/bop.csv")?
        .has_header(true)
        .with_dtypes(schema_override)
        .with_null_values(null_values)
        .finish()?;
 
     // split list based on arg
-    let mut mask = df.column("Country Name")?.lt("Luxemb")?;
-    if suffix == "1" {
-       mask = df.column("Country Name")?.gt_eq("Luxemb")?;
+    match partition.as_str() {
+       "0" => {
+           let mask = df.column("Country Name")?.lt("Ethiopia")?;
+           df = df.filter(&mask)?;
+       },
+       "1" => {
+           let mask = df.column("Country Name")?.gt_eq("Ethiopia")?;
+           df = df.filter(&mask)?;
+           let mask = df.column("Country Name")?.lt("Romania")?;
+           df = df.filter(&mask)?;
+       },
+       "2" => {
+           let mask = df.column("Country Name")?.gt_eq("Romania")?;
+           df = df.filter(&mask)?;
+       },
+       _ => { panic!("partition must be 0, 1 or 2"); }
     }
-    let df = df.filter(&mask)?;
 
     // values not status, selected cols
     let mut df = df