cleanup & prepare for 2nd db
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
from sqlmodel import create_engine, SQLModel, Session
|
from sqlmodel import create_engine, Session
|
||||||
|
|
||||||
from eveal import models_sde
|
from eveal import models_sde
|
||||||
|
|
||||||
sqlite_file_name = "eveal.db"
|
sqlite_sde_file_name = "sde.db"
|
||||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
sde_engine = create_engine(f"sqlite:///{sqlite_sde_file_name}", echo=True, future=True)
|
||||||
engine = create_engine(sqlite_url, echo=True, future=True)
|
|
||||||
|
|
||||||
def get_session():
|
def get_sde_session():
|
||||||
db = Session(engine)
|
db = Session(sde_engine)
|
||||||
try:
|
try:
|
||||||
yield db
|
yield db
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ from typing import List
|
|||||||
from sqlmodel import SQLModel, Session, select
|
from sqlmodel import SQLModel, Session, select
|
||||||
|
|
||||||
from eveal.schemas import Evepraisal, PriceReprocess
|
from eveal.schemas import Evepraisal, PriceReprocess
|
||||||
from eveal.database import engine, get_session
|
from eveal.database import sde_engine, get_sde_session
|
||||||
from eveal import models_sde
|
from eveal import models_sde
|
||||||
|
|
||||||
SQLModel.metadata.create_all(engine)
|
SQLModel.metadata.create_all(sde_engine) # remove? db should be created by import_sde.py
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
||||||
@@ -21,13 +21,13 @@ async def root():
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/reprocess/")
|
@app.post("/reprocess/")
|
||||||
async def reprocess(ep_items: Evepraisal, ep_mat: Evepraisal, efficiency: float = .55, db: Session = Depends(get_session)):
|
async def reprocess(ep_items: Evepraisal, ep_mat: Evepraisal, efficiency: float = .55, sde: Session = Depends(get_sde_session)):
|
||||||
matprices = {item.typeID: {'sell': item.prices.sell.min, 'buy': item.prices.buy.max} for item in ep_mat.items}
|
matprices = {item.typeID: {'sell': item.prices.sell.min, 'buy': item.prices.buy.max} for item in ep_mat.items}
|
||||||
|
|
||||||
item_reprocess: List[PriceReprocess] = []
|
item_reprocess: List[PriceReprocess] = []
|
||||||
for rawitem in ep_items.items:
|
for rawitem in ep_items.items:
|
||||||
# item = db.exec(select(models_sde.Type).where(models_sde.Type.id == rawitem.typeID)).one()
|
# item = sde.exec(select(models_sde.Type).where(models_sde.Type.id == rawitem.typeID)).one()
|
||||||
item = db.get(models_sde.Type, rawitem.typeID)
|
item = sde.get(models_sde.Type, rawitem.typeID)
|
||||||
buy_reprocess = sell_reprocess = 0.0
|
buy_reprocess = sell_reprocess = 0.0
|
||||||
for mat in item.materials.all():
|
for mat in item.materials.all():
|
||||||
buy_reprocess += matprices[mat.type.id]['buy'] * mat.quantity * efficiency
|
buy_reprocess += matprices[mat.type.id]['buy'] * mat.quantity * efficiency
|
||||||
|
|||||||
@@ -1,28 +1,32 @@
|
|||||||
import yaml
|
import yaml
|
||||||
from eveal.database import engine
|
from eveal.database import sde_engine, sqlite_sde_file_name
|
||||||
from sqlmodel import Session, SQLModel
|
from sqlmodel import Session, SQLModel
|
||||||
from eveal import models_sde
|
from eveal import models_sde
|
||||||
|
|
||||||
import os
|
import os
|
||||||
os.remove("eveal.db")
|
try:
|
||||||
SQLModel.metadata.create_all(engine)
|
os.remove(sqlite_sde_file_name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
SQLModel.metadata.create_all(sde_engine)
|
||||||
|
|
||||||
|
|
||||||
print("Importing SDE data...")
|
print("Importing SDE data...")
|
||||||
print("Importing icons...")
|
print("Importing icons...")
|
||||||
with open("static_eve/sde/fsd/iconIDs.yaml", "r") as f:
|
with open("static_eve/sde/fsd/iconIDs.yaml", "r", encoding="utf-8") as f:
|
||||||
icons = yaml.safe_load(f)
|
icons = yaml.safe_load(f)
|
||||||
|
|
||||||
with Session(engine) as db:
|
with Session(sde_engine) as db:
|
||||||
for id, icon in icons.items():
|
for id, icon in icons.items():
|
||||||
db.add(models_sde.Icon(id=id, **icon))
|
db.add(models_sde.Icon(id=id, **icon))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
print("Importing categories...")
|
print("Importing categories...")
|
||||||
with open("static_eve/sde/fsd/categoryIDs.yaml", "r") as f:
|
with open("static_eve/sde/fsd/categoryIDs.yaml", "r", encoding="utf-8") as f:
|
||||||
categories = yaml.safe_load(f)
|
categories = yaml.safe_load(f)
|
||||||
|
|
||||||
with Session(engine) as db:
|
with Session(sde_engine) as db:
|
||||||
for id, category in categories.items():
|
for id, category in categories.items():
|
||||||
db.add(models_sde.Category(id=id,
|
db.add(models_sde.Category(id=id,
|
||||||
icon_id=category['iconID'] if 'iconID' in category else None,
|
icon_id=category['iconID'] if 'iconID' in category else None,
|
||||||
@@ -32,10 +36,10 @@ with Session(engine) as db:
|
|||||||
|
|
||||||
|
|
||||||
print("Importing groups...")
|
print("Importing groups...")
|
||||||
with open("static_eve/sde/fsd/groupIDs.yaml", "r") as f:
|
with open("static_eve/sde/fsd/groupIDs.yaml", "r", encoding="utf-8") as f:
|
||||||
groups = yaml.safe_load(f)
|
groups = yaml.safe_load(f)
|
||||||
|
|
||||||
with Session(engine) as db:
|
with Session(sde_engine) as db:
|
||||||
for id, group in groups.items():
|
for id, group in groups.items():
|
||||||
db.add(models_sde.Group(id=id,
|
db.add(models_sde.Group(id=id,
|
||||||
anchorable=group['anchorable'],
|
anchorable=group['anchorable'],
|
||||||
@@ -51,11 +55,10 @@ with Session(engine) as db:
|
|||||||
|
|
||||||
|
|
||||||
print("Importing marketgroups...")
|
print("Importing marketgroups...")
|
||||||
with open("static_eve/sde/fsd/marketGroups.yaml", "r") as f:
|
with open("static_eve/sde/fsd/marketGroups.yaml", "r", encoding="utf-8") as f:
|
||||||
marketgroups = yaml.safe_load(f)
|
marketgroups = yaml.safe_load(f)
|
||||||
|
|
||||||
|
with Session(sde_engine) as db:
|
||||||
with Session(engine) as db:
|
|
||||||
for id, marketgroup in marketgroups.items():
|
for id, marketgroup in marketgroups.items():
|
||||||
db.add(models_sde.MarketGroup(id=id,
|
db.add(models_sde.MarketGroup(id=id,
|
||||||
description=marketgroup['descriptionID']['en'] if 'descriptionID' in marketgroup else None,
|
description=marketgroup['descriptionID']['en'] if 'descriptionID' in marketgroup else None,
|
||||||
@@ -68,10 +71,10 @@ with Session(engine) as db:
|
|||||||
|
|
||||||
|
|
||||||
print("Importing types...")
|
print("Importing types...")
|
||||||
with open("static_eve/sde/fsd/typeIDs.yaml", "r") as f:
|
with open("static_eve/sde/fsd/typeIDs.yaml", "r", encoding="utf-8") as f:
|
||||||
types = yaml.safe_load(f)
|
types = yaml.safe_load(f)
|
||||||
|
|
||||||
with Session(engine) as db:
|
with Session(sde_engine) as db:
|
||||||
for id, type in types.items():
|
for id, type in types.items():
|
||||||
try:
|
try:
|
||||||
db.add(models_sde.Type(id=id,
|
db.add(models_sde.Type(id=id,
|
||||||
@@ -92,10 +95,10 @@ with Session(engine) as db:
|
|||||||
|
|
||||||
|
|
||||||
print("Importing materials...")
|
print("Importing materials...")
|
||||||
with open("static_eve/sde/fsd/typeMaterials.yaml", "r") as f:
|
with open("static_eve/sde/fsd/typeMaterials.yaml", "r", encoding="utf-8") as f:
|
||||||
materials = yaml.safe_load(f)
|
materials = yaml.safe_load(f)
|
||||||
|
|
||||||
with Session(engine) as db:
|
with Session(sde_engine) as db:
|
||||||
for id, material in materials.items():
|
for id, material in materials.items():
|
||||||
for mat in material:
|
for mat in material:
|
||||||
db.add(models_sde.TypeMaterial(type_id=id,
|
db.add(models_sde.TypeMaterial(type_id=id,
|
||||||
|
|||||||
Reference in New Issue
Block a user