From da43fd41dbef3d07a8afbbd9839719e4e96c5cda Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Fri, 8 Sep 2023 11:18:43 -0400 Subject: [PATCH] added crafting database --- Database/__pycache__/id.cpython-311.pyc | Bin 260 -> 0 bytes .../crafting/__pycache__/id.cpython-311.pyc | Bin 0 -> 290 bytes Database/{ => crafting}/createTables.py | 0 Database/crafting/data/ammo.csv | 2 + Database/crafting/data/food.csv | 2 + Database/crafting/data/gear.csv | 2 + Database/crafting/data/material.csv | 2 + Database/crafting/data/med.csv | 2 + Database/crafting/data/scrap.csv | 2 + Database/crafting/data/weapon.csv | 2 + Database/crafting/database.db | Bin 0 -> 32768 bytes Database/crafting/id.py | 10 +++ Database/{ => crafting}/importData.py | 0 Database/{ => crafting}/main.py | 0 Database/data/med.csv | 16 ---- Database/items/__pycache__/id.cpython-311.pyc | Bin 0 -> 277 bytes Database/items/createTables.py | 78 ++++++++++++++++++ Database/{ => items}/data/ammo.csv | 0 Database/{ => items}/data/craft.csv | 0 Database/{ => items}/data/gear.csv | 0 Database/items/data/med.csv | 16 ++++ Database/{ => items}/data/part.csv | 0 Database/{ => items}/data/reload.csv | 0 Database/{ => items}/data/weapon.csv | 0 Database/{ => items}/database.db | Bin 32768 -> 32768 bytes Database/{ => items}/id.py | 5 +- Database/items/importData.py | 47 +++++++++++ Database/items/main.py | 21 +++++ 28 files changed, 189 insertions(+), 18 deletions(-) delete mode 100644 Database/__pycache__/id.cpython-311.pyc create mode 100644 Database/crafting/__pycache__/id.cpython-311.pyc rename Database/{ => crafting}/createTables.py (100%) create mode 100644 Database/crafting/data/ammo.csv create mode 100644 Database/crafting/data/food.csv create mode 100644 Database/crafting/data/gear.csv create mode 100644 Database/crafting/data/material.csv create mode 100644 Database/crafting/data/med.csv create mode 100644 Database/crafting/data/scrap.csv create mode 100644 Database/crafting/data/weapon.csv create mode 100644 Database/crafting/database.db create mode 100644 Database/crafting/id.py rename Database/{ => crafting}/importData.py (100%) rename Database/{ => crafting}/main.py (100%) delete mode 100644 Database/data/med.csv create mode 100644 Database/items/__pycache__/id.cpython-311.pyc create mode 100644 Database/items/createTables.py rename Database/{ => items}/data/ammo.csv (100%) rename Database/{ => items}/data/craft.csv (100%) rename Database/{ => items}/data/gear.csv (100%) create mode 100644 Database/items/data/med.csv rename Database/{ => items}/data/part.csv (100%) rename Database/{ => items}/data/reload.csv (100%) rename Database/{ => items}/data/weapon.csv (100%) rename Database/{ => items}/database.db (87%) rename Database/{ => items}/id.py (62%) create mode 100644 Database/items/importData.py create mode 100644 Database/items/main.py diff --git a/Database/__pycache__/id.cpython-311.pyc b/Database/__pycache__/id.cpython-311.pyc deleted file mode 100644 index bd9c37d1cf70d62ccb138b91d0beb8b566374881..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 260 zcmZ3^%ge<81d$rQQlC%vKX5PziQnK6yum93AwO`l S2{3(N01^#6AXvl+R0;q@?nWU1 diff --git a/Database/crafting/__pycache__/id.cpython-311.pyc b/Database/crafting/__pycache__/id.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0fb00eec58fbef56aaa00e01811a0e10a31cb2f9 GIT binary patch literal 290 zcmZ3^%ge<81Qyo6Qx*Z~#~=<2utOQ2C4h|S3@HpLj44bh%qc7>tSM}B*rFIx*n=4~ zIWk``GcaUc0IJU1!3`u9@B@hsVIZNQ%)p?@c8eu3H#h$lOIm(@$}N`k)Wo7&9Jz@l zsYRKIIk(u#QxgmF^KP*gCl@6a_-QiU;wdgkEGo&&OOMY?DPGC&8RUpx#?DqT&iN^+ zF#$#SS*gh-#W4jChHFk{j7wrkVp3vpY7EebG?31i%oM$X%3mBdx%nxjIjMF}@1|ASB0tF2Kpe|66 literal 0 HcmV?d00001 diff --git a/Database/createTables.py b/Database/crafting/createTables.py similarity index 100% rename from Database/createTables.py rename to Database/crafting/createTables.py diff --git a/Database/crafting/data/ammo.csv b/Database/crafting/data/ammo.csv new file mode 100644 index 00000000..0690e534 --- /dev/null +++ b/Database/crafting/data/ammo.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 diff --git a/Database/crafting/data/food.csv b/Database/crafting/data/food.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/food.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/data/gear.csv b/Database/crafting/data/gear.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/gear.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/data/material.csv b/Database/crafting/data/material.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/material.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/data/med.csv b/Database/crafting/data/med.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/med.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/data/scrap.csv b/Database/crafting/data/scrap.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/scrap.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/data/weapon.csv b/Database/crafting/data/weapon.csv new file mode 100644 index 00000000..fcf80197 --- /dev/null +++ b/Database/crafting/data/weapon.csv @@ -0,0 +1,2 @@ +id,result,input1,qty1,input2,qty2,input3,qty3,input4,qty4 +NULL,10000,20000,1,20002,1,20005,1,20001,15 \ No newline at end of file diff --git a/Database/crafting/database.db b/Database/crafting/database.db new file mode 100644 index 0000000000000000000000000000000000000000..5b384b2d4572627e0851f5e86b0d02e7877249c7 GIT binary patch literal 32768 zcmeI)(Q4CB9LMpTtZTN;*}*7bj=@nFb11G`r{JA)1QAMLGlF-T*-R^K(`6arjWFXg zc(GUTQM~aXd=O94O?p}bUhc^Etfxu-IXlbmGZ_3S?8QO5n?~|DPWoXgTh@{#g!M#9 z%d#%ioKy2^{7@&As|$4$W9Mb37uJIhKNrXLx~0tg_0 z00Id7Cjwvg9mic+5nsbJJnBUsqi`4x)O%T7-L>}*y}iJb!QRuhCr95Q@7AOm-Hr^r zSHXRCasGa^aduDNSZy%#Pa8;?M5kxHR6h3u@0oX)Z>oO6V0e~p>$Q{g(?q3MwKKJ9 zqEf7CO|6=!6svZpR{g2eHqWD~b5Z|gsTTtQ1Q0*~0R#|0 z009ILKmY**3>LU078jj|KFki zFNNX;0tg_000IagfB*srAbNF)6V)H72tpHMck>GexhU@)w6qZhlH>PO4oI56}QcATHJf5+9fu85uut jFz}1q;1RsRD+D5eh>QONFS`KK2L>R~zypFspwIvSI(AFe literal 0 HcmV?d00001 diff --git a/Database/items/createTables.py b/Database/items/createTables.py new file mode 100644 index 00000000..0660c275 --- /dev/null +++ b/Database/items/createTables.py @@ -0,0 +1,78 @@ +import sqlite3 +import os +import csv + + +def get_data_type(value): + try: + int(value) + return "INTEGER" + except ValueError: + try: + float(value) + return "REAL" + except ValueError: + return "TEXT" + + +# Connect to the SQLite database and delete existing tables +conn = sqlite3.connect("database.db") +cursor = conn.cursor() + +# Get a list of CSV files in the "data" directory +data_dir = "data" # Change this to your data directory path +csv_files = [f for f in os.listdir(data_dir) if f.endswith(".csv")] + +# Drop all existing tables except for sqlite_sequence +cursor.execute("PRAGMA foreign_keys = OFF;") +cursor.execute( + "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_sequence';" +) +existing_tables = cursor.fetchall() +for table in existing_tables: + cursor.execute(f"DROP TABLE IF EXISTS {table[0]};") + +# Commit the changes to delete existing tables +conn.commit() + +# Iterate through CSV files and create new tables +for csv_file in csv_files: + table_name = os.path.splitext(csv_file)[0] + + # Read the first row of the CSV file to determine the column names + with open(os.path.join(data_dir, csv_file), newline="") as csvfile: + csv_reader = csv.reader(csvfile) + header = next(csv_reader) + + # Read the second row to determine data types + with open(os.path.join(data_dir, csv_file), newline="") as csvfile: + csv_reader = csv.reader(csvfile) + next(csv_reader) # Skip the header row + data_row = next(csv_reader) + data_types = [get_data_type(value) for value in data_row] + + # Add a primary key column if needed (replace 'unique_id' with your unique identifier column name) + if "unique_id" in header: + header[header.index("unique_id")] += " PRIMARY KEY" + + # Generate the CREATE TABLE statement dynamically based on the column names and data types + create_table_sql = f"CREATE TABLE IF NOT EXISTS {table_name} (\n" + for column_name, data_type in zip(header, data_types): + create_table_sql += f" {column_name} {data_type},\n" + create_table_sql = create_table_sql.rstrip(",\n") + "\n);" + + # Execute the CREATE TABLE statement + cursor.execute(create_table_sql) + + # Read and insert data from the CSV file into the table + with open(os.path.join(data_dir, csv_file), newline="") as csvfile: + csv_reader = csv.reader(csvfile) + next(csv_reader) # Skip the header row + for row in csv_reader: + placeholders = ",".join(["?"] * len(row)) + insert_sql = f"INSERT INTO {table_name} VALUES ({placeholders});" + cursor.execute(insert_sql, row) + +# Commit the changes and close the connection +conn.commit() +conn.close() diff --git a/Database/data/ammo.csv b/Database/items/data/ammo.csv similarity index 100% rename from Database/data/ammo.csv rename to Database/items/data/ammo.csv diff --git a/Database/data/craft.csv b/Database/items/data/craft.csv similarity index 100% rename from Database/data/craft.csv rename to Database/items/data/craft.csv diff --git a/Database/data/gear.csv b/Database/items/data/gear.csv similarity index 100% rename from Database/data/gear.csv rename to Database/items/data/gear.csv diff --git a/Database/items/data/med.csv b/Database/items/data/med.csv new file mode 100644 index 00000000..d8a18411 --- /dev/null +++ b/Database/items/data/med.csv @@ -0,0 +1,16 @@ +id,type,name,rarity,weight,height,width,stack,value +NULL,bleed1,Bandage,1,0.1411,1,1,5,6500 +NULL,health,Small Health Kit (SHK),1,0.18,1,1,1,32000 +NULL,health,Individual First Aid Kit,2,0.22046,1,1,1,60000 +NULL,health,Dual First Aid Kit,2,0.44092,1,2,2,100000 +NULL,health,Group First Aid Kit,3,0.88184,2,2,4,120000 +NULL,health,Adaptive First Aid Kit,4,0.22046,1,1,1,90000 +NULL,surgery,Surgery Kit,2,0.88185,1,1,2,100000 +NULL,surgery,Surgery Kit (L),3,1.32278,1,2,3,150000 +NULL,stim,Adrenaline,3,0.22046,1,1,1,50000 +NULL,stim,Pain killer,1,0.05512,1,1,4,10000 +NULL,stim,Morphine,2,0.22046,1,1,1,40000 +NULL,stim,Caffeine (pill),2,0.05512,1,1,4,2500 +NULL,bleed2,Tourniquet,1,0.37371,1,1,2,11000 +NULL,stim,Muscle Stimulant,4,0,0,0,0,0 +NULL,stim,Rad-x,0,0,0,0,0,0 diff --git a/Database/data/part.csv b/Database/items/data/part.csv similarity index 100% rename from Database/data/part.csv rename to Database/items/data/part.csv diff --git a/Database/data/reload.csv b/Database/items/data/reload.csv similarity index 100% rename from Database/data/reload.csv rename to Database/items/data/reload.csv diff --git a/Database/data/weapon.csv b/Database/items/data/weapon.csv similarity index 100% rename from Database/data/weapon.csv rename to Database/items/data/weapon.csv diff --git a/Database/database.db b/Database/items/database.db similarity index 87% rename from Database/database.db rename to Database/items/database.db index 35a50d64f495fd9e46154006985108a251c7daff..7b634c5a47fdf89116dd005cb2c5b525f1227780 100644 GIT binary patch delta 1924 zcmZvcT}WGJ7{_x?tT`v~oMYzBdvs}<_|Zj;Cg+^w2y5jlrN4HW*5`i!pZ5i_!IBWsJhu^B!XoLjz)R ze$VrN|L^m@=fA#AudmaaHfzyfFfj0U@cH4}rc=*Ts*Zh0@ zG~dHh+#Yv>yTrZ1MLub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