pont 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18654cfa783089d03298ab20ca5bee85fe9a472c
4
- data.tar.gz: 37c71c12955309ed7388e74e6c370a31e6141c5b
3
+ metadata.gz: a8cc14f121d178db09510fe185e0e677a6b32a69
4
+ data.tar.gz: c22b0f25278e599e565c378a12136795fa21755a
5
5
  SHA512:
6
- metadata.gz: 38639e421d5b8166a544b40e37d09b49228e202b181ed16aee4e56608bf9d4dfc5727390e30c1f6e2f344b5843d002744cb838c691bc792d0ffa9a4eb7f782fa
7
- data.tar.gz: dee26d31e8226dd8691e6d188a59d3b053837f59586bbfabb5f59dda95465ece19fc50c499cb63509b8e01643334a3abb06ea51333087d7ad1462ba98785356c
6
+ metadata.gz: 81a4c36c3f7d066f0cebadf410da2301c9ac1e48cea17614c2e70b76ae772610e91ea8eb0b5a3d98e759d19cd0364ec00b57e1ced226a53f966baa8d6816be15
7
+ data.tar.gz: 241561e10cb29fc2c6dfd5d39e9d242a0ffd733b1cfa232b053a501b49782e43b0c6dc11740e9376795f4504c97fd2fe3ff337586dae5b907d16935d568c6ca9
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pont
4
+ class CompAttributes
5
+ BASE = [
6
+ :channel_code,
7
+ :contract_type_code,
8
+ :enrollment_type,
9
+ :in_gas_eligible_market,
10
+ :market_code,
11
+ :office_code,
12
+ :order_type,
13
+ :plan_comp_filter,
14
+ :product_type_code,
15
+ :sourced_by_source_code,
16
+ :valid_email
17
+ ].freeze
18
+
19
+ PIVOT = [
20
+ :account_confirmed_start_dt,
21
+ :account_offer_reason,
22
+ :account_status,
23
+ :avg_annual_usage,
24
+ :campaign_code,
25
+ :comp_ineligible_dt,
26
+ :comp_type_code,
27
+ :confirmed_start_dt,
28
+ :failed_validation,
29
+ :installation_required,
30
+ :is_cancelled,
31
+ :is_duplicate,
32
+ :is_partial,
33
+ :is_rejected,
34
+ :is_rescinded,
35
+ :is_winback,
36
+ :payable_status_reason,
37
+ :revenue_class_code,
38
+ :sale_dt,
39
+ :state_code,
40
+ :total_residuals
41
+ ].concat(BASE).sort.freeze
42
+
43
+ # TODO: Move this to after party
44
+ # Run this in garcon after adding new attributes
45
+ # heroku run padrino runner "Pont::CompAttributes.create_pivot" --remote production
46
+ def self.create_pivot
47
+ quoted_attributes = PIVOT.map { |attribute| "$$#{attribute}$$" }.join(', ')
48
+ typed_attributes = PIVOT.map { |attribute| "#{attribute} text" }.join(', ')
49
+
50
+ if defined?(Rails)
51
+ ApplicationRecord.transaction do
52
+ ActiveRecord::Base.connection.execute('DROP VIEW IF EXISTS "comp_attribute_pivot"')
53
+ query = %(
54
+ CREATE VIEW \"comp_attribute_pivot\" AS
55
+ select * from crosstab('select comp_id, comp_attribute_key, comp_attribute_value from comp_attributes
56
+ order by 1, 2'::text,
57
+ 'select unnest(array[?])'::text) comp_attributes(comp_id integer, ?)
58
+ order by comp_id
59
+ )
60
+ sanitized_query = ActiveRecord::Base.send(:sanitize_sql_array, [query, quoted_attributes, typed_attributes])
61
+ ActiveRecord::Base.connection.execute(sanitized_query)
62
+ end
63
+ else
64
+ Sequel::Model.db.transaction do
65
+ Sequel::Model.db.drop_view(:comp_attribute_pivot, if_exists: true)
66
+ Sequel::Model.db.create_view(:comp_attribute_pivot, "select * from crosstab('select comp_id, comp_attribute_key, comp_attribute_value from comp_attributes order by 1, 2'::text, 'select unnest(array[#{quoted_attributes}])'::text) comp_attributes(comp_id integer, #{typed_attributes}) order by comp_id")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
data/lib/pont/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pont
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/lib/pont.rb CHANGED
@@ -9,6 +9,7 @@ end
9
9
  require 'active_support'
10
10
 
11
11
  require_relative 'pont/attribution'
12
+ require_relative 'pont/comp_attributes'
12
13
  require_relative 'pont/configuration'
13
14
  require_relative 'pont/logger'
14
15
  require_relative 'pont/prospect_event'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Marren
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,6 +100,7 @@ files:
100
100
  - bin/setup
101
101
  - lib/pont.rb
102
102
  - lib/pont/attribution.rb
103
+ - lib/pont/comp_attributes.rb
103
104
  - lib/pont/configuration.rb
104
105
  - lib/pont/logger.rb
105
106
  - lib/pont/prospect_event.rb