commit 270da5f92beda45d8e7da0ec9950170daf9f5683 Author: Kaladaran Date: Tue Jul 25 20:51:15 2023 +0200 init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cbdb117 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..11817bf --- /dev/null +++ b/main.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d3f6d75 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi +httpx +uvicorn[standard] \ No newline at end of file diff --git a/schemas.py b/schemas.py new file mode 100644 index 0000000..245daf7 --- /dev/null +++ b/schemas.py @@ -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 + +