1313class EnergyBillV1EnergyUsage (FieldPositionMixin , FieldConfidenceMixin ):
1414 """Details of energy consumption."""
1515
16+ consumption : Optional [float ]
17+ """The price per unit of energy consumed."""
1618 description : Optional [str ]
1719 """Description or details of the energy usage."""
1820 end_date : Optional [str ]
@@ -23,6 +25,8 @@ class EnergyBillV1EnergyUsage(FieldPositionMixin, FieldConfidenceMixin):
2325 """The rate of tax applied to the total cost."""
2426 total : Optional [float ]
2527 """The total cost of energy consumed."""
28+ unit : Optional [str ]
29+ """The unit of measurement for energy consumption."""
2630 unit_price : Optional [float ]
2731 """The price per unit of energy consumed."""
2832 page_n : int
@@ -44,53 +48,63 @@ def __init__(
4448 else :
4549 self .page_n = page_id
4650
51+ self .consumption = to_opt_float (raw_prediction , "consumption" )
4752 self .description = raw_prediction ["description" ]
4853 self .end_date = raw_prediction ["end_date" ]
4954 self .start_date = raw_prediction ["start_date" ]
5055 self .tax_rate = to_opt_float (raw_prediction , "tax_rate" )
5156 self .total = to_opt_float (raw_prediction , "total" )
57+ self .unit = raw_prediction ["unit" ]
5258 self .unit_price = to_opt_float (raw_prediction , "unit_price" )
5359
5460 def _printable_values (self ) -> Dict [str , str ]:
5561 """Return values for printing."""
5662 out_dict : Dict [str , str ] = {}
63+ out_dict ["consumption" ] = float_to_string (self .consumption )
5764 out_dict ["description" ] = format_for_display (self .description )
5865 out_dict ["end_date" ] = format_for_display (self .end_date )
5966 out_dict ["start_date" ] = format_for_display (self .start_date )
6067 out_dict ["tax_rate" ] = float_to_string (self .tax_rate )
6168 out_dict ["total" ] = float_to_string (self .total )
69+ out_dict ["unit" ] = format_for_display (self .unit )
6270 out_dict ["unit_price" ] = float_to_string (self .unit_price )
6371 return out_dict
6472
6573 def _table_printable_values (self ) -> Dict [str , str ]:
6674 """Return values for printing inside an RST table."""
6775 out_dict : Dict [str , str ] = {}
76+ out_dict ["consumption" ] = float_to_string (self .consumption )
6877 out_dict ["description" ] = format_for_display (self .description , 36 )
6978 out_dict ["end_date" ] = format_for_display (self .end_date , 10 )
7079 out_dict ["start_date" ] = format_for_display (self .start_date , None )
7180 out_dict ["tax_rate" ] = float_to_string (self .tax_rate )
7281 out_dict ["total" ] = float_to_string (self .total )
82+ out_dict ["unit" ] = format_for_display (self .unit , None )
7383 out_dict ["unit_price" ] = float_to_string (self .unit_price )
7484 return out_dict
7585
7686 def to_table_line (self ) -> str :
7787 """Output in a format suitable for inclusion in an rST table."""
7888 printable = self ._table_printable_values ()
79- out_str : str = f"| { printable ['description' ]:<36} | "
89+ out_str : str = f"| { printable ['consumption' ]:<11} | "
90+ out_str += f"{ printable ['description' ]:<36} | "
8091 out_str += f"{ printable ['end_date' ]:<10} | "
8192 out_str += f"{ printable ['start_date' ]:<10} | "
8293 out_str += f"{ printable ['tax_rate' ]:<8} | "
8394 out_str += f"{ printable ['total' ]:<9} | "
95+ out_str += f"{ printable ['unit' ]:<15} | "
8496 out_str += f"{ printable ['unit_price' ]:<10} | "
8597 return clean_out_string (out_str )
8698
8799 def __str__ (self ) -> str :
88100 """Default string representation."""
89101 printable = self ._printable_values ()
90- out_str : str = f"Description: { printable ['description' ]} , \n "
102+ out_str : str = f"Consumption: { printable ['consumption' ]} , \n "
103+ out_str += f"Description: { printable ['description' ]} , \n "
91104 out_str += f"End Date: { printable ['end_date' ]} , \n "
92105 out_str += f"Start Date: { printable ['start_date' ]} , \n "
93106 out_str += f"Tax Rate: { printable ['tax_rate' ]} , \n "
94107 out_str += f"Total: { printable ['total' ]} , \n "
108+ out_str += f"Unit of Measure: { printable ['unit' ]} , \n "
95109 out_str += f"Unit Price: { printable ['unit_price' ]} , \n "
96110 return clean_out_string (out_str )
0 commit comments