|
1 | 1 | use super::aga_xls::AusGovActMortXLS; |
2 | 2 | use super::ifoa_xls::IFOAMortXLS; |
3 | 3 | use super::soa_xml::SOAMortXML; |
4 | | -use crate::RSLifeResult; |
5 | 4 | use crate::mt_config::spreadsheet_helpers::*; |
| 5 | +use crate::RSLifeResult; |
6 | 6 | use bon::bon; |
7 | | -use calamine::{Reader, open_workbook_auto}; |
| 7 | +use calamine::{open_workbook_auto, Reader}; |
8 | 8 | use polars::prelude::*; |
9 | 9 | use spreadsheet_ods::read_ods; |
10 | 10 | use std::fs; |
@@ -586,6 +586,7 @@ impl MortData { |
586 | 586 | // ======================================================== |
587 | 587 | // IFOA XLS PARSING |
588 | 588 | // ======================================================== |
| 589 | + |
589 | 590 | pub fn from_ifoa_xls_file_path_str(file_path: &str, sheet_name: &str) -> RSLifeResult<Self> { |
590 | 591 | let data = IFOAMortXLS::from_xls_file_path_str(file_path, sheet_name)?; |
591 | 592 | let result = Self::new( |
@@ -626,29 +627,6 @@ impl MortData { |
626 | 627 | Ok(result) |
627 | 628 | } |
628 | 629 |
|
629 | | - // ======================================================== |
630 | | - // COMMON PRELOADED TABLES (FxHashMap cache) |
631 | | - // ======================================================== |
632 | | - |
633 | | - /// Load a mortality table from the preloaded builtin cache. |
634 | | - /// |
635 | | - /// Tables are loaded once at first access and cached in an `FxHashMap`. |
636 | | - /// Subsequent calls are O(1) lookups with no I/O overhead. |
637 | | - /// |
638 | | - /// # Supported IDs |
639 | | - /// - IFOA: `AM92`, `PFA92`, `PMA92` |
640 | | - /// - IFOA: `PFA92C10`, `PMA92C10`, `PFA92C20`, `PMA92C20` |
641 | | - /// - SOA: `ELT15_F`, `ELT15_M`, `SULT` |
642 | | - /// |
643 | | - /// # Errors |
644 | | - /// Returns an error if the id is not in the builtin cache. |
645 | | - pub fn from_builtin(id: &str) -> RSLifeResult<Self> { |
646 | | - super::builtin::BUILTIN_MORT_DATA |
647 | | - .get(id) |
648 | | - .cloned() |
649 | | - .ok_or_else(|| format!("Builtin mortality table '{id}' not available").into()) |
650 | | - } |
651 | | - |
652 | 630 | // ======================================================== |
653 | 631 | // AUSTRALIAN GOVERNMENT ACTUARY XLS PARSING |
654 | 632 | // ======================================================== |
@@ -692,6 +670,7 @@ impl MortData { |
692 | 670 | // ======================================================== |
693 | 671 | // OTHER PARSING METHODS |
694 | 672 | // ======================================================== |
| 673 | + |
695 | 674 | /// Create mortality table from existing Polars DataFrame. |
696 | 675 | /// |
697 | 676 | /// Convenience method to create MortData from a pre-existing DataFrame |
@@ -881,6 +860,29 @@ impl MortData { |
881 | 860 | "Created from XLSX file {xlsx_file_path_str}, sheet {sheet_name}.".to_string(); |
882 | 861 | Self::new(category, description, df) |
883 | 862 | } |
| 863 | + |
| 864 | + // ======================================================== |
| 865 | + // COMMON PRELOADED TABLES (FxHashMap cache) |
| 866 | + // ======================================================== |
| 867 | + |
| 868 | + /// Load a mortality table from the preloaded builtin cache. |
| 869 | + /// |
| 870 | + /// Tables are loaded once at first access and cached in an `FxHashMap`. |
| 871 | + /// Subsequent calls are O(1) lookups with no I/O overhead. |
| 872 | + /// |
| 873 | + /// # Supported IDs |
| 874 | + /// - IFOA: `AM92`, `AF92`, `PFA92`, `PMA92` |
| 875 | + /// - IFOA: `PFA92C10`, `PMA92C10`, `PFA92C20`, `PMA92C20` |
| 876 | + /// - SOA: `ELT15_F`, `ELT15_M`, `SULT` |
| 877 | + /// |
| 878 | + /// # Errors |
| 879 | + /// Returns an error if the id is not in the builtin cache. |
| 880 | + pub fn from_builtin(id: &str) -> RSLifeResult<Self> { |
| 881 | + super::builtin::BUILTIN_MORT_DATA |
| 882 | + .get(id) |
| 883 | + .cloned() |
| 884 | + .ok_or_else(|| format!("Builtin mortality table '{id}' not available").into()) |
| 885 | + } |
884 | 886 | } |
885 | 887 |
|
886 | 888 | // ================================================ |
|
0 commit comments