-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombine.go
151 lines (126 loc) · 5.21 KB
/
combine.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"fmt"
"reflect"
"strings"
"time"
)
type GenericLobbyist struct {
FirstName string
LastName string
}
type GenericFiling struct {
OrganizationName string
ClientName string
SenateID string
HouseID string
ReportYear string
ReportType string
Lobbyist []GenericLobbyist
}
func convertHouseFiling(houseFiling HouseFiling) GenericFiling {
tmpFiling := GenericFiling{}
tmpFiling.OrganizationName = houseFiling.OrganizationName
tmpFiling.ClientName = houseFiling.ClientName
tmpFiling.SenateID = houseFiling.SenateID
tmpFiling.HouseID = houseFiling.HouseID
tmpFiling.ReportYear = houseFiling.ReportYear
tmpFiling.ReportType = houseFiling.ReportType
tmpLobbyistArray := make([]GenericLobbyist, len(houseFiling.Lobbyist))
for _, houseLobbyist := range houseFiling.Lobbyist {
tmpLobbyistArray = append(tmpLobbyistArray, GenericLobbyist{houseLobbyist.FirstName, houseLobbyist.LastName})
}
tmpFiling.Lobbyist = tmpLobbyistArray
return tmpFiling
}
func convertSenateFiling(senateFiling SenateFiling) GenericFiling {
tmpFiling := GenericFiling{}
tmpFiling.OrganizationName = senateFiling.Registrant.RegistrantName
tmpFiling.ClientName = senateFiling.Client.ClientName
tmpFiling.SenateID = senateFiling.ID
//tmpFiling.HouseID = nil //no house ID provided in senate filings; because senate register before house?
tmpFiling.ReportYear = senateFiling.Year
tmpFiling.ReportType = senateFiling.Type
tmpLobbyistArray := make([]GenericLobbyist, len(senateFiling.Lobbyists))
for _, senateLobbyist := range senateFiling.Lobbyists {
//attempt to get first and last name
var firstName string
var lastName string
if strings.Index(senateLobbyist.LobbyistName, ",") < 0 {
firstName = senateLobbyist.LobbyistName
lastName = senateLobbyist.LobbyistName
} else {
firstName = senateLobbyist.LobbyistName[strings.Index(senateLobbyist.LobbyistName, ",")+1:]
lastName = senateLobbyist.LobbyistName[:strings.Index(senateLobbyist.LobbyistName, ",")]
}
tmpLobbyistArray = append(tmpLobbyistArray, GenericLobbyist{firstName, lastName})
}
tmpFiling.Lobbyist = tmpLobbyistArray
return tmpFiling
}
func combineSingleFiling(unknownFiling interface{}, combinedFilings *[]GenericFiling) {
switch unknownFiling.(type) {
case HouseFiling:
*combinedFilings = append(*combinedFilings, convertHouseFiling(unknownFiling.(HouseFiling)))
case SenateFiling:
*combinedFilings = append(*combinedFilings, convertSenateFiling(unknownFiling.(SenateFiling)))
default:
fmt.Println("Unknown object received by combine. Object is of type", reflect.TypeOf(unknownFiling))
}
}
func combine(houseFilingArray []HouseFiling, senateFilingArray []SenateFiling) []GenericFiling {
beginParseTime := time.Now()
fmt.Println("Combining", len(houseFilingArray)+len(senateFilingArray), "filings...")
allHouseFilings := make([]GenericFiling, len(houseFilingArray)+len(senateFilingArray))
combinedFilingCounter := 0
for _, houseFiling := range houseFilingArray {
tmpFiling := GenericFiling{}
tmpFiling.OrganizationName = houseFiling.OrganizationName
tmpFiling.ClientName = houseFiling.ClientName
tmpFiling.SenateID = houseFiling.SenateID
tmpFiling.HouseID = houseFiling.HouseID
tmpFiling.ReportYear = houseFiling.ReportYear
tmpFiling.ReportType = houseFiling.ReportType
tmpLobbyistArray := make([]GenericLobbyist, len(houseFiling.Lobbyist))
for _, houseLobbyist := range houseFiling.Lobbyist {
tmpLobbyistArray = append(tmpLobbyistArray, GenericLobbyist{houseLobbyist.FirstName, houseLobbyist.LastName})
}
tmpFiling.Lobbyist = tmpLobbyistArray
combinedFilingCounter++
if combinedFilingCounter%10000 == 0 {
fmt.Println("Combined", combinedFilingCounter, "filings")
}
allHouseFilings = append(allHouseFilings, tmpFiling)
}
for _, senateFiling := range senateFilingArray {
tmpFiling := GenericFiling{}
tmpFiling.OrganizationName = senateFiling.Registrant.RegistrantName
tmpFiling.ClientName = senateFiling.Client.ClientName
tmpFiling.SenateID = senateFiling.ID
//tmpFiling.HouseID = nil //no house ID provided in senate filings; because senate register before house?
tmpFiling.ReportYear = senateFiling.Year
tmpFiling.ReportType = senateFiling.Type
tmpLobbyistArray := make([]GenericLobbyist, len(senateFiling.Lobbyists))
for _, senateLobbyist := range senateFiling.Lobbyists {
//attempt to get first and last name
var firstName string
var lastName string
if strings.Index(senateLobbyist.LobbyistName, ",") < 0 {
firstName = senateLobbyist.LobbyistName
lastName = senateLobbyist.LobbyistName
} else {
firstName = senateLobbyist.LobbyistName[strings.Index(senateLobbyist.LobbyistName, ",")+1:]
lastName = senateLobbyist.LobbyistName[:strings.Index(senateLobbyist.LobbyistName, ",")]
}
tmpLobbyistArray = append(tmpLobbyistArray, GenericLobbyist{firstName, lastName})
}
tmpFiling.Lobbyist = tmpLobbyistArray
combinedFilingCounter++
if combinedFilingCounter%10000 == 0 {
fmt.Println("Combined", combinedFilingCounter, "filings")
}
allHouseFilings = append(allHouseFilings, tmpFiling)
}
fmt.Println("Done combining", len(houseFilingArray)+len(senateFilingArray), "filings in", time.Since(beginParseTime).String())
return allHouseFilings
}