Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #8

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,32 @@
from kivy.animation import Animation
from kivy.clock import Clock
import random
from questions import questions_list
import sqlite3
from collections import Counter

conn = sqlite3.connect('quiz_questions.db')
cursor = conn.cursor()

# Create a table for questions
cursor.execute('''
CREATE TABLE IF NOT EXISTS questions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
question TEXT NOT NULL,
options TEXT NOT NULL,
correct_answer TEXT NOT NULL,
subject TEXT NOT NULL
)
''')

class Question:
def __init__(self, question, options, correct_answer, subject):
self.question = question
self.options = options
self.correct_answer = correct_answer
self.subject = subject



class HomeScreen(Screen):
pass

Expand All @@ -25,9 +48,22 @@ def on_pre_enter(self):
self.update_subject_counts()

def update_subject_counts(self):
subjects = [q.subject for q in questions_list]
self.subject_counts = dict(Counter(subjects))
self.total_questions = len(questions_list)
conn = sqlite3.connect('quiz_questions.db')
cursor = conn.cursor()

# Get total question count
cursor.execute('SELECT COUNT(*) FROM questions')
self.total_questions = cursor.fetchone()[0]

# Get subject counts
cursor.execute('SELECT subject, COUNT(*) FROM questions GROUP BY subject')
rows = cursor.fetchall()
conn.close()

# Update subject_counts dictionary
self.subject_counts = {row[0]: row[1] for row in rows}

# Clear existing widgets and add new ones
self.ids.subject_counts_box.clear_widgets()
for subject, count in self.subject_counts.items():
self.ids.subject_counts_box.add_widget(
Expand All @@ -45,6 +81,7 @@ def update_subject_counts(self):
def open_github_link(self):
webbrowser.open('https://github.com/vaibhav-rm/Dcet-prep-app')


class QuizScreen(Screen):
question_text = StringProperty()
options = ListProperty()
Expand All @@ -55,14 +92,24 @@ class QuizScreen(Screen):

def __init__(self, **kwargs):
super(QuizScreen, self).__init__(**kwargs)
self.questions = questions_list
self.questions = self.load_questions_from_db() # Load questions from the database
self.start_new_round()

def load_questions_from_db(self):
conn = sqlite3.connect('quiz_questions.db')
cursor = conn.cursor()
cursor.execute('SELECT question, options, correct_answer, subject FROM questions')
rows = cursor.fetchall()
conn.close()

# Convert rows to Question objects
return [Question(question=row[0], options=row[1].split(','), correct_answer=row[2], subject=row[3]) for row in rows]

def start_new_round(self):
self.current_questions = random.sample(self.questions, 5)
self.current_question_index = 0
self.round_score = 0
self.load_question()
self.load_question() # Call load_question to display the first question

def load_question(self):
if self.current_question_index < len(self.current_questions):
Expand Down Expand Up @@ -106,7 +153,7 @@ def next_question(self):
self.current_question_index += 1
self.ids.feedback.text = ""
self.ids.next_button.disabled = True
self.load_question()
self.load_question() # Call load_question to load the next question

class ResultScreen(Screen):
round_score = NumericProperty(0)
Expand Down Expand Up @@ -136,3 +183,5 @@ def build(self):
if __name__ == '__main__':
dectquiz().run()

conn.commit()
conn.close()
51 changes: 51 additions & 0 deletions questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ def __init__(self, question, options, correct_answer, subject):
self.correct_answer = correct_answer
self.subject = subject

import sqlite3


# Connect to SQLite database

conn = sqlite3.connect('quiz_questions.db')

cursor = conn.cursor()

cursor.execute('''

CREATE TABLE IF NOT EXISTS questions (

id INTEGER PRIMARY KEY AUTOINCREMENT,

question TEXT NOT NULL,

options TEXT NOT NULL,

correct_answer TEXT NOT NULL,

subject TEXT NOT NULL

)

''')

questions_list = [
Question(
"The project ______ relieves a project team from most regular work such as planning, tracking, and reporting responsibility?",
Expand Down Expand Up @@ -271,3 +298,27 @@ def __init__(self, question, options, correct_answer, subject):
"Project Management Skills"
)
]

# Prepare data for insertion

data_to_insert = [

(q.question, ','.join(q.options), q.correct_answer, q.subject) for q in questions_list

]


# Insert questions into the database

cursor.executemany('''

INSERT INTO questions (question, options, correct_answer, subject) VALUES (?, ?, ?, ?)

''', data_to_insert)


# Commit changes and close the connection

conn.commit()

conn.close()
Binary file added quiz_questions.db
Binary file not shown.
Loading