Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
apachedex
Commits
575011b1
Commit
575011b1
authored
Apr 07, 2013
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for "week" and "quarter" periods.
parent
ff90c6f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
apachedex/__init__.py
apachedex/__init__.py
+36
-0
No files found.
apachedex/__init__.py
View file @
575011b1
...
@@ -505,11 +505,31 @@ def _asMonthString(timestamp):
...
@@ -505,11 +505,31 @@ def _asMonthString(timestamp):
_
,
month
,
year
=
dt
.
split
(
':'
,
1
)[
0
].
split
(
'/'
)
_
,
month
,
year
=
dt
.
split
(
':'
,
1
)[
0
].
split
(
'/'
)
return
'%s/%02i'
%
(
year
,
MONTH_VALUE_DICT
[
month
])
return
'%s/%02i'
%
(
year
,
MONTH_VALUE_DICT
[
month
])
def
_asWeekString
(
timestamp
):
dt
,
_
=
timestamp
.
split
(
' '
)
day
,
month
,
year
=
dt
.
split
(
':'
,
1
)[
0
].
split
(
'/'
)
return
'%s/%02i/%02i'
%
(
year
,
MONTH_VALUE_DICT
[
month
],
int
(
day
)
/
7
*
7
+
1
)
def
_weekStringAsQuarterString
(
timestamp
):
year
,
month
,
_
=
timestamp
.
split
(
'/'
)
return
'%s/%02i'
%
(
year
,
int
(
month
)
/
3
*
3
+
1
)
def
_asDayString
(
timestamp
):
def
_asDayString
(
timestamp
):
dt
,
_
=
timestamp
.
split
(
' '
)
dt
,
_
=
timestamp
.
split
(
' '
)
day
,
month
,
year
=
dt
.
split
(
':'
,
1
)[
0
].
split
(
'/'
)
day
,
month
,
year
=
dt
.
split
(
':'
,
1
)[
0
].
split
(
'/'
)
return
'%s/%02i/%s'
%
(
year
,
MONTH_VALUE_DICT
[
month
],
day
)
return
'%s/%02i/%s'
%
(
year
,
MONTH_VALUE_DICT
[
month
],
day
)
def
_as6HourString
(
timestamp
):
dt
,
_
=
timestamp
.
split
(
' '
)
date
,
hour
,
_
=
dt
.
split
(
':'
,
2
)
day
,
month
,
year
=
date
.
split
(
'/'
)
return
'%s/%02i/%s %02i'
%
(
year
,
MONTH_VALUE_DICT
[
month
],
day
,
int
(
hour
)
/
6
*
6
)
def
_hourAsWeekString
(
timestamp
):
dt
=
datetime
.
strptime
(
timestamp
,
'%Y/%m/%d %H'
)
return
(
dt
-
timedelta
(
dt
.
weekday
())).
date
().
strftime
(
'%Y/%m/%d'
)
def
_asHourString
(
timestamp
):
def
_asHourString
(
timestamp
):
dt
,
_
=
timestamp
.
split
(
' '
)
dt
,
_
=
timestamp
.
split
(
' '
)
date
,
hour
,
_
=
dt
.
split
(
':'
,
2
)
date
,
hour
,
_
=
dt
.
split
(
':'
,
2
)
...
@@ -535,6 +555,15 @@ period_parser = {
...
@@ -535,6 +555,15 @@ period_parser = {
# Longest month: 31 days
# Longest month: 31 days
timedelta
(
31
),
timedelta
(
31
),
),
),
'quarter'
:
(
_asWeekString
,
_weekStringAsQuarterString
,
# Note: Not calendar weeks, but chunks of 7 days starting on first month's
# day. Cheaper to compute, and *should* not be a problem.
'7 days'
,
'%Y/%m/%d'
,
timedelta
(
7
),
),
'month'
:
(
'month'
:
(
_asDayString
,
_asDayString
,
lambda
x
:
'/'
.
join
(
x
.
split
(
'/'
,
2
)[:
2
]),
lambda
x
:
'/'
.
join
(
x
.
split
(
'/'
,
2
)[:
2
]),
...
@@ -543,6 +572,13 @@ period_parser = {
...
@@ -543,6 +572,13 @@ period_parser = {
# Longest day: 24 hours + 1h DST (never more ?)
# Longest day: 24 hours + 1h DST (never more ?)
timedelta
(
seconds
=
3600
*
25
),
timedelta
(
seconds
=
3600
*
25
),
),
),
'week'
:
(
_as6HourString
,
_hourAsWeekString
,
'6 hours'
,
'%Y/%m/%d %H'
,
timedelta
(
seconds
=
3600
*
6
),
),
'day'
:
(
'day'
:
(
_asHourString
,
_asHourString
,
lambda
x
:
x
.
split
(
' '
)[
0
],
lambda
x
:
x
.
split
(
' '
)[
0
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment