Skip to content

Commit

Permalink
stubbing out some sql calls to get useful information
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jul 19, 2024
1 parent c182432 commit 338c294
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CMakeCache.txt
CMakeFiles/
doc/html/
doc/latex/
data/
__pycache__/
*.pyc
dist
Binary file added etc/data/mcm.db
Binary file not shown.
31 changes: 31 additions & 0 deletions etc/translate_mcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sqlite3
import re

statements = {
"number_of_reactions": "SELECT COUNT(DISTINCT ReactioNID) FROM Reactions WHERE Mechanism = 'MCM';",
"number_of_rate_constants": "SELECT COUNT(DISTINCT RATE) FROM Reactions INNER JOIN Rates USING(Rate) WHERE Mechanism = 'MCM';",
"rate_types": "SELECT RateType, COUNT(*) FROM Rates GROUP BY RateType;",
"reactions_with_rate_types": "SELECT r.ReactionID, r.Rate, rates.RateType FROM Reactions r INNER JOIN Rates rates ON r.Rate = rates.Rate;",
"get_reactants_and_products_per_reaction": "SELECT r.ReactionID, r.Rate, GROUP_CONCAT(reactants.Species, ', ') AS ReactantSpecies, GROUP_CONCAT(products.Species, ', ') AS ProductSpecies FROM Reactions r LEFT JOIN Reactants reactants ON r.ReactionID = reactants.ReactionID LEFT JOIN Products products ON r.ReactionID = products.ReactionID WHERE r.Mechanism = 'MCM' GROUP BY r.ReactionID;"
}

def get_count(cursor, stmt):
cursor.execute(stmt)
stmt = cursor.fetchone()[0]
return stmt

def get_all(cursor, stmt):
cursor.execute(stmt)
stmt = cursor.fetchall()
return stmt

def translate_mcm():
conn = sqlite3.connect('data/mcm.db')
cursor = conn.cursor()
print(get_count(cursor, statements["number_of_reactions"]))
print(get_count(cursor, statements["number_of_rate_constants"]))
print(get_all(cursor, statements["rate_types"]))
print(get_all(cursor, statements["reactions_with_rate_types"])[:10])
print(get_all(cursor, statements["get_reactants_and_products_per_reaction"])[:10])

translate_mcm()

0 comments on commit 338c294

Please sign in to comment.