From 482794473972a1265308fcb89069066483bbdda0 Mon Sep 17 00:00:00 2001 From: Starfall Date: Wed, 7 Feb 2024 17:54:47 -0600 Subject: dropcalc: Median XL .txt parser Was intended to eventually become a drop calculator. Might work for other Diablo II mods without changes, I don't think there are any MXL-specific fields involved in this. Abandoned due to lack of organizational structure on the project and ... creative differences with one of the lead devs. --- dropcalc/create_db.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 dropcalc/create_db.py (limited to 'dropcalc/create_db.py') diff --git a/dropcalc/create_db.py b/dropcalc/create_db.py new file mode 100755 index 0000000..be60fb6 --- /dev/null +++ b/dropcalc/create_db.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import csv +import mxl_types +from argparse import ArgumentParser +from pathlib import Path +from sqlalchemy import create_engine, text +from sqlalchemy.orm import Session + + +def generate_tcs(): + # TODO + # grab weapons, armor, misc? with spawnable=1 *and* who have itemtype with TreasureClass=1 (any itemtype? just direct?) + # qlvl 1-3 in weap3, 4-6 in weap6, 7-9 in weap9 ... 91-93 in weap93 + # armo3 ... armo99 + # vanilla has bow3 ... bow87 as well, unknown but probably based on the itemtype having Shoots and Quiver + # don't know if misc TCs are generated, neither median nor vanilla actually uses them if they are + pass + + +def create_db(folder): + engine = create_engine("sqlite+pysqlite:///:memory:", echo=False) + mxl_types.BaseDAO.metadata.create_all(engine) + + try1 = (Path(folder) / "Data" / "global" / "excel") + if try1.exists(): + data_folder = try1 + else: + data_folder = folder + + types = [ + mxl_types.ItemRatio, + mxl_types.ItemType, + mxl_types.Weapon, + mxl_types.Armor, + mxl_types.Misc, + mxl_types.UniqueItem, + mxl_types.SetItem, + mxl_types.TreasureClass, + ] + for mytype in types: + file = data_folder / mytype.filename + with file.open(encoding='windows-1252') as csvfile, Session(engine) as session: + reader = csv.DictReader(csvfile, dialect='excel-tab') + for csv_row in reader: + db_row = mytype(csv_row) + if not db_row.is_valid(): + continue + session.add(db_row) + session.commit() + count = session.scalar(text(f'select count(*) from {mytype.__tablename__}')) + print(f'Counted {count} {mytype.__tablename__}') + + +def handle_args(): + parser = ArgumentParser() + parser.add_argument('folder', help='Location of Median XL .txt files') + return parser.parse_args() + + +def main(): + args = handle_args() + create_db(args.folder) + + +if __name__ == '__main__': + import sys + + sys.exit(main()) -- cgit