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:
2020-07-24 20:55:53 +02:00
parent 9b9afc2b5a
commit b6b12c45bb
4 changed files with 24 additions and 24 deletions

View File

@@ -31,7 +31,7 @@ struct Environment {
/// export as csv format
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
/// 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::path::Path;
//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://blog.burntsushi.net/csv/
fn import(p: &mut String, data_list: &mut PolicyDataList,
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
-> Result<usize, Box<dyn Error>> {
policy_numbers: &mut HashMap<u64, PolicyCode>, lang: &String)
-> Result<u64, Box<dyn Error>> {
use std::fs::File;
use std::path::Path;
use std::ffi::OsStr;
@@ -172,8 +172,8 @@ fn import(p: &mut String, data_list: &mut PolicyDataList,
#[allow(dead_code)]
/// validate a given policy number
/// result will return true or false
fn is_valid(policy_number: &usize, policy_list: &PolicyDataList,
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
fn is_valid(policy_number: &u64, policy_list: &PolicyDataList,
policy_numbers: &mut HashMap<u64, PolicyCode>, lang: &String)
-> Result<bool, Box<dyn std::error::Error>> {
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");
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();
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
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);
//let policy_number : usize = 1999999999;
//let policy_number : u64 = 1999999999;
//match is_valid(&policy_number, &policy_data, &mut policy_numbers, &lang) {
// Ok(true) => {
// use Hashmap method 'get' to check if we have the given key

View File

@@ -70,8 +70,8 @@ pub struct PolicyCheckState {
button_menu: Entity,
menu: Entity,
popup_progress: Entity,
policy_data_count: usize,
policy_numbers: HashMap<usize, PolicyCode>,
policy_data_count: u64,
policy_numbers: HashMap<u64, PolicyCode>,
progress_bar: Entity,
progress_count: f64,
theme: String
@@ -105,7 +105,7 @@ impl PolicyCheckState {
let mut policy_data = PolicyDataList::new(res);
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 ...
//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");
if policy_number_length == 10 {
// cast policy_number_sting to <usize>
match policy_number_string.parse::<usize>() {
// cast policy_number_sting to <u64>
match policy_number_string.parse::<u64>() {
Ok(p) => {
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
result_wrapper.set_text("");

View File

@@ -95,7 +95,7 @@ pub struct CsvExportRecord {
/// Versicherungsschein Code
pub policy_code: String,
/// Versicherungsscheinnummer (10-stellig, numerisch)
pub policy_number: usize,
pub policy_number: u64,
/// Anrufer: "Vorname, Nachname"
pub policy_holder: String,
/// Sachverhalt: "Kurzschilderung"
@@ -150,7 +150,7 @@ pub struct PolicyCheck {
/// Referenz zum Versicherungsschein-Typ
pub policy_code: PolicyCode,
/// Referenz zur Versicherungsschein-Nummer
pub policy_number: usize,
pub policy_number: u64,
/// Validitätsergebnis
pub policy_number_status: Status
}
@@ -313,7 +313,7 @@ pub struct PolicyData {
pub policy_code: PolicyCode,
/// Versicherungsscheinnummer (10stellig, numerisch)
#[serde(rename = "POLLFNR")]
pub policy_number: usize,
pub policy_number: u64,
/// Status des Versicherungsscheins
pub status: Option<Status>
}

View File

@@ -21,10 +21,10 @@ use crate::data::structures::{PolicyCode, PolicyDataList, PolicyData};
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
/// https://blog.burntsushi.net/csv/
pub fn import(p: &mut String, data_list: &mut PolicyDataList,
policy_numbers: &mut HashMap<usize, PolicyCode>,
policy_data_count: &mut usize,
policy_numbers: &mut HashMap<u64, PolicyCode>,
policy_data_count: &mut u64,
lang: &String)
-> Result<(usize, Duration), Box<dyn Error>> {
-> Result<(u64, Duration), Box<dyn Error>> {
use std::fs::File;
use std::path::Path;
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
let mut count : usize = 0;
let mut count : u64 = 0;
for result in csv_reader.deserialize() {
// The iterator yields Result<StringRecord, Error>, so we check the
// error here.
@@ -75,7 +75,7 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
//}
// 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);
// push record as new vector elements
@@ -101,13 +101,13 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
#[test]
fn test_import() {
// 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]);
let mut csv_import_path = String::from("data/POLLFNR_TEST.txt");
let mut policy_data = PolicyDataList::new("PolicyDataList");
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
let mut policy_data_count: usize = 0;
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
let mut policy_data_count: u64 = 0;
let lang = "en".to_string();
match import(&mut csv_import_path, &mut policy_data,