-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchpairgen.py
165 lines (143 loc) · 5.32 KB
/
benchpairgen.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import csv
from datetime import datetime
from datasets import load_dataset
import random
def get_dates(date_str):
"""
This function takes a date string in the format "MM/DD/YYYY"
and returns a datetime object.
"""
dateRange = date_str
dateRange = dateRange.split("-")
try:
date1 = datetime.strptime(dateRange[0], '%m/%d/%y')
date2 = datetime.strptime(dateRange[1], '%m/%d/%y')
except ValueError:
date1 = datetime.strptime(dateRange[0], '%m/%d/%Y')
date2 = datetime.strptime(dateRange[1], '%m/%d/%Y')
return date1, date2
def scorer(date):
month, day, year = map(int, date.split('/'))
if year < 100: # Assuming two-digit years are 2000s
year += 2000
score = year * 10000 + month * 100 + day * 1
return score
dataset = open("benchmarks/BENCHMARK_PARAM.csv", "w", newline="")
writer = csv.writer(dataset, delimiter="|")
writer.writerow(["Query", "D1", "D2", "Score"])
value_computed_dict = {}
with open('csv/bulk.csv') as file:
reader = csv.reader(file)
for row in reader:
if "Computed" in row or "xx" in row[1]:
continue
value_computed_dict[row[0]] = row[1]
gradient_count = 1000
i = 0
values = list(value_computed_dict.keys())
# while i < gradient_count:
# query = random.choice(values)
# if (query.count("/") == 2):
# continue
# document = value_computed_dict[query].split("-")[0]
# month, day, year = map(int, document.split('/'))
# # if random.random() < 0.2:
# # month = str(random.randint(1, 12)).zfill(2)
# # if random.random() < 0.1:
# # year = str(random.randint(2000, 2021))
# # if random.random() < 0.8:
# # day = str(random.randint(1, 28)).zfill(2)
# startd = f"{month}/{day}/{year}"
# #generate another startd using the same randomized logic
# month, day, year = map(int, document.split('/'))
# if random.random() < 0.2:
# month = str(random.randint(1, 12)).zfill(2)
# if random.random() < 0.1:
# year = str(random.randint(2000, 2021))
# if random.random() < 0.8:
# day = str(random.randint(1, 28)).zfill(2)
# init_startd = f"{month}/{day}/{year}"
# #score the doc date, startd, and init_startd. 1 if startd is closer to doc date than init_startd else 0
# if abs(scorer(startd) - scorer(document)) < abs(scorer(init_startd) - scorer(document)):
# score = 1
# else:
# score = 0
# vals = startd.split("/")
# for j in range(len(vals)):
# vals[j] = vals[j].zfill(2)
# startd = "/".join(vals)
# #SAME THING FOR init_startd
# vals = init_startd.split("/")
# for j in range(len(vals)):
# vals[j] = vals[j].zfill(2)
# init_startd = "/".join(vals)
# query = query.replace("\n", "")
# startd = startd.replace("\n", "")
# writer.writerow([query, startd, init_startd, score])
# i += 1
#open lastx and add 1000 of these using the same strategy
value_computed_dict = {}
with open('csv/lastx_updated.csv') as file:
reader = csv.reader(file)
for row in reader:
if "Computed" in row or "xx" in row[1]:
continue
if random.randint(0,10) > 7:
value_computed_dict[row[0]] = row[1]
with open('csv/relatives_dates_updated.csv') as file:
reader = csv.reader(file)
for row in reader:
if "Computed" in row or "xx" in row[1]:
continue
if random.randint(0,10) > 7:
value_computed_dict[row[0]] = row[1]
with open('csv/dates_updated.csv') as file:
reader = csv.reader(file)
for row in reader:
if "Computed" in row or "xx" in row[1]:
continue
if random.randint(0,10) > 7:
value_computed_dict[row[0]] = row[1]
gradient_count = 1000
i = 0
values = list(value_computed_dict.keys())
while i < gradient_count:
query = random.choice(values)
# if (query.count("/") == 2):
# continue
document = value_computed_dict[query].split("-")[0]
month, day, year = map(int, document.split('/'))
# if random.random() < 0.7:
# month = str(random.randint(1, 12)).zfill(2)
# if random.random() < 0.1:
# year = str(random.randint(2000, 2021))
# if random.random() < 0.8:
# day = str(random.randint(1, 28)).zfill(2)
startd = f"{month}/{day}/{year}"
#generate another startd using the same randomized logic
month, day, year = map(int, document.split('/'))
if random.random() < 0.7:
month = str(random.randint(1, 12)).zfill(2)
if random.random() < 0.1:
year = str(random.randint(2000, 2021))
if random.random() < 0.8:
day = str(random.randint(1, 28)).zfill(2)
init_startd = f"{month}/{day}/{year}"
#score the doc date, startd, and init_startd. 1 if startd is closer to doc date than init_startd else 0
if abs(scorer(startd) - scorer(document)) < abs(scorer(init_startd) - scorer(document)):
score = 1
else:
score = 0
vals = startd.split("/")
for j in range(len(vals)):
vals[j] = vals[j].zfill(2)
startd = "/".join(vals)
#SAME THING FOR init_startd
vals = init_startd.split("/")
for j in range(len(vals)):
vals[j] = vals[j].zfill(2)
init_startd = "/".join(vals)
query = query.replace("\n", "")
startd = startd.replace("\n", "")
writer.writerow([query, startd, init_startd, score])
i += 1