Autoindex

This commit is contained in:
2021-12-14 10:27:43 -06:00
parent b41a0ce81f
commit df36291b7e
5 changed files with 66 additions and 39 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
/target
.~lock.data.xlsx#
data.db

View File

@@ -1 +0,0 @@
,robviren,Compy550,12.12.2021 20:08,file:///home/robviren/.config/libreoffice/4;

BIN
data.db

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
use std::error::Error;
use std::{collections::HashMap, error::Error};
use calamine::{open_workbook, Reader, Xlsx};
use rusqlite::{Connection, Result};
@@ -31,37 +31,64 @@ struct Data {
fn main() -> Result<(), Box<dyn Error>> {
let now = chrono::offset::Local::now();
let mut data_vec = Vec::with_capacity(100000);
let mut excel: Xlsx<_> = open_workbook("file.xlsx").unwrap();
if let Some(Ok(r)) = excel.worksheet_range("Export") {
for row in r.rows().skip(1) {
if row[34].get_string() == None {
let mut excel: Xlsx<_> = open_workbook("data.xlsx").unwrap();
let r = excel
.worksheet_range("Export")
.expect("Is There")
.expect("Excel Read Error");
let mut indexs = HashMap::new();
let mut skip_count = 0;
'outer: for row in r.rows() {
skip_count += 1;
for (i, elm) in row.iter().enumerate() {
let header = elm.get_string().expect("header issue");
match header {
"FiscalYearMonth" => indexs.insert("date", i),
"Level2" => indexs.insert("level2", i),
"Level3" => indexs.insert("level3", i),
"MaterialEntered" => indexs.insert("sku", i),
"Quantity" => indexs.insert("quantity", i),
"SalesRevenue" => indexs.insert("revenue", i),
"CostOfGoodsSold" => indexs.insert("cost", i),
"ProductDescription" => indexs.insert("description", i),
_ => None,
};
if indexs.len() == 8 {
break 'outer;
}
}
}
for row in r.rows().skip(skip_count) {
if row[indexs["sku"]].get_string() == None {
break;
}
let datestring = row[28].get_string().expect("Date Parsing Issue");
let datestring = row[indexs["date"]].get_string().expect("Date Parsing Issue");
let year = datestring[0..4].parse::<i64>().unwrap();
let month = datestring[5..].parse::<i64>().unwrap();
data_vec.push(Data {
description: String::from(row[46].get_string().unwrap().replace("\"", "")),
sku: String::from(row[35].get_string().unwrap()),
level2: String::from(row[31].get_string().unwrap()),
level3: String::from(row[32].get_string().unwrap()),
revenue: match row[76].get_float() {
description: String::from(row[indexs["description"]].get_string().unwrap().replace("\"", "")),
sku: String::from(row[indexs["sku"]].get_string().unwrap()),
level2: String::from(row[indexs["level2"]].get_string().unwrap()),
level3: String::from(row[indexs["level3"]].get_string().unwrap()),
revenue: match row[indexs["revenue"]].get_float() {
Some(x) => x,
None => match row[76].get_int() {
None => match row[indexs["revenue"]].get_int() {
Some(x) => x as f64,
None => 0.0,
},
},
cost: match row[74].get_float() {
cost: match row[indexs["cost"]].get_float() {
Some(x) => x,
None => match row[74].get_int() {
None => match row[indexs["cost"]].get_int() {
Some(x) => x as f64,
None => 0.0,
},
},
quantity: match row[75].get_int() {
quantity: match row[indexs["quantity"]].get_int() {
Some(x) => x,
None => match row[75].get_float() {
None => match row[indexs["quantity"]].get_float() {
Some(x) => x as i64,
None => 0,
},
@@ -70,7 +97,6 @@ fn main() -> Result<(), Box<dyn Error>> {
month: month,
});
}
}
let conn = Connection::open("data.db")?;
conn.execute("DROP TABLE IF EXISTS data;", [])?;