Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web
Commits
f5ee2e49
Commit
f5ee2e49
authored
5 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Simplify lowest-timedelta search in get_origin_visit.
parent
1d0d63e6
No related branches found
No related tags found
1 merge request
!140
Simplify lowest-timedelta search in get_origin_visit.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/web/common/origin_visits.py
+9
-20
9 additions, 20 deletions
swh/web/common/origin_visits.py
with
9 additions
and
20 deletions
swh/web/common/origin_visits.py
+
9
−
20
View file @
f5ee2e49
...
...
@@ -149,29 +149,18 @@ def get_origin_visit(origin_info, visit_ts=None, visit_id=None,
return
v
return
visits
[
-
1
]
parsed_visit_ts
=
math
.
floor
(
parse_timestamp
(
visit_ts
).
timestamp
())
visit_idx
=
None
for
i
,
visit
in
enumerate
(
visits
):
ts
=
math
.
floor
(
parse_timestamp
(
visit
[
'
date
'
]).
timestamp
())
if
i
==
0
and
parsed_visit_ts
<=
ts
:
return
visit
elif
i
==
len
(
visits
)
-
1
:
if
parsed_visit_ts
>=
ts
:
return
visit
else
:
next_ts
=
math
.
floor
(
parse_timestamp
(
visits
[
i
+
1
][
'
date
'
]).
timestamp
())
if
parsed_visit_ts
>=
ts
and
parsed_visit_ts
<
next_ts
:
if
(
parsed_visit_ts
-
ts
)
<
(
next_ts
-
parsed_visit_ts
):
visit_idx
=
i
break
else
:
visit_idx
=
i
+
1
break
target_visit_ts
=
math
.
floor
(
parse_timestamp
(
visit_ts
).
timestamp
())
# Find the visit with date closest to the target (in absolute value)
(
abs_time_delta
,
visit_idx
)
=
min
(
((
math
.
floor
(
parse_timestamp
(
visit
[
'
date
'
]).
timestamp
()),
i
)
for
(
i
,
visit
)
in
enumerate
(
visits
)),
key
=
lambda
ts_and_i
:
abs
(
ts_and_i
[
0
]
-
target_visit_ts
))
if
visit_idx
is
not
None
:
visit
=
visits
[
visit_idx
]
# If multiple visits have the same date, select the one with
# the largest id.
while
visit_idx
<
len
(
visits
)
-
1
and
\
visit
[
'
date
'
]
==
visits
[
visit_idx
+
1
][
'
date
'
]:
visit_idx
=
visit_idx
+
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment