my_tank_info 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +17 -0
  3. data/.gitignore +9 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +74 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +253 -0
  10. data/Rakefile +12 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/my_tank_info/client.rb +106 -0
  14. data/lib/my_tank_info/collection.rb +33 -0
  15. data/lib/my_tank_info/error.rb +6 -0
  16. data/lib/my_tank_info/errors/missing_required_attribute_error.rb +6 -0
  17. data/lib/my_tank_info/object.rb +18 -0
  18. data/lib/my_tank_info/objects/alarm.rb +6 -0
  19. data/lib/my_tank_info/objects/alarm_note.rb +6 -0
  20. data/lib/my_tank_info/objects/csld_result.rb +6 -0
  21. data/lib/my_tank_info/objects/environmental_sitegroup.rb +9 -0
  22. data/lib/my_tank_info/objects/inventory_sitegroup.rb +9 -0
  23. data/lib/my_tank_info/objects/line_leak_result.rb +6 -0
  24. data/lib/my_tank_info/objects/notification_code.rb +6 -0
  25. data/lib/my_tank_info/objects/notification_contact.rb +6 -0
  26. data/lib/my_tank_info/objects/notification_rule.rb +9 -0
  27. data/lib/my_tank_info/objects/notification_rule_contact.rb +6 -0
  28. data/lib/my_tank_info/objects/notification_site.rb +6 -0
  29. data/lib/my_tank_info/objects/sensor_status_result.rb +6 -0
  30. data/lib/my_tank_info/objects/site.rb +6 -0
  31. data/lib/my_tank_info/objects/sitegroup_inventory_dashboard.rb +9 -0
  32. data/lib/my_tank_info/objects/tank.rb +6 -0
  33. data/lib/my_tank_info/objects/tank_daily_usage_record.rb +6 -0
  34. data/lib/my_tank_info/objects/tank_delivery_record.rb +6 -0
  35. data/lib/my_tank_info/objects/tank_inventory_record.rb +6 -0
  36. data/lib/my_tank_info/objects/tank_leak_result.rb +6 -0
  37. data/lib/my_tank_info/objects/tank_reconciliation_record.rb +30 -0
  38. data/lib/my_tank_info/objects/tank_rule.rb +6 -0
  39. data/lib/my_tank_info/objects/tank_runout_record.rb +6 -0
  40. data/lib/my_tank_info/resource.rb +75 -0
  41. data/lib/my_tank_info/resources/active_alarms.rb +29 -0
  42. data/lib/my_tank_info/resources/alarm_history.rb +25 -0
  43. data/lib/my_tank_info/resources/alarm_notes.rb +13 -0
  44. data/lib/my_tank_info/resources/csld_results.rb +10 -0
  45. data/lib/my_tank_info/resources/environmental_sitegroups.rb +9 -0
  46. data/lib/my_tank_info/resources/inventory_sitegroups.rb +9 -0
  47. data/lib/my_tank_info/resources/line_leak_results.rb +10 -0
  48. data/lib/my_tank_info/resources/notification_contacts.rb +32 -0
  49. data/lib/my_tank_info/resources/notification_rules.rb +28 -0
  50. data/lib/my_tank_info/resources/sensor_status_results.rb +10 -0
  51. data/lib/my_tank_info/resources/sitegroup_inventory_dashboards.rb +12 -0
  52. data/lib/my_tank_info/resources/tank_daily_usage.rb +10 -0
  53. data/lib/my_tank_info/resources/tank_deliveries.rb +27 -0
  54. data/lib/my_tank_info/resources/tank_inventory.rb +10 -0
  55. data/lib/my_tank_info/resources/tank_leak_results.rb +10 -0
  56. data/lib/my_tank_info/resources/tank_reconciliation_records.rb +34 -0
  57. data/lib/my_tank_info/resources/tank_rules.rb +15 -0
  58. data/lib/my_tank_info/resources/tank_runout.rb +10 -0
  59. data/lib/my_tank_info/resources/tanks.rb +24 -0
  60. data/lib/my_tank_info/resources/tokens.rb +10 -0
  61. data/lib/my_tank_info/tank_reconciliation_record_collection.rb +51 -0
  62. data/lib/my_tank_info/tank_reconciliation_record_summary.rb +113 -0
  63. data/lib/my_tank_info/version.rb +5 -0
  64. data/lib/my_tank_info.rb +68 -0
  65. data/my_tank_info.gemspec +34 -0
  66. metadata +138 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class TokensResource < Resource
5
+ def generate(**attributes)
6
+ response = post_request("api/token", body: attributes)
7
+ response.body.delete('"')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class TankReconciliationRecordCollection
5
+ attr_reader :data, :size, :site_id, :reconciliation_period, :started_at, :ended_at
6
+
7
+ def self.from_response(response, reconciliation_period:)
8
+ body = response.body
9
+
10
+ @collection = new(
11
+ data: body.map { |attrs| TankReconciliationRecord.new(attrs) },
12
+ reconciliation_period: reconciliation_period
13
+ )
14
+ end
15
+
16
+ def initialize(data:, reconciliation_period:)
17
+ @data = data
18
+ @size = @data.size
19
+ @reconciliation_period = reconciliation_period
20
+
21
+ @site_id = @data.first.site_id
22
+ @started_at = @data.min_by(&:started_at).started_at
23
+ @ended_at = @data.max_by(&:started_at).started_at
24
+ end
25
+
26
+ def tanks
27
+ @data.map { |record|
28
+ records = @data.select { _1.tank_number == record.tank_number }.sort_by(&:started_at)
29
+ summary =
30
+ TankReconciliationRecordSummary.new(
31
+ records,
32
+ capacity: record.total_tanks_capacity,
33
+ reconciliation_period: @reconciliation_period
34
+ )
35
+
36
+ Tank.new(
37
+ name: record.name,
38
+ product_name: record.product_name,
39
+ tank_number: record.tank_number,
40
+ tank_numbers: record.tank_numbers,
41
+ capacity: record.total_tanks_capacity,
42
+ reconciliation_records: records,
43
+ reconciliation_summary: summary,
44
+ passed?: summary.passed?,
45
+ failed?: summary.failed?
46
+ )
47
+ }.uniq { |tank| tank.name }
48
+ .sort_by(&:tank_number)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class TankReconciliationRecordSummary
5
+ attr_reader :records
6
+
7
+ MONTHLY_FUDGE_NUMBER = 130
8
+ TEN_DAY_MULTIPLIER = 0.0075
9
+ SEVEN_DAY_MULTIPLIER = 0.005
10
+
11
+ def initialize(records, capacity:, reconciliation_period:)
12
+ @records = records
13
+ @capacity = capacity
14
+ @reconciliation_period = reconciliation_period
15
+ end
16
+
17
+ def total_deliveries_volume
18
+ @records.sum(&:deliveries_volume).round(0)
19
+ end
20
+
21
+ def total_sales_volume
22
+ @records.sum(&:sales_volume).round(0)
23
+ end
24
+
25
+ def total_over_short
26
+ @records.sum(&:difference_volume).round(0)
27
+ end
28
+
29
+ def absolute_difference_volume
30
+ total_over_short.abs
31
+ end
32
+
33
+ # Monthly Reconciliation Specific Logic
34
+ def total_gallons_pumped
35
+ total_sales_volume
36
+ end
37
+
38
+ def leak_check_number
39
+ # DROP THE LAST 2 DIGITS FROM THE PUMPED NUMBER AND ENTER ON THE LEAK CHECK
40
+ (total_gallons_pumped.to_f / 100).round(0).to_i
41
+ end
42
+
43
+ def leak_check_result
44
+ leak_check_number + MONTHLY_FUDGE_NUMBER
45
+ end
46
+
47
+ def leak_check_result_unacceptable?
48
+ absolute_difference_volume > leak_check_result
49
+ end
50
+
51
+ # 10 Day Reconciliation Specific Logic
52
+ def allowance_multiplier
53
+ [@capacity, total_deliveries_volume, total_sales_volume].max
54
+ end
55
+
56
+ def allowable_tolerance
57
+ (allowance_multiplier.to_f * TEN_DAY_MULTIPLIER).round(0).to_i
58
+ end
59
+
60
+ def variance_is_gt_allowable_tolerance?
61
+ absolute_difference_volume > allowable_tolerance
62
+ end
63
+
64
+ # Weekly / 7 Day Reconciliation Specific Logic
65
+ def weekly_number_to_check
66
+ [total_gallons_pumped, @capacity].max
67
+ end
68
+
69
+ def weekly_check_number
70
+ (weekly_number_to_check.to_f * SEVEN_DAY_MULTIPLIER).round(0).to_i
71
+ end
72
+
73
+ def total_gallons_larger_than_leak_check?
74
+ absolute_difference_volume > weekly_check_number
75
+ end
76
+
77
+ def allowable_variance
78
+ case @reconciliation_period
79
+ when :monthly
80
+ leak_check_result
81
+ when :ten_day
82
+ allowable_tolerance
83
+ when :weekly
84
+ weekly_check_number
85
+ else
86
+ raise ReconciliationPeriodMissingError.new
87
+ end
88
+ end
89
+
90
+ def failed?
91
+ case @reconciliation_period
92
+ when :monthly
93
+ leak_check_result_unacceptable?
94
+ when :ten_day
95
+ variance_is_gt_allowable_tolerance?
96
+ when :weekly
97
+ total_gallons_larger_than_leak_check?
98
+ else
99
+ raise ReconciliationPeriodMissingError.new
100
+ end
101
+ end
102
+
103
+ def passed?
104
+ !failed?
105
+ end
106
+ end
107
+
108
+ class ReconciliationPeriodMissingError < Error
109
+ def initialize
110
+ super("reconciliation_period must be one of the following values: :monthly, :ten_day, :weekly")
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "my_tank_info/version"
4
+
5
+ module MyTankInfo
6
+ MYTI_DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%:z"
7
+
8
+ autoload :Client, "my_tank_info/client"
9
+ autoload :Object, "my_tank_info/object"
10
+ autoload :Resource, "my_tank_info/resource"
11
+ autoload :Collection, "my_tank_info/collection"
12
+ autoload :Error, "my_tank_info/error"
13
+ autoload :TankReconciliationRecordCollection, "my_tank_info/tank_reconciliation_record_collection"
14
+
15
+ autoload :TankReconciliationRecordSummary, "my_tank_info/tank_reconciliation_record_summary"
16
+
17
+ autoload :EnvironmentalSitegroup, "my_tank_info/objects/environmental_sitegroup"
18
+ autoload :InventorySitegroup, "my_tank_info/objects/inventory_sitegroup"
19
+ autoload :Site, "my_tank_info/objects/site"
20
+ autoload :Tank, "my_tank_info/objects/tank"
21
+ autoload :Alarm, "my_tank_info/objects/alarm"
22
+ autoload :AlarmNote, "my_tank_info/objects/alarm_note"
23
+ autoload :TankLeakResult, "my_tank_info/objects/tank_leak_result"
24
+ autoload :LineLeakResult, "my_tank_info/objects/line_leak_result"
25
+ autoload :CsldResult, "my_tank_info/objects/csld_result"
26
+ autoload :SensorStatusResult, "my_tank_info/objects/sensor_status_result"
27
+
28
+ autoload :SitegroupInventoryDashboard, "my_tank_info/objects/sitegroup_inventory_dashboard"
29
+ autoload :TankDailyUsageRecord, "my_tank_info/objects/tank_daily_usage_record"
30
+ autoload :TankDeliveryRecord, "my_tank_info/objects/tank_delivery_record"
31
+ autoload :TankInventoryRecord, "my_tank_info/objects/tank_inventory_record"
32
+ autoload :TankRunoutRecord, "my_tank_info/objects/tank_runout_record"
33
+ autoload :TankRule, "my_tank_info/objects/tank_rule"
34
+
35
+ autoload :TankReconciliationRecord, "my_tank_info/objects/tank_reconciliation_record"
36
+
37
+ autoload :NotificationContact, "my_tank_info/objects/notification_contact"
38
+ autoload :NotificationSite, "my_tank_info/objects/notification_site"
39
+ autoload :NotificationRule, "my_tank_info/objects/notification_rule"
40
+ autoload :NotificationCode, "my_tank_info/objects/notification_code"
41
+ autoload :NotificationRuleContact, "my_tank_info/objects/notification_rule_contact"
42
+
43
+ autoload :ActiveAlarmsResource, "my_tank_info/resources/active_alarms"
44
+ autoload :AlarmHistoryResource, "my_tank_info/resources/alarm_history"
45
+ autoload :AlarmNotesResource, "my_tank_info/resources/alarm_notes"
46
+
47
+ autoload :EnvironmentalSitegroupsResource, "my_tank_info/resources/environmental_sitegroups"
48
+ autoload :TankLeakResultsResource, "my_tank_info/resources/tank_leak_results"
49
+ autoload :LineLeakResultsResource, "my_tank_info/resources/line_leak_results"
50
+ autoload :CsldResultsResource, "my_tank_info/resources/csld_results"
51
+ autoload :SensorStatusResultsResource, "my_tank_info/resources/sensor_status_results"
52
+
53
+ autoload :TankReconciliationRecordsResource, "my_tank_info/resources/tank_reconciliation_records"
54
+
55
+ autoload :InventorySitegroupsResource, "my_tank_info/resources/inventory_sitegroups"
56
+ autoload :SitegroupInventoryDashboardsResource, "my_tank_info/resources/sitegroup_inventory_dashboards"
57
+ autoload :TanksResource, "my_tank_info/resources/tanks"
58
+ autoload :TankDailyUsageResource, "my_tank_info/resources/tank_daily_usage"
59
+ autoload :TankDeliveriesResource, "my_tank_info/resources/tank_deliveries"
60
+ autoload :TankInventoryResource, "my_tank_info/resources/tank_inventory"
61
+ autoload :TankRunoutResource, "my_tank_info/resources/tank_runout"
62
+ autoload :TankRulesResource, "my_tank_info/resources/tank_rules"
63
+
64
+ autoload :NotificationContactsResource, "my_tank_info/resources/notification_contacts"
65
+ autoload :NotificationRulesResource, "my_tank_info/resources/notification_rules"
66
+
67
+ autoload :TokensResource, "my_tank_info/resources/tokens"
68
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/my_tank_info/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "my_tank_info"
7
+ spec.version = MyTankInfo::VERSION
8
+ spec.authors = ["Kyle Keesling"]
9
+ spec.email = ["me@kylekeesling.com"]
10
+
11
+ spec.summary = "A ruby gem to communicate with MyTankInfo (mytankinfo.com)"
12
+ spec.homepage = "https://github.com/kylekeesling/my_tank_info"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/kylekeesling/my_tank_info"
18
+ spec.metadata["changelog_uri"] = "https://github.com/kylekeesling/my_tank_info/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday", "~> 1.7"
30
+ spec.add_dependency "faraday_middleware", "~> 1.1"
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_tank_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Keesling
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description:
42
+ email:
43
+ - me@kylekeesling.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/main.yml"
49
+ - ".gitignore"
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/my_tank_info.rb
60
+ - lib/my_tank_info/client.rb
61
+ - lib/my_tank_info/collection.rb
62
+ - lib/my_tank_info/error.rb
63
+ - lib/my_tank_info/errors/missing_required_attribute_error.rb
64
+ - lib/my_tank_info/object.rb
65
+ - lib/my_tank_info/objects/alarm.rb
66
+ - lib/my_tank_info/objects/alarm_note.rb
67
+ - lib/my_tank_info/objects/csld_result.rb
68
+ - lib/my_tank_info/objects/environmental_sitegroup.rb
69
+ - lib/my_tank_info/objects/inventory_sitegroup.rb
70
+ - lib/my_tank_info/objects/line_leak_result.rb
71
+ - lib/my_tank_info/objects/notification_code.rb
72
+ - lib/my_tank_info/objects/notification_contact.rb
73
+ - lib/my_tank_info/objects/notification_rule.rb
74
+ - lib/my_tank_info/objects/notification_rule_contact.rb
75
+ - lib/my_tank_info/objects/notification_site.rb
76
+ - lib/my_tank_info/objects/sensor_status_result.rb
77
+ - lib/my_tank_info/objects/site.rb
78
+ - lib/my_tank_info/objects/sitegroup_inventory_dashboard.rb
79
+ - lib/my_tank_info/objects/tank.rb
80
+ - lib/my_tank_info/objects/tank_daily_usage_record.rb
81
+ - lib/my_tank_info/objects/tank_delivery_record.rb
82
+ - lib/my_tank_info/objects/tank_inventory_record.rb
83
+ - lib/my_tank_info/objects/tank_leak_result.rb
84
+ - lib/my_tank_info/objects/tank_reconciliation_record.rb
85
+ - lib/my_tank_info/objects/tank_rule.rb
86
+ - lib/my_tank_info/objects/tank_runout_record.rb
87
+ - lib/my_tank_info/resource.rb
88
+ - lib/my_tank_info/resources/active_alarms.rb
89
+ - lib/my_tank_info/resources/alarm_history.rb
90
+ - lib/my_tank_info/resources/alarm_notes.rb
91
+ - lib/my_tank_info/resources/csld_results.rb
92
+ - lib/my_tank_info/resources/environmental_sitegroups.rb
93
+ - lib/my_tank_info/resources/inventory_sitegroups.rb
94
+ - lib/my_tank_info/resources/line_leak_results.rb
95
+ - lib/my_tank_info/resources/notification_contacts.rb
96
+ - lib/my_tank_info/resources/notification_rules.rb
97
+ - lib/my_tank_info/resources/sensor_status_results.rb
98
+ - lib/my_tank_info/resources/sitegroup_inventory_dashboards.rb
99
+ - lib/my_tank_info/resources/tank_daily_usage.rb
100
+ - lib/my_tank_info/resources/tank_deliveries.rb
101
+ - lib/my_tank_info/resources/tank_inventory.rb
102
+ - lib/my_tank_info/resources/tank_leak_results.rb
103
+ - lib/my_tank_info/resources/tank_reconciliation_records.rb
104
+ - lib/my_tank_info/resources/tank_rules.rb
105
+ - lib/my_tank_info/resources/tank_runout.rb
106
+ - lib/my_tank_info/resources/tanks.rb
107
+ - lib/my_tank_info/resources/tokens.rb
108
+ - lib/my_tank_info/tank_reconciliation_record_collection.rb
109
+ - lib/my_tank_info/tank_reconciliation_record_summary.rb
110
+ - lib/my_tank_info/version.rb
111
+ - my_tank_info.gemspec
112
+ homepage: https://github.com/kylekeesling/my_tank_info
113
+ licenses:
114
+ - MIT
115
+ metadata:
116
+ homepage_uri: https://github.com/kylekeesling/my_tank_info
117
+ source_code_uri: https://github.com/kylekeesling/my_tank_info
118
+ changelog_uri: https://github.com/kylekeesling/my_tank_info/CHANGELOG.md
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.4.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 3.2.25
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A ruby gem to communicate with MyTankInfo (mytankinfo.com)
138
+ test_files: []