[add]: code refractoring and cleanup
This commit is contained in:
+8
-5
@@ -1,20 +1,23 @@
|
|||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the current directory contents into the container at /app
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y libpq-dev && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y libpq-dev && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
COPY salary_analytics/ ./salary_analytics/
|
|
||||||
|
|
||||||
RUN mkdir -p output/csv output/plots output/models
|
RUN mkdir -p output/csv output/plots output/models
|
||||||
|
|
||||||
ENV PYTHONPATH=/app
|
|
||||||
ENV HOST=0.0.0.0
|
ENV FLASK_APP=wsgi.py
|
||||||
ENV PORT=8000
|
ENV FLASK_RUN_HOST=0.0.0.0
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["uvicorn", "salary_analytics.api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "wsgi:wsgi_app"]
|
||||||
@@ -2,6 +2,15 @@ from flask import Flask
|
|||||||
import os
|
import os
|
||||||
from .extensions import db, migrate
|
from .extensions import db, migrate
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Salary Analytics Package
|
||||||
|
A package for analyzing and predicting salary patterns from transaction data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__version__ = "0.1.0"
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object('salary_analytics.config')
|
app.config.from_object('salary_analytics.config')
|
||||||
@@ -11,7 +20,7 @@ def create_app():
|
|||||||
migrate.init_app(app, db)
|
migrate.init_app(app, db)
|
||||||
|
|
||||||
# Register blueprints or CLI commands here if needed
|
# Register blueprints or CLI commands here if needed
|
||||||
from . import commands
|
from .commands import commands
|
||||||
app.cli.add_command(commands.upload_xls_cli)
|
app.cli.add_command(commands.upload_xls_cli)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import httpx
|
import httpx
|
||||||
import json
|
import json
|
||||||
from salary_analytics.config import SIMBRELLA_BASE_URL, SIMBRELLA_ENDPOINT_RAC_CHECKS
|
from app.config import SIMBRELLA_BASE_URL, SIMBRELLA_ENDPOINT_RAC_CHECKS
|
||||||
import logging
|
from app.utils.logger import logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class SimbrellaIntegration:
|
class SimbrellaIntegration:
|
||||||
BASE_URL = SIMBRELLA_BASE_URL
|
BASE_URL = SIMBRELLA_BASE_URL
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
import threading
|
import threading
|
||||||
import requests
|
import requests
|
||||||
from .config import SALARY_DETECT_URL, SALARY_DETECT_HEADERS, get_random_salary_payload
|
from ...config import SALARY_DETECT_URL, SALARY_DETECT_HEADERS, get_random_salary_payload
|
||||||
|
from app.utils.logger import logger
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class SalaryDetect:
|
class SalaryDetect:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
from .main import SalaryAnalyticsPipeline
|
||||||
|
from .data_loader import DataLoader
|
||||||
|
from .keyword_analyzer import KeywordAnalyzer
|
||||||
|
from .consistent_amount_analyzer import ConsistentAmountAnalyzer
|
||||||
|
from .transaction_type_analyzer import TransactionTypeAnalyzer
|
||||||
|
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
||||||
|
from .salary_predictor import SalaryPredictor
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Salary Analytics Package
|
||||||
|
A package for analyzing and predicting salary patterns from transaction data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__version__ = "0.1.0"
|
||||||
|
__all__ = [
|
||||||
|
"SalaryAnalyticsPipeline",
|
||||||
|
"DataLoader",
|
||||||
|
"KeywordAnalyzer",
|
||||||
|
"ConsistentAmountAnalyzer",
|
||||||
|
"TransactionTypeAnalyzer",
|
||||||
|
"SalaryEarnerAnalyzer",
|
||||||
|
"SalaryPredictor"
|
||||||
|
]
|
||||||
@@ -8,8 +8,7 @@ from datetime import datetime
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from .config import DB_CONFIG, TABLE_NAME
|
from .config import DB_CONFIG, TABLE_NAME
|
||||||
|
from app.utils.logger import logger
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class DataLoader:
|
class DataLoader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -9,8 +9,7 @@ from .consistent_amount_analyzer import ConsistentAmountAnalyzer
|
|||||||
from .transaction_type_analyzer import TransactionTypeAnalyzer
|
from .transaction_type_analyzer import TransactionTypeAnalyzer
|
||||||
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
||||||
from .salary_predictor import SalaryPredictor
|
from .salary_predictor import SalaryPredictor
|
||||||
|
from app.utils.logger import logger
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class SalaryAnalyticsPipeline:
|
class SalaryAnalyticsPipeline:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
+1
-8
@@ -6,15 +6,8 @@ import pandas as pd
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib_venn import venn3
|
from matplotlib_venn import venn3
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
|
||||||
from .config import MODEL_CONFIG, OUTPUT_PATHS
|
from .config import MODEL_CONFIG, OUTPUT_PATHS
|
||||||
|
from app.utils.logger import logger
|
||||||
# Configure logging
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO,
|
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class SalaryEarnerAnalyzer:
|
class SalaryEarnerAnalyzer:
|
||||||
def __init__(self, df):
|
def __init__(self, df):
|
||||||
@@ -17,20 +17,15 @@ from sqlalchemy import text, Table, Column, Integer, String, Float, DateTime, Me
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import warnings
|
import warnings
|
||||||
import time
|
import time
|
||||||
from .main import SalaryAnalyticsPipeline
|
from .analytics.services.main import SalaryAnalyticsPipeline
|
||||||
from .config import OUTPUT_PATHS, TABLE_NAME, BATCH_RESULTS_TABLE
|
from .config import OUTPUT_PATHS, TABLE_NAME, BATCH_RESULTS_TABLE
|
||||||
from .data_loader import DataLoader
|
from .data_loader import DataLoader
|
||||||
from .salary_predictor import SalaryPredictor
|
from .salary_predictor import SalaryPredictor
|
||||||
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
||||||
from .db_operations import DatabaseOperations
|
from .db_operations import DatabaseOperations
|
||||||
from .salary_detect import SalaryDetect
|
from .analytics.integrations.salary_detect import SalaryDetect
|
||||||
|
from app.utils.logger import logger
|
||||||
|
|
||||||
# Configure logging
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO,
|
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# Suppress warnings
|
# Suppress warnings
|
||||||
warnings.filterwarnings('ignore', category=RuntimeWarning, module='numpy')
|
warnings.filterwarnings('ignore', category=RuntimeWarning, module='numpy')
|
||||||
@@ -2,8 +2,8 @@ import click
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
from salary_analytics.app.extensions import db
|
from app.extensions import db
|
||||||
from salary_analytics.app.models import RawTransaction
|
from app.models import RawTransaction
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def commands():
|
def commands():
|
||||||
@@ -2,12 +2,10 @@
|
|||||||
Database operations module for salary analytics.
|
Database operations module for salary analytics.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
from .config import BATCH_RESULTS_TABLE
|
from .config import BATCH_RESULTS_TABLE
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from app.utils.logger import logger
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class DatabaseOperations:
|
class DatabaseOperations:
|
||||||
def __init__(self, engine):
|
def __init__(self, engine):
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from .extensions import db
|
from app.extensions import db
|
||||||
|
|
||||||
class RawTransaction(db.Model):
|
class RawTransaction(db.Model):
|
||||||
__tablename__ = 'analytics_raw_transactions'
|
__tablename__ = 'analytics_raw_transactions'
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||||
|
handlers=[
|
||||||
|
# logging.StreamHandler(),
|
||||||
|
logging.FileHandler("app.log", mode='a') # Log to file
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger("DetectionService")
|
||||||
+6
-7
@@ -3,14 +3,13 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT:-4800}:8000"
|
- "${APP_PORT:-4800}:8000"
|
||||||
volumes:
|
|
||||||
- ./output:/app/output
|
|
||||||
environment:
|
environment:
|
||||||
- DB_USER=salaryloan
|
- FLASK_APP=${FLASK_APP}
|
||||||
- DB_PASSWORD=salaryloan
|
- FLASK_ENV=${FLASK_ENV}
|
||||||
- DB_NAME=salaryloan
|
- DATABASE_URL=postgresql+psycopg2://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
|
||||||
- DB_PORT=10532
|
volumes:
|
||||||
- DB_HOST=dev-data.simbrellang.net
|
- .:/app
|
||||||
|
- ./output:/app/output
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- salary_network
|
- salary_network
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ if config.config_file_name is not None:
|
|||||||
# from myapp import Base
|
# from myapp import Base
|
||||||
# target_metadata = Base.metadata
|
# target_metadata = Base.metadata
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from salary_analytics.app.extensions import db
|
from app.extensions import db
|
||||||
|
|
||||||
config.set_main_option('sqlalchemy.url',
|
config.set_main_option('sqlalchemy.url',
|
||||||
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
|
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ Flask>=2.0.0
|
|||||||
Flask-SQLAlchemy>=3.0.0
|
Flask-SQLAlchemy>=3.0.0
|
||||||
Flask-Migrate>=4.0.0
|
Flask-Migrate>=4.0.0
|
||||||
alembic>=1.8.0
|
alembic>=1.8.0
|
||||||
|
requests>=2.26.0
|
||||||
|
gunicorn
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import os
|
|
||||||
from salary_analytics.app import create_app
|
|
||||||
|
|
||||||
app = create_app()
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
"""
|
|
||||||
Salary Analytics Package
|
|
||||||
A package for analyzing and predicting salary patterns from transaction data.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__version__ = "0.1.0"
|
|
||||||
Reference in New Issue
Block a user