13
13
class EnergyBillV1EnergyUsage (FieldPositionMixin , FieldConfidenceMixin ):
14
14
"""Details of energy consumption."""
15
15
16
+ consumption : Optional [float ]
17
+ """The price per unit of energy consumed."""
16
18
description : Optional [str ]
17
19
"""Description or details of the energy usage."""
18
20
end_date : Optional [str ]
@@ -23,6 +25,8 @@ class EnergyBillV1EnergyUsage(FieldPositionMixin, FieldConfidenceMixin):
23
25
"""The rate of tax applied to the total cost."""
24
26
total : Optional [float ]
25
27
"""The total cost of energy consumed."""
28
+ unit : Optional [str ]
29
+ """The unit of measurement for energy consumption."""
26
30
unit_price : Optional [float ]
27
31
"""The price per unit of energy consumed."""
28
32
page_n : int
@@ -44,53 +48,63 @@ def __init__(
44
48
else :
45
49
self .page_n = page_id
46
50
51
+ self .consumption = to_opt_float (raw_prediction , "consumption" )
47
52
self .description = raw_prediction ["description" ]
48
53
self .end_date = raw_prediction ["end_date" ]
49
54
self .start_date = raw_prediction ["start_date" ]
50
55
self .tax_rate = to_opt_float (raw_prediction , "tax_rate" )
51
56
self .total = to_opt_float (raw_prediction , "total" )
57
+ self .unit = raw_prediction ["unit" ]
52
58
self .unit_price = to_opt_float (raw_prediction , "unit_price" )
53
59
54
60
def _printable_values (self ) -> Dict [str , str ]:
55
61
"""Return values for printing."""
56
62
out_dict : Dict [str , str ] = {}
63
+ out_dict ["consumption" ] = float_to_string (self .consumption )
57
64
out_dict ["description" ] = format_for_display (self .description )
58
65
out_dict ["end_date" ] = format_for_display (self .end_date )
59
66
out_dict ["start_date" ] = format_for_display (self .start_date )
60
67
out_dict ["tax_rate" ] = float_to_string (self .tax_rate )
61
68
out_dict ["total" ] = float_to_string (self .total )
69
+ out_dict ["unit" ] = format_for_display (self .unit )
62
70
out_dict ["unit_price" ] = float_to_string (self .unit_price )
63
71
return out_dict
64
72
65
73
def _table_printable_values (self ) -> Dict [str , str ]:
66
74
"""Return values for printing inside an RST table."""
67
75
out_dict : Dict [str , str ] = {}
76
+ out_dict ["consumption" ] = float_to_string (self .consumption )
68
77
out_dict ["description" ] = format_for_display (self .description , 36 )
69
78
out_dict ["end_date" ] = format_for_display (self .end_date , 10 )
70
79
out_dict ["start_date" ] = format_for_display (self .start_date , None )
71
80
out_dict ["tax_rate" ] = float_to_string (self .tax_rate )
72
81
out_dict ["total" ] = float_to_string (self .total )
82
+ out_dict ["unit" ] = format_for_display (self .unit , None )
73
83
out_dict ["unit_price" ] = float_to_string (self .unit_price )
74
84
return out_dict
75
85
76
86
def to_table_line (self ) -> str :
77
87
"""Output in a format suitable for inclusion in an rST table."""
78
88
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} | "
80
91
out_str += f"{ printable ['end_date' ]:<10} | "
81
92
out_str += f"{ printable ['start_date' ]:<10} | "
82
93
out_str += f"{ printable ['tax_rate' ]:<8} | "
83
94
out_str += f"{ printable ['total' ]:<9} | "
95
+ out_str += f"{ printable ['unit' ]:<15} | "
84
96
out_str += f"{ printable ['unit_price' ]:<10} | "
85
97
return clean_out_string (out_str )
86
98
87
99
def __str__ (self ) -> str :
88
100
"""Default string representation."""
89
101
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 "
91
104
out_str += f"End Date: { printable ['end_date' ]} , \n "
92
105
out_str += f"Start Date: { printable ['start_date' ]} , \n "
93
106
out_str += f"Tax Rate: { printable ['tax_rate' ]} , \n "
94
107
out_str += f"Total: { printable ['total' ]} , \n "
108
+ out_str += f"Unit of Measure: { printable ['unit' ]} , \n "
95
109
out_str += f"Unit Price: { printable ['unit_price' ]} , \n "
96
110
return clean_out_string (out_str )
0 commit comments