Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed assets/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions backend/Authentication/AuthenticationAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def register():
if telegramHandle.startswith('@'):
telegramHandle = telegramHandle[1:]

if db.User.find({'userID': userID}).count(): # entry exists
if db.User.count_documents({'userID': userID}): # entry exists
return jsonify({'message': 'User already exists'}), 401
# add to User table
# note: if the user data does not adhere to defined validation standards, an error will be thrown here
Expand All @@ -140,7 +140,7 @@ def register():
"bio": bio,
"block": block,
"telegramHandle": telegramHandle,
"profilePictureURI": "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon"
"imageKey": "default/profile_pic.png"
})
except Exception as e:
print(e)
Expand Down
59 changes: 59 additions & 0 deletions backend/CrowdAnalyser/CrowdAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from AuthFunction import authenticate
from db import *
from flask import jsonify, request, make_response
from AuthFunction import authenticate
from datetime import datetime, timedelta
import time
from flask_cors import cross_origin
from flask import Blueprint
import sys

sys.path.append("../")

crowd_api = Blueprint("crowd", __name__)

@crowd_api.route('/')
@cross_origin()
def root_route():
return 'hey'

@crowd_api.route('/getweekly', methods = ["GET"])
@cross_origin(supports_credentials=True)
def get_weekly_crowd():
try:
# Get today's date and facilityID
today = request.args.get('endDate')
facilityID = request.args.get('facilityID')

# Calculate the date of the start of the current week (Monday)
start_of_week = today - timedelta(days = today.weekday())

# Create a datetime object representing the start of the week
start_of_week_datetime = datetime.combine(start_of_week, datetime.min.time())

# Convert the datetime object to Unix timestamp
start_of_week_unix = int(time.mktime(start_of_week_datetime.timetuple()))

# Initialise counter for loop to find avg crowd on each day of the week
counter = today.weekday() + 1
start_of_day = start_of_week_unix;
crowd_result = []
for _ in range(0, counter):
# Find all the data for the current day
data = list(db.Crowd.find({"facilityID": int(facilityID),
"time": {"$gte": start_of_day, "$lte": start_of_day + 86400}}))

# Calculate average of the crowd level for the current day
level_sum = 0
for item in data:
level_sum += item['level']
avg_level = level_sum / len(data) if level_sum != 0 else 0
crowd_result.append(avg_level)

# Increment the start of the day by 1 day
start_of_day = start_of_day + 86400
response = {"facilityID": facilityID, "level": crowd_result, "status": "success"}
except Exception as e:
print(e)
return {"err": "An error has occured", "status": "failed"}, 500
return make_response(response)
124 changes: 123 additions & 1 deletion backend/FacilityBooking/FacilitiesAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

facilities_api = Blueprint("facilities", __name__)

# Used to convert CCA ID into CCA Name


# Used to convert CCA ID into CCA Name
def conversion(ccaID):
return str(db.CCA.find_one({"ccaID": ccaID})["ccaName"])

Expand All @@ -38,6 +38,58 @@ def all_facilities():
return make_response(response)


@ facilities_api.route('/available', methods=["GET"])
@ cross_origin(supports_credentials=True)
def available_facilities_within_time():
try:
all_facilities = list(db.Facilities.find({}, {"_id": 0}).sort("facilityID", 1))
startTime = int(request.args.get('startTime')) if request.args.get('startTime') else 0
endTime = int(request.args.get('endTime')) if request.args.get('endTime') else -1
if endTime <= startTime:
return {"err": "Invalid start and end time", "status": "failed"}, 400

condition = {
"$and": [
{
"startTime": {
"$lt": endTime
}
},
{
"endTime": {
"$gt": startTime
}
}
]
}

pipeline = [
{'$match':
condition
},
{'$lookup': {
'from': 'Facilities',
'localField': 'facilityID',
'foreignField': 'facilityID',
'as': 'facility'
}},
{'$unwind': {'path': '$facility', 'preserveNullAndEmptyArrays': True}},
{'$addFields': {
'facilityName': '$facility.facilityName',
'facilityLocation': '$facility.facilityLocation'
}},
{'$project': {'facilityID': 1, 'facilityName': 1, 'facilityLocation': 1, '_id': 0}},
]

occupied_facilities = list(db.Bookings.aggregate(pipeline))
available_facilities = list(filter(lambda fac: fac not in occupied_facilities, all_facilities))
response = {"available_facilities": available_facilities, "status": "success"}, 200
except Exception as e:
print(e)
return {"err": "An error has occurred", "status": "failed"}, 500
return make_response(response)


@ facilities_api.route('/facilities/<facilityID>', methods=["GET"])
@ cross_origin(supports_credentials=True)
def get_facility_name(facilityID):
Expand Down Expand Up @@ -248,6 +300,76 @@ def check_bookings(facilityID):
return make_response(response)


@ facilities_api.route('/bookings', methods=["GET"])
@ cross_origin(supports_credentials=True)
def check_bookings_within_time():
try:
startTime = int(request.args.get('startTime')) if request.args.get('startTime') else 0
endTime = int(request.args.get('endTime')) if request.args.get('endTime') else -1
if endTime <= startTime:
return {"err": "Invalid start and end time", "status": "failed"}, 400

condition = {
"$and": [
{
"startTime": {
"$lt": endTime
}
},
{
"endTime": {
"$gt": startTime
}
}
]
}

pipeline = [
{'$match':
condition
},
{'$lookup': {
'from': 'User',
'localField': 'userID',
'foreignField': 'userID',
'as': 'profile'
}},
{'$unwind': {'path': '$profile', 'preserveNullAndEmptyArrays': True}},
{'$addFields': {
'displayName': '$profile.displayName'
}},
{'$lookup': {
'from': 'CCA',
'localField': 'ccaID',
'foreignField': 'ccaID',
'as': 'cca'
}},
{'$unwind': {'path': '$cca', 'preserveNullAndEmptyArrays': True}},
{'$addFields': {
'ccaName': '$cca.ccaName'
}},
{'$lookup': {
'from': 'Facilities',
'localField': 'facilityID',
'foreignField': 'facilityID',
'as': 'facility'
}},
{'$unwind': {'path': '$facility', 'preserveNullAndEmptyArrays': True}},
{'$addFields': {
'facilityName': '$facility.facilityName'
}},
{'$project': {'profile': 0, 'cca': 0, 'facility': 0, '_id': 0}}
]

data = list(db.Bookings.aggregate(pipeline))
data.sort(key=lambda x: x.get('startTime'))
response = {"startTime": startTime, "endTime": endTime, "bookings_placed": data, "status": "success"}, 200
except Exception as e:
print(e)
return {"err": "An error has occurred", "status": "failed"}, 500
return make_response(response)


@ facilities_api.route('/bookings', methods=['POST'])
@ cross_origin(supports_credentials=True)
def add_booking():
Expand Down
1 change: 0 additions & 1 deletion backend/GymFeatures/GymAPI.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from curses import keyname
from operator import is_
from numpy import sort
from db import *
Expand Down
2 changes: 2 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from Supper.SupperAPI import supper_api
from Authentication.AuthenticationAPI import authentication_api
from GymFeatures.GymAPI import gym_api
from CrowdAnalyser.CrowdAPI import crowd_api;
from db import *
from gevent.pywsgi import WSGIServer
from prometheus_flask_exporter import PrometheusMetrics
Expand All @@ -26,6 +27,7 @@
app.register_blueprint(supper_api, url_prefix="/supper")
app.register_blueprint(authentication_api, url_prefix="/auth")
app.register_blueprint(gym_api, url_prefix="/gym")
app.register_blueprint(crowd_api, url_prefix="/crowd")

@app.route("/")
def hello():
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
expose:
- 8080
restart: on-failure
env_file:
- ./secrets/rhapp_env
networks:
- intranet
labels:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
expose:
- 8080
restart: on-failure
env_file:
- ./secrets/rhapp_env
networks:
- intranet
labels:
Expand Down
12 changes: 9 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "0.1.0",
"version": "2.1.0",
"private": true,
"dependencies": {
"@ant-design/icons": "^4.3.0",
Expand All @@ -22,10 +22,11 @@
"antd": "^4.16.6",
"antd-mobile": "^2.3.4",
"axios": "^0.21.0",
"babel-plugin-import": "^1.13.3",
"babel-plugin-import": "^1.13.5",
"bcrypt": "^5.0.0",
"crypto-js": "^4.0.0",
"customize-cra": "^1.0.0",
"date-fns": "^2.28.0",
"dayjs": "^1.9.7",
"dotenv": "^8.2.0",
"dotenv-webpack": "^7.0.1",
Expand Down Expand Up @@ -61,10 +62,12 @@
"web-vitals": "^0.2.4"
},
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"docs": "typedoc",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix"
},
"eslintConfig": {
Expand Down Expand Up @@ -101,6 +104,9 @@
"eslint": "^7.29.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.2.1"
"eslint-plugin-react": "^7.30.0",
"prettier": "^2.2.1",
"react-test-renderer": "^18.1.0",
"source-map-explorer": "^2.5.3"
}
}
14 changes: 7 additions & 7 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/>
<meta name="theme-color" content="#000000" />
<meta name="Rh App" content="Nobody asked but we delivered" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/black_logo_192.png" />
<link rel="icon" sizes="152x152" href="%PUBLIC_URL%/black_logo_152.png" />
<link rel="icon" sizes="180x180" href="%PUBLIC_URL%/black_logo_180.png" />
<link rel="icon" sizes="192x192" href="%PUBLIC_URL%/black_logo_192.png" />
<link rel="icon" sizes="256x256" href="%PUBLIC_URL%/black_logo_256.png" />
<link rel="icon" sizes="512x512" href="%PUBLIC_URL%/black_logo_512.png" />
<link rel="icon" sizes="1024x1024" href="%PUBLIC_URL%/black_logo_1024.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/icons/black_logo_192.png" />
<link rel="icon" sizes="152x152" href="%PUBLIC_URL%/icons/black_logo_152.png" />
<link rel="icon" sizes="180x180" href="%PUBLIC_URL%/icons/black_logo_180.png" />
<link rel="icon" sizes="192x192" href="%PUBLIC_URL%/icons/black_logo_192.png" />
<link rel="icon" sizes="256x256" href="%PUBLIC_URL%/icons/black_logo_256.png" />
<link rel="icon" sizes="512x512" href="%PUBLIC_URL%/icons/black_logo_512.png" />
<link rel="icon" sizes="1024x1024" href="%PUBLIC_URL%/icons/black_logo_1024.png" />
<link href="https://fonts.googleapis.com/css2?family=Inter&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet" type="text/css" />
<!--
Expand Down
1 change: 1 addition & 0 deletions frontend/src/GlobalStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const GlobalStyle = createGlobalStyle`

html {
--antd-wave-shadow-color: rgb(222, 95, 76) !important;
scroll-behavior: smooth;
}

.ant-select-selector {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/assets/calendarTime.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/circleRightArrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/door.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/assets/messageIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/assets/viewBookingCardButton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading