-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
231 lines (188 loc) · 6.19 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"regexp"
"strings"
"unicode/utf8"
)
type gaza_list struct {
Name string `json:"name"`
Id string `json:"id"`
Dob string `json:"dob"`
Sex string `json:"sex"`
Age int `json:"age"`
Source string `json:"source"`
En_name string `json:"en_name"`
}
var genericNames = map[string]bool{
"محمد": true,
"أحمد": true,
"علي": true,
"حسن": true,
"عبد": true,
"محمود": true,
"يوسف": true,
"إبراهيم": true,
"خالد": true,
"سعيد": true,
"عمر": true,
"إسماعيل": true,
"جمال": true,
"صالح": true,
"سامي": true,
"نادر": true,
"رشيد": true,
"حاتم": true,
"يحيى": true,
"زياد": true,
"ماهر": true,
"حسين": true,
"فارس": true,
"رامي": true,
"أمين": true,
"كمال": true,
"وائل": true,
"علاء": true,
"حمزة": true,
"شريف": true,
"منير": true,
"عادل": true,
"باسم": true,
"طارق": true,
"سامر": true,
"نبيل": true,
"هيثم": true,
"عدنان": true,
"مازن": true,
"عمار": true,
"مالك": true,
"إياد": true,
"أنس": true,
"مراد": true,
"سيف": true,
"بدر": true,
"راشد": true,
"منصور": true,
"عصام": true,
"زكريا": true,
"غسان": true,
"مصطفى": true,
"رائد": true,
"سامح": true,
"نزار": true,
"وهيب": true,
"أيمن": true,
}
var data []*gaza_list
func main() {
list, err := http.Get("https://data.techforpalestine.org/api/v2/killed-in-gaza.json")
if err != nil {
fmt.Println("We've had an error in getting JSON!")
} else {
fmt.Println("success!")
}
fmt.Println("Content-Type:", list.Header.Get("Content-Type"))
defer list.Body.Close()
body, err := io.ReadAll(list.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
if utf8.Valid(body) {
fmt.Println("The response body is valid UTF-8 encoded.")
} else {
fmt.Println("The response body is NOT UTF-8 encoded.")
}
var amountOfMalesNamedAsFemales = 0
var amountOfPallywoodFromMOH = 0
var amountOfPallywoodFromJudiciary = 0
var amountOfPallywoodFromPublicSubmission = 0
var amountOfWomen = 0
var amountOfCivilians = 0
var totalAmount = 0
var amountOfSourcesFromMOH = 0
var amountOfSourcesFromJudiciary = 0
var amountOfSourcesFromPublicSubmission = 0
for _, item := range data {
totalAmount++
if item.Source == "h" {
amountOfSourcesFromMOH++
}
if item.Source == "c" {
amountOfSourcesFromPublicSubmission++
}
if item.Source == "j" {
amountOfSourcesFromJudiciary++
}
words := strings.Fields(item.Name)
if item.Sex == "f" && len(words) > 0 && genericNames[words[0]] {
fmt.Printf("Found record: ID: %s, Name: %s, Age: %d, Sex: %s, Dob: %s, Source: %s, EN_name: %s\n",
item.Id, item.Name, item.Age, item.Sex, item.Dob, item.Source, item.En_name)
amountOfMalesNamedAsFemales++
if item.Source == "h" {
amountOfPallywoodFromMOH++
}
if item.Source == "c" {
amountOfPallywoodFromPublicSubmission++
}
if item.Source == "j" {
amountOfPallywoodFromJudiciary++
}
}
if item.Sex == "f" {
amountOfWomen++
}
if item.Sex == "f" || (item.Sex == "m" && item.Age <= 10) {
amountOfCivilians++
}
}
fmt.Printf("This is the end of the PALLYWOOD names \n\n")
fmt.Printf("This is the beginning of names without the population registry ID\n")
// Define the regular expression pattern for exactly 9 digits
pattern := `^\d{9}$`
// Compile the regular expression
re := regexp.MustCompile(pattern)
var completeData = 0
var incompleteData = 0
for _, item := range data {
if re.MatchString(item.Id) {
completeData++
} else {
fmt.Printf("Found record: ID: %s, Name: %s, Age: %d, Sex: %s, Dob: %s, Source: %s, EN_name: %s\n",
item.Id, item.Name, item.Age, item.Sex, item.Dob, item.Source, item.En_name)
incompleteData++
}
}
fmt.Printf("This is the end of names without the population registry ID\n\n")
amountOfWomen = amountOfWomen - amountOfMalesNamedAsFemales
var ProportionofWomenToTotal float32 = float32(amountOfWomen-amountOfMalesNamedAsFemales) / float32(totalAmount) * 100
var ProportionOfCiviliansToTotal float32 = (float32(amountOfCivilians) - float32(amountOfMalesNamedAsFemales)) / float32(totalAmount) * 100
fmt.Println()
fmt.Printf("The amount of people with generic male names listed as having a Sex = f: %d\n\n", amountOfMalesNamedAsFemales)
fmt.Printf("The amount of PALLYWOOD from the Ministry Of Health: %d\n", amountOfPallywoodFromMOH)
fmt.Printf("The amount of PALLYWOOD from the Judicial Or House Committee: %d\n", amountOfPallywoodFromJudiciary)
fmt.Printf("The amount of PALYYWOOD from the Public Submission: %d\n\n", amountOfPallywoodFromPublicSubmission)
fmt.Printf("Total amount of people recorded: %d\n\n", totalAmount)
fmt.Printf("Total amount of women recorded: %d\n", amountOfWomen)
fmt.Printf("women:total = %f\n\n", ProportionofWomenToTotal)
fmt.Printf("Total amount of civilians: %d\n", amountOfCivilians)
fmt.Printf("civilian:total = %f\n\n", ProportionOfCiviliansToTotal)
fmt.Printf("The margin of error for the total numbers: %f\n\n", float32(totalAmount)*0.02)
fmt.Printf("Complete data: %d\n", completeData)
fmt.Printf("Incomplete data: %d\n\n", incompleteData)
fmt.Printf("The amount from the Ministry Of Health: %d\n", amountOfSourcesFromMOH)
fmt.Printf("The amount from the Judicial Or House Committee: %d\n", amountOfSourcesFromJudiciary)
fmt.Printf("The amount from the Public Submission: %d\n\n", amountOfSourcesFromPublicSubmission)
fmt.Printf("MOH:Total = %f\n", float32(amountOfSourcesFromMOH)/float32(totalAmount)*100)
fmt.Printf("Judicial Or House:Total = %f\n", float32(amountOfSourcesFromJudiciary)/float32(totalAmount)*100)
fmt.Printf("Public:Total = %f\n", float32(amountOfSourcesFromPublicSubmission)/float32(totalAmount)*100)
fmt.Printf("Estimated ratio of civilians to militants: %f\n", ProportionofWomenToTotal*2)
}