[add]: code refractoring and cleanup
This commit is contained in:
+8
-5
@@ -1,20 +1,23 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set the working directory in the container
|
||||
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/*
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY salary_analytics/ ./salary_analytics/
|
||||
|
||||
RUN mkdir -p output/csv output/plots output/models
|
||||
|
||||
ENV PYTHONPATH=/app
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=8000
|
||||
|
||||
ENV FLASK_APP=wsgi.py
|
||||
ENV FLASK_RUN_HOST=0.0.0.0
|
||||
|
||||
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
|
||||
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():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('salary_analytics.config')
|
||||
@@ -11,7 +20,7 @@ def create_app():
|
||||
migrate.init_app(app, db)
|
||||
|
||||
# Register blueprints or CLI commands here if needed
|
||||
from . import commands
|
||||
from .commands import commands
|
||||
app.cli.add_command(commands.upload_xls_cli)
|
||||
|
||||
return app
|
||||
@@ -1,10 +1,8 @@
|
||||
from django.conf import settings
|
||||
import httpx
|
||||
import json
|
||||
from salary_analytics.config import SIMBRELLA_BASE_URL, SIMBRELLA_ENDPOINT_RAC_CHECKS
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.config import SIMBRELLA_BASE_URL, SIMBRELLA_ENDPOINT_RAC_CHECKS
|
||||
from app.utils.logger import logger
|
||||
|
||||
class SimbrellaIntegration:
|
||||
BASE_URL = SIMBRELLA_BASE_URL
|
||||
@@ -1,11 +1,8 @@
|
||||
import time
|
||||
import logging
|
||||
import threading
|
||||
import requests
|
||||
from .config import SALARY_DETECT_URL, SALARY_DETECT_HEADERS, get_random_salary_payload
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
from ...config import SALARY_DETECT_URL, SALARY_DETECT_HEADERS, get_random_salary_payload
|
||||
from app.utils.logger import logger
|
||||
|
||||
class SalaryDetect:
|
||||
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 os
|
||||
from .config import DB_CONFIG, TABLE_NAME
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.utils.logger import logger
|
||||
|
||||
class DataLoader:
|
||||
def __init__(self):
|
||||
@@ -9,8 +9,7 @@ from .consistent_amount_analyzer import ConsistentAmountAnalyzer
|
||||
from .transaction_type_analyzer import TransactionTypeAnalyzer
|
||||
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
||||
from .salary_predictor import SalaryPredictor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.utils.logger import logger
|
||||
|
||||
class SalaryAnalyticsPipeline:
|
||||
def __init__(self):
|
||||
+1
-8
@@ -6,15 +6,8 @@ import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib_venn import venn3
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
from .config import MODEL_CONFIG, OUTPUT_PATHS
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.utils.logger import logger
|
||||
|
||||
class SalaryEarnerAnalyzer:
|
||||
def __init__(self, df):
|
||||
@@ -17,20 +17,15 @@ from sqlalchemy import text, Table, Column, Integer, String, Float, DateTime, Me
|
||||
import numpy as np
|
||||
import warnings
|
||||
import time
|
||||
from .main import SalaryAnalyticsPipeline
|
||||
from .analytics.services.main import SalaryAnalyticsPipeline
|
||||
from .config import OUTPUT_PATHS, TABLE_NAME, BATCH_RESULTS_TABLE
|
||||
from .data_loader import DataLoader
|
||||
from .salary_predictor import SalaryPredictor
|
||||
from .salary_earner_analyzer import SalaryEarnerAnalyzer
|
||||
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
|
||||
warnings.filterwarnings('ignore', category=RuntimeWarning, module='numpy')
|
||||
@@ -2,8 +2,8 @@ import click
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
from flask.cli import with_appcontext
|
||||
from salary_analytics.app.extensions import db
|
||||
from salary_analytics.app.models import RawTransaction
|
||||
from app.extensions import db
|
||||
from app.models import RawTransaction
|
||||
|
||||
@click.group()
|
||||
def commands():
|
||||
@@ -2,12 +2,10 @@
|
||||
Database operations module for salary analytics.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from .config import BATCH_RESULTS_TABLE
|
||||
from datetime import datetime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.utils.logger import logger
|
||||
|
||||
class DatabaseOperations:
|
||||
def __init__(self, engine):
|
||||
@@ -1,4 +1,4 @@
|
||||
from .extensions import db
|
||||
from app.extensions import db
|
||||
|
||||
class RawTransaction(db.Model):
|
||||
__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: .
|
||||
ports:
|
||||
- "${APP_PORT:-4800}:8000"
|
||||
volumes:
|
||||
- ./output:/app/output
|
||||
environment:
|
||||
- DB_USER=salaryloan
|
||||
- DB_PASSWORD=salaryloan
|
||||
- DB_NAME=salaryloan
|
||||
- DB_PORT=10532
|
||||
- DB_HOST=dev-data.simbrellang.net
|
||||
- FLASK_APP=${FLASK_APP}
|
||||
- FLASK_ENV=${FLASK_ENV}
|
||||
- DATABASE_URL=postgresql+psycopg2://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
|
||||
volumes:
|
||||
- .:/app
|
||||
- ./output:/app/output
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- salary_network
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ if config.config_file_name is not None:
|
||||
# from myapp import Base
|
||||
# target_metadata = Base.metadata
|
||||
from flask import current_app
|
||||
from salary_analytics.app.extensions import db
|
||||
from app.extensions import db
|
||||
|
||||
config.set_main_option('sqlalchemy.url',
|
||||
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
|
||||
|
||||
+3
-1
@@ -17,4 +17,6 @@ openpyxl>=3.0.10
|
||||
Flask>=2.0.0
|
||||
Flask-SQLAlchemy>=3.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