Compare commits

..

No commits in common. "63a468046e15629d263a527b392f8e11b1953e15" and "68baef221f8a84109b67911222e3b0277ad7aaeb" have entirely different histories.

12 changed files with 138 additions and 136 deletions

131
app.py
View File

@ -1,11 +1,16 @@
from flask import Flask, render_template, g, abort, request, jsonify, send_from_directory, url_for from flask import Flask, render_template, g, abort, request, jsonify, send_from_directory, url_for
import sqlite3, os, csv
import os from src.python.breed import get_breed_id, get_breeding_pairs, get_used_in_breeds
from src.util.utils import *
app = Flask(__name__) app = Flask(__name__)
DATABASE = "src/database.db"
def connect_db():
return sqlite3.connect(DATABASE)
@app.before_request @app.before_request
def before_request(): def before_request():
@ -39,15 +44,19 @@ def serve_monster_sprite(selected_monster):
def serve_favicon(): def serve_favicon():
return send_from_directory( '','static/img/favicon.ico') return send_from_directory( '','static/img/favicon.ico')
#TO-DO: Split the rest of these API Calls
#API Calls #API Calls
from src.api.get_families import *
app.register_blueprint(get_families_bp) # List All Families
@app.route("/api/families")
def json_families():
cursor = g.db.cursor()
cursor.execute("SELECT DISTINCT name FROM families")
families = [row[0] for row in cursor.fetchall()]
return jsonify(families)
# List All Monsters # List All Monsters
@app.route("/api/monsters") @app.route("/api/monsters")
def get_monsters(): def json_monsters():
selected_family = request.args.get("family") selected_family = request.args.get("family")
cursor = g.db.cursor() cursor = g.db.cursor()
@ -75,7 +84,7 @@ def get_monsters():
@app.route("/api/monsters/stats") @app.route("/api/monsters/stats")
def get_monster_stats(): def json_monsters_stats():
cursor = g.db.cursor() cursor = g.db.cursor()
# Check if 'monster' argument is provided # Check if 'monster' argument is provided
@ -213,103 +222,13 @@ def get_breeding_combinations():
used_in_breeds=used_in_breeds, used_in_breeds=used_in_breeds,
) )
def get_used_in_breeds(target_monster): def read_csv(file_path):
cursor = g.db.cursor() data = []
with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:
# Fetch breed IDs where the selected monster is used as a base reader = csv.DictReader(csvfile)
cursor.execute( for row in reader:
""" data.append(row)
SELECT breed_id return data
FROM breed_requirements
WHERE requirement_type = 'base'
AND requirement_value = ?
""",
(target_monster,),
)
base_breed_ids = [row[0] for row in cursor.fetchall()]
# Fetch breed IDs where the selected monster is used as a mate
cursor.execute(
"""
SELECT breed_id
FROM breed_requirements
WHERE requirement_type = 'mate'
AND requirement_value = ?
""",
(target_monster,),
)
mate_breed_ids = [row[0] for row in cursor.fetchall()]
# Combine the results from both queries
used_in_breed_ids = base_breed_ids + mate_breed_ids
# Fetch the target monsters for the obtained breed IDs
used_in_breeds = []
for breed_id in used_in_breed_ids:
cursor.execute(
"""
SELECT target
FROM breeds
WHERE id = ?
""",
(breed_id,),
)
target_monster = cursor.fetchone()
if target_monster:
used_in_breeds.append(target_monster[0])
return used_in_breeds
def get_breed_id(target_monster):
cursor = g.db.cursor()
# Fetch breed ID based on the selected monster as a target
cursor.execute(
"""
SELECT breeds.id
FROM breeds
WHERE breeds.target = ?
""",
(target_monster,),
)
breed_id = cursor.fetchone()
if breed_id:
return breed_id[0]
else:
return None
def get_breeding_pairs(breed_id):
cursor = g.db.cursor()
# Fetch base and mate breeding combinations based on the breed ID
cursor.execute(
"""
SELECT requirement_type, requirement_value
FROM breed_requirements
WHERE breed_id = ?
""",
(breed_id,),
)
breeding_info = cursor.fetchall()
base_pair = [
value
for (requirement_type, value) in breeding_info
if requirement_type == "base"
]
mate_pair = [
value
for (requirement_type, value) in breeding_info
if requirement_type == "mate"
]
return base_pair, mate_pair
@app.route('/skills') @app.route('/skills')
def skills(): def skills():

View File

View File

@ -1,11 +0,0 @@
from flask import Blueprint, g, jsonify
get_families_bp = Blueprint('families', __name__)
# List All Families
@get_families_bp.route("/api/families")
def get_families():
cursor = g.db.cursor()
cursor.execute("SELECT DISTINCT name FROM families")
families = [row[0] for row in cursor.fetchall()]
return jsonify(families)

4
src/python/__innit__.py Normal file
View File

@ -0,0 +1,4 @@
from .breed import get_breeding_pairs, get_breed_id, get_used_in_breeds
__all__ = ["breed",]

99
src/python/breed.py Normal file
View File

@ -0,0 +1,99 @@
from flask import g
def get_used_in_breeds(target_monster):
cursor = g.db.cursor()
# Fetch breed IDs where the selected monster is used as a base
cursor.execute(
"""
SELECT breed_id
FROM breed_requirements
WHERE requirement_type = 'base'
AND requirement_value = ?
""",
(target_monster,),
)
base_breed_ids = [row[0] for row in cursor.fetchall()]
# Fetch breed IDs where the selected monster is used as a mate
cursor.execute(
"""
SELECT breed_id
FROM breed_requirements
WHERE requirement_type = 'mate'
AND requirement_value = ?
""",
(target_monster,),
)
mate_breed_ids = [row[0] for row in cursor.fetchall()]
# Combine the results from both queries
used_in_breed_ids = base_breed_ids + mate_breed_ids
# Fetch the target monsters for the obtained breed IDs
used_in_breeds = []
for breed_id in used_in_breed_ids:
cursor.execute(
"""
SELECT target
FROM breeds
WHERE id = ?
""",
(breed_id,),
)
target_monster = cursor.fetchone()
if target_monster:
used_in_breeds.append(target_monster[0])
return used_in_breeds
def get_breed_id(target_monster):
cursor = g.db.cursor()
# Fetch breed ID based on the selected monster as a target
cursor.execute(
"""
SELECT breeds.id
FROM breeds
WHERE breeds.target = ?
""",
(target_monster,),
)
breed_id = cursor.fetchone()
if breed_id:
return breed_id[0]
else:
return None
def get_breeding_pairs(breed_id):
cursor = g.db.cursor()
# Fetch base and mate breeding combinations based on the breed ID
cursor.execute(
"""
SELECT requirement_type, requirement_value
FROM breed_requirements
WHERE breed_id = ?
""",
(breed_id,),
)
breeding_info = cursor.fetchall()
base_pair = [
value
for (requirement_type, value) in breeding_info
if requirement_type == "base"
]
mate_pair = [
value
for (requirement_type, value) in breeding_info
if requirement_type == "mate"
]
return base_pair, mate_pair

View File

View File

@ -1,14 +0,0 @@
import sqlite3, csv
DATABASE = "src/data/database.db"
def connect_db():
return sqlite3.connect(DATABASE)
def read_csv(file_path):
data = []
with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
return data

View File

@ -655,11 +655,6 @@ video {
border-color: rgb(148 163 184 / var(--tw-border-opacity)); border-color: rgb(148 163 184 / var(--tw-border-opacity));
} }
.bg-gray-900 {
--tw-bg-opacity: 1;
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}
.bg-neutral-800 { .bg-neutral-800 {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(38 38 38 / var(--tw-bg-opacity)); background-color: rgb(38 38 38 / var(--tw-bg-opacity));
@ -670,6 +665,11 @@ video {
background-color: rgb(15 23 42 / var(--tw-bg-opacity)); background-color: rgb(15 23 42 / var(--tw-bg-opacity));
} }
.bg-gray-900 {
--tw-bg-opacity: 1;
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}
.p-2 { .p-2 {
padding: 0.5rem; padding: 0.5rem;
} }
@ -736,6 +736,11 @@ video {
line-height: 1.75rem; line-height: 1.75rem;
} }
.text-blue-500 {
--tw-text-opacity: 1;
color: rgb(59 130 246 / var(--tw-text-opacity));
}
.text-purple-400 { .text-purple-400 {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(192 132 252 / var(--tw-text-opacity)); color: rgb(192 132 252 / var(--tw-text-opacity));