commit 853529b871a554e2c01f43c437e82f9354c1a18e Author: Edwin Eames Date: Mon Jul 15 17:55:45 2024 -0400 first commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2b0834 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.12-bullseye + +ENV PYTHONFAULTHANDLER=1 + +ENV PYTHONUNBUFFERED=1 + +RUN mkdir -p /app + +COPY requirements.txt /app + +WORKDIR /app +RUN pip3 install fastapi +RUN pip3 install sqlalchemy +RUN pip3 install -r requirements.txt + +EXPOSE 8000 + +COPY . /app \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..3b0bcf9 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,17 @@ +FROM python:3.12-bullseye + +ENV PYTHONFAULTHANDLER=1 + +ENV PYTHONUNBUFFERED=1 + +RUN mkdir -p /app + +COPY requirements.txt /app + +WORKDIR /app + +RUN pip3 install -r requirements.txt + +EXPOSE 8001 + +COPY . /app \ No newline at end of file diff --git a/__pycache__/database.cpython-312.pyc b/__pycache__/database.cpython-312.pyc new file mode 100644 index 0000000..d5b6f3c Binary files /dev/null and b/__pycache__/database.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..843f197 Binary files /dev/null and b/__pycache__/main.cpython-312.pyc differ diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__pycache__/__init__.cpython-312.pyc b/app/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..cc71883 Binary files /dev/null and b/app/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models/__pycache__/__init__.cpython-312.pyc b/app/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..8d0c60e Binary files /dev/null and b/app/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/models/__pycache__/auto.cpython-312.pyc b/app/models/__pycache__/auto.cpython-312.pyc new file mode 100644 index 0000000..d89af21 Binary files /dev/null and b/app/models/__pycache__/auto.cpython-312.pyc differ diff --git a/app/models/auto.py b/app/models/auto.py new file mode 100644 index 0000000..c7a8d40 --- /dev/null +++ b/app/models/auto.py @@ -0,0 +1,46 @@ +from sqlalchemy import Column, Integer,\ + DECIMAL, Text,\ + VARCHAR, TIMESTAMP, Date, INTEGER +from datetime import datetime, timezone +from database import Base + + +class Auto_Temp(Base): + __tablename__ = 'auto_temp' + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + todays_date = Column(TIMESTAMP(), default=datetime.utcnow()) + temp = Column(DECIMAL(50, 2)) + temp_max = Column(DECIMAL(50, 2)) + temp_min = Column(DECIMAL(50, 2)) + temp_avg = Column(DECIMAL(50, 2)) + degree_day = Column(INTEGER()) + + + +class Auto_Delivery(Base): + __tablename__ = 'auto_delivery' + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + customer_id = Column(INTEGER()) + account_number = Column(VARCHAR(25)) + customer_town = Column(VARCHAR(140)) + customer_state = Column(INTEGER) + customer_address = Column(VARCHAR(1000)) + customer_zip = Column(VARCHAR(25)) + customer_full_name = Column(VARCHAR(250)) + last_fill = Column(TIMESTAMP()) + last_updated = Column(TIMESTAMP()) + estimated_gallons_left = Column(INTEGER()) + estimated_gallons_left_prev_day = Column(INTEGER()) + tank_height = Column(VARCHAR(25)) + tank_size = Column(VARCHAR(25)) + house_factor = Column(DECIMAL(5, 2)) \ No newline at end of file diff --git a/app/models/customer.py b/app/models/customer.py new file mode 100644 index 0000000..c41921b --- /dev/null +++ b/app/models/customer.py @@ -0,0 +1,32 @@ +from sqlalchemy import (Column, Integer, + DECIMAL, Text, + VARCHAR, TIMESTAMP, + Date, INTEGER) +from datetime import datetime, timezone +from database import Base + + +class Customer_Customer(Base): + __tablename__ = 'customer_customer' + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + account_number = Column(VARCHAR(25)) + customer_last_name = Column(VARCHAR(250)) + customer_first_name = Column(VARCHAR(250)) + customer_town = Column(VARCHAR(140)) + customer_state = Column(INTEGER) + customer_zip = Column(VARCHAR(25)) + customer_first_call = Column(TIMESTAMP()) + customer_email = Column(VARCHAR(500)) + customer_automatic = Column(INTEGER) + customer_phone_number = Column(VARCHAR(25)) + customer_home_type = Column(INTEGER) + customer_apt = Column(VARCHAR(140)) + customer_address = Column(VARCHAR(1000)) + company_id = Column(INTEGER) + + diff --git a/app/models/delivery.py b/app/models/delivery.py new file mode 100644 index 0000000..1ba7ff8 --- /dev/null +++ b/app/models/delivery.py @@ -0,0 +1,50 @@ +from sqlalchemy import (Column, Integer, + DECIMAL, Text, + VARCHAR, TIMESTAMP, Date) +import datetime +from database import Base + + +class Delivery(Base): + __tablename__ = "delivery_delivery" + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + customer_id = Column(Integer) + customer_name = Column(VARCHAR(1000)) + customer_address = Column(VARCHAR(1000)) + customer_town = Column(VARCHAR(140)) + customer_state = Column(VARCHAR(140)) + customer_zip = Column(Integer) + + gallons_ordered = Column(Integer) + customer_asked_for_fill = Column(Integer) + gallons_delivered = Column(DECIMAL(50, 2)) + customer_filled = Column(Integer) + + delivery_status = Column(Integer) + when_ordered = Column(TIMESTAMP(), default=datetime.datetime.utcnow()) + when_delivered = Column(TIMESTAMP(), default=None) + expected_delivery_date = Column(Date(), default=None) + automatic = Column(Integer) + oil_id = Column(Integer) + supplier_price = Column(DECIMAL(50, 2)) + customer_price = Column(DECIMAL(50, 2)) + customer_temperature = Column(DECIMAL(50, 2)) + dispatcher_notes = Column(Text()) + prime = Column(Integer) + same_day = Column(Integer) + payment_type = Column(Integer) + payment_card_id = Column(Integer) + cash_recieved = Column(DECIMAL(50, 2)) + + driver_employee_id = Column(Integer) + driver_first_name = Column(VARCHAR(140)) + driver_last_name = Column(VARCHAR(140)) + + pre_charge_amount = Column(DECIMAL(50, 2)) + total_price = Column(DECIMAL(50, 2)) + final_price = Column(DECIMAL(50, 2)) \ No newline at end of file diff --git a/app/models/money.py b/app/models/money.py new file mode 100644 index 0000000..95520f2 --- /dev/null +++ b/app/models/money.py @@ -0,0 +1,28 @@ +from sqlalchemy import (Column, Integer, + DECIMAL, Text, + VARCHAR, TIMESTAMP, Date) +from datetime import datetime, timezone +from database import Base + + +class MoneyDelivery(Base): + __tablename__ = 'money_delivery' + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + delivery_id = Column(Integer) + time_added = Column(TIMESTAMP(), default=datetime.utcnow()) + gallons_delivered = Column(DECIMAL(50, 2)) + supplier_price = Column(DECIMAL(50, 2)) + customer_price = Column(DECIMAL(50, 2)) + total_amount_oil = Column(DECIMAL(50, 2)) + total_amount_prime = Column(DECIMAL(50, 2)) + total_amount_same_day = Column(DECIMAL(50, 2)) + total_amount_fee = Column(DECIMAL(50, 2)) + total_amount = Column(DECIMAL(50, 2)) + taxes_paid = Column(DECIMAL(50, 2)) + total_profit = Column(DECIMAL(50, 2)) + total_profit_oil = Column(DECIMAL(50, 2)) \ No newline at end of file diff --git a/app/models/pricing.py b/app/models/pricing.py new file mode 100644 index 0000000..33b744e --- /dev/null +++ b/app/models/pricing.py @@ -0,0 +1,34 @@ +from sqlalchemy import (Column, Integer, DECIMAL, TIMESTAMP) +from datetime import datetime +from database import Base + + +class Pricing_Oil_Oil(Base): + __tablename__ = 'pricing_oil_oil' + + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + + price_from_supplier = Column(DECIMAL(50, 2)) + price_for_customer = Column(DECIMAL(50, 2)) + price_for_employee = Column(DECIMAL(50, 2)) + price_same_day = Column(DECIMAL(50, 2)) + price_prime = Column(DECIMAL(50, 2)) + date = Column(TIMESTAMP(), default=datetime.utcnow()) + + + +class Pricing_Taxes(Base): + __tablename__ = 'taxes_pricing' + + + id = Column(Integer, + primary_key=True, + autoincrement=True, + unique=False) + state_id = Column(Integer) + taxes_oil = Column(DECIMAL(50, 2)) + taxes_other = Column(DECIMAL(50, 2)) \ No newline at end of file diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/routers/__pycache__/__init__.cpython-312.pyc b/app/routers/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..80ae602 Binary files /dev/null and b/app/routers/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/routers/__pycache__/main.cpython-312.pyc b/app/routers/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..743c712 Binary files /dev/null and b/app/routers/__pycache__/main.cpython-312.pyc differ diff --git a/app/routers/main.py b/app/routers/main.py new file mode 100644 index 0000000..7c37b1d --- /dev/null +++ b/app/routers/main.py @@ -0,0 +1,107 @@ +from fastapi import APIRouter + +from database import session +from pyowm import OWM + +from app.models.auto import Auto_Delivery, Auto_Temp + + +router = APIRouter( + prefix="/main", + tags=["main"], + responses={404: {"description": "Not found"}}, +) + + + +def Average(lst): + return sum(lst) / len(lst) + +@router.route("/update", methods=["GET"]) +def update_auto(): + + + today_temp = session\ + .query(Auto_Temp)\ + .order_by(Auto_Temp.id.desc())\ + .first() + + # get all automatic customers + auto_customers = session\ + .query(Auto_Delivery)\ + .order_by(Auto_Delivery.last_updated.desc())\ + .limit(25) + + for f in auto_customers: + pass + + + + return ({"ok": True}), 200 + + +@router.get("/temp") +def update_temp(): + + temps = [] + + owm = OWM('21648d8c8d1a4ae495ace0b7810b4d36') + mgr = owm.weather_manager() + + # Search for current weather in London (Great Britain) and get details + observation = mgr.weather_at_place('Worcester, US') + w = observation.weather + + temp_dict_kelvin = w.temperature() # a dict in Kelvin units (default when no temperature units provided) + temp_dict_kelvin['temp_min'] + temp_dict_kelvin['temp_max'] + temp_dict_fahrenheit = w.temperature('fahrenheit') + + low_temp = temp_dict_kelvin['temp_min'] + high_temp = temp_dict_kelvin['temp_max'] + temps.append(temp_dict_fahrenheit['temp_max']) + temps.append(temp_dict_fahrenheit['temp_min']) + + get_avg = Average(temps) + rounded_temp = round(get_avg) + + dday = (65 - ((low_temp + high_temp) /2)) + + + add_new_temp = Auto_Temp( + temp = temp_dict_fahrenheit['temp'], + temp_max = temp_dict_fahrenheit['temp_max'], + temp_min = temp_dict_fahrenheit['temp_min'], + temp_avg = rounded_temp, + degree_day = dday + ) + + session.add(add_new_temp) + session.commit() + + + return ({"ok": True}), 200 + + +@router.get("/today") +def auto_today(): + today_auto = session.query().filter().first() + + return ({"ok": True}), 200 + + +@router.get("/week") +def auto_this_week(): + print("here") + return ({"ok": True}), 200 + + + +@router.get("/all") +def all_auto(): + return ({"ok": True}), 200 + + +@router.get("/completed") +def completed_auto(): + return ({"ok": True}), 200 \ No newline at end of file diff --git a/app/schema/delivery.py b/app/schema/delivery.py new file mode 100644 index 0000000..f20f825 --- /dev/null +++ b/app/schema/delivery.py @@ -0,0 +1,46 @@ +from pydantic import BaseModel, Field +from datetime import datetime, timezone + + +def datetime_now() -> datetime: + return datetime.now(timezone.utc) + +class DeliverPricing(BaseModel): + prime: bool + same_day: bool + gallons_delivered: float + + + +class SchemaDelivery(BaseModel): + customer_id: int + customer_name: str + customer_address: str + customer_town: str + customer_state: int + customer_zip: int + gallons_ordered: float + customer_asked_for_fill: int + gallons_delivered: float + customer_filled: int + delivery_status: int + when_ordered: datetime = Field(default_factory=datetime_now) + when_delivered: datetime = Field(default_factory=datetime_now) + expected_delivery_date: datetime = Field(default_factory=datetime_now) + automatic: int + oil_id: int + supplier_price: float + customer_price: float + customer_temperature: float + dispatcher_notes: str + prime: int + same_day: int + payment_type: int + payment_card_id: int + cash_recieved: float + driver_employee_id: int + driver_first_name: str + driver_last_name: str + pre_charge_amount: float + total_price: float + final_price: float \ No newline at end of file diff --git a/app/schema/money.py b/app/schema/money.py new file mode 100644 index 0000000..a80ac63 --- /dev/null +++ b/app/schema/money.py @@ -0,0 +1,21 @@ +from pydantic import BaseModel, Field +from datetime import datetime, timezone + + +def datetime_now() -> datetime: + return datetime.now(timezone.utc) + +class SchemaMoney(BaseModel): + delivery_id: int + time_added: datetime + gallons_delivered: float + supplier_price: float + customer_price: float + total_amount_oil: float + total_amount_prime: float + total_amount_same_day: float + total_amount_fee: float + total_amount: float + taxes_paid: float + total_profit: float + diff --git a/database.py b/database.py new file mode 100644 index 0000000..0242857 --- /dev/null +++ b/database.py @@ -0,0 +1,21 @@ +from sqlalchemy import create_engine +from sqlalchemy.engine import URL +from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import declarative_base + +url = URL.create( + drivername="postgresql", + username="postgres", + password="password", + host="192.168.1.204", + database="eamco", + port=5432 +) + +engine = create_engine(url) + +Session = sessionmaker(autocommit=False, autoflush=False, bind=engine) +session = Session() + +Base = declarative_base() +Base.metadata.create_all(engine) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..d285c6c --- /dev/null +++ b/main.py @@ -0,0 +1,29 @@ +from fastapi import FastAPI +from app.routers import main +from fastapi.middleware.cors import CORSMiddleware + +app = FastAPI() + +app.include_router(main.router) + + +origins = [ + "http://localhost:9000", + "https://localhost:5173", + "http://localhost", + +] + + + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +@app.get("/") +def read_root(): + return {"Status": "Auto Service is online"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..43bf3a5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +fastapi +uvicorn[standard] +psycopg2-binary +sqlalchemy +pyowm \ No newline at end of file