init
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user