Skip to content

Commit 25dbad6

Browse files
authored
Merge pull request #2 from junli-liang-johnny/main
fixed sql feedback query
2 parents 2bbf3a5 + 2c6b6d6 commit 25dbad6

File tree

2 files changed

+48
-32
lines changed

2 files changed

+48
-32
lines changed

check_db.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sqlite3
2+
3+
# Connect to the SQLite database
4+
conn = sqlite3.connect('assessment_results.db')
5+
6+
# Create a cursor object
7+
cursor = conn.cursor()
8+
9+
# Use PRAGMA table_info() to get information about the table
10+
cursor.execute("PRAGMA table_info(feedback)")
11+
12+
# Fetch all rows from the cursor to get information about each column
13+
columns_info = cursor.fetchall()
14+
15+
# Print the schema of the table
16+
print("Table Schema:")
17+
for column in columns_info:
18+
column_id, column_name, data_type, not_null, default_value, primary_key = column
19+
print(f"Column ID: {column_id}, Name: {column_name}, Type: {data_type}, Not Null: {not_null}, Default Value: {default_value}, Primary Key: {primary_key}")
20+
21+
# sample_data = {'familiarity': 'intermediate_knowledge', 'role': 'data_protection_officer', 'experience': '15_20', 'location': 'Ireland', 'use_frequently': 'Neutral', 'complexity': 'Neutral', 'ease_of_use': 'Neutral', 'need_support': 'Neutral', 'integration': 'Neutral', 'inconsistency': 'Neutral', 'learn_quickly': 'Neutral', 'cumbersome': 'Neutral', 'confidence': 'Neutral', 'learning_curve': 'Neutral', 'navigation': 'Neutral', 'relevance': 'Neutral', 'comprehensive': 'Neutral', 'useful_recommendations': 'Neutral', 'overall_satisfaction': 'Not specified', 'recommend': '5', 'best_feature': 'dadaw', 'biggest_difficulty': 'dawdawd', 'missing_feature': 'dadwadwa', 'additional_comments': 'wadwadaw'}
22+
23+
# columns = ', '.join(sample_data.keys())
24+
# placeholders = ', '.join(['?'] * len(sample_data))
25+
26+
# # Prepare the INSERT statement
27+
# sql = f"INSERT INTO feedback ({columns}) VALUES ({placeholders})"
28+
# print(sql)
29+
# cursor.execute(sql, tuple(sample_data.values()))
30+
# conn.commit()
31+
32+
# Close the connection
33+
conn.close()

main.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_answer_definition(self, question_number, answer_label):
8080
query = f'''
8181
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
8282
PREFIX assess: <http://JP_ontology.org/assessment/>
83-
83+
8484
SELECT ?answerDef
8585
WHERE {{
8686
?answer rdf:type assess:MCQ.{question_number} ;
@@ -95,7 +95,7 @@ def get_answer_definition(self, question_number, answer_label):
9595
else:
9696
return None
9797

98-
def get_article_info(self, article_label):
98+
def get_article_info(self, article_label):
9999
"""Fetches information about an article given its label."""
100100
query = f'''
101101
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@@ -111,7 +111,7 @@ def get_article_info(self, article_label):
111111
FILTER (LANG(?definition) = "en")
112112
}}
113113
'''
114-
114+
115115
results = self.run_sparql_query(query)
116116
return results
117117

@@ -200,7 +200,7 @@ def get_recommendation(self, mcq_number):
200200
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
201201
PREFIX dct: <http://purl.org/dc/terms/>
202202
PREFIX nis2v: <http://JP_ontology.org/nis2v#>
203-
203+
204204
SELECT ?control ?recommendation
205205
WHERE {{
206206
?question skos:altLabel "MCQ.{mcq_number}"@en ;
@@ -219,7 +219,7 @@ def get_article_label_for_question(self, mcq_number):
219219
query = f'''
220220
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
221221
PREFIX dct: <http://purl.org/dc/terms/>
222-
222+
223223
SELECT ?articleLabel ?definition
224224
WHERE {{
225225
?question skos:altLabel "MCQ.{mcq_number}"@en ;
@@ -228,7 +228,7 @@ def get_article_label_for_question(self, mcq_number):
228228
skos:definition ?definition .
229229
}}
230230
'''
231-
231+
232232
results = self.run_sparql_query(query)
233233

234234
if results['results']['bindings']:
@@ -530,7 +530,7 @@ def complete():
530530
details = json.dumps(grouped_choices)
531531
conn = sqlite3.connect('assessment_results.db')
532532
c = conn.cursor()
533-
c.execute('''UPDATE results SET total_score=?, compliance_percentage=?, details=?
533+
c.execute('''UPDATE results SET total_score=?, compliance_percentage=?, details=?
534534
WHERE user_id=?''', (total_score, compliance_percentage, details, user_id))
535535
conn.commit()
536536
conn.close()
@@ -628,7 +628,7 @@ def init_db():
628628
total_score INTEGER,
629629
compliance_percentage REAL,
630630
details TEXT,
631-
consent TEXT,
631+
consent TEXT,
632632
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
633633
)
634634
''')
@@ -864,8 +864,8 @@ def feedback():
864864

865865
@app.route('/submit_feedback', methods=['POST'])
866866
def submit_feedback():
867-
user_id = request.form.get('user_id')
868867
feedback_data = {
868+
'user_id': request.form.get('user_id'),
869869
'familiarity': request.form.get('familiarity'),
870870
'role': request.form.get('role'),
871871
'experience': request.form.get('experience'),
@@ -884,7 +884,7 @@ def submit_feedback():
884884
'relevance': request.form.get('relevance'),
885885
'comprehensive': request.form.get('comprehensive'),
886886
'useful_recommendations': request.form.get('useful_recommendations'),
887-
'overall_satisfaction': request.form.get('overall_satisfaction'),
887+
'overall_satisfaction': request.form.get('overall_satisfaction', "Not specified"),
888888
'recommend': request.form.get('recommend'),
889889
'best_feature': request.form.get('best_feature'),
890890
'biggest_difficulty': request.form.get('biggest_difficulty'),
@@ -894,27 +894,13 @@ def submit_feedback():
894894

895895
conn = sqlite3.connect('assessment_results.db')
896896
c = conn.cursor()
897-
c.execute('''
898-
INSERT INTO feedback (
899-
user_id, familiarity, role, experience, location, use_frequently, complexity,
900-
ease_of_use, need_support, integration, inconsistency, learn_quickly,
901-
cumbersome, confidence, learning_curve, navigation, relevance,
902-
comprehensive, useful_recommendations, overall_satisfaction,
903-
recommend, best_feature, biggest_difficulty, missing_feature,
904-
additional_comments
905-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
906-
''', (
907-
user_id, feedback_data['familiarity'], feedback_data['role'], feedback_data['experience'], feedback_data['location'],
908-
feedback_data['use_frequently'], feedback_data['complexity'], feedback_data['ease_of_use'],
909-
feedback_data['need_support'], feedback_data['integration'], feedback_data['inconsistency'],
910-
feedback_data['learn_quickly'], feedback_data['cumbersome'], feedback_data['confidence'],
911-
feedback_data['learning_curve'], feedback_data['navigation'], feedback_data['relevance'],
912-
feedback_data['comprehensive'], feedback_data['useful_recommendations'], feedback_data['overall_satisfaction'],
913-
feedback_data['recommend'], feedback_data['best_feature'], feedback_data['biggest_difficulty'],
914-
feedback_data['missing_feature'], feedback_data['additional_comments']
915-
))
916897

898+
columns = ', '.join(feedback_data.keys())
899+
placeholders = ', '.join(['?'] * len(feedback_data))
917900

901+
# Prepare the INSERT statement
902+
sql = f"INSERT INTO feedback ({columns}) VALUES ({placeholders})"
903+
c.execute(sql, tuple(feedback_data.values()))
918904

919905
# Commit the transaction and close the connection
920906
conn.commit()
@@ -923,9 +909,6 @@ def submit_feedback():
923909
# Redirect to a thank you page or another appropriate page
924910
return redirect(url_for('thank_you'))
925911

926-
# Render the feedback form
927-
return render_template('feedback.html')
928-
929912
@app.route('/view_feedback')
930913
def view_feedback():
931914
conn = sqlite3.connect('assessment_results.db')

0 commit comments

Comments
 (0)