This project implements a multilayered positioning system utilizing machine learning models for classification and regression. It provides RESTful API endpoints to handle fingerprint data and retrieve predicted positions based on input access points.
The classification model is responsible for predicting the zone number based on the received access points data.
from util.feature_selection import open_joblib_file
from util.string_utils import StringUtils
classification_model = None
def load_classification_model():
global classification_model
classification_model = open_joblib_file(StringUtils.classification_model)
def classification_preds(X_test):
preds = classification_model.predict(X_test).tolist()[0]
return preds
The regression model predicts the X and Y coordinates of the position based on the input data.
from util.feature_selection import open_joblib_file
from util.string_utils import StringUtils
regression_model = None
def load_regression_model():
global regression_model
regression_model = open_joblib_file(StringUtils.regression_model)
def regression_preds(X_test):
preds = regression_model.predict(X_test).tolist()[0]
return preds
This module manages the database configuration and connection setup using environment variables.
import os
from dotenv import load_dotenv
from sqlalchemy import create_engine
# Loads the environment variable file
load_dotenv()
...
This module handles database sessions and model initialization.
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from database.config import get_database
engine = get_database()
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
...
This API manages the storage of fingerprint data.
from flask import Blueprint, request
from flask_restful import Api, Resource
from models import Point, AccessPoint
from database.db import db_session
point_app = Blueprint('point_app', __name__, url_prefix='/api/v1/fingerprint')
api = Api(point_app)
class PointAPI(Resource):
...
api.add_resource(PointAPI, '/points')
This API provides predictions for the position based on the provided access points.
from flask import Blueprint, request
from flask_restful import Api, Resource
from ml_models.classification import classification_preds
from ml_models.regression import regression_preds
from util.feature_selection import get_x_test
position_app = Blueprint('position_app', __name__, url_prefix='/api/v1/fingerprint')
api = Api(position_app)
class PositionAPI(Resource):
...
api.add_resource(PositionAPI, '/position')
This module handles conversion between database tables and DataFrames.
from datetime import datetime
import pandas as pd
from database.db import engine
from models import AccessPoint
def sql_table_to_df():
...
This module manages the selection and processing of features for model input.
import joblib
import numpy as np
from pathlib import Path
def open_joblib_file(file_path):
...
The application is structured in the following way:
project_root/
├── app.py
├── config.py
├── database/
│ ├── config.py
│ └── db.py
├── ml_models/
│ ├── classification.py
│ └── regression.py
├── point/
│ └── routes.py
├── position/
│ └── routes.py
├── util/
│ ├── db_to_df.py
│ └── feature_selection.py
└── requirements.txt
To run this project, make sure you have the following dependencies installed:
Flask
Flask-RESTful
SQLAlchemy
python-dotenv
joblib
numpy
pandas
-
Clone the repository:
git clone <repository_url> cd <repository_folder>
-
Install the required packages:
pip install -r requirements.txt
-
Set up your environment variables in a
.env
file based on the configuration provided inconfig.py
. -
Run the application:
python manager.py
-
Access the APIs via
http://localhost:3000/api/v1/fingerprint
.