1
1
//! iLEAP Data Model Extension data model
2
- use std:: error:: Error ;
3
-
4
2
use chrono:: { DateTime , Utc } ;
5
3
use pact_data_model:: {
6
4
CarbonFootprint , CharacterizationFactors , CompanyIdSet , CrossSectoralStandard ,
@@ -631,7 +629,7 @@ pub fn to_pcf(
631
629
product_or_sector_specific_rules : None , // TODO: get clarity on whether GLEC should be specified
632
630
biogenic_accounting_methodology : None ,
633
631
boundary_processes_description : "" . to_string ( ) ,
634
- reference_period_start : Utc :: now ( ) ,
632
+ reference_period_start : Utc :: now ( ) , // TODO: turn into parameter.
635
633
reference_period_end : ( Utc :: now ( ) + chrono:: Duration :: days ( 364 ) ) ,
636
634
geographic_scope : None ,
637
635
secondary_emission_factor_sources : None ,
@@ -658,8 +656,8 @@ pub fn to_pcf(
658
656
}
659
657
}
660
658
661
- pub fn gen_rnd_demo_data ( ) -> Result < Vec < ProductFootprint > , Box < dyn Error > > {
662
- let mut og = Gen :: new ( 10 ) ;
659
+ pub fn gen_rnd_demo_data ( size : usize ) -> Vec < ProductFootprint > {
660
+ let mut og = Gen :: new ( size ) ;
663
661
664
662
let mut shipment_footprints = vec ! [ ] ;
665
663
let mut tocs = vec ! [ ] ;
@@ -674,6 +672,7 @@ pub fn gen_rnd_demo_data() -> Result<Vec<ProductFootprint>, Box<dyn Error>> {
674
672
675
673
let mut i = 0 ;
676
674
let limit = u8:: arbitrary ( & mut og) % 5 + 1 ;
675
+ // TODO: improve code through pair programming with Martin.
677
676
loop {
678
677
let mut tce = Tce :: arbitrary ( & mut og) ;
679
678
@@ -708,12 +707,10 @@ pub fn gen_rnd_demo_data() -> Result<Vec<ProductFootprint>, Box<dyn Error>> {
708
707
tce. distance = GlecDistance :: Actual ( Decimal :: from ( 0 ) . into ( ) ) ;
709
708
tce. transport_activity = Decimal :: from ( 0 ) . into ( ) ;
710
709
711
- tce. co2e_wtw = WrappedDecimal :: from (
712
- ( ( hoc. co2e_intensity_wtw . 0 * tce. mass . 0 ) ) . round_dp ( 2 ) ,
713
- ) ;
714
- tce. co2e_ttw = WrappedDecimal :: from (
715
- ( ( hoc. co2e_intensity_ttw . 0 * tce. mass . 0 ) ) . round_dp ( 2 ) ,
716
- ) ;
710
+ tce. co2e_wtw =
711
+ WrappedDecimal :: from ( ( hoc. co2e_intensity_wtw . 0 * tce. mass . 0 ) . round_dp ( 2 ) ) ;
712
+ tce. co2e_ttw =
713
+ WrappedDecimal :: from ( ( hoc. co2e_intensity_ttw . 0 * tce. mass . 0 ) . round_dp ( 2 ) ) ;
717
714
718
715
let hoc = to_pcf (
719
716
ILeapType :: Hoc ( hoc) ,
@@ -773,14 +770,20 @@ pub fn gen_rnd_demo_data() -> Result<Vec<ProductFootprint>, Box<dyn Error>> {
773
770
shipment_footprints. push ( ship_foot) ;
774
771
}
775
772
776
- println ! ( "{shipment_footprints:#?}" ) ;
777
- println ! ( "{tocs:#?}" ) ;
778
- println ! ( "{hocs:#?}" ) ;
779
-
780
- let footprints: Vec < ProductFootprint > = vec ! [ shipment_footprints, tocs, hocs]
773
+ vec ! [ shipment_footprints, tocs, hocs]
781
774
. into_iter ( )
782
775
. flatten ( )
783
- . collect ( ) ;
776
+ . collect ( )
777
+ }
778
+
779
+ #[ cfg( test) ]
780
+ mod tests {
781
+ use super :: * ;
784
782
785
- Ok ( footprints)
783
+ #[ test]
784
+ fn test_gen_rnd_demo_data ( ) {
785
+ let footprints = gen_rnd_demo_data ( 10 ) ;
786
+
787
+ println ! ( "{footprints:#?}" ) ;
788
+ }
786
789
}
0 commit comments