Last active
October 15, 2018 19:24
-
-
Save beweinreich/a275271c403c1512f19ce8be56d448cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# get capacity | |
url = 'https://api.density.io/v2/spaces/:space_id' | |
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer REPLACE_ME'} | |
response = requests.get(url, headers=headers) | |
json_data = response.json() | |
capacity = json_data['capacity'] | |
# get space counts and max occupancy | |
url = 'https://api.density.io/v2/spaces/:space_id/counts\ | |
?start_time=2017-09-19T15:00:00Z\ | |
&end_time=2017-09-19T18:00:00Z\ | |
&interval=5m' | |
response = requests.get(url, headers=headers) | |
json_data = response.json() | |
max_occupancy_intervals = [] | |
for result in json_data['results']: | |
max_count = result['interval']['analytics']['max'] | |
max_occupancy = max_count / capacity | |
max_occupancy_intervals.append(max_occupancy) | |
# calculate utilization | |
sum_max_occupancy = sum(max_occupancy_intervals) | |
number_of_minutes_in_time_range = 180 | |
interval = 5 | |
utilization = (interval / number_of_minutes_in_time_range) * sum_max_occupancy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment