Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,80 +8,57 @@ import csv
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
-
def fetch_personalized_data():
|
| 12 |
# Connect to the database
|
| 13 |
conn = mysql.connector.connect(
|
| 14 |
host="18.153.94.89",
|
| 15 |
user="root",
|
| 16 |
password="N12RXMKtKxRj",
|
| 17 |
database="lionessdb"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
# Create a cursor object
|
| 21 |
-
cursor = conn.cursor()
|
| 22 |
-
|
| 23 |
# Replace the placeholders with your actual database and table names
|
| 24 |
core_table = "e5390g37096_core"
|
| 25 |
decisions_table = "e5390g37096_decisions"
|
| 26 |
session_index = "eb3636167d3a63fbeee32934610e5b2f"
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
# Query to fetch relevant data from both tables based on session_index
|
| 32 |
-
query = f"""
|
| 33 |
-
SELECT
|
| 34 |
-
{core_table}.playerNr,
|
| 35 |
-
{core_table}.subjectNr,
|
| 36 |
-
{core_table}.onPage,
|
| 37 |
-
{decisions_table}.transfer1,
|
| 38 |
-
{decisions_table}.tripledAmount1,
|
| 39 |
-
{decisions_table}.keptForSelf1,
|
| 40 |
-
{decisions_table}.returned1,
|
| 41 |
-
{decisions_table}.newCreditRound2,
|
| 42 |
-
{decisions_table}.transfer2,
|
| 43 |
-
{decisions_table}.tripledAmount2,
|
| 44 |
-
{decisions_table}.keptForSelf2,
|
| 45 |
-
{decisions_table}.returned2,
|
| 46 |
-
{decisions_table}.resultsWithoutAI
|
| 47 |
-
FROM {core_table}
|
| 48 |
-
JOIN {decisions_table} ON
|
| 49 |
-
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 50 |
-
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 51 |
-
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 52 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 53 |
-
"""
|
| 54 |
cursor.execute(query)
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
except mysql.connector.Error as err:
|
| 58 |
-
print(f"Error
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
# Fetch all rows and convert to a list of dictionaries
|
| 62 |
-
rows = cursor.fetchall()
|
| 63 |
-
if not rows:
|
| 64 |
-
print("No rows found for the given session_index.")
|
| 65 |
-
return noresult = []
|
| 66 |
-
for row in rows:
|
| 67 |
-
d = {}
|
| 68 |
-
for i, col in enumerate(cursor.description):
|
| 69 |
-
d[col[0]] = row[i]
|
| 70 |
-
result.append(d)
|
| 71 |
-
|
| 72 |
-
# Convert the list of dictionaries to JSON
|
| 73 |
-
personalized_result = json.dumps(result)
|
| 74 |
-
print(personalized_result)
|
| 75 |
-
|
| 76 |
-
# Close the database connection
|
| 77 |
-
conn.close()
|
| 78 |
-
return personalized_result
|
| 79 |
|
| 80 |
-
# Call the function to fetch data
|
| 81 |
personalized_data = fetch_personalized_data()
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
get_window_url_params = """
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
+
def fetch_personalized_data():
|
| 12 |
# Connect to the database
|
| 13 |
conn = mysql.connector.connect(
|
| 14 |
host="18.153.94.89",
|
| 15 |
user="root",
|
| 16 |
password="N12RXMKtKxRj",
|
| 17 |
database="lionessdb"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
# Create a cursor object
|
| 21 |
+
cursor = conn.cursor(dictionary=True) # Use dictionary cursor for easier data manipulation
|
| 22 |
+
|
| 23 |
# Replace the placeholders with your actual database and table names
|
| 24 |
core_table = "e5390g37096_core"
|
| 25 |
decisions_table = "e5390g37096_decisions"
|
| 26 |
session_index = "eb3636167d3a63fbeee32934610e5b2f"
|
| 27 |
+
|
| 28 |
+
# Query to fetch relevant data from both tables based on session_index
|
| 29 |
+
query = f"""
|
| 30 |
+
SELECT e5390g37096_core.playerNr,
|
| 31 |
+
e5390g37096_core.groupNr,
|
| 32 |
+
e5390g37096_core.subjectNr
|
| 33 |
+
FROM e5390g37096_core
|
| 34 |
+
JOIN e5390g37096_decisions ON
|
| 35 |
+
e5390g37096_core.playerNr = e5390g37096_decisions.playerNr
|
| 36 |
+
WHERE e5390g37096_decisions.session_index = '{session_index}'
|
| 37 |
+
"""
|
| 38 |
|
| 39 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
cursor.execute(query)
|
| 41 |
+
|
| 42 |
+
# Fetch all rows as dictionaries
|
| 43 |
+
rows = cursor.fetchall()
|
| 44 |
+
|
| 45 |
+
# Close the database connection
|
| 46 |
+
conn.close()
|
| 47 |
+
|
| 48 |
+
return rows # Return the fetched rows
|
| 49 |
+
|
| 50 |
except mysql.connector.Error as err:
|
| 51 |
+
print(f"Error: {err}")
|
| 52 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
# Call the function to fetch data
|
| 55 |
personalized_data = fetch_personalized_data()
|
| 56 |
+
|
| 57 |
+
if personalized_data:
|
| 58 |
+
for row in personalized_data:
|
| 59 |
+
print(row) # Print each row
|
| 60 |
+
else:
|
| 61 |
+
print("No data found.")
|
| 62 |
|
| 63 |
|
| 64 |
get_window_url_params = """
|