Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. def create_protovis_data_from tweeps, tweep_edges
  2. counter = 0
  3. tweep_index_lookup = {}
  4.  
  5. File.open('strangeloop_words.js', 'w'){|file|
  6. file.puts 'var miserables = {'
  7. file.puts 'nodes:['
  8.  
  9. tweeps.each{|tweep|
  10. tweep_index_lookup[tweep] = counter
  11. file.puts "{nodeName:\"#{tweep}\", group:1}, //#{tweep_index_lookup[tweep]}"
  12. counter += 1
  13. }
  14.  
  15. file.puts '],'
  16. file.puts 'links:['
  17.  
  18. tweep_edges.each{ |edge, strength|
  19. from_tweep = edge[:from]
  20. to_tweep = edge[:to]
  21.  
  22. raise "bad to tweep!!" if not tweep_index_lookup.include? to_tweep
  23. raise "bad to tweep!!" if not tweep_index_lookup.include? from_tweep
  24.  
  25. from_index = tweep_index_lookup[from_tweep]
  26. to_index = tweep_index_lookup[to_tweep]
  27.  
  28. file.puts "{source:#{from_index}, target:#{to_index}, value: #{(2)**strength}},"
  29. }
  30.  
  31. file.puts ']};'
  32. }
  33. end
Add Comment
Please, Sign In to add comment