-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse-json.rb
53 lines (46 loc) · 1.24 KB
/
parse-json.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Author Lucian Ghinda
# Purpose:
# to parse the aggregated JSON data and split it based on programming languages
# or frameworks.
require "json"
require 'byebug'
require 'pry'
require 'pp'
def prog_lang_to_filename(prog_lang)
prog_lang.tr("+","plus").tr("#","sharp").tr('.','').tr(" ",'')
end
file = File.read './startups-list.json'
data = JSON.parse(file)
groupped = {}
data.each do |company|
company['original_programming_language'].each do |prog_lang|
unless groupped.keys.include?(prog_lang)
groupped[prog_lang] = {
count: 0,
total_funding: 0,
startup_list: {
"YCombinator": 0,
"TechStars": 0,
},
companies: [],
}
end
groupped[prog_lang][:companies] << company
begin
groupped[prog_lang][:count] += 1
groupped[prog_lang][:total_funding] += company["money_raised_so_far"]
groupped[prog_lang][:startup_list][company["startup_list"].to_sym] += 1
rescue NoMethodError => e
byebug
end
end
end
groupped.sort_by do |k,v|
v[:count]
end.reverse!
groupped.each do |key, value|
json_filename = File.join('./groupped', "#{prog_lang_to_filename(key)}.json")
File.open(json_filename, 'w') do |f|
f.write(value.to_json)
end
end