diff --git a/unity_package/Runtime/VELConnectManager.cs b/unity_package/Runtime/VELConnectManager.cs index 9831b77..3c7e3e6 100644 --- a/unity_package/Runtime/VELConnectManager.cs +++ b/unity_package/Runtime/VELConnectManager.cs @@ -166,7 +166,7 @@ namespace VELConnect { "version", Application.version }, { "platform", SystemInfo.operatingSystem }, }; - PostRequestCallback(velConnectUrl + "/api/update_user_count", JsonConvert.SerializeObject(postData)); + PostRequestCallback(velConnectUrl + "/api/v2/update_user_count", JsonConvert.SerializeObject(postData)); }); } diff --git a/velconnect/main.py b/velconnect/main.py index f7769f1..cf5c444 100644 --- a/velconnect/main.py +++ b/velconnect/main.py @@ -6,6 +6,7 @@ from fastapi.staticfiles import StaticFiles from routes.api import router as api_router from routes.api_v2 import router as api_v2_router from routes.user_count import router as user_count_router +from routes.user_count_v2 import router as user_count_v2_router from routes.oculus_api import router as oculus_api_router from routes.website import router as website_router @@ -31,6 +32,7 @@ app.mount("/static", StaticFiles(directory="static"), name="static") app.include_router(api_router) app.include_router(api_v2_router) app.include_router(user_count_router) +app.include_router(user_count_v2_router) app.include_router(oculus_api_router) app.include_router(website_router) diff --git a/velconnect/routes/api_v2.py b/velconnect/routes/api_v2.py index a4e0723..902f8de 100644 --- a/velconnect/routes/api_v2.py +++ b/velconnect/routes/api_v2.py @@ -50,6 +50,10 @@ async def read_root(): def get_all_devices(): """Returns a list of all devices and details associated with them.""" values = db.query("SELECT * FROM `Device`;") + values = [dict(v) for v in values] + for device in values: + if 'data' in device and len(device['data']) > 0: + device['data'] = json.loads(device['data']) return values diff --git a/velconnect/routes/user_count.py b/velconnect/routes/user_count.py index f51d0d9..2ba4063 100644 --- a/velconnect/routes/user_count.py +++ b/velconnect/routes/user_count.py @@ -27,42 +27,28 @@ post_user_count_example = { } -@router.post('/update_user_count') -def update_user_count(data: dict = fastapi.Body(..., examples=post_user_count_example)) -> dict: - if 'app_id' not in data: - data['app_id'] = "" - +@router.post('/update_user_count', tags=["User Count"]) +def update_user_count(data: dict): db.insert(""" - REPLACE INTO `UserCount` ( - timestamp, - hw_id, - app_id, - room_id, - total_users, - room_users, - version, - platform - ) + REPLACE INTO `UserCount` VALUES( CURRENT_TIMESTAMP, - :hw_id, - :app_id, - :room_id, - :total_users, - :room_users, - :version, - :platform + %(hw_id)s, + %(room_id)s, + %(total_users)s, + %(room_users)s, + %(version)s, + %(platform)s ); """, data) return {'success': True} -@router.get('/get_user_count') -def get_user_count(app_id: str = None, hours: float = 24) -> list: +@router.get('/get_user_count', tags=["User Count"]) +def get_user_count(hours: float = 24): values = db.query(""" - SELECT timestamp, total_users - FROM `UserCount` - WHERE app_id = :app_id AND - timestamp > datetime('now', '-""" + str(hours) + """ Hour'); - """, {"app_id": app_id}) - return values + SELECT timestamp, total_users + FROM `UserCount` + WHERE TIMESTAMP > DATE_SUB(NOW(), INTERVAL """ + str(hours) + """ HOUR); + """) + return values \ No newline at end of file diff --git a/velconnect/routes/user_count_v2.py b/velconnect/routes/user_count_v2.py new file mode 100644 index 0000000..68ac0fa --- /dev/null +++ b/velconnect/routes/user_count_v2.py @@ -0,0 +1,68 @@ +import fastapi + +import db + +db = db.DB("velconnect_v2.db") + +# APIRouter creates path operations for user module +router = fastapi.APIRouter( + prefix="/api/v2", + tags=["User Count V2"], + responses={404: {"description": "Not found"}}, +) + +post_user_count_example = { + "default": { + "summary": "Example insert for user count", + "value": { + "hw_id": "1234", + "app_id": "example", + "room_id": "0", + "total_users": 1, + "room_users": 1, + "version": "0.1", + "platform": "Windows" + } + } +} + + +@router.post('/update_user_count') +def update_user_count(data: dict = fastapi.Body(..., examples=post_user_count_example)) -> dict: + if 'app_id' not in data: + data['app_id'] = "" + + db.insert(""" + REPLACE INTO `UserCount` ( + timestamp, + hw_id, + app_id, + room_id, + total_users, + room_users, + version, + platform + ) + VALUES( + CURRENT_TIMESTAMP, + :hw_id, + :app_id, + :room_id, + :total_users, + :room_users, + :version, + :platform + ); + """, data) + return {'success': True} + + +@router.get('/get_user_count') +def get_user_count(app_id: str = None, hours: float = 24) -> list: + values = db.query(""" + SELECT timestamp, total_users + FROM `UserCount` + WHERE app_id = :app_id AND + timestamp > datetime('now', '-""" + str(hours) + """ Hour'); + """, {"app_id": app_id}) + return values