user count history
parent
1e7ac86940
commit
5f2c142336
|
|
@ -41,4 +41,12 @@ CREATE TABLE `APIKey` (
|
|||
`date_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`last_used` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`uses` INT DEFAULT 0
|
||||
);
|
||||
DROP TABLE IF EXISTS `UserCount`;
|
||||
CREATE TABLE `UserCount` (
|
||||
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP PRIMARY KEY,
|
||||
`hw_id` VARCHAR(64) NOT NULL,
|
||||
`room_id` VARCHAR(64) NOT NULL,
|
||||
`total_users` INT NOT NULL DEFAULT 0,
|
||||
`room_users` INT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
|
@ -122,6 +122,80 @@ def get_headset_details_db(hw_id):
|
|||
return {'user': headsets[0], 'room': room}
|
||||
|
||||
|
||||
|
||||
|
||||
@bp.route('/set_headset_details/<hw_id>', methods=['POST'])
|
||||
@require_api_key(10)
|
||||
def set_headset_details_generic(hw_id):
|
||||
data = request.json
|
||||
logger.error(data)
|
||||
conn, curr = connectToDB()
|
||||
|
||||
try:
|
||||
for key in data:
|
||||
# protected keys
|
||||
if key == 'hw_id' \
|
||||
or key == 'owned_room' \
|
||||
or key == 'date_created' \
|
||||
or key == 'last_used' \
|
||||
:
|
||||
continue
|
||||
|
||||
if key == 'current_room':
|
||||
create_room(data['current_room'])
|
||||
query = """
|
||||
UPDATE `Headset` SET `%(key)s`=%(value)s WHERE `hw_id`=%(hw_id)s;
|
||||
"""
|
||||
curr.execute(query, {'key': key, 'value': data[key], 'hw_id': hw_id})
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
curr.close()
|
||||
logger.error(e)
|
||||
return 'Error', 400
|
||||
|
||||
curr.close()
|
||||
|
||||
response = jsonify({'success': True})
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
|
||||
|
||||
|
||||
|
||||
@bp.route('/set_room_details/<room_id>', methods=['POST'])
|
||||
@require_api_key(10)
|
||||
def set_room_details_generic(room_id):
|
||||
data = request.json
|
||||
logger.error(data)
|
||||
conn, curr = connectToDB()
|
||||
|
||||
try:
|
||||
for key in data:
|
||||
# protected keys
|
||||
if key == 'room_id' \
|
||||
or key == 'date_created' \
|
||||
or key == 'last_modified' \
|
||||
or key == 'owner' \
|
||||
:
|
||||
continue
|
||||
|
||||
query = """
|
||||
UPDATE `Room` SET `%(key)s`=%(value)s WHERE `room_id`=%(room_id)s;
|
||||
"""
|
||||
curr.execute(query, {'key': key, 'value': data[key], 'room_id': room_id})
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
curr.close()
|
||||
logger.error(e)
|
||||
return 'Error', 400
|
||||
|
||||
curr.close()
|
||||
|
||||
response = jsonify({'success': True})
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
|
||||
|
||||
@bp.route('/set_headset_details/<hw_id>/current_room', methods=['POST'])
|
||||
@require_api_key(10)
|
||||
def set_headset_details(hw_id):
|
||||
|
|
@ -337,3 +411,48 @@ def set_room_details_carpet_color(room_id):
|
|||
response = jsonify({'room_id': room_id})
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
|
||||
|
||||
|
||||
|
||||
@bp.route('/update_user_count', methods=['POST'])
|
||||
@require_api_key(10)
|
||||
def update_user_count():
|
||||
conn, curr = connectToDB()
|
||||
query = """
|
||||
INSERT INTO `UserCount`
|
||||
VALUES(
|
||||
CURRENT_TIMESTAMP,
|
||||
%(hw_id)s,
|
||||
%(room_id)s,
|
||||
%(total_users)s,
|
||||
%(room_users)s
|
||||
);
|
||||
"""
|
||||
data = request.json
|
||||
curr.execute(query, data)
|
||||
conn.commit()
|
||||
curr.close()
|
||||
response = jsonify({'success': True})
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
|
||||
|
||||
|
||||
|
||||
@bp.route('/get_user_count', methods=['GET'])
|
||||
def get_user_count():
|
||||
hours = request.args.get('hours', 24)
|
||||
conn, curr = connectToDB()
|
||||
query = """
|
||||
SELECT timestamp, total_users
|
||||
FROM `UserCount`
|
||||
WHERE TIMESTAMP > DATE_SUB(NOW(), INTERVAL """ + str(hours) + """ HOUR);
|
||||
"""
|
||||
data = request.json
|
||||
curr.execute(query, data)
|
||||
values = [dict(row) for row in curr.fetchall()]
|
||||
curr.close()
|
||||
response = jsonify(values)
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@
|
|||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://connect.vel.workers.dev/api/"
|
||||
"url": "http://velconnect.ugavel.com/api/"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:5000/api/"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
|
|
@ -113,6 +116,34 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/update_user_count": {
|
||||
"post": {
|
||||
"summary": "Update User Count",
|
||||
"description" : "Updates the current user count for a room and globally.",
|
||||
"tags": ["User Count"],
|
||||
"parameters": [
|
||||
]
|
||||
}
|
||||
},
|
||||
"/get_user_count": {
|
||||
"get": {
|
||||
"summary": "Get User Count",
|
||||
"description" : "Gets a list of the recent user counts.",
|
||||
"tags": ["User Count"],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "hours",
|
||||
"example": "24",
|
||||
"in": "path",
|
||||
"description": "Number of hours to get user counts for",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
primary-color = "#bc1f2d"
|
||||
show-header = "false"
|
||||
show-info = "true"
|
||||
spec-url = "{% include 'api_url.html' %}/api/api_spec.json"
|
||||
spec-url = "{% include 'api_url.html' %}api/api_spec.json"
|
||||
default-schema-tab = 'example'
|
||||
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
http://localhost:5000
|
||||
/
|
||||
|
|
@ -198,17 +198,18 @@
|
|||
}, (status) => {
|
||||
loading.style.display = "none";
|
||||
failure.style.display = "block";
|
||||
window.location.href = "/pair";
|
||||
});
|
||||
|
||||
function setUserData(endpoint, data) {
|
||||
httpPostAsync('{% include "api_url.html" %}/api/set_headset_details/' + hw_id + '/' + endpoint,
|
||||
function setUserData(data) {
|
||||
httpPostAsync('{% include "api_url.html" %}/api/set_headset_details/' + hw_id,
|
||||
data,
|
||||
(resp) => { console.log('success'); },
|
||||
(status) => { console.log('fail'); }
|
||||
);
|
||||
}
|
||||
function setRoomData(endpoint, data) {
|
||||
httpPostAsync('{% include "api_url.html" %}/api/set_room_details/' + current_room.value + '/' + endpoint,
|
||||
function setRoomData(data) {
|
||||
httpPostAsync('{% include "api_url.html" %}/api/set_room_details/' + current_room.value,
|
||||
data,
|
||||
(resp) => { console.log('success'); },
|
||||
(status) => { console.log('fail'); }
|
||||
|
|
@ -216,22 +217,22 @@
|
|||
}
|
||||
|
||||
set_room_id.addEventListener('click', () => {
|
||||
setUserData('current_room', { "current_room": current_room.value });
|
||||
setUserData({ "current_room": current_room.value });
|
||||
});
|
||||
document.getElementById('set_user_color').addEventListener('click', () => {
|
||||
setUserData('user_color', { "user_color": document.getElementById('user_color').value });
|
||||
setUserData({ "user_color": document.getElementById('user_color').value });
|
||||
});
|
||||
document.getElementById('set_user_name').addEventListener('click', () => {
|
||||
setUserData('user_name', { "user_name": document.getElementById('user_name').value });
|
||||
setUserData({ "user_name": document.getElementById('user_name').value });
|
||||
});
|
||||
document.getElementById('set_tv_url').addEventListener('click', () => {
|
||||
setRoomData('tv_url', { "tv_url": document.getElementById('tv_url').value });
|
||||
setRoomData({ "tv_url": document.getElementById('tv_url').value });
|
||||
});
|
||||
document.getElementById('set_carpet_color').addEventListener('click', () => {
|
||||
setRoomData('carpet_color', { "carpet_color": document.getElementById('carpet_color').value });
|
||||
setRoomData({ "carpet_color": document.getElementById('carpet_color').value });
|
||||
});
|
||||
document.getElementById('set_avatar_url').addEventListener('click', () => {
|
||||
setUserData('avatar_url', { "avatar_url": document.getElementById('avatar_url').value });
|
||||
setUserData({ "avatar_url": document.getElementById('avatar_url').value });
|
||||
});
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -62,10 +62,9 @@ title: VEL Connect
|
|||
<div class="tile-content">
|
||||
<div class="tile-title text-bold">User Name</div>
|
||||
<input class="btn user_name" type="text" id="user_name" placeholder="----">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_user_name" data-tooltip="">Set</button>
|
||||
</div>
|
||||
<div class="tile-action">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_user_name"
|
||||
data-tooltip="">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
|
@ -73,10 +72,9 @@ title: VEL Connect
|
|||
<div class="tile-content">
|
||||
<div class="tile-title text-bold">TV URL</div>
|
||||
<input class="btn tv_url" type="text" id="tv_url" placeholder="----">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_tv_url" data-tooltip="">Set</button>
|
||||
</div>
|
||||
<div class="tile-action">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_tv_url"
|
||||
data-tooltip="">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
|
@ -84,10 +82,9 @@ title: VEL Connect
|
|||
<div class="tile-content">
|
||||
<div class="tile-title text-bold">User Color</div>
|
||||
<input class="btn user_color coloris" type="text" id="user_color" placeholder="#ffffff">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_user_color" data-tooltip="Set User Color">Set</button>
|
||||
</div>
|
||||
<div class="tile-action">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_user_color"
|
||||
data-tooltip="Set User Color">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
|
@ -95,10 +92,9 @@ title: VEL Connect
|
|||
<div class="tile-content">
|
||||
<div class="tile-title text-bold">Carpet Color</div>
|
||||
<input class="btn carpet_color coloris" type="text" id="carpet_color" placeholder="#ffffff">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_carpet_color" data-tooltip="Set Carpet Color">Set</button>
|
||||
</div>
|
||||
<div class="tile-action">
|
||||
<button class="btn btn-primary btn-lg tooltip tooltip-left" id="set_carpet_color"
|
||||
data-tooltip="Set Carpet Color">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
|
|
|||
Loading…
Reference in New Issue