Allow showing from amounts in overhead allocation
This commit is contained in:
72
src/lib.rs
72
src/lib.rs
@@ -108,16 +108,21 @@ pub extern "C" fn allocate_overheads_from_text(
|
||||
};
|
||||
let mut output_writer = csv::Writer::from_writer(vec![]);
|
||||
reciprocal_allocation(
|
||||
csv::Reader::from_reader(lines.to_bytes()),
|
||||
csv::Reader::from_reader(accounts.to_bytes()),
|
||||
csv::Reader::from_reader(allocation_statistics.to_bytes()),
|
||||
csv::Reader::from_reader(areas.to_bytes()),
|
||||
csv::Reader::from_reader(cost_centres.to_bytes()),
|
||||
&mut csv::Reader::from_reader(lines.to_bytes()),
|
||||
&mut csv::Reader::from_reader(accounts.to_bytes()),
|
||||
&mut csv::Reader::from_reader(allocation_statistics.to_bytes()),
|
||||
&mut csv::Reader::from_reader(areas.to_bytes()),
|
||||
&mut csv::Reader::from_reader(cost_centres.to_bytes()),
|
||||
&mut output_writer,
|
||||
use_numeric_accounts,
|
||||
false,
|
||||
true,
|
||||
account_type.to_str().unwrap().to_owned(),
|
||||
// This needs to be false when we return just a string, as the
|
||||
// amount of data produced could easily go out of memory (9000ccs + 1000
|
||||
// accounts can reach 2gb)
|
||||
false,
|
||||
0.1,
|
||||
)
|
||||
.expect("Failed to allocate overheads");
|
||||
let inner = output_writer.into_inner().unwrap();
|
||||
@@ -126,6 +131,63 @@ pub extern "C" fn allocate_overheads_from_text(
|
||||
.into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn allocate_overheads_from_text_to_file(
|
||||
lines: *const c_char,
|
||||
accounts: *const c_char,
|
||||
allocation_statistics: *const c_char,
|
||||
areas: *const c_char,
|
||||
cost_centres: *const c_char,
|
||||
account_type: *const c_char,
|
||||
output_path: *const c_char,
|
||||
use_numeric_accounts: bool,
|
||||
show_from: bool,
|
||||
) {
|
||||
let lines = unsafe {
|
||||
assert!(!lines.is_null());
|
||||
CStr::from_ptr(lines)
|
||||
};
|
||||
let accounts = unsafe {
|
||||
assert!(!accounts.is_null());
|
||||
CStr::from_ptr(accounts)
|
||||
};
|
||||
let allocation_statistics = unsafe {
|
||||
assert!(!allocation_statistics.is_null());
|
||||
CStr::from_ptr(allocation_statistics)
|
||||
};
|
||||
let areas = unsafe {
|
||||
assert!(!areas.is_null());
|
||||
CStr::from_ptr(areas)
|
||||
};
|
||||
let cost_centres = unsafe {
|
||||
assert!(!cost_centres.is_null());
|
||||
CStr::from_ptr(cost_centres)
|
||||
};
|
||||
let account_type = unsafe {
|
||||
assert!(!account_type.is_null());
|
||||
CStr::from_ptr(account_type)
|
||||
};
|
||||
let output_path = unsafe {
|
||||
assert!(!output_path.is_null());
|
||||
CStr::from_ptr(output_path)
|
||||
};
|
||||
reciprocal_allocation(
|
||||
&mut csv::Reader::from_reader(lines.to_bytes()),
|
||||
&mut csv::Reader::from_reader(accounts.to_bytes()),
|
||||
&mut csv::Reader::from_reader(allocation_statistics.to_bytes()),
|
||||
&mut csv::Reader::from_reader(areas.to_bytes()),
|
||||
&mut csv::Reader::from_reader(cost_centres.to_bytes()),
|
||||
&mut csv::Writer::from_path(output_path.to_str().unwrap()).unwrap(),
|
||||
use_numeric_accounts,
|
||||
false,
|
||||
true,
|
||||
account_type.to_str().unwrap().to_owned(),
|
||||
show_from,
|
||||
0.1,
|
||||
)
|
||||
.expect("Failed to allocate overheads");
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn allocate_overheads_from_text_free(s: *mut c_char) {
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user