optic-rails 0.3.0 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 839393a02e1ac1355010b1f72749cb9ef4c225afb5d448b73b43c01f2fc3031a
4
- data.tar.gz: 935ddbf9996bd050150c1e6a2444330710a1dc87d263d4a945f90267ea30ba99
3
+ metadata.gz: 06b399f733fcb87bf9a26a5fc1902e064b4ce7e5b32a35253e2b63b88cad331e
4
+ data.tar.gz: bfaff9398cf437369963fde66ac45adfd6d6f2886ea6888dfb411865943492a0
5
5
  SHA512:
6
- metadata.gz: a3a55432f89f9aff3dd29272325b81d9992e7e6af1530f61b881b946e8c67375dc6c6eb02dabcde5ec972a02a7ebceee7fd79c4e984f93200a7d232788445af4
7
- data.tar.gz: 184cb515429f62a679310b459b9f43d80febc16bdbf1abb5cf05c696a7a5ba472eb85bb181afbe56240c4eef8c89db854d90a60434e2fe9a20c86f2424fdebf3
6
+ metadata.gz: '0682290823c71deaf2f14433fc8c0ed0323c9f2c5756f5e6c24c6a8f292bb1abf4591cc37b6eb50a111c5145c520e14c180f653f9285713576c66107b72961e1'
7
+ data.tar.gz: a9502628fcb48228d913fc337eb0cf4cc73c82f56cae10c685f1224b9639325a2259d37ff0396104eed772860226db6eede29a56b3c4d52f7399e48c45e055b7
data/lib/optic/rails.rb CHANGED
@@ -119,17 +119,15 @@ module Optic
119
119
 
120
120
  def self.get_metrics(pivot_name)
121
121
  with_connection do |connection|
122
- pivot = pivot_name.constantize
123
- pivot_values = connection.execute(pivot.unscoped.select("*").to_sql).to_a
124
-
125
- result = {
126
- entity_totals: [],
127
- pivot_name: pivot.name,
128
- # TODO filter columns, spread over multiple queries
129
- pivot_values: pivot_values,
130
- pivoted_totals: []
131
- # TODO also return computed "spanning" tree of objects from the pivot's POV (using the dijkstra paths from below)
132
- }
122
+ result = {entity_totals: []}
123
+ pivot = nil
124
+
125
+ if pivot_name
126
+ pivot = pivot_name.constantize
127
+ result[:pivot_name] = pivot.name
128
+ result[:pivot_values] = connection.execute(pivot.unscoped.select("*").to_sql).to_a
129
+ result[:pivoted_totals] = []
130
+ end
133
131
 
134
132
  graph = entity_graph
135
133
 
@@ -141,32 +139,31 @@ module Optic
141
139
  count_query = vertex.unscoped.select("COUNT(*)").to_sql
142
140
  result[:entity_totals] << { name: vertex.name, total: connection.execute(count_query).first["count"] }
143
141
 
144
- next if vertex == pivot # Skip pivoted metrics if this is the pivot
145
-
146
- # TODO weight edges to give preference to non-optional belongs_to (and other attributes?)
147
- path = graph.dijkstra_shortest_path(edge_weights, vertex, pivot)
148
- if path
149
- # Generate a SQL query to count the number of vertex instances grouped by pivot id, with appropriate joins from the path
150
- belongs_to_names = path.each_cons(2).map do |join_from, join_to|
151
- # TODO we shouldn't have to look up the edge again - use a graph model that allows us to annotate the edges with the reflections
152
- reflections = join_from.reflect_on_all_associations(:belongs_to).find_all { |reflection| !reflection.options[:polymorphic] && reflection.klass == join_to }
153
- # TODO warn if more than one reflection
154
- reflection = reflections.min_by { |r| r.options.size }
155
- reflection.name
142
+ if pivot && vertex != pivot
143
+ # TODO weight edges to give preference to non-optional belongs_to (and other attributes?)
144
+ path = graph.dijkstra_shortest_path(edge_weights, vertex, pivot)
145
+ if path
146
+ # Generate a SQL query to count the number of vertex instances grouped by pivot id, with appropriate joins from the path
147
+ belongs_to_names = path.each_cons(2).map do |join_from, join_to|
148
+ # TODO we shouldn't have to look up the edge again - use a graph model that allows us to annotate the edges with the reflections
149
+ reflections = join_from.reflect_on_all_associations(:belongs_to).find_all { |reflection| !reflection.options[:polymorphic] && reflection.klass == join_to }
150
+ # TODO warn if more than one reflection
151
+ reflection = reflections.min_by { |r| r.options.size }
152
+ reflection.name
153
+ end
154
+
155
+ joins = belongs_to_names.reverse.inject { |acc, elt| { elt => acc } }
156
+ query = vertex.unscoped.joins(joins).group(qualified_primary_key(pivot)).select(qualified_primary_key(pivot), "COUNT(*)").to_sql
157
+
158
+ result[:pivoted_totals] << { entity_name: vertex.name, totals: Hash[connection.execute(query).map { |record| [record["id"], record["count"]] }] }
159
+ else
160
+ # TODO print warning that we couldn't find a path from the pivot to the vertex
156
161
  end
157
-
158
- joins = belongs_to_names.reverse.inject { |acc, elt| { elt => acc } }
159
- query = vertex.unscoped.joins(joins).group(qualified_primary_key(pivot)).select(qualified_primary_key(pivot), "COUNT(*)").to_sql
160
-
161
- result[:pivoted_totals] << { entity_name: vertex.name, totals: Hash[connection.execute(query).map { |record| [record["id"], record["count"]] }] }
162
- else
163
- p "WARNING: No path from #{vertex.name} to #{pivot.name}"
164
162
  end
165
163
  end
166
164
 
167
165
  result
168
166
  end
169
167
  end
170
-
171
168
  end
172
169
  end
@@ -25,7 +25,7 @@ module Optic
25
25
  end
26
26
 
27
27
  api_key = app.config.optic_api_key
28
- uri = app.config.respond_to?(:optic_uri) ? app.config.optic_uri : "wss://tikal-api-staging.herokuapp.com"
28
+ uri = app.config.respond_to?(:optic_uri) ? app.config.optic_uri : "wss://tikal-api-staging.herokuapp.com/cable"
29
29
 
30
30
  logger.debug "Starting worker thread"
31
31
  worker = Thread.new do
@@ -1,5 +1,5 @@
1
1
  module Optic
2
2
  module Rails
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optic-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Vaynshtok