Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/COS301-SE-2024/occupi in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
Tinashe-Austin committed Aug 12, 2024
2 parents f6f32c5 + fde50e2 commit 232077e
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 5 deletions.
4 changes: 4 additions & 0 deletions documentation/occupi-docs/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"index": "Introduction",
"api-documentation": "Api documentation",
"coding-standards": "Coding Standards",
"installation": {
"title": "Installation",
"type": "page"
},
"srs": {
"title": "Software Requirements Specification",
"type": "page"
Expand Down
127 changes: 127 additions & 0 deletions documentation/occupi-docs/pages/installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
### Occupi Installation Manual

---

### Mobile

---

#### Introduction
Occupi is an advanced occupancy prediction application designed to help organizations manage and optimize office space usage efficiently. Available on both Android and iOS platforms, the app leverages AI and machine learning to provide accurate predictions of office capacity, allowing for informed decision-making regarding space allocation and management. This manual will guide you through the necessary steps to install the Occupi mobile application on your device and ensure all system components are properly configured.

#### Prerequisites
Before installing Occupi, ensure the following prerequisites are met:

1. **Supported Devices**:
- Android: Version 8.0 (Oreo) or higher
- iOS: Version 13.0 or higher

2. **Internet Connectivity**:
- A stable internet connection is required for installation and regular use of the application.

3. **Mobile Device Permissions**:
- Location Services: Must be enabled for real-time occupancy tracking.
- Notifications: Enabled to receive alerts and updates.

**Installing Prerequisites**:
- For Android devices, ensure Google Play Services are up to date.
- For iOS devices, ensure the latest version of iOS is installed.
- Follow your device's standard procedure to enable location services and notifications under Settings.

#### Installation
Follow these steps to install the Occupi mobile app:

1. **Android Installation**:
- Open the Google Play Store on your Android device.
- Search for "Occupi."
- Tap on the app and select "Install."
- Once installed, open the app to begin setup.

2. **iOS Installation**:
- Open the App Store on your iOS device.
- Search for "Occupi."
- Tap on the app and select "Get."
- Authenticate if necessary, and the app will begin downloading and installing.
- Once installed, open the app to begin setup.

#### Deployment/Running
Once the Occupi app is installed, follow these steps to run it:

1. **Launching the App**:
- Locate the Occupi icon on your device’s home screen and tap to open it.

2. **Initial Setup**:
- The app will prompt you to enable necessary permissions, such as location services and notifications.
- Log in with your credentials or sign up if you are a new user.

3. **Backend Connection**:
- The app will automatically connect to the backend server to sync data. Ensure you have a stable internet connection.

4. **Using Occupi**:
- After the initial setup, you can start using the app to monitor and predict office occupancy.
- For detailed instructions on using Occupi, refer to the [User Manual](#).

---

### Occupi Web Interface Installation Manual

---

#### Introduction
The Occupi web interface is designed for admin users to manage office occupancy, view detailed predictions, and configure settings for the mobile application. This web-based platform is compatible with all major browsers, with optimal performance on Google Chrome, Microsoft Edge, and Firefox. This manual will guide you through the necessary steps to access and set up the Occupi web interface on your preferred browser.

#### Prerequisites
Before accessing the Occupi web interface, ensure the following prerequisites are met:

1. **Supported Browsers**:
- Google Chrome: Latest version
- Microsoft Edge: Latest version
- Firefox: Latest version

2. **Admin Access**:
- Ensure you have valid admin credentials to log in to the web interface.

3. **Internet Connectivity**:
- A stable internet connection is required to access and use the web interface effectively.

**Installing Prerequisites**:
- **Browser Installation**:
- **Google Chrome**:
- Visit [Google Chrome Download](https://www.google.com/chrome/) and follow the instructions to download and install the latest version.
- **Microsoft Edge**:
- Visit [Microsoft Edge Download](https://www.microsoft.com/edge) and follow the instructions to download and install the latest version.
- **Firefox**:
- Visit [Firefox Download](https://www.mozilla.org/firefox/new/) and follow the instructions to download and install the latest version.
- **Internet Connectivity**:
- Ensure your device is connected to a reliable internet network.

#### Installation
Since the Occupi web interface is a browser-based platform, no traditional installation is required. However, follow these steps to set up and access the web interface:

1. **Open Your Preferred Browser**:
- Launch Google Chrome, Microsoft Edge, or Firefox on your device.

2. **Access the Occupi Web Interface**:
- In the browser's address bar, enter the following URL: `https://admin.occupi.com`
- Press Enter to load the login page.

3. **Logging In**:
- Enter your admin credentials (username and password) on the login page.
- Click "Login" to access the dashboard.

#### Deployment/Running
Once logged in, you can start using the Occupi web interface:

1. **Navigating the Dashboard**:
- After logging in, you will be directed to the admin dashboard, where you can view occupancy data, manage settings, and generate reports.

2. **Admin Controls**:
- Use the sidebar to navigate through different sections, including Occupancy Predictions, User Management, and Settings.

3. **Saving and Bookmarking**:
- To quickly access the Occupi web interface in the future, bookmark the URL (`https://admin.occupi.com`) in your browser.

4. **Using the Interface**:
- For detailed instructions on using the Occupi web interface, refer to the [Admin User Manual](#).

---
129 changes: 124 additions & 5 deletions python-code/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from flask import Flask, request, jsonify
import logging
from flask_cors import CORS
from datetime import datetime, timedelta
from prediction import get_prediction
import joblib

# Initialize the Flask application
app = Flask(__name__)

CORS(app, resources={r"/*": {"origins": ["https://dev.occupi.tech", "https://app.occupi.tech"]}})

# Load the scaler
scaler = joblib.load('attendance_scaler.pkl')

Expand Down Expand Up @@ -35,8 +38,6 @@ def predict():
day_of_month = current_date.day
weekend = is_weekend(current_date)
special_event = is_special_event(current_date)
# Set factor based on special event
# factor = 1.5 if special_event else 1.0

predicted_class, predicted_attendance_level = get_prediction(day_of_week, month, day_of_month, weekend, special_event, scaler)

Expand Down Expand Up @@ -74,9 +75,6 @@ def predict_week():
weekend = is_weekend(date)
special_event = is_special_event(date)

# Set factor based on special event
# factor = 1.5 if special_event else 1.0

# Get prediction
predicted_class, predicted_attendance_level = get_prediction(day_of_week, month, day_of_month, weekend, special_event, scaler)

Expand All @@ -97,5 +95,126 @@ def predict_week():
logging.error(f"Error in predict_week endpoint: {str(e)}")
return jsonify({"error": str(e)}), 500

@app.route('/predict_date', methods=['GET'])
def predict_date():
try:
# Get the date from query parameters
date_str = request.args.get('date')
if not date_str:
return jsonify({"error": "Date parameter is required"}), 400

# Parse the date
date = datetime.strptime(date_str, '%Y-%m-%d')

# Extract day of the week, month, and day of the month
day_of_week = date.weekday()
month = date.month
day_of_month = date.day
weekend = is_weekend(date)
special_event = is_special_event(date)

# Get prediction
predicted_class, predicted_attendance_level = get_prediction(day_of_week, month, day_of_month, weekend, special_event, scaler)

return jsonify({
'Date': date_str,
'Day_of_Week': day_of_week,
'Month': month,
'Day_of_month': day_of_month,
'Is_Weekend': weekend,
'Special_Event': special_event,
'Predicted_Class': predicted_class,
'Predicted_Attendance_Level': predicted_attendance_level
})
except Exception as e:
logging.error(f"Error in predict_date endpoint: {str(e)}")
return jsonify({"error": str(e)}), 500

@app.route('/predict_week_from_date', methods=['GET'])
def predict_week_from_date():
try:
# Get the date from query parameters
date_str = request.args.get('date')
if not date_str:
return jsonify({"error": "Date parameter is required"}), 400

# Parse the date
start_date = datetime.strptime(date_str, '%Y-%m-%d')

predictions = []
for i in range(7):
# Calculate the date for each day of the week
date = start_date + timedelta(days=i)

# Extract day of the week, month, and day of the month
day_of_week = date.weekday()
month = date.month
day_of_month = date.day
weekend = is_weekend(date)
special_event = is_special_event(date)

# Get prediction
predicted_class, predicted_attendance_level = get_prediction(day_of_week, month, day_of_month, weekend, special_event, scaler)

# Append the results
predictions.append({
'Date': date.strftime('%Y-%m-%d'),
'Day_of_Week': day_of_week,
'Month': month,
'Day_of_month': day_of_month,
'Is_Weekend': weekend,
'Special_Event': special_event,
'Predicted_Class': predicted_class,
'Predicted_Attendance_Level': predicted_attendance_level
})

return jsonify(predictions)
except Exception as e:
logging.error(f"Error in predict_week_from_date endpoint: {str(e)}")
return jsonify({"error": str(e)}), 500

@app.route('/predict_7_days', methods=['GET'])
def predict_week_from_date():
try:
# Get the date from query parameters
date_str = request.args.get('date')
if not date_str:
return jsonify({"error": "Date parameter is required"}), 400

# Parse the date
start_date = datetime.strptime(date_str, '%Y-%m-%d')

predictions = []
for i in range(7):
# Calculate the date for each day of the week
date = start_date + timedelta(days=i)

# Extract day of the week, month, and day of the month
day_of_week = date.weekday()
month = date.month
day_of_month = date.day
weekend = is_weekend(date)
special_event = is_special_event(date)

# Get prediction
predicted_class, predicted_attendance_level = get_prediction(day_of_week, month, day_of_month, weekend, special_event, scaler)

# Append the results
predictions.append({
'Date': date.strftime('%Y-%m-%d'),
'Day_of_Week': day_of_week,
'Month': month,
'Day_of_month': day_of_month,
'Is_Weekend': weekend,
'Special_Event': special_event,
'Predicted_Class': predicted_class,
'Predicted_Attendance_Level': predicted_attendance_level
})

return jsonify(predictions)
except Exception as e:
logging.error(f"Error in predict_week_from_date endpoint: {str(e)}")
return jsonify({"error": str(e)}), 500

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=9000)
36 changes: 36 additions & 0 deletions python-code/docker-compose_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

services:
attendance-model:
build:
context: .
dockerfile: Dockerfile
container_name: attendance-model
networks:
- webnet
ports:
- "9000:9000"
extra_hosts:
- "host.docker.internal:host-gateway"
restart: on-failure:5
depends_on:
- model

model:
image: tensorflow/serving:latest
container_name: model
environment:
MODEL_NAME: attendance_model
volumes:
- /models/attendance_model:/models/attendance_model # Ensure this path is correct
ports:
- "8501:8501"
command: >
sh -c 'tensorflow_model_server --port=8501 --model_name=attendance_model --model_base_path=/models/attendance_model'
networks:
- webnet
restart: on-failure:5

networks:
webnet:
external: true
1 change: 1 addition & 0 deletions python-code/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ scikit-learn
seaborn
matplotlib
gunicorn
flask-cors

0 comments on commit 232077e

Please sign in to comment.