Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3a2528d
project startup instructions in README
jiayangliu-LJY Oct 20, 2024
6282487
revoke mod on README
jiayangliu-LJY Oct 30, 2024
9943d89
update .gitignore to ignore venv files
jiayangliu-LJY Nov 5, 2024
b4d0a9c
instructions on running the project in README
jiayangliu-LJY Nov 5, 2024
19733ea
Convert gender/citizen from text to digit
jiayangliu-LJY Nov 5, 2024
0256a17
Merge branch 'criteria2'
jiayangliu-LJY Nov 5, 2024
e0c7afa
refactor: clean_input_data
jiayangliu-LJY Nov 5, 2024
9ea744e
refactor: alias in PredictionInput
jiayangliu-LJY Nov 5, 2024
2bc0698
refactor: data type conversion
jiayangliu-LJY Nov 7, 2024
bb0ac74
refactor: preserve col order in .env config file
jiayangliu-LJY Nov 7, 2024
014f5d7
Merge branch 'criteria2'
jiayangliu-LJY Nov 7, 2024
229063a
Update sprints
jiayangliu-LJY Nov 7, 2024
f8fc182
add test code
Nov 13, 2024
2cc1df2
modelchangingfeature
MollyMoriJing Nov 18, 2024
9e1a32a
update sprint3
jiayangliu-LJY Nov 19, 2024
e6ea601
create pylint-action
JiayangLJY Nov 21, 2024
ecb532c
update pylint-action
jiayangliu-LJY Nov 21, 2024
731ffb0
exclude test files
jiayangliu-LJY Nov 21, 2024
1f1f40e
Create docker-action.yml
JiayangLJY Nov 27, 2024
b96d340
add dockerfile
jiayangliu-LJY Nov 27, 2024
d8c67be
refine docker-action
jiayangliu-LJY Nov 27, 2024
7e8256d
Merge pull request #15 from JiayangLJY/test
ShqiW Nov 27, 2024
130d319
run test
Nov 27, 2024
b5c0df0
run test code again
Nov 27, 2024
a2d653d
sleep + app/tests/test
Nov 27, 2024
26bacb3
update requirements
Nov 27, 2024
b7c7839
re-update req
Nov 27, 2024
6c5765c
update reqs
Nov 27, 2024
d11f2ac
modified
MollyMoriJing Nov 28, 2024
80acd44
Merge branch 'main' into criteria1
MollyMoriJing Nov 28, 2024
3ba9736
fix: read configs in logic.py, fix model training in model.py
jiayangliu-LJY Dec 2, 2024
6039465
remove cols in .env
jiayangliu-LJY Dec 2, 2024
92de16c
feat: feature cols in .env
jiayangliu-LJY Dec 2, 2024
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
54 changes: 54 additions & 0 deletions .github/workflows/docker-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Docker-Action

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-test:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Log in to Docker Hub (optional, if pushing images)
# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# Step 3: Build the Docker image
- name: Build Docker image
run: |
docker build -t thoughtful-app .

# Step 4: Run the Docker container
- name: Run Docker container
run: |
docker run -d --name thoughtful-app-container thoughtful-app

# Step 5: Run tests inside the container
# - name: Run tests
# run: |
# docker exec thoughtful-app-container python /app/clients/service/model.py
# Step 5: Run tests inside the container
- name: Run tests
run: |
docker exec thoughtful-app-container python /app/tests/test.py

# Step 6: Clean up
- name: Stop and remove container
run: |
docker stop thoughtful-app-container
docker rm thoughtful-app-container

- name: Remove Docker image
run: |
docker rmi thoughtful-app
25 changes: 25 additions & 0 deletions .github/workflows/pylint-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pylint-Action

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
echo "::log::Pylint processing"
pylint --disable=C,R,W app/*.py
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@
.idea
__pycache__
.DS_Store

# Ignore virtual environment folder
env/
venv/

# Ignore Python cache files
__pycache__/
*.pyc
*.pyo

# Ignore Jupyter Notebook checkpoints
.ipynb_checkpoints/

# Ignore VS Code settings
.vscode/

# Ignore shell Scripts
*.sh
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use an official Python runtime as a parent image
FROM python:3.10-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Run tests by default
# CMD ["python", "/app/clients/service/model.py"]
CMD ["sleep","1h"]
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,102 @@ This will contain the model used for the project that based on the input informa
The model works off of dummy data of several combinations of clients alongside the interventions chosen for them as well as their success rate at finding a job afterward. The model will be updated by the case workers by inputing new data for clients with their updated outcome information, and it can be updated on a daily, weekly, or monthly basis.

This also has an API file to interact with the front end, and logic in order to process the interventions coming from the front end. This includes functions to clean data, create a matrix of all possible combinations in order to get the ones with the highest increase of success, and output the results in a way the front end can interact with.

## Run the FastAPI project

- Clone the git repo

```bash
# clone the project from git repo
git clone https://github.com/JiayangLJY/CommonAssessmentTool-Group-Thoughtful.git
```



* Prepare the virtual environment

```bash
# cd to the project root dir
cd CommonAssessmentTool-Group-Thoughtful

# create a virtual env for the current project
python3 -m venv venv

# activate the virtual env
source venv/bin/activate

# install denpendency packages
pip install -r requirements.txt

# export python path
export PYTHONPATH=$(pwd):$PYTHONPATH
```

> - to deactivate the current virtual env:
>
> ```bash
> deactivate
> ```



- Run Fastapi application

```bash
# cd to the {project}/app dir
cd app

# run project in dev mode
fastapi dev main.py
```

- Then open the url `http://127.0.0.1:8000/docs` in the browser to view the doc page of the current running project



## Sprint 1

4 tasks have been assigned to each of the group member:

1. Configurable machine learning model

- A config file will be included to configure the type and hyperparameter for ML model
- Create an abstraction layer for training and evaluation

2. Maintenance on form data naming, ordering and converting

- The naming and order of the form data will be uniformly maintained in the schema.py
- Text conversion will be encapsulated within the data model

3. Unit tests for server-side data processing steps

- Test model selection logic in `/predict` endpoint
- Test data processing logic of `interpret_and_calculate()`
- Test frontend validation and form submission
- Validate the input data

4. Functional test for front-back end interaction

- Update the frontend to support dynamic model selection and hyperparameter configuration
- Conduct comprehensive integration tests to ensure the new features work correctly across the API and frontend



## Sprint 2

- Environments of backend and front end projects were successfully set up and both projects are now runnable in our local machines
- Intergrated test was perfromed on the `clients/predictions` API to make sure the API is working
- `field_serializer` from Pydantic package was used to convert string type into numerical types
- We are investigating FastAPI docs and finding that we can use environment variables to configure some parameters in code
- Primary study showed that we need to retrieve some intermediate variables to suit our code with test



## Sprint 3

- Different machine learning models, including LinearRegression, GradientBoostingRegressor and SVR were trained and tested to expand the choice in prediction.
- The task of data type convertion was refactored to be conducted by the `PredictionInput` class.
- Order of features (columns from the frontend form) was configured in `.env` file.
- Unit tests were added to make sure the code works during the refactoring work.
- Intergrated test was perfromed on the `clients/predictions` API to make sure the API is working.

10 changes: 10 additions & 0 deletions app/clients/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FEATURE_COLS_IN_SEQ=["age", "gender", "work_experience", "canada_workex", "dep_num", "canada_born", "citizen_status", "level_of_schooling", "fluent_english", "reading_english_scale", "speaking_english_scale", "writing_english_scale", "numeracy_scale", "computer_scale", "transportation_bool", "caregiver_bool", "housing", "income_source", "felony_bool", "attending_school", "currently_employed", "substance_use", "time_unemployed", "need_mental_health_support_bool"]
#FEATURE_COLS_IN_SEQ=["age", "gender", "canada_workex", "work_experience", "dep_num", "canada_born", "citizen_status", "level_of_schooling", "fluent_english", "reading_english_scale", "speaking_english_scale", "writing_english_scale", "numeracy_scale", "computer_scale", "transportation_bool", "caregiver_bool", "housing", "income_source", "felony_bool", "attending_school", "currently_employed", "substance_use", "time_unemployed", "need_mental_health_support_bool"]


# Options: RandomForestRegressor, LinearRegression, GradientBoostingRegressor, SVR
MODEL_TYPE=SVR
MODEL_OUTPUT_NAME=svr_model.pkl

#MODEL_TYPE=RandomForestRegressor
#MODEL_OUTPUT_NAME=random_forest_model.pkl
10 changes: 4 additions & 6 deletions app/clients/router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from fastapi import APIRouter
from fastapi.responses import HTMLResponse

from app.clients.service.logic import interpret_and_calculate
from app.clients.schema import PredictionInput


router = APIRouter(prefix="/clients", tags=["clients"])


@router.post("/predictions")
async def predict(data: PredictionInput):
print("HERE")
print(data.model_dump())
return interpret_and_calculate(data.model_dump())


print(data.model_dump(by_alias=True))
return interpret_and_calculate(data.model_dump(by_alias=True))
Loading