first commit
This commit is contained in:
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@@ -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
|
||||||
17
Dockerfile.prod
Normal file
17
Dockerfile.prod
Normal file
@@ -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
|
||||||
BIN
__pycache__/database.cpython-312.pyc
Normal file
BIN
__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-312.pyc
Normal file
BIN
__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
BIN
app/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
0
app/models/__init__.py
Normal file
0
app/models/__init__.py
Normal file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/auto.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/auto.cpython-312.pyc
Normal file
Binary file not shown.
46
app/models/auto.py
Normal file
46
app/models/auto.py
Normal file
@@ -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))
|
||||||
32
app/models/customer.py
Normal file
32
app/models/customer.py
Normal file
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
50
app/models/delivery.py
Normal file
50
app/models/delivery.py
Normal file
@@ -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))
|
||||||
28
app/models/money.py
Normal file
28
app/models/money.py
Normal file
@@ -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))
|
||||||
34
app/models/pricing.py
Normal file
34
app/models/pricing.py
Normal file
@@ -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))
|
||||||
0
app/routers/__init__.py
Normal file
0
app/routers/__init__.py
Normal file
BIN
app/routers/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/routers/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/routers/__pycache__/main.cpython-312.pyc
Normal file
BIN
app/routers/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
107
app/routers/main.py
Normal file
107
app/routers/main.py
Normal file
@@ -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
|
||||||
46
app/schema/delivery.py
Normal file
46
app/schema/delivery.py
Normal file
@@ -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
|
||||||
21
app/schema/money.py
Normal file
21
app/schema/money.py
Normal file
@@ -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
|
||||||
|
|
||||||
21
database.py
Normal file
21
database.py
Normal file
@@ -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)
|
||||||
29
main.py
Normal file
29
main.py
Normal file
@@ -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"}
|
||||||
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
fastapi
|
||||||
|
uvicorn[standard]
|
||||||
|
psycopg2-binary
|
||||||
|
sqlalchemy
|
||||||
|
pyowm
|
||||||
Reference in New Issue
Block a user