Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
c7625a5d
Commit
c7625a5d
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
removed import, added docs
parent
8a852c7a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!171
Feature/daily availability
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/officeAvailability.py
+20
-4
20 additions, 4 deletions
smash/web/officeAvailability.py
with
20 additions
and
4 deletions
smash/web/officeAvailability.py
+
20
−
4
View file @
c7625a5d
...
@@ -4,7 +4,7 @@ from datetime import timedelta
...
@@ -4,7 +4,7 @@ from datetime import timedelta
import
logging
import
logging
import
pandas
as
pd
import
pandas
as
pd
from
web.utils
import
timeit
,
get_today_midnight_date
from
web.utils
import
get_today_midnight_date
from
web.models.holiday
import
Holiday
from
web.models.holiday
import
Holiday
from
web.models.availability
import
Availability
from
web.models.availability
import
Availability
from
web.models.appointment
import
Appointment
from
web.models.appointment
import
Appointment
...
@@ -49,20 +49,34 @@ class OfficeAvailability(object):
...
@@ -49,20 +49,34 @@ class OfficeAvailability(object):
self
.
availability
=
pd
.
Series
(
index
=
self
.
range
,
data
=
0
)
# initialize range at 0
self
.
availability
=
pd
.
Series
(
index
=
self
.
range
,
data
=
0
)
# initialize range at 0
def
_get_duration
(
self
):
def
_get_duration
(
self
):
'''
Private method. Returns the differ
'''
return
self
.
availability
.
index
[
-
1
]
-
self
.
availability
.
index
[
0
]
return
self
.
availability
.
index
[
-
1
]
-
self
.
availability
.
index
[
0
]
def
add_availability
(
self
,
range
,
only_working_hours
=
False
):
def
add_availability
(
self
,
range
,
only_working_hours
=
False
):
'''
Receives a pandas date_range `pd.date_range` object.
Sets the availability to one for the specific interval of the provided range.
'''
if
only_working_hours
:
if
only_working_hours
:
range
=
range
.
to_series
().
between_time
(
self
.
office_start
,
self
.
office_end
)
range
=
range
.
to_series
().
between_time
(
self
.
office_start
,
self
.
office_end
)
self
.
availability
[
range
]
=
1
self
.
availability
[
range
]
=
1
def
remove_availability
(
self
,
range
,
only_working_hours
=
False
):
def
remove_availability
(
self
,
range
,
only_working_hours
=
False
):
'''
Receives a pandas date_range `pd.date_range` object.
Sets the availability to zero for the specific interval of the provided range.
'''
if
only_working_hours
:
if
only_working_hours
:
range
=
range
.
to_series
().
between_time
(
self
.
office_start
,
self
.
office_end
)
range
=
range
.
to_series
().
between_time
(
self
.
office_start
,
self
.
office_end
)
self
.
availability
[
range
]
=
0
self
.
availability
[
range
]
=
0
def
consider_this
(
self
,
appointment_availability_or_holiday
,
only_working_hours
=
False
):
def
consider_this
(
self
,
appointment_availability_or_holiday
,
only_working_hours
=
False
):
'''
'''
:appointment_availability_or_holiday can be an object from the following classes: Availability, Holiday, Appointment, AppointmentTypeLink.
:only_working_hours if true, only consider the defined working hours
Availability repeat every week.
Availability repeat every week.
Availability always refers to a moment in which the worker should be working. Never the opposite.
Availability always refers to a moment in which the worker should be working. Never the opposite.
...
@@ -107,7 +121,7 @@ class OfficeAvailability(object):
...
@@ -107,7 +121,7 @@ class OfficeAvailability(object):
portion
=
self
.
availability
[
pd
.
date_range
(
start
=
start
,
end
=
end
,
freq
=
self
.
minimum_slot
)]
#select the specific range
portion
=
self
.
availability
[
pd
.
date_range
(
start
=
start
,
end
=
end
,
freq
=
self
.
minimum_slot
)]
#select the specific range
set_to
=
0
set_to
=
0
else
:
else
:
logger
.
error
(
'
Expected
Holiday or
Availability objects.
'
)
logger
.
error
(
'
Expected Availability
, Holiday, Appointment or AppointmentTypeLink
objects.
'
)
raise
TypeError
raise
TypeError
if
only_working_hours
:
if
only_working_hours
:
...
@@ -141,15 +155,17 @@ class OfficeAvailability(object):
...
@@ -141,15 +155,17 @@ class OfficeAvailability(object):
return
availability
.
mean
()
*
100
#better to isolate the operation in case we change it later
return
availability
.
mean
()
*
100
#better to isolate the operation in case we change it later
def
is_availab
i
le
(
self
,
only_working_hours
=
False
):
def
is_available
(
self
,
only_working_hours
=
False
):
'''
'''
Returns True if on the selected period is available at least 50% of the time
Returns True if on the selected period is available at least 50% of the time
Otherwise returns False
Otherwise returns False
'''
'''
return
self
.
get_availability_percentage
(
only_working_hours
=
only_working_hours
)
>
50.0
return
self
.
get_availability_percentage
(
only_working_hours
=
only_working_hours
)
>
50.0
@timeit
def
plot_availability
(
self
):
def
plot_availability
(
self
):
'''
Plot availability chart.
'''
fig
=
plt
.
figure
()
#create new figure. This should ensure thread safe method
fig
=
plt
.
figure
()
#create new figure. This should ensure thread safe method
ax
=
fig
.
gca
()
#get current axes
ax
=
fig
.
gca
()
#get current axes
matplotlib
.
rcParams
[
'
hatch.linewidth
'
]
=
1
matplotlib
.
rcParams
[
'
hatch.linewidth
'
]
=
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