Class: Tronprint::Statistics
- Inherits:
-
Object
- Object
- Tronprint::Statistics
- Defined in:
- lib/tronprint/statistics.rb
Overview
The Statistics class is your gateway to fetching statistics about the energy usage and footprint of your app.
Instance Attribute Summary (collapse)
-
- (Object) aggregator
Returns the value of attribute aggregator.
-
- (Object) cpu_monitor
Returns the value of attribute cpu_monitor.
Instance Method Summary (collapse)
- - (Object) emission_estimate(from = nil, to = nil)
-
- (Object) impact(from = nil, to = nil)
Calculate emissions using aggregated data.
-
- (Statistics) initialize(aggregator, cpu_monitor)
constructor
A new instance of Statistics.
-
- (Object) range_duration(from, to)
Fetch total CPU time (in seconds) for a given range.
-
- (Object) total_duration
Fetch the total CPU time (in seconds) used by the application.
-
- (Object) total_electricity
The total amount of electricity used by the application.
-
- (Object) total_footprint
The total amount of CO2e generated by the application.
-
- (Object) total_footprint_methodology
A URL for the methodology statement of the total_footprint calculation.
Constructor Details
- (Statistics) initialize(aggregator, cpu_monitor)
A new instance of Statistics
8 9 10 11 |
# File 'lib/tronprint/statistics.rb', line 8 def initialize(aggregator, cpu_monitor) self.aggregator = aggregator self.cpu_monitor = cpu_monitor end |
Instance Attribute Details
- (Object) aggregator
Returns the value of attribute aggregator
6 7 8 |
# File 'lib/tronprint/statistics.rb', line 6 def aggregator @aggregator end |
- (Object) cpu_monitor
Returns the value of attribute cpu_monitor
6 7 8 |
# File 'lib/tronprint/statistics.rb', line 6 def cpu_monitor @cpu_monitor end |
Instance Method Details
- (Object) emission_estimate(from = nil, to = nil)
34 35 36 37 38 |
# File 'lib/tronprint/statistics.rb', line 34 def emission_estimate(from = nil, to = nil) if response = impact(from, to) response.decisions.carbon.object.value end end |
- (Object) impact(from = nil, to = nil)
Calculate emissions using aggregated data. A call is made to Brighter Planet's CM1 emission estimate service. Specifically, the call is made to the computation emitter
26 27 28 29 30 31 32 |
# File 'lib/tronprint/statistics.rb', line 26 def impact(from = nil, to = nil) duration = from.nil? ? total_duration : range_duration(from, to) app = Application.new :zip_code => Tronprint.zip_code, :duration => duration, :brighter_planet_key => Tronprint.brighter_planet_key app.impact end |
- (Object) range_duration(from, to)
Fetch total CPU time (in seconds) for a given range
19 20 21 |
# File 'lib/tronprint/statistics.rb', line 19 def range_duration(from, to) aggregator.range_total cpu_monitor.key, from, to end |
- (Object) total_duration
Fetch the total CPU time (in seconds) used by the application.
14 15 16 |
# File 'lib/tronprint/statistics.rb', line 14 def total_duration aggregator[cpu_monitor.key] end |
- (Object) total_electricity
The total amount of electricity used by the application.
46 47 48 49 50 |
# File 'lib/tronprint/statistics.rb', line 46 def total_electricity if response = impact impact.decisions.electricity_use.object end end |
- (Object) total_footprint
The total amount of CO2e generated by the application.
41 42 43 |
# File 'lib/tronprint/statistics.rb', line 41 def total_footprint emission_estimate end |
- (Object) total_footprint_methodology
A URL for the methodology statement of the total_footprint calculation.
53 54 55 56 57 |
# File 'lib/tronprint/statistics.rb', line 53 def total_footprint_methodology if response = impact response.methodology end end |