Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
swf2userSessions
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sepia-pub
mael
swf2userSessions
Commits
d1d79384
Commit
d1d79384
authored
2 years ago
by
Maël Madon
Browse files
Options
Downloads
Patches
Plain Diff
refac: python convention public/private methods
parent
2bc77b84
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
user_session_builder.py
+12
-15
12 additions, 15 deletions
user_session_builder.py
with
12 additions
and
15 deletions
user_session_builder.py
+
12
−
15
View file @
d1d79384
...
@@ -41,8 +41,8 @@ class User:
...
@@ -41,8 +41,8 @@ class User:
self
.
max_nb_res
=
0
self
.
max_nb_res
=
0
#
@private
#
####### Private methods ########
def
is_new_session
(
self
,
date_now
):
def
__
is_new_session
(
self
,
date_now
):
"""
Checks if a new session should be started according to the delimitation approach (see Zackay and Feitelson 2013)
"""
"""
Checks if a new session should be started according to the delimitation approach (see Zackay and Feitelson 2013)
"""
if
self
.
delim_approach
==
'
arrival
'
:
if
self
.
delim_approach
==
'
arrival
'
:
...
@@ -57,12 +57,11 @@ class User:
...
@@ -57,12 +57,11 @@ class User:
think_time
=
date_now
-
self
.
max_finish_time
think_time
=
date_now
-
self
.
max_finish_time
return
(
think_time
>
self
.
delim_threshold
)
return
(
think_time
>
self
.
delim_threshold
)
def
sessions_finished_at_time
(
self
,
t
):
def
__
sessions_finished_at_time
(
self
,
t
):
"""
Return the list of session that were finished at time t
"""
"""
Return the list of session that were finished at time t
"""
return
[
s
for
s
in
self
.
sessions
.
values
()
if
s
.
max_finish_time
<=
t
]
return
[
s
for
s
in
self
.
sessions
.
values
()
if
s
.
max_finish_time
<=
t
]
#@private
def
__update_session_graph
(
self
,
date_now
):
def
update_session_graph
(
self
,
date_now
):
"""
Add the dependencies for the active session
"""
"""
Add the dependencies for the active session
"""
active_session
=
self
.
sessions
[
self
.
active_session_id
]
active_session
=
self
.
sessions
[
self
.
active_session_id
]
...
@@ -72,7 +71,7 @@ class User:
...
@@ -72,7 +71,7 @@ class User:
if
not
self
.
dynamic_reduction
:
if
not
self
.
dynamic_reduction
:
# For all sessions that were finished when the current session was
# For all sessions that were finished when the current session was
# started, add a directed edge weighted by the thinking time
# started, add a directed edge weighted by the thinking time
for
finish_sess
in
self
.
sessions_finished_at_time
(
date_now
):
for
finish_sess
in
self
.
__
sessions_finished_at_time
(
date_now
):
think_time
=
date_now
-
finish_sess
.
max_finish_time
# >=0
think_time
=
date_now
-
finish_sess
.
max_finish_time
# >=0
active_session
.
preceding_sessions
.
append
(
finish_sess
.
id
)
active_session
.
preceding_sessions
.
append
(
finish_sess
.
id
)
...
@@ -109,8 +108,7 @@ class User:
...
@@ -109,8 +108,7 @@ class User:
sess
.
id
,
sess
.
id
,
weight
=
think_time
)
weight
=
think_time
)
#@private
def
__create_new_session
(
self
,
date_now
):
def
create_new_session
(
self
,
date_now
):
"""
Create a new active session and achive the old one
"""
"""
Create a new active session and achive the old one
"""
if
self
.
active_session_id
>
0
:
if
self
.
active_session_id
>
0
:
...
@@ -125,12 +123,11 @@ class User:
...
@@ -125,12 +123,11 @@ class User:
new_session
=
Session
(
self
.
active_session_id
,
date_now
)
new_session
=
Session
(
self
.
active_session_id
,
date_now
)
self
.
sessions
[
self
.
active_session_id
]
=
new_session
self
.
sessions
[
self
.
active_session_id
]
=
new_session
#@private
def
__add_job_to_active_session
(
self
,
job
):
def
add_job_to_active_session
(
self
,
job
):
active_sess
=
self
.
sessions
[
self
.
active_session_id
]
active_sess
=
self
.
sessions
[
self
.
active_session_id
]
active_sess
.
add_job
(
job
)
active_sess
.
add_job
(
job
)
#
@public
#
####### Public methods ########
def
add_job
(
self
,
job
):
def
add_job
(
self
,
job
):
"""
Add a job to the job list of the user, creating a new session and
"""
Add a job to the job list of the user, creating a new session and
handling its dependencies, if needed.
"""
handling its dependencies, if needed.
"""
...
@@ -140,10 +137,10 @@ class User:
...
@@ -140,10 +137,10 @@ class User:
date_now
=
job
.
submit_time
date_now
=
job
.
submit_time
# does the job start a new session?
# does the job start a new session?
if
self
.
is_new_session
(
date_now
):
if
self
.
__
is_new_session
(
date_now
):
self
.
create_new_session
(
date_now
)
self
.
__
create_new_session
(
date_now
)
self
.
update_session_graph
(
date_now
)
self
.
__
update_session_graph
(
date_now
)
self
.
add_job_to_active_session
(
job
)
self
.
__
add_job_to_active_session
(
job
)
# Updating variables
# Updating variables
self
.
last_submit_time
=
job
.
submit_time
self
.
last_submit_time
=
job
.
submit_time
...
...
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