-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
138 lines (105 loc) · 5.19 KB
/
run.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import json
import yaml
from census_interactive.process import (load_commit_stack_line, load_contributor_stack_line,
load_contributor_bar, load_contributor_dumbbell, load_contributor_percent,
load_contributor_pie, load_contributor_stack)
CONTRIBUTOR_STORE_PATH = './census_interactive/data/processed/contributor/'
COMMIT_STORE_PATH = './census_interactive/data/processed/commit/'
CONTRIBUTOR_RETRIEVE_PATH = './census_interactive/data/raw/final_gender_contrib/'
COMMIT_RETRIEVE_PATH = './census_interactive/data/raw/final_gender_commit/'
# Launch visualizations
def main():
################ SETTINGS ################
with open ("config.yaml", 'r') as stream:
config = yaml.safe_load(stream)
langs = [] if config["languages"] is None else config["languages"]
# Alphabetize langs list
langs.sort()
##########################################
## Comparison Graph Data
data = dict()
# Contributor
data["Contributor"] = dict()
for lang in langs:
dat_path = CONTRIBUTOR_RETRIEVE_PATH+lang+'.csv'
load_contributor_stack_line(lang, dat_path, CONTRIBUTOR_STORE_PATH)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+lang+'.json') as json_file:
add_data = json.load(json_file)
data["Contributor"][lang] = add_data
# Commits
data["Commit"] = dict()
for lang in langs:
dat_path = COMMIT_RETRIEVE_PATH+lang+'.csv'
load_commit_stack_line(lang, dat_path, COMMIT_STORE_PATH)
# Save graph data to overall JSON data
with open(COMMIT_STORE_PATH+lang+'.json') as json_file:
add_data = json.load(json_file)
data["Commit"][lang] = add_data
## Single Contributor Graph Data
########################## SINGLE GRAPH SETTINGS ###########################
# Single graph x axis options, syntax YEAR#
year_opts = [] if config["years"] is None else config["years"]
############################################################################
## Pie Graph ##
data_pie = dict()
# Focus on Contributor for bar graphs
data_pie["Contributor"] = dict()
for year_opt in year_opts:
# Updates processed JSON file
load_contributor_pie( CONTRIBUTOR_RETRIEVE_PATH, CONTRIBUTOR_STORE_PATH,
langs, year_opt)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+'all_pie'+'.json') as json_file:
add_data = json.load(json_file)
data_pie["Contributor"][year_opt] = add_data
## Bar Graph ##
data_bar = dict()
# Focus on Contributor for bar graphs
data_bar["Contributor"] = dict()
# Updates processed JSON file
load_contributor_bar( CONTRIBUTOR_RETRIEVE_PATH, CONTRIBUTOR_STORE_PATH, langs)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+'all_bar'+'.json') as json_file:
add_data = json.load(json_file)
data_bar["Contributor"]['male_female'] = add_data
## Stacked Area Graph ##
data_stack = dict()
# Focus on Contributor for bar graphs
data_stack["Contributor"] = dict()
# Updates processed JSON file
load_contributor_stack( CONTRIBUTOR_RETRIEVE_PATH, CONTRIBUTOR_STORE_PATH, langs)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+'all_stack'+'.json') as json_file:
add_data = json.load(json_file)
data_stack["Contributor"] = add_data
## Percent Area Graph ##
data_percent = dict()
# Focus on Contributor for bar graphs
data_percent["Contributor"] = dict()
# Updates processed JSON file
load_contributor_percent( CONTRIBUTOR_RETRIEVE_PATH, CONTRIBUTOR_STORE_PATH)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+'all_percent'+'.json') as json_file:
add_data = json.load(json_file)
data_percent["Contributor"] = add_data
## Dumbbell Graph ##
data_dumbbell = dict()
# Focus on Contributor for bar graphs
data_dumbbell["Contributor"] = dict()
# Updates processed JSON file
load_contributor_dumbbell(CONTRIBUTOR_RETRIEVE_PATH, CONTRIBUTOR_STORE_PATH, langs)
# Save graph data to overall JSON data
with open(CONTRIBUTOR_STORE_PATH+'all_dumbbell'+'.json') as json_file:
add_data = json.load(json_file)
data_dumbbell["Contributor"] = add_data
## Combine all JSON to one dictionary in js/
with open('./public/js/data.js', 'w', encoding="utf-8") as out_file:
out_file.write(f'var data = {json.dumps(data,indent=4, sort_keys=True)};')
out_file.write(f'var data_pie = {json.dumps(data_pie,indent=4, sort_keys=True)};')
out_file.write(f'var data_bar = {json.dumps(data_bar,indent=4, sort_keys=True)};')
out_file.write(f'var data_stack = {json.dumps(data_stack,indent=4, sort_keys=True)};')
out_file.write(f'var data_percent = {json.dumps(data_percent,indent=4, sort_keys=True)};')
out_file.write(f'var data_dumbbell = {json.dumps(data_dumbbell,indent=4, sort_keys=True)};')
if __name__== "__main__" :
main()