u64 update
* policynumber has 10 unsigned integers. usize is 32bit on on 32 machines. So we need to use u64 to assign the needed ram space to fit numbers like '9999999999' Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -31,7 +31,7 @@ struct Environment {
|
|||||||
/// export as csv format
|
/// export as csv format
|
||||||
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
||||||
/// https://blog.burntsushi.net/csv/
|
/// https://blog.burntsushi.net/csv/
|
||||||
fn export(p: &mut String, lang: &String) -> Result<usize, Box<dyn Error>> {
|
fn export(p: &mut String, lang: &String) -> Result<u64, Box<dyn Error>> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
//use std::ffi::OsStr;
|
//use std::ffi::OsStr;
|
||||||
@@ -83,8 +83,8 @@ fn export(p: &mut String, lang: &String) -> Result<usize, Box<dyn Error>> {
|
|||||||
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
||||||
/// https://blog.burntsushi.net/csv/
|
/// https://blog.burntsushi.net/csv/
|
||||||
fn import(p: &mut String, data_list: &mut PolicyDataList,
|
fn import(p: &mut String, data_list: &mut PolicyDataList,
|
||||||
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
|
policy_numbers: &mut HashMap<u64, PolicyCode>, lang: &String)
|
||||||
-> Result<usize, Box<dyn Error>> {
|
-> Result<u64, Box<dyn Error>> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -172,8 +172,8 @@ fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
/// validate a given policy number
|
/// validate a given policy number
|
||||||
/// result will return true or false
|
/// result will return true or false
|
||||||
fn is_valid(policy_number: &usize, policy_list: &PolicyDataList,
|
fn is_valid(policy_number: &u64, policy_list: &PolicyDataList,
|
||||||
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
|
policy_numbers: &mut HashMap<u64, PolicyCode>, lang: &String)
|
||||||
-> Result<bool, Box<dyn std::error::Error>> {
|
-> Result<bool, Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let mut res = t!("policy.validation.started", lang);
|
let mut res = t!("policy.validation.started", lang);
|
||||||
@@ -340,7 +340,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mut policy_data = PolicyDataList::new("Allianz-Import 20200628");
|
let mut policy_data = PolicyDataList::new("Allianz-Import 20200628");
|
||||||
println!("Policy Data List {:?} ", policy_data.name);
|
println!("Policy Data List {:?} ", policy_data.name);
|
||||||
|
|
||||||
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
|
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
|
||||||
|
|
||||||
let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
match import(&mut csv_import_path, &mut policy_data,
|
match import(&mut csv_import_path, &mut policy_data,
|
||||||
@@ -355,9 +355,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test if policy_number is_valid
|
// test if policy_number is_valid
|
||||||
let test_policy_number = v.get::<i32>("test_policy_number").unwrap() as usize;
|
let test_policy_number = v.get::<i32>("test_policy_number").unwrap() as u64;
|
||||||
trace!(target: "csv-test", test_policy_number = ?test_policy_number);
|
trace!(target: "csv-test", test_policy_number = ?test_policy_number);
|
||||||
//let policy_number : usize = 1999999999;
|
//let policy_number : u64 = 1999999999;
|
||||||
//match is_valid(&policy_number, &policy_data, &mut policy_numbers, &lang) {
|
//match is_valid(&policy_number, &policy_data, &mut policy_numbers, &lang) {
|
||||||
// Ok(true) => {
|
// Ok(true) => {
|
||||||
// use Hashmap method 'get' to check if we have the given key
|
// use Hashmap method 'get' to check if we have the given key
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ pub struct PolicyCheckState {
|
|||||||
button_menu: Entity,
|
button_menu: Entity,
|
||||||
menu: Entity,
|
menu: Entity,
|
||||||
popup_progress: Entity,
|
popup_progress: Entity,
|
||||||
policy_data_count: usize,
|
policy_data_count: u64,
|
||||||
policy_numbers: HashMap<usize, PolicyCode>,
|
policy_numbers: HashMap<u64, PolicyCode>,
|
||||||
progress_bar: Entity,
|
progress_bar: Entity,
|
||||||
progress_count: f64,
|
progress_count: f64,
|
||||||
theme: String
|
theme: String
|
||||||
@@ -105,7 +105,7 @@ impl PolicyCheckState {
|
|||||||
let mut policy_data = PolicyDataList::new(res);
|
let mut policy_data = PolicyDataList::new(res);
|
||||||
trace!(target: "advotracker", policy_data = ?policy_data);
|
trace!(target: "advotracker", policy_data = ?policy_data);
|
||||||
|
|
||||||
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
|
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
|
||||||
|
|
||||||
// Wip: use cli parameter stored in viperus ...
|
// Wip: use cli parameter stored in viperus ...
|
||||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
@@ -250,8 +250,8 @@ impl PolicyCheckState {
|
|||||||
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
||||||
|
|
||||||
if policy_number_length == 10 {
|
if policy_number_length == 10 {
|
||||||
// cast policy_number_sting to <usize>
|
// cast policy_number_sting to <u64>
|
||||||
match policy_number_string.parse::<usize>() {
|
match policy_number_string.parse::<u64>() {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
||||||
result_wrapper.set_text("");
|
result_wrapper.set_text("");
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ pub struct CsvExportRecord {
|
|||||||
/// Versicherungsschein Code
|
/// Versicherungsschein Code
|
||||||
pub policy_code: String,
|
pub policy_code: String,
|
||||||
/// Versicherungsscheinnummer (10-stellig, numerisch)
|
/// Versicherungsscheinnummer (10-stellig, numerisch)
|
||||||
pub policy_number: usize,
|
pub policy_number: u64,
|
||||||
/// Anrufer: "Vorname, Nachname"
|
/// Anrufer: "Vorname, Nachname"
|
||||||
pub policy_holder: String,
|
pub policy_holder: String,
|
||||||
/// Sachverhalt: "Kurzschilderung"
|
/// Sachverhalt: "Kurzschilderung"
|
||||||
@@ -150,7 +150,7 @@ pub struct PolicyCheck {
|
|||||||
/// Referenz zum Versicherungsschein-Typ
|
/// Referenz zum Versicherungsschein-Typ
|
||||||
pub policy_code: PolicyCode,
|
pub policy_code: PolicyCode,
|
||||||
/// Referenz zur Versicherungsschein-Nummer
|
/// Referenz zur Versicherungsschein-Nummer
|
||||||
pub policy_number: usize,
|
pub policy_number: u64,
|
||||||
/// Validitätsergebnis
|
/// Validitätsergebnis
|
||||||
pub policy_number_status: Status
|
pub policy_number_status: Status
|
||||||
}
|
}
|
||||||
@@ -313,7 +313,7 @@ pub struct PolicyData {
|
|||||||
pub policy_code: PolicyCode,
|
pub policy_code: PolicyCode,
|
||||||
/// Versicherungsscheinnummer (10stellig, numerisch)
|
/// Versicherungsscheinnummer (10stellig, numerisch)
|
||||||
#[serde(rename = "POLLFNR")]
|
#[serde(rename = "POLLFNR")]
|
||||||
pub policy_number: usize,
|
pub policy_number: u64,
|
||||||
/// Status des Versicherungsscheins
|
/// Status des Versicherungsscheins
|
||||||
pub status: Option<Status>
|
pub status: Option<Status>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData};
|
|||||||
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
||||||
/// https://blog.burntsushi.net/csv/
|
/// https://blog.burntsushi.net/csv/
|
||||||
pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
||||||
policy_numbers: &mut HashMap<usize, PolicyCode>,
|
policy_numbers: &mut HashMap<u64, PolicyCode>,
|
||||||
policy_data_count: &mut usize,
|
policy_data_count: &mut u64,
|
||||||
lang: &String)
|
lang: &String)
|
||||||
-> Result<(usize, Duration), Box<dyn Error>> {
|
-> Result<(u64, Duration), Box<dyn Error>> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -65,7 +65,7 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over each record, deserialize und write to our structures
|
// Iterate over each record, deserialize und write to our structures
|
||||||
let mut count : usize = 0;
|
let mut count : u64 = 0;
|
||||||
for result in csv_reader.deserialize() {
|
for result in csv_reader.deserialize() {
|
||||||
// The iterator yields Result<StringRecord, Error>, so we check the
|
// The iterator yields Result<StringRecord, Error>, so we check the
|
||||||
// error here.
|
// error here.
|
||||||
@@ -75,7 +75,7 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// WIP: write to redis backend
|
// WIP: write to redis backend
|
||||||
// append the policy_number to the HashMap
|
// for now: append the policy_number to the HashMap
|
||||||
policy_numbers.insert(record.policy_number, record.policy_code);
|
policy_numbers.insert(record.policy_number, record.policy_code);
|
||||||
|
|
||||||
// push record as new vector elements
|
// push record as new vector elements
|
||||||
@@ -101,13 +101,13 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_import() {
|
fn test_import() {
|
||||||
// Takes a reference and returns Option<&V>
|
// Takes a reference and returns Option<&V>
|
||||||
let my_policy_numbers : [usize; 2] = [1511111111, 9999999993];
|
let my_policy_numbers : [u64; 2] = [1511111111, 9999999993];
|
||||||
assert_eq!(my_policy_numbers, [1511111111, 9999999993]);
|
assert_eq!(my_policy_numbers, [1511111111, 9999999993]);
|
||||||
|
|
||||||
let mut csv_import_path = String::from("data/POLLFNR_TEST.txt");
|
let mut csv_import_path = String::from("data/POLLFNR_TEST.txt");
|
||||||
let mut policy_data = PolicyDataList::new("PolicyDataList");
|
let mut policy_data = PolicyDataList::new("PolicyDataList");
|
||||||
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
|
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
|
||||||
let mut policy_data_count: usize = 0;
|
let mut policy_data_count: u64 = 0;
|
||||||
let lang = "en".to_string();
|
let lang = "en".to_string();
|
||||||
|
|
||||||
match import(&mut csv_import_path, &mut policy_data,
|
match import(&mut csv_import_path, &mut policy_data,
|
||||||
|
|||||||
Reference in New Issue
Block a user