Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused load_json fucntion #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions protocol/src/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,43 +140,6 @@ pub fn load_data(data: Arc<RwLock<KeyedCSV>>, path: &str, has_headers: bool) {
}
}

pub fn load_json(data: Arc<RwLock<KeyedCSV>>, json_table: &str, has_headers: bool) -> bool {
// Read json object from dynamic str into the expected Vec<Vec> form (previously from a CSV)
let table: Value = serde_json::from_str(json_table).unwrap();
let table: &Vec<Value> = table.as_array().unwrap();
let table_len = table.len();

let mut lines: Vec<Vec<String>> = vec![vec!["".to_string()]; table.len()]; // -OR- files::read_csv_as_strings(path)
for (row_num, row) in table.iter().enumerate() {
lines[row_num] = vec![row.as_str().unwrap().to_string()];
}

let mut ret = false;
if let Ok(mut wguard) = data.write() {
if wguard.records.is_empty() {
let mut line_it = lines.drain(..);
if has_headers {
if let Some(headers) = line_it.next() {
wguard.headers = headers;
}
}
for line in line_it {
if let Some((key, rest)) = line.split_first() {
wguard.records.insert(key.to_string(), rest.to_vec());
}
}
let keys_len = wguard.records.len();
info!(
"Read {} lines from json (dedup: {} lines)",
table_len,
table_len - keys_len
);
ret = true
}
}
ret
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
13 changes: 1 addition & 12 deletions protocol/src/private_id/company.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use common::{
};

use crate::{
fileio::{load_data, load_json, KeyedCSV},
fileio::{load_data, KeyedCSV},
private_id::traits::CompanyPrivateIdProtocol,
};

Expand Down Expand Up @@ -69,17 +69,6 @@ impl CompanyPrivateId {
);
}

pub fn load_json(&self, path: &str, input_with_headers: bool) -> bool {
let status = load_json(self.plain_data.clone(), path, input_with_headers);
if status {
fill_permute(
self.permutation.clone(),
(*self.plain_data.clone().read().unwrap()).records.len(),
);
}
status
}

pub fn get_e_company_size(&self) -> usize {
self.e_company.read().unwrap().len()
}
Expand Down
7 changes: 1 addition & 6 deletions protocol/src/private_id/partner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crypto::{
};

use crate::{
fileio::{load_data, load_json, KeyedCSV},
fileio::{load_data, KeyedCSV},
private_id::traits::PartnerPrivateIdProtocol,
};

Expand Down Expand Up @@ -51,11 +51,6 @@ impl PartnerPrivateId {
Ok(())
}

pub fn load_json(&self, path: &str, input_with_headers: bool) -> Result<(), ProtocolError> {
load_json(self.plain_data.clone(), path, input_with_headers);
Ok(())
}

pub fn get_size(&self) -> usize {
self.plain_data.clone().read().unwrap().records.len()
}
Expand Down