botsi commited on
Commit
ee1def5
·
verified ·
1 Parent(s): 8924407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -50
app.py CHANGED
@@ -8,7 +8,7 @@ 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",
@@ -59,7 +59,7 @@ if personalized_data:
59
  print(row) # Print each row
60
  else:
61
  print("No data found.")
62
-
63
 
64
  get_window_url_params = """
65
  function() {
@@ -98,63 +98,42 @@ with gr.Blocks() as demo:
98
  """
99
  # Connect to the database
100
  conn = mysql.connector.connect(
101
- host="18.153.94.89",
102
- user="root",
103
- password="N12RXMKtKxRj",
104
- database="lionessdb"
105
  )
106
-
107
  # Create a cursor object
108
- cursor = conn.cursor()
109
-
110
  # Replace the placeholders with your actual database and table names
111
  core_table = "e5390g37096_core"
112
  decisions_table = "e5390g37096_decisions"
113
- session_index = session_index
114
- #print(session_index)
115
- playerNr = "1"
116
-
117
  # Query to fetch relevant data from both tables based on session_index
118
  query = f"""
119
- SELECT
120
- {core_table}.playerNr,
121
- {core_table}.subjectNr,
122
- {core_table}.onPage,
123
- {decisions_table}.transfer1,
124
- {decisions_table}.tripledAmount1,
125
- {decisions_table}.keptForSelf1,
126
- {decisions_table}.returned1,
127
- {decisions_table}.newCreditRound2,
128
- {decisions_table}.transfer2,
129
- {decisions_table}.tripledAmount2,
130
- {decisions_table}.keptForSelf2,
131
- {decisions_table}.returned2,
132
- {decisions_table}.resultsWithoutAI
133
- FROM {core_table}
134
- JOIN {decisions_table} ON
135
- {core_table}.playerNr = {decisions_table}.playerNr AND
136
- {core_table}.groupNr = {decisions_table}.groupNr AND
137
- {core_table}.subjectNr = {decisions_table}.subjectNr
138
- WHERE {decisions_table}.session_index = '{session_index}'
139
  """
140
- cursor.execute(query)
141
-
142
- # Fetch all rows and convert to a list of dictionaries
143
- rows = cursor.fetchall()
144
- result = []
145
- for row in rows:
146
- d = {}
147
- for i, col in enumerate(cursor.description):
148
- d[col[0]] = row[i]
149
- result.append(d)
150
 
151
- # Convert the list of dictionaries to JSON
152
- personalized_result = json.dumps(result)
153
- print(personalized_result)
154
-
155
- # Close the database connection
156
- conn.close()
157
-
 
 
 
 
 
158
  elif "print data" in history[-1][0]:
159
  personalized_data = fetch_personalized_data()
160
  print(personalized_data)
 
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",
 
59
  print(row) # Print each row
60
  else:
61
  print("No data found.")
62
+ '''
63
 
64
  get_window_url_params = """
65
  function() {
 
98
  """
99
  # Connect to the database
100
  conn = mysql.connector.connect(
101
+ host="18.153.94.89",
102
+ user="root",
103
+ password="N12RXMKtKxRj",
104
+ database="lionessdb"
105
  )
106
+
107
  # Create a cursor object
108
+ cursor = conn.cursor(dictionary=True) # Use dictionary cursor for easier data manipulation
109
+
110
  # Replace the placeholders with your actual database and table names
111
  core_table = "e5390g37096_core"
112
  decisions_table = "e5390g37096_decisions"
113
+
 
 
 
114
  # Query to fetch relevant data from both tables based on session_index
115
  query = f"""
116
+ SELECT e5390g37096_core.playerNr,
117
+ e5390g37096_core.groupNr,
118
+ e5390g37096_core.subjectNr
119
+ FROM e5390g37096_core
120
+ JOIN e5390g37096_decisions ON
121
+ e5390g37096_core.playerNr = e5390g37096_decisions.playerNr
122
+ WHERE e5390g37096_decisions.session_index = '{session_index}'
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  """
 
 
 
 
 
 
 
 
 
 
124
 
125
+ try:
126
+ cursor.execute(query)
127
+ # Fetch all rows as dictionaries
128
+ rows = cursor.fetchall()
129
+ print(rows)
130
+ # Close the database connection
131
+ conn.close()
132
+ return rows # Return the fetched rows
133
+ except mysql.connector.Error as err:
134
+ print(f"Error: {err}")
135
+ return None
136
+
137
  elif "print data" in history[-1][0]:
138
  personalized_data = fetch_personalized_data()
139
  print(personalized_data)