Skip to content

The Apartment Allocation System is a FastAPI app that randomly assigns apartments from Excel files, tracks allocations, and allows data export or reset. It’s lightweight and deployable on AWS EC2.

Notifications You must be signed in to change notification settings

nimradev064/Apartment-Allocation-System

Repository files navigation

# 🏢 Apartment Allocation System

This is a FastAPI-based service that manages apartment allocation from predefined Excel blocks. It reads customer records, randomly assigns apartments, tracks remaining records, and allows for data resets and exports.

---

## 📦 Features

- Randomly fetch and remove customer records from Excel files.
- Track allocations and remaining records.
- Export assigned records as a downloadable Excel file.
- Reset data to the original state.
- CORS enabled for cross-origin access.

---

## 🧾 Directory Overview

├── main.py # FastAPI application
├── Resources/ # Active Excel files (Block_A/B/C.xlsx)
├── Original_Folder/ # Backup of the original Excel files
├── Final_output.xlsx # Collected assigned records (auto-created)
├── Preprocessing.ipynb # Jupyter notebook for manual data preparation
└── README.md # This documentation


---

## 🚀 API Endpoints

### `GET /records`
- Fetches one random record from a non-empty block (A, B, or C).
- Removes the record from the source file and adds it to `Final_output.xlsx`.

### `GET /download`
- Download the `Final_output.xlsx` file.

### `GET /reset`
- Deletes `Final_output.xlsx`.
- Restores original block files from `Original_Folder` into `Resources`.

---

## 📊 Data Format Requirements

Each Excel file must include the following **required columns**:
- `Customer Name`
- `Number of Rooms`
- `Type of Apartment`

Optional column:
- `FlatID` — if present, used to generate the full `Flat_ID`.

---

## ⚙️ Setup Instructions

1. Install dependencies:
```bash
pip install fastapi uvicorn pandas openpyxl
  1. Run the application:
uvicorn main:app --reload
  1. Open your browser and visit:
http://127.0.0.1:8000/docs

🧹 Preprocessing

The Preprocessing.ipynb file contains logic for cleaning or preparing Excel data before use. This may involve:

  • Formatting column names
  • Generating missing IDs
  • Removing invalid rows

Run this notebook before placing files in Resources/.


☁️ Deployment on AWS EC2 Instance

Follow these steps to deploy this API on an AWS EC2 server:

1. Launch EC2 Instance

  • Use Ubuntu (recommended).
  • Open ports 22, 80, and 8000 in the Security Group.

2. Connect to EC2 via SSH

ssh -i your-key.pem ubuntu@your-ec2-public-ip

3. Install Python and Pip

sudo apt update
sudo apt install python3-pip python3-venv -y

4. Clone or Upload Your Project

git clone https://github.com/your-repo-url.git
cd your-project-folder

Or use scp to upload files:

scp -i your-key.pem -r ./local-folder ubuntu@your-ec2-public-ip:/home/ubuntu/

5. Install Dependencies in a Virtual Environment

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Or manually:

pip install fastapi uvicorn pandas openpyxl

6. Run the App

uvicorn main:app --host 0.0.0.0 --port 8000

7. Access API

Go to:

http://your-ec2-public-ip:8000/docs

For production, consider using Gunicorn + Nginx or PM2 for process management.


About

The Apartment Allocation System is a FastAPI app that randomly assigns apartments from Excel files, tracks allocations, and allows data export or reset. It’s lightweight and deployable on AWS EC2.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published