Skip to content

Commit 1591925

Browse files
committed
2 parents 789acf4 + b937907 commit 1591925

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

paramgenerator/generateparamsbi.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import json
66
import os
77
import codecs
8-
from datetime import date
8+
import calendar
9+
import time
10+
from datetime import date,datetime,timedelta
911
from timeparameters import *
1012
from calendar import timegm
1113

14+
START_DATE=datetime.strptime("2010-01-01","%Y-%m-%d")
15+
END_DATE=datetime.strptime("2013-01-01","%Y-%m-%d")
16+
17+
def format_date(date):
18+
return int(time.mktime(date.timetuple())*1000)
19+
1220
# class ParamsWriter:
1321
# def __init__(self, name, num_params):
1422
# self.files = []
@@ -105,7 +113,6 @@ def post_month_params(sample, lower_bound, upper_bound):
105113
# results.append([[start_day, end_day], count_sum])
106114
# return results
107115

108-
109116
def key_params(sample, lower_bound, upper_bound):
110117
results = []
111118
for key, count in sample:
@@ -124,14 +131,14 @@ def serialize_q2(country_sets, post_day_ranges):
124131
for country_set, count_country in country_sets:
125132
for day_range, count_post in post_day_ranges:
126133
if random.randint(0,len(country_sets) + len(post_day_ranges)) == 0:
127-
writer.append([str(day_range[0]), str(day_range[1]), "2013-01-01", ",".join(country_set)], [count_post,count_post,count_country,333])
134+
writer.append([str(day_range[0]), str(day_range[1]), ";".join(country_set), str(format_date(END_DATE))], [count_post,count_post,count_country,333])
128135

129136
def serialize_q3(post_months):
130-
writer = ParamsWriter("q3", ["todo1","todo2"])
137+
writer = ParamsWriter("q3", ["range1Start","range1End","range2Start","range2End"])
131138
for ix in range(0,len(post_months)):
132139
week_range_a, count_a = post_months[ix]
133140
for week_range_b, count_b in post_months[ix+1:]:
134-
writer.append([str(week_range_a),str(week_range_b)], [count_a,count_b])
141+
writer.append([str(week_range_a[0]),str(week_range_a[1]),str(week_range_b[0]),str(week_range_b[1])], [count_a,count_b])
135142

136143
def serialize_q4(tagclasses, countries):
137144
writer = ParamsWriter("q4", ["tagClass","country"])
@@ -172,6 +179,9 @@ def serialize_q10(tags):
172179
for tag, count in tags:
173180
writer.append([tag], [count])
174181

182+
def serialize_q11():
183+
writer = ParamsWriter("q11", ["country", "blacklist"])
184+
175185
def serialize_q12(post_weeks):
176186
writer = ParamsWriter("q12", ["creationDate", "likeCount"])
177187
for week, count in post_weeks:
@@ -185,7 +195,7 @@ def serialize_q13(countries):
185195
def serialize_q14(creationdates):
186196
writer = ParamsWriter("q14", ["begin","todoEnd"])
187197
for creation, count in creationdates:
188-
writer.append([str(creation),"todo"], [count])
198+
writer.append([str(creation),str(1278888800000)], [count])
189199

190200
def serialize_q15(countries):
191201
writer = ParamsWriter("q15", ["country"])
@@ -215,10 +225,13 @@ def serialize_q19(tagclasses):
215225
for tag_class_b, count_b in tagclasses[ix+1:]:
216226
writer.append([str("1989-1-1"),tag_class_a, tag_class_b], [count_a, count_b])
217227

228+
def serialize_q20():
229+
writer = ParamsWriter("q20", [])
230+
218231
def serialize_q21(countries):
219232
writer = ParamsWriter("q21", ["country","endDate"])
220233
for country, count in countries:
221-
writer.append([country,str("2013-02-01")], [count])
234+
writer.append([country,str(format_date(END_DATE))], [count])
222235

223236
def serialize_q22(countries):
224237
writer = ParamsWriter("q22", ["country1","country2"])
@@ -237,15 +250,23 @@ def serialize_q24(tagclasses):
237250
for tagclass, count in tagclasses:
238251
writer.append([tagclass], [count])
239252

253+
def add_months(sourcedate,months):
254+
month = sourcedate.month - 1 + months
255+
year = int(sourcedate.year + month / 12 )
256+
month = month % 12 + 1
257+
day = min(sourcedate.day,calendar.monthrange(year,month)[1])
258+
return sourcedate.replace(year, month, day)
259+
240260
def convert_posts_histo(histogram):
241261
week_posts = []
242262
month = 0
243263
while (histogram.existParam(month)):
244264
monthTotal = histogram.getValue(month, "p")
245-
week_posts.append([month*30, monthTotal/4])
246-
week_posts.append([month*30+7, monthTotal/4])
247-
week_posts.append([month*30+14, monthTotal/4])
248-
week_posts.append([month*30+21, monthTotal/4])
265+
baseDate=add_months(START_DATE,month)
266+
week_posts.append([format_date(baseDate), monthTotal/4])
267+
week_posts.append([format_date(baseDate+timedelta(days=7)), monthTotal/4])
268+
week_posts.append([format_date(baseDate+timedelta(days=14)), monthTotal/4])
269+
week_posts.append([format_date(baseDate+timedelta(days=21)), monthTotal/4])
249270
month = month + 1
250271
return week_posts
251272

@@ -299,8 +320,10 @@ def main(argv=None):
299320
post_upper_threshold = 0.1*total_posts*1.1
300321
post_day_ranges = post_date_range_params(week_posts, post_lower_threshold, post_upper_threshold)
301322

302-
post_lower_threshold = (total_posts/(week_posts[len(week_posts)-1][0]/7/4))*0.8
303-
post_upper_threshold = (total_posts/(week_posts[len(week_posts)-1][0]/7/4))*1.2
323+
#post_lower_threshold = (total_posts/(week_posts[len(week_posts)-1][0]/7/4))*0.8
324+
#post_upper_threshold = (total_posts/(week_posts[len(week_posts)-1][0]/7/4))*1.2
325+
post_lower_threshold = (total_posts/(len(week_posts)/4))*0.8
326+
post_upper_threshold = (total_posts/(len(week_posts)/4))*1.2
304327
post_months = post_month_params(week_posts, post_lower_threshold, post_upper_threshold)
305328

306329
serialize_q2(country_sets, post_day_ranges)
@@ -329,5 +352,8 @@ def main(argv=None):
329352
serialize_q23(key_params(country_sample, total_posts/200, total_posts/100))
330353
serialize_q24(key_params(tagclass_posts, total_posts/140, total_posts/5))
331354

355+
serialize_q11()
356+
serialize_q20()
357+
332358
if __name__ == "__main__":
333359
sys.exit(main())

0 commit comments

Comments
 (0)