Commit 61598f8f authored by Vincent Pelletier's avatar Vincent Pelletier

Add --period halfday and --period halfhour

parent 57731c74
...@@ -121,6 +121,13 @@ ITEMGETTER0 = itemgetter(0) ...@@ -121,6 +121,13 @@ ITEMGETTER0 = itemgetter(0)
ITEMGETTER1 = itemgetter(1) ITEMGETTER1 = itemgetter(1)
APDEX_TOLERATING_COEF = 4 APDEX_TOLERATING_COEF = 4
AUTO_PERIOD_COEF = 200 AUTO_PERIOD_COEF = 200
# X -> Y: Z Switch from period X to Y after Z periods
# quarter -> year: 15 quarters (3.75 years)
# month -> quarter: 6.5 months
# week -> month: 7.14 weeks (50 days)
# day -> week: 8.3 days
# halfday -> day: 8.2 halfdays (100 hours, 4.1 days)
# halfhour -> halfday: 6.6 halfhours (200 minutes)
# Larger (x < LARGER_THAN_INTEGER_STR == True) than any string starting with # Larger (x < LARGER_THAN_INTEGER_STR == True) than any string starting with
# a number # a number
...@@ -940,6 +947,27 @@ def _asHourString(timestamp): ...@@ -940,6 +947,27 @@ def _asHourString(timestamp):
day, month, year = dt_date.split('/') day, month, year = dt_date.split('/')
return '%s/%02i/%s %s' % (year, MONTH_VALUE_DICT[month], day, hour) return '%s/%02i/%s %s' % (year, MONTH_VALUE_DICT[month], day, hour)
def _asHalfDayString(timestamp):
prefix, _ = timestamp.rsplit(':', 1)
prefix, hours = prefix.split(' ')
return '%s %02i' % (prefix, int(hours) // 12 * 12)
def _as30MinutesString(timestamp):
dt, _ = timestamp.split(' ')
dt_date, hour, minute, _ = dt.split(':', 3)
day, month, year = dt_date.split('/')
return '%s/%02i/%s %s:%02i' % (year, MONTH_VALUE_DICT[month], day, hour, int(minute) // 30 * 30)
def _asMinuteString(timestamp):
dt, _ = timestamp.split(' ')
dt_date, hour, minute, _ = dt.split(':', 3)
day, month, year = dt_date.split('/')
return '%s/%02i/%s %s:%s' % (year, MONTH_VALUE_DICT[month], day, hour, minute)
def _asHalfHourString(timestamp):
prefix, minute = timestamp.rsplit(':', 1)
return '%s:%02i' % (prefix, int(minute) // 30 * 30)
# Key: argument (represents table granularity) # Key: argument (represents table granularity)
# Value: # Value:
# - cheap conversion from apache date format to graph granularity # - cheap conversion from apache date format to graph granularity
...@@ -958,6 +986,7 @@ def _asHourString(timestamp): ...@@ -958,6 +986,7 @@ def _asHourString(timestamp):
# than what it should be. # than what it should be.
period_parser = { period_parser = {
'year': ( 'year': (
# graph/table ratio: 12
_asMonthString, _asMonthString,
lambda x: x.split('/', 1)[0], lambda x: x.split('/', 1)[0],
'month', 'month',
...@@ -969,6 +998,7 @@ period_parser = { ...@@ -969,6 +998,7 @@ period_parser = {
lambda x: 31. / calendar.monthrange(x.year, x.month)[1], lambda x: 31. / calendar.monthrange(x.year, x.month)[1],
), ),
'quarter': ( 'quarter': (
# graph/table ratio: 13(.2)
_asWeekString, _asWeekString,
_weekStringAsQuarterString, _weekStringAsQuarterString,
# Note: Not calendar weeks, but chunks of 7 days starting on first year's # Note: Not calendar weeks, but chunks of 7 days starting on first year's
...@@ -981,6 +1011,7 @@ period_parser = { ...@@ -981,6 +1011,7 @@ period_parser = {
_getWeekCoefficient, _getWeekCoefficient,
), ),
'month': ( 'month': (
# graph/table ratio: 31
_asDayString, _asDayString,
lambda x: '/'.join(x.split('/', 2)[:2]), lambda x: '/'.join(x.split('/', 2)[:2]),
'day', 'day',
...@@ -992,6 +1023,7 @@ period_parser = { ...@@ -992,6 +1023,7 @@ period_parser = {
lambda x: 1, lambda x: 1,
), ),
'week': ( 'week': (
# graph/table ratio: 28
_as6HourString, _as6HourString,
_hourAsWeekString, _hourAsWeekString,
'6 hours', '6 hours',
...@@ -1002,6 +1034,7 @@ period_parser = { ...@@ -1002,6 +1034,7 @@ period_parser = {
lambda x: 1, lambda x: 1,
), ),
'day': ( 'day': (
# graph/table ratio: 24
_asHourString, _asHourString,
lambda x: x.split(' ')[0], lambda x: x.split(' ')[0],
'hour', 'hour',
...@@ -1012,6 +1045,26 @@ period_parser = { ...@@ -1012,6 +1045,26 @@ period_parser = {
# Error margin without correction: (leap) 1/3600 = .03% # Error margin without correction: (leap) 1/3600 = .03%
lambda x: 1, lambda x: 1,
), ),
'halfday': (
# graph/table ratio: 24
_as30MinutesString,
_asHalfDayString,
'30 minutes',
'%Y/%m/%d %H:%M',
timedelta(seconds=30 * 60),
lambda x: x.replace(minute=x.minute // 30 * 30),
lambda x: 1,
),
'halfhour': (
# graph/table ratio: 30
_asMinuteString,
_asHalfHourString,
'minute',
'%Y/%m/%d %H:%M',
timedelta(seconds=60),
lambda x: x,
lambda x: 1,
),
} }
apdex_y_scale_dict = { apdex_y_scale_dict = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment