Last active
October 15, 2018 19:52
-
-
Save beweinreich/e943eb865b8aa796b3c0a0ddd6b69eea 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 | |
TAG_NAME = 'meeting-room' | |
WASTED_PERCENT = 15 | |
# get meeting rooms | |
url = f'https://api.density.io/v2/tags/{TAG_NAME}' | |
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer REPLACE_ME'} | |
requests.get(url, headers=headers) | |
response = requests.get(url, headers=headers) | |
tagged_spaces = response.json() | |
# calculate utilization for each space | |
for space in tagged_spaces['spaces']: | |
space_id = space['id'] | |
# get space capacity | |
url = f'https://api.density.io/v2/spaces/{space_id}' | |
response = requests.get(url, headers=headers) | |
space_data = response.json() | |
capacity = space_data['capacity'] | |
# get counts for occupancy | |
url = f'https://api.density.io/v2/spaces/{space_id}/counts?start_time=2018-10-10T21:00:00Z&end_time=2018-10-10T23: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 = 120 | |
interval = 5 | |
utilization = (interval / number_of_minutes_in_time_range) * sum_max_occupancy | |
if utilization < WASTED_PERCENT: | |
space_name = space['name'] | |
print(f'{space_name}: {utilization * 100}% utilization') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment