neo4j_bolt 0.1.14 → 0.1.15

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: ee1cca8c165dbe635457982dd05a846f11289b0c38060e00d55d2d62285eb318
4
- data.tar.gz: a415990608856c52c675e43b8cb8436f62b24aff81111950afedca13b8b1ff1f
3
+ metadata.gz: 04aa3226c239b35ccde7096230fd8421734dae517029af0501bf5381892b16e4
4
+ data.tar.gz: b267b7da10112ea640f326531c8db9260d9ea64fd722c9daa8f95a5473d8b740
5
5
  SHA512:
6
- metadata.gz: 211bf207bc1275bb93352711786ab655ac549418911d8fbca03f785fac09d4d6f82245cd78f957de351e2be566531eb77c9360a8e7cb04de1a9cbc551a2cbc1c
7
- data.tar.gz: 3d8acb0acbd55b19939fa475515d9cbc3752d2394c768be533f0ef960ed8e5de637e527d4d632a2a1f9ced2d5e300be2c21278c580b8b2c7de6639673856ffd3
6
+ metadata.gz: 9c25238c42c83abdcab871eea6b2dadba8fe7c0ef3e40ce56ef1a161a7b2763f95b618f00d67aa24d766337ac20f0047263c0bca7921c532647c5c24fcf4f413
7
+ data.tar.gz: c6f653050a7928ca389aac06ad37b508e5b967745f557c5fcf920eeb0c0471ab83c37b085d2d6c5478de4f91fcbc1cf1fc1068b56bdea0000434f4425d11eba6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neo4j_bolt (0.1.12)
4
+ neo4j_bolt (0.1.15)
5
5
  gli
6
6
 
7
7
  GEM
data/bin/neo4j_bolt CHANGED
@@ -166,7 +166,7 @@ class App
166
166
  properties_for_label = {}
167
167
  counts_for_label = {}
168
168
 
169
- all_labels.to_a.sort.each do |label|
169
+ all_labels.to_a.each do |label|
170
170
  properties_for_label[label] ||= {}
171
171
  if options[:properties]
172
172
  neo4j_query("MATCH (n:#{label}) RETURN n") do |entry|
@@ -174,8 +174,26 @@ class App
174
174
  counts_for_label[label] += 1
175
175
  node = entry['n']
176
176
  node.each_pair do |key, value|
177
- properties_for_label[label][key] ||= {:classes => Set.new()}
178
- properties_for_label[label][key][:classes] << value.class
177
+ properties_for_label[label][key] ||= {:classes => Set.new(), :counts => {}, :min => {}, :max => {}, :sum => {}}
178
+ c = TR[value.class.to_s] || value.class.to_s
179
+ properties_for_label[label][key][:classes] << c
180
+ properties_for_label[label][key][:counts][c] ||= 0
181
+ properties_for_label[label][key][:counts][c] += 1
182
+ sz = if c == 'string' || c == 'list'
183
+ value.size
184
+ elsif c == 'int' || c == 'float'
185
+ value
186
+ else
187
+ nil
188
+ end
189
+ unless sz.nil?
190
+ properties_for_label[label][key][:min][c] ||= sz
191
+ properties_for_label[label][key][:min][c] = [properties_for_label[label][key][:min][c], sz].min
192
+ properties_for_label[label][key][:max][c] ||= sz
193
+ properties_for_label[label][key][:max][c] = [properties_for_label[label][key][:max][c], sz].max
194
+ properties_for_label[label][key][:sum][c] ||= 0
195
+ properties_for_label[label][key][:sum][c] += sz
196
+ end
179
197
  end
180
198
  end
181
199
  end
@@ -193,8 +211,26 @@ class App
193
211
  counts_for_label[s] += 1
194
212
  rel = entry['r']
195
213
  rel.each_pair do |key, value|
196
- properties_for_label[s][key] ||= {:classes => Set.new()}
197
- properties_for_label[s][key][:classes] << value.class
214
+ properties_for_label[s][key] ||= {:classes => Set.new(), :counts => {}, :min => {}, :max => {}, :sum => {}}
215
+ c = TR[value.class.to_s] || value.class.to_s
216
+ properties_for_label[s][key][:classes] << c
217
+ properties_for_label[s][key][:counts][c] ||= 0
218
+ properties_for_label[s][key][:counts][c] += 1
219
+ sz = if c == 'string' || c == 'list'
220
+ value.size
221
+ elsif c == 'int' || c == 'float'
222
+ value
223
+ else
224
+ nil
225
+ end
226
+ unless sz.nil?
227
+ properties_for_label[s][key][:min][c] ||= sz
228
+ properties_for_label[s][key][:min][c] = [properties_for_label[s][key][:min][c], sz].min
229
+ properties_for_label[s][key][:max][c] ||= sz
230
+ properties_for_label[s][key][:max][c] = [properties_for_label[s][key][:max][c], sz].max
231
+ properties_for_label[s][key][:sum][c] ||= 0
232
+ properties_for_label[s][key][:sum][c] += sz
233
+ end
198
234
  end
199
235
  end
200
236
  end
@@ -225,6 +261,47 @@ class App
225
261
  end
226
262
 
227
263
  dot = StringIO.open do |io|
264
+ print_properties = lambda do |props, lbl, rel|
265
+ label = ''
266
+ (props[lbl] || {}).keys.sort do |a, b|
267
+ partsa = Set.new()
268
+ ((((indexes[:node] || {})[lbl] || {})[a.to_s]) || Set.new()).each { |it| partsa << INDEX_TR[it] || it }
269
+ partsb = Set.new()
270
+ ((((indexes[:node] || {})[lbl] || {})[b.to_s]) || Set.new()).each { |it| partsb << INDEX_TR[it] || it }
271
+ (partsa.size == partsb.size) ? (a <=> b) : (partsb.size <=> partsa.size)
272
+ end.each do |key|
273
+ props[lbl][key][:classes].to_a.sort.each.with_index do |c, i|
274
+ label += "<tr>"
275
+ if i == 0
276
+ parts = Set.new()
277
+ ((((indexes[:node] || {})[lbl] || {})[key.to_s]) || Set.new()).each do |it|
278
+ parts << INDEX_TR[it] || it
279
+ end
280
+ index_s = parts.empty? ? '' : " <i>(#{parts.join(', ')})</i>"
281
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='left' colspan='1' rowspan='#{props[lbl][key][:classes].size}'>#{key}#{index_s}</td>"
282
+ end
283
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='left' colspan='1'>#{TR[c] || c}</td>"
284
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='right' colspan='1'>#{sprintf('%d%%', props[lbl][key][:counts][c] * 100.0 / counts_for_label[lbl])}</td>"
285
+ if props[lbl][key][:sum][c]
286
+ mean_s = sprintf('%1.1f', props[lbl][key][:sum][c].to_f / props[lbl][key][:counts][c]).chomp('.0')
287
+ min_s = (c == 'float') ? sprintf('%1.1f', props[lbl][key][:min][c]) : props[lbl][key][:min][c]
288
+ max_s = (c == 'float') ? sprintf('%1.1f', props[lbl][key][:max][c]) : props[lbl][key][:max][c]
289
+ if props[lbl][key][:min][c] == props[lbl][key][:max][c]
290
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='center' colspan='3'>#{min_s}</td>"
291
+ else
292
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='right' colspan='1'>#{min_s}</td>"
293
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='right' colspan='1'>#{mean_s}</td>"
294
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='right' colspan='1'>#{max_s}</td>"
295
+ end
296
+ else
297
+ label += "<td border='1' color='#{rel ? '#888888' : '#000000'}' valign='top' align='left' colspan='3'></td>"
298
+ end
299
+ label += "</tr>"
300
+ end
301
+ end
302
+ label
303
+ end
304
+
228
305
  io.puts "digraph {"
229
306
  io.puts "graph [fontname = Helvetica, fontsize = 10, nodesep = 0.2, ranksep = 0.3];"
230
307
  io.puts "node [fontname = Helvetica, fontsize = 10, shape = none, margin = 0];"
@@ -233,22 +310,12 @@ class App
233
310
  io.puts 'splines=true;'
234
311
  properties_for_label.keys.sort.each do |lbl|
235
312
  label = "<<table valign='top' align='left' border='0' cellborder='0' cellspacing='0' cellpadding='4'>"
236
- label += "<tr><td border='1' bgcolor='#fce94f' valign='top' align='left' colspan='2'><b>#{lbl}</b>"
313
+ label += "<tr><td border='1' bgcolor='#fce94f' valign='top' align='left' colspan='6'><b>#{lbl}</b>"
237
314
  if options[:properties]
238
315
  label += " <i>(#{counts_for_label[lbl]})</i>"
239
316
  end
240
317
  label += "</td></tr>"
241
- properties_for_label[lbl].keys.sort.each do |key|
242
- label += "<tr>"
243
- parts = Set.new()
244
- ((((indexes[:node] || {})[lbl] || {})[key.to_s]) || Set.new()).each do |it|
245
- parts << INDEX_TR[it] || it
246
- end
247
- index_s = parts.empty? ? '' : " <i>(#{parts.join(', ')})</i>"
248
- label += "<td border='1' valign='top' align='left' colspan='1'>#{key}#{index_s}</td>"
249
- label += "<td border='1' valign='top' align='left' colspan='1'>#{properties_for_label[lbl][key][:classes].to_a.map { |x| TR[x.to_s] || x.to_s }.sort.join(' / ')}</td>"
250
- label += "</tr>"
251
- end
318
+ label += print_properties.call(properties_for_label, lbl, false)
252
319
  label += "</table>>"
253
320
  io.puts "\"#{lbl}\" [label = #{label}, pencolor = \"#000000\"];"
254
321
  end
@@ -259,27 +326,24 @@ class App
259
326
  lb = parts[2]
260
327
 
261
328
  label = "<<table valign='top' align='left' border='0' cellborder='0' cellspacing='0' cellpadding='4'>"
262
- label += "<tr><td border='1' color='#888888' bgcolor='#d3d7cf' valign='top' align='left' colspan='2'>#{type}"
329
+ label += "<tr><td border='1' color='#888888' bgcolor='#d3d7cf' valign='top' align='left' colspan='6'>#{type}"
263
330
  if options[:properties]
264
331
  label += " <i>(#{counts_for_label[s]})</i>"
265
332
  end
266
333
  label += "</td></tr>"
267
- (properties_for_label[s] || {}).keys.sort.each do |key|
268
- label += "<tr>"
269
- parts = Set.new()
270
- ((((indexes[:relationship] || {})[type] || {})[key.to_s]) || Set.new()).each do |it|
271
- parts << INDEX_TR[it] || it
272
- end
273
- index_s = parts.empty? ? '' : " <i>(#{parts.join(', ')})</i>"
274
- label += "<td border='1' color='#888888' valign='top' align='left' colspan='1'>#{key}#{index_s}</td>"
275
- label += "<td border='1' color='#888888' valign='top' align='left' colspan='1'>#{properties_for_label[s][key][:classes].to_a.map { |x| TR[x.to_s] || x.to_s }.sort.join(' / ')}</td>"
276
- label += "</tr>"
277
- end
334
+ label += print_properties.call(properties_for_label, s, true)
335
+
278
336
  label += "</table>>"
279
337
  io.puts "\"#{s}\" [label = #{label}, pencolor = \"#000000\"];"
280
338
 
281
- io.puts "\"#{la}\" -> \"#{s}\";"
282
- io.puts "\"#{s}\" -> \"#{lb}\";"
339
+ cardinality = (counts_for_label[la] > counts_for_label[s]) ?
340
+ "#{sprintf('%1.1f', counts_for_label[la].to_f / counts_for_label[s]).chomp('.0')}:1" :
341
+ "1:#{sprintf('%1.1f', counts_for_label[s].to_f / counts_for_label[la]).chomp('.0')}"
342
+ io.puts "\"#{la}\" -> \"#{s}\" [label = \"#{cardinality}\", fontcolor=\"#888888\"];"
343
+ cardinality = (counts_for_label[lb] > counts_for_label[s]) ?
344
+ "1:#{sprintf('%1.1f', counts_for_label[lb].to_f / counts_for_label[s]).chomp('.0')}" :
345
+ "#{sprintf('%1.1f', counts_for_label[s].to_f / counts_for_label[lb]).chomp('.0')}:1"
346
+ io.puts "\"#{s}\" -> \"#{lb}\" [label = \"#{cardinality}\", fontcolor=\"#888888\"];"
283
347
  end
284
348
 
285
349
  io.puts "}"
@@ -1,3 +1,3 @@
1
1
  module Neo4jBolt
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j_bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Specht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-29 00:00:00.000000000 Z
11
+ date: 2022-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec