-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_generator.py
More file actions
186 lines (141 loc) · 6.85 KB
/
data_generator.py
File metadata and controls
186 lines (141 loc) · 6.85 KB
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
"""
Created on Mon Dec 3 23:32:59 2018
@author: root
"""
import random
from selenium import webdriver
#from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
#binary = FirefoxBinary('/root/firefox/firefox')
#browser = webdriver.Firefox(firefox_binary=binary)
browser = webdriver.Firefox()
#csv_file_train = open("color-data-train.csv", "w+")
url = "https://contrast-ratio.com/#"
url_last_part = ""
string_for_train = ""
cant_see_count_black = 0
cant_see_count_white = 0
can_see_count_black = 0
can_see_count_white = 0
"""
#"Can't see" set when black text on black. "0" indicates "Can't see" for both black or white text
browser.get("https://contrast-ratio.com/#black-on-black")
url_last_part = ""
for red_pixel in range(257):
for green_pixel in range(257):
for blue_pixel in range(257):
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "black-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val <= 1.03):
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(0) + "," + str(0)
csv_file_train.write(string_for_train + "\n")
cant_see_count_black = cant_see_count_black + 1
url_last_part = ""
string_for_train = ""
else:
url_last_part = ""
string_for_train = ""
break
print(cant_see_count_black)
#"Can't see" set when white text on white. "0" indicates "Can't see" for both white or black text
#csv_file_train = open("color_data_train.csv", "a+")
browser.get("https://contrast-ratio.com/#white-on-white")
url_last_part = ""
for red_pixel in range(256, -1, -1):
for green_pixel in range(256,-1, -1):
for blue_pixel in range(256, -1, -1):
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "white-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val <= 1.06): #1.06 threshold when text is white
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(1) + "," + str(0)
csv_file_train.write(string_for_train + "\n")
cant_see_count_white = cant_see_count_white + 1
url_last_part = ""
string_for_train = ""
else:
url_last_part = ""
string_for_train = ""
break
print(cant_see_count_white)
csv_file_train.close()
total_cant_see = 3495 + 15298 # black + white count
total_half = total_cant_see / 2
#"Can see" set when text is black. "1" in last column indicates "Can see"
#csv_file_train = open("color-data-train.csv", "a+")
csv_file_test = open("color-test-data.csv", "a+")
while(True):
red_pixel = random.randint(0,256)
green_pixel = random.randint(0,256)
blue_pixel = random.randint(0,256)
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "black-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val > 1.03):
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(0) + "," + str(1)
csv_file_test.write(string_for_train + "\n")
can_see_count_black = can_see_count_black + 1
url_last_part = ""
string_for_train = ""
if(can_see_count_black >= total_half):
break
#"Can see" set when text is white. "1" in last column indicates "Can See"
while(True):
red_pixel = random.randint(0,256)
green_pixel = random.randint(0,256)
blue_pixel = random.randint(0,256)
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "white-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val > 1.06):
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(1) + "," + str(1)
csv_file_test.write(string_for_train + "\n")
can_see_count_white = can_see_count_white + 1
url_last_part = ""
string_for_train = ""
if(can_see_count_white >= total_half):
break
csv_file_test.close()
"""
#DEV-SET
#"Can see" set when text is black. "1" in last column indicates "Can see"
#csv_file_train = open("color-data-train.csv", "a+")
csv_file_dev = open("color-dev-data.csv", "a+")
while(True):
red_pixel = random.randint(0,256)
green_pixel = random.randint(0,256)
blue_pixel = random.randint(0,256)
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "black-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val > 1.03):
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(0) + "," + str(1)
csv_file_dev.write(string_for_train + "\n")
can_see_count_black = can_see_count_black + 1
url_last_part = ""
string_for_train = ""
if(can_see_count_black >= 20000):
break
#"Can see" set when text is white. "1" in last column indicates "Can See"
while(True):
red_pixel = random.randint(0,256)
green_pixel = random.randint(0,256)
blue_pixel = random.randint(0,256)
url_last_part = url_last_part + "rgb%28" + str(red_pixel) + "%2C" + str(green_pixel) + "%2C" + str(blue_pixel) + "%29"
browser.get(url + "white-on-" + url_last_part)
web_elem_threshold = browser.find_element_by_css_selector("output strong")
curr_threshold_val = float(web_elem_threshold.text)
if(curr_threshold_val > 1.06):
string_for_train = string_for_train + str(red_pixel) + "," + str(green_pixel) + "," + str(blue_pixel) + "," + str(1) + "," + str(1)
csv_file_dev.write(string_for_train + "\n")
can_see_count_white = can_see_count_white + 1
url_last_part = ""
string_for_train = ""
if(can_see_count_white >= 20000):
break
csv_file_dev.close()