Guest User

Untitled

a guest
Jun 21st, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.78 KB | None | 0 0
  1. import sqlite3
  2.  
  3. # Path to full SDE
  4. SDE_PATH = r"C:\Users\nario\Documents\Coding Stuff\Eve-Code\ManuOptimizer\Utils\sde.sqlite"
  5.  
  6. # Output mini SDE
  7. mini_conn = sqlite3.connect('mini_sde.sqlite')
  8. mini_cursor = mini_conn.cursor()
  9.  
  10. # Load full SDE
  11. full_conn = sqlite3.connect(SDE_PATH)
  12. full_cursor = full_conn.cursor()
  13.  
  14. # 1. Create invTypes table
  15.  
  16. mini_cursor.execute('''
  17. CREATE TABLE IF NOT EXISTS invTypes (
  18.    typeID INTEGER PRIMARY KEY,
  19.    typeName TEXT
  20. )
  21. ''')
  22.  
  23. full_cursor.execute('SELECT typeID, typeName FROM invTypes WHERE published = 1')
  24. invtype_rows = full_cursor.fetchall()
  25. mini_cursor.executemany("INSERT INTO invTypes (typeID, typeName) VALUES (?, ?)", invtype_rows)
  26.  
  27. # 2. Create materialClassifications table
  28. mini_cursor.execute('''
  29. CREATE TABLE IF NOT EXISTS materialClassifications (
  30.    typeID INTEGER PRIMARY KEY,
  31.    typeName TEXT,
  32.    groupID INTEGER,
  33.    groupName TEXT,
  34.    categoryID INTEGER,
  35.    categoryName TEXT,
  36.    manufacturingCategory TEXT
  37. )
  38. ''')
  39.  
  40. # Mapping of groupName -> Manufacturing Category
  41. MANUFACTURING_GROUP_MAP = {
  42.     # True Minerals
  43.     'Minerals': 'Minerals',
  44.  
  45.     # Planetary Interaction
  46.     'Planetary Commodities': 'Planetary Materials',
  47.     'Refined Commodities': 'Planetary Materials',
  48.  
  49.     # Reactions
  50.     'Intermediate Materials': 'Reaction Materials',
  51.     'Processed Materials': 'Reaction Materials',
  52.     'Hybrid Polymers': 'Reaction Materials',
  53.     'Advanced Moon Materials': 'Reaction Materials',
  54.     'Composite Materials': 'Reaction Materials',
  55.     'Gas Clouds': 'Reaction Materials',
  56.     'Ice Products': 'Reaction Materials',
  57.  
  58.     # Components
  59.     'Components': 'Components',
  60.     'Advanced Components': 'Advanced Components',
  61.     'Structure Components': 'Structure Components',
  62.     'Construction Components': 'Components',
  63.  
  64.     # Salvage
  65.     'Salvaged Materials': 'Salvage',
  66.  
  67.     # Other pre-defined T1 modules
  68.     'Fuel Blocks': 'Fuel',
  69.     'Datacores': 'Invention Materials',
  70.     'Decryptors': 'Invention Materials',
  71. }
  72.  
  73. # Build groupID -> manufacturing category
  74. full_cursor.execute('SELECT groupID, groupName FROM invGroups')
  75. group_map = full_cursor.fetchall()
  76. group_to_category = {
  77.     group_id: MANUFACTURING_GROUP_MAP.get(group_name)
  78.     for group_id, group_name in group_map
  79.     if MANUFACTURING_GROUP_MAP.get(group_name)
  80. }
  81.  
  82.  
  83. # 3. Fetch all relevant items
  84.  
  85. full_cursor.execute('''
  86. SELECT t.typeID, t.typeName, g.groupID, g.groupName, c.categoryID, c.categoryName
  87. FROM invTypes t
  88. JOIN invGroups g ON t.groupID = g.groupID
  89. JOIN invCategories c ON g.categoryID = c.categoryID
  90. WHERE t.published = 1
  91. ''')
  92.  
  93. rows = full_cursor.fetchall()
  94. inserted_ids = set()
  95.  
  96. filtered = []
  97. for typeID, typeName, groupID, groupName, categoryID, categoryName in rows:
  98.     manu_cat = group_to_category.get(groupID)
  99.  
  100.     # Check for explicit category match
  101.     if manu_cat:
  102.         filtered.append((typeID, typeName, groupID, groupName, categoryID, categoryName, manu_cat))
  103.         inserted_ids.add(typeID)
  104.         continue
  105.  
  106.     # Heuristic: If name ends in " I" and not " II", it's a T1 item
  107.     if typeName.endswith(" I") and not typeName.endswith(" II"):
  108.         if typeID not in inserted_ids:
  109.             filtered.append((typeID, typeName, groupID, groupName, categoryID, categoryName, "Items"))
  110.             inserted_ids.add(typeID)
  111.  
  112.  
  113. # 4. Insert filtered materials
  114. mini_cursor.executemany('''
  115. INSERT OR IGNORE INTO materialClassifications
  116. (typeID, typeName, groupID, groupName, categoryID, categoryName, manufacturingCategory)
  117. VALUES (?, ?, ?, ?, ?, ?, ?)
  118. ''', filtered)
  119.  
  120. # 5. Hardcode core minerals if not already present
  121. known_minerals = [
  122.     "Tritanium", "Pyerite", "Mexallon", "Isogen",
  123.     "Nocxium", "Zydrine", "Megacyte", "Morphite"
  124. ]
  125.  
  126. for mineral in known_minerals:
  127.     full_cursor.execute('''
  128.        SELECT t.typeID, t.typeName, g.groupID, g.groupName, c.categoryID, c.categoryName
  129.        FROM invTypes t
  130.        JOIN invGroups g ON t.groupID = g.groupID
  131.        JOIN invCategories c ON g.categoryID = c.categoryID
  132.        WHERE t.typeName = ? AND t.published = 1
  133.    ''', (mineral,))
  134.     row = full_cursor.fetchone()
  135.     if row:
  136.         typeID, typeName, groupID, groupName, categoryID, categoryName = row
  137.         if typeID not in inserted_ids:
  138.             try:
  139.                 mini_cursor.execute('''
  140.                    INSERT INTO materialClassifications
  141.                    (typeID, typeName, groupID, groupName, categoryID, categoryName, manufacturingCategory)
  142.                    VALUES (?, ?, ?, ?, ?, ?, ?)
  143.                ''', (typeID, typeName, groupID, groupName, categoryID, categoryName, "Minerals"))
  144.                 inserted_ids.add(typeID)
  145.             except sqlite3.IntegrityError:
  146.                 pass
  147.  
  148.  
  149. # 6. Finalize
  150. mini_conn.commit()
  151. full_conn.close()
  152. mini_conn.close()
  153.  
Advertisement
Add Comment
Please, Sign In to add comment