init
This commit is contained in:
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
RUN adduser -u 5678 --disabled-password --gecos "" appuser
|
||||
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN python -m pip install --no-cache-dir --upgrade -r requirements.txt
|
||||
COPY --chown=appuser:appuser *.py .
|
||||
COPY --chown=appuser:appuser invTypeMaterials.csv .
|
||||
|
||||
USER appuser
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
38
main.py
Normal file
38
main.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from fastapi import FastAPI
|
||||
from typing import List
|
||||
from schemas import Evepraisal, PriceReprocess
|
||||
import csv
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
invtypematerials = defaultdict(dict)
|
||||
with open("invTypeMaterials.csv") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
invtypematerials[int(row['typeID'])].update({int(row['materialTypeID']): int(row['quantity'])})
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
|
||||
@app.post("/reprocess/")
|
||||
async def reprocess(ep_items: Evepraisal, ep_mat: Evepraisal, efficiency: float = .55):
|
||||
matprices = {item.typeID: {'sell': item.prices.sell.min, 'buy': item.prices.buy.max} for item in ep_mat.items}
|
||||
|
||||
item_reprocess: List[PriceReprocess] = []
|
||||
for item in ep_items.items:
|
||||
buy_reprocess = sell_reprocess = 0.0
|
||||
for mat in invtypematerials[item.typeID]:
|
||||
buy_reprocess += matprices[mat]['buy'] * invtypematerials[item.typeID][mat] * efficiency
|
||||
sell_reprocess += matprices[mat]['sell'] * invtypematerials[item.typeID][mat] * efficiency
|
||||
item_reprocess.append(PriceReprocess(typeID=item.typeID,
|
||||
buy=item.prices.buy.max,
|
||||
sell=item.prices.sell.min,
|
||||
buy_reprocess=buy_reprocess,
|
||||
sell_reprocess=sell_reprocess,
|
||||
))
|
||||
return item_reprocess
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
fastapi
|
||||
httpx
|
||||
uvicorn[standard]
|
||||
51
schemas.py
Normal file
51
schemas.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Price(BaseModel):
|
||||
avg: float
|
||||
max: float
|
||||
median: float
|
||||
min: float
|
||||
percentile: float
|
||||
stddev: float
|
||||
volume: int
|
||||
order_count: int
|
||||
|
||||
class Prices(BaseModel):
|
||||
all: Price
|
||||
buy: Price
|
||||
sell: Price
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
typeID: int
|
||||
typeName: str
|
||||
typeVolume: float
|
||||
quantity: int
|
||||
prices: Prices
|
||||
|
||||
class Total_price(BaseModel):
|
||||
buy: float
|
||||
sell: float
|
||||
volume: float
|
||||
|
||||
class Evepraisal(BaseModel):
|
||||
id: str
|
||||
created: int
|
||||
kind: str
|
||||
market_name: str
|
||||
items: list[Item]
|
||||
totals: Total_price
|
||||
price_percentage: float
|
||||
raw: str
|
||||
|
||||
|
||||
class PriceReprocess(BaseModel):
|
||||
typeID: int
|
||||
buy: float
|
||||
sell: float
|
||||
buy_reprocess: float
|
||||
sell_reprocess: float
|
||||
|
||||
|
||||
Reference in New Issue
Block a user