Skip to content

Commit

Permalink
Merge pull request #79 from Eugene600/ask_Me
Browse files Browse the repository at this point in the history
Ask me Tool
  • Loading branch information
IamMuuo authored Sep 2, 2024
2 parents d5cbb3a + e3cdb75 commit ba331f3
Show file tree
Hide file tree
Showing 38 changed files with 2,305 additions and 5 deletions.
Binary file added assets/images/askMe_Home.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/congratulations_askMe.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/think.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/constants/tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,16 @@ final List<Map<String, dynamic>> allTools = [
},
"description":
"Having trouble keeping track of your Assignments? We've got you covered",
},
{
"id": 10,
"name": "Ask Me",
"action": "Ask Me",
"image": "assets/images/think.jpeg",
"ontap": () {
Get.to(AskMeHome());
},
"description": "Generate quiz questions from your notes and study materials with our AI tool."

}
];
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void main() async {
GetMaterialApp(
home: const Academia(),
theme: lightModeTheme,
darkTheme: darkModeTheme,
debugShowCheckedModeBanner: false,
// darkTheme: darkModeTheme,
),
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/auth/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ class _LoginPageState extends State<LoginPage> {
isLoading = false;
});
},
// onPressed: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) => const LayoutPage(),
// ),
// );
// },
icon: const Icon(Ionicons.lock_closed),
label: const Text("Login"),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/storage/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
///
/// The database helper class is a singleton class that provides
///
/// 1. The atabase connection instance.
/// 1. The database connection instance.
/// 2. The database name
///
/// By default the database should be stored in the application's
Expand Down
22 changes: 21 additions & 1 deletion lib/storage/schemas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,25 @@ const schemas = <String, String>{
name TEXT NOT NULL,
description TEXT NOT NULL
);
"""
""",
//Ask Me
//Files from Ask Me from which questions are being generated
"askme_files": """
CREATE TABLE IF NOT EXISTS askme_files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
filePath TEXT NOT NULL,
avgScore INTEGER NOT NULL
);
""",

//AskMe Scores
"askme_scores": """
CREATE TABLE IF NOT EXISTS askme_scores (
id INTEGER PRIMARY KEY AUTOINCREMENT,
score INTEGER NOT NULL,
filesId INTEGER,
FOREIGN KEY (filesId) REFERENCES askme_files(id) ON DELETE CASCADE
);
""",
};
6 changes: 5 additions & 1 deletion lib/themes/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const lightColorScheme = ColorScheme(
shadow: Color(0xFF000000),
surfaceTint: Color(0xFF006399),
outlineVariant: Color(0xFFC2C7CF),
scrim: Color(0xFF000000),
scrim: Color(0xFF000000),
background: Colors.white,
onBackground: Colors.black,
);

const darkColorScheme = ColorScheme(
Expand Down Expand Up @@ -60,4 +62,6 @@ const darkColorScheme = ColorScheme(
surfaceTint: Color(0xFF94CCFF),
outlineVariant: Color(0xFF42474E),
scrim: Color(0xFF000000),
background: Colors.black,
onBackground: Colors.white,
);
1 change: 1 addition & 0 deletions lib/tools/ask_me/ask_me.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'pages/pages.dart';
2 changes: 2 additions & 0 deletions lib/tools/ask_me/controllers/controllers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'files_controller.dart';
export 'quizSettings_controller.dart';
64 changes: 64 additions & 0 deletions lib/tools/ask_me/controllers/files_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:get/get.dart';
import '../models/models.dart';

class FilesController extends GetxController {
RxList<AskMeFiles> files = <AskMeFiles>[].obs;
RxList<AskMeScores> scores = <AskMeScores>[].obs;

@override
void onInit() {
super.onInit();
loadFiles();
}

Future<void> loadFiles() async {
// Fetch files
FilesModelHelper().queryAll().then((value) {
files.value = value.map((e) => AskMeFiles.fromJson(e)).toList();
});

//Fetch all scores
ScoresModelHelper().queryAll().then((value) {
scores.value = value.map((e) => AskMeScores.fromJson(e)).toList();
});
}

// Fetch scores by file ID
Future<void> fetchScoresByFileId(int fileId) async {
final scoreList = await ScoresModelHelper().queryScoresByFileId(fileId);
scores.value = scoreList.map((score) => AskMeScores.fromJson(score)).toList();
}

//Adds Scores
Future<void> addScores(AskMeScores score) async {
final id = await ScoresModelHelper().create(score.toJson());
score.id = id;
scores.add(score);

// Reload files and scores
await loadFiles();
}

Future<void> addFile(AskMeFiles file) async {
final id = await FilesModelHelper().create(file.toJson());
file.id = id;
files.add(file);
await loadFiles();
}
//Update an existing file
Future<void> updateFile(AskMeFiles file) async {
await FilesModelHelper().update(file.toJson());
files[files.indexWhere((f) => f.id == file.id)] = file;

await loadFiles();
}

// Delete a file and its associated scores
Future<void> deleteFile(AskMeFiles file) async {
await FilesModelHelper().delete(file.toJson());
files.remove(file);

await loadFiles();
}
}

31 changes: 31 additions & 0 deletions lib/tools/ask_me/controllers/quizSettings_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:get/get.dart';
class QuizSettingsController extends GetxController {
var fileTitle = ''.obs;
var filePath = ''.obs;
var questionType = 'Multiple choice'.obs;
var multipleChoice = true.obs;
var selectedTimer = 2.obs;
var minute = 2.obs;
var seconds = 30.obs;

void setQuestionType(String type, bool choice) {
questionType.value = type;
multipleChoice.value = choice;
}

void setFileTitle(String title) {
fileTitle.value = title;
}
void setFilePath(String path) {
filePath.value = path;
}

void setSelectedTimer(int timer) {
selectedTimer.value = timer;
}

void setTimer(int min, sec) {
minute.value = min;
seconds.value = sec;
}
}
31 changes: 31 additions & 0 deletions lib/tools/ask_me/models/core/askMeFiles.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class AskMeFiles {
int? id;
final String title;
final String filePath;
int avgScore;

AskMeFiles({
this.id,
required this.title,
required this.filePath,
required this.avgScore,
});

factory AskMeFiles.fromJson(Map<String, dynamic> json) {
return AskMeFiles(
id: json["id"],
title: json["title"],
filePath: json['filePath'],
avgScore: json['avgScore'],
);
}

Map<String, dynamic> toJson() {
return {
'id': id,
'title': title,
'filePath': filePath,
'avgScore': avgScore,
};
}
}
28 changes: 28 additions & 0 deletions lib/tools/ask_me/models/core/askMeScores.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class AskMeScores {
int? id;
final int score;
final int filesId;

AskMeScores({
this.id,
required this.score,
required this.filesId,
});


factory AskMeScores.fromJson(Map<String, dynamic> json) {
return AskMeScores(
id: json['id'],
score: json['score'],
filesId: json['filesId'],
);
}

Map<String, dynamic> toJson() {
return {
'id': id,
'score': score,
'filesId': filesId,
};
}
}
54 changes: 54 additions & 0 deletions lib/tools/ask_me/models/core/files_model_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:academia/storage/storage.dart';
import 'package:sqflite/sqflite.dart';
import 'package:flutter/material.dart';

class FilesModelHelper implements DatabaseOperations {
static final FilesModelHelper _instance =
FilesModelHelper._internal();

factory FilesModelHelper() {
return _instance;
}

FilesModelHelper._internal();

@override
Future<int> create(Map<String, dynamic> data) async {
final db = await DatabaseHelper().database;
final id = await db.insert(
'askme_files',
data,
conflictAlgorithm: ConflictAlgorithm.replace,
);

debugPrint("[+] Files written successfully");
return id;
}

@override
Future<List<Map<String, dynamic>>> queryAll() async {
final db = await DatabaseHelper().database;
final files = await db.query('askme_files');
return files;
}

@override
Future<int> delete(Map<String, dynamic> data) async {
final db = await DatabaseHelper().database;
return await db
.delete('askme_files', where: 'id =?', whereArgs: [data["id"]]);
}

@override
Future<int> update(Map<String, dynamic> data) async {
final db = await DatabaseHelper().database;
return await db
.update('askme_files', data, where: 'id =?', whereArgs: [data['id']]);
}

@override
Future<void> truncate() async {
final db = await DatabaseHelper().database;
await db.execute('DELETE FROM askme_files');
}
}
48 changes: 48 additions & 0 deletions lib/tools/ask_me/models/core/multiple_choice.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class MultipleChoiceQuestion{
String question;
List<String> choices;
String correctAnswer;

MultipleChoiceQuestion({
required this.question,
required this.choices,
required this.correctAnswer,
});

factory MultipleChoiceQuestion.fromJson(Map<String, dynamic> json) {
return MultipleChoiceQuestion(
question: json['question'],
choices: List<String>.from(json['multiple_choice']),
correctAnswer: json['correct_answer'],
);
}

Map<String, dynamic> toJson() {
return {
'question': question,
'multiple_choice': choices,
'correct_answer': correctAnswer,
};
}
}

//Multiple choice Quiz model
class MultipleChoiceQuiz {
List<MultipleChoiceQuestion> questions;

MultipleChoiceQuiz({required this.questions});

factory MultipleChoiceQuiz.fromJson(Map<String, dynamic> json) {
return MultipleChoiceQuiz(
questions: List<MultipleChoiceQuestion>.from(
json['questions'].map((questionJson) => MultipleChoiceQuestion.fromJson(questionJson)),
),
);
}

Map<String, dynamic> toJson() {
return {
'questions': questions.map((question) => question.toJson()).toList(),
};
}
}
26 changes: 26 additions & 0 deletions lib/tools/ask_me/models/core/question.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Question {
final String question;
final String answer;

const Question({required this.question, required this.answer});

factory Question.fromJson(Map<String, dynamic> json) {
return Question(
question: json['question'],
answer: json['answer'],
);
}

Map<String, dynamic> toJson() {
return {
'question': question,
'answer': answer
};
}
}






Loading

0 comments on commit ba331f3

Please sign in to comment.