-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
117 lines (111 loc) · 2.87 KB
/
main.go
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
package main
import (
"encoding/csv"
"io"
"log"
"os"
"sort"
"strconv"
"strings"
)
// 2021 columns:
// ResponseId,MainBranch,Employment,Country,US_State,UK_Country,EdLevel,Age1stCode,LearnCode,YearsCode,YearsCodePro,DevType,OrgSize,
// Currency,CompTotal,CompFreq,LanguageHaveWorkedWith,LanguageWantToWorkWith,DatabaseHaveWorkedWith,DatabaseWantToWorkWith,
// PlatformHaveWorkedWith,PlatformWantToWorkWith,WebframeHaveWorkedWith,WebframeWantToWorkWith,MiscTechHaveWorkedWith,MiscTechWantToWorkWith,
// ToolsTechHaveWorkedWith,ToolsTechWantToWorkWith,NEWCollabToolsHaveWorkedWith,NEWCollabToolsWantToWorkWith,OpSys,NEWStuck,NEWSOSites,
// SOVisitFreq,SOAccount,SOPartFreq,SOComm,NEWOtherComms,Age,Gender,Trans,Sexuality,Ethnicity,Accessibility,MentalHealth,
// SurveyLength,SurveyEase,ConvertedCompYearly
func main() {
f, err := os.Open("/Users/sameer/Downloads/stack-overflow-developer-survey-2021/survey_results_public.csv")
if err != nil {
log.Fatal(err)
}
defer f.Close()
r := csv.NewReader(f)
var (
schema map[string]int
counts = make(map[string]map[string]int)
)
for {
rec, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
if schema == nil {
schema = make(map[string]int)
for i, field := range rec {
schema[field] = i
}
continue
}
techSet := make(map[string]bool)
addTechs := func(key string) {
for _, tech := range strings.Split(rec[schema[key]], ";") {
techSet[tech] = true
}
}
addTechs("LanguageHaveWorkedWith")
addTechs("DatabaseHaveWorkedWith")
addTechs("PlatformHaveWorkedWith")
addTechs("WebframeHaveWorkedWith")
addTechs("MiscTechHaveWorkedWith")
addTechs("ToolsTechHaveWorkedWith")
addTechs("NEWCollabToolsHaveWorkedWith")
if techSet["AWS"] || techSet["Microsoft Azure"] || techSet["Google Cloud Platform"] {
techSet["ANY CLOUD"] = true
}
if rec[schema["OrgSize"]] == "10,000 or more employees" {
techSet["ANY ENTERPRISE"] = true
}
techSet["ANY"] = true
var techs []string
for tech := range techSet {
techs = append(techs, tech)
}
sort.Strings(techs)
inc := func(k1, k2 string) {
if k2 < k1 {
k1, k2 = k2, k1
}
if counts[k1] == nil {
counts[k1] = make(map[string]int)
}
counts[k1][k2]++
}
for i, t1 := range techs {
for _, t2 := range techs[i:] {
inc(t1, t2)
}
}
}
techSet := make(map[string]bool)
for t1, m := range counts {
techSet[t1] = true
for t2 := range m {
techSet[t2] = true
}
}
var techs []string
for tech := range techSet {
techs = append(techs, tech)
}
sort.Strings(techs)
w := csv.NewWriter(os.Stdout)
defer w.Flush()
w.Write(append([]string{"Tech"}, techs...))
for _, t1 := range techs {
rec := make([]string, len(techs)+1)
rec[0] = t1
for i, t2 := range techs {
k1, k2 := t1, t2
if k2 < k1 {
k1, k2 = k2, k1
}
rec[i+1] = strconv.Itoa(counts[k1][k2])
}
w.Write(rec)
}
}