🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

This project integrates two C++ programs to create a smart task manager combined with an AI-based productivity analyzer. The two programs work together by sharing a MySQL database.
The task manager helps users in:
Creating, deleting, organizing, and updating tasks.
Storing task data in a MySQL database.
Managing tasks through a lightweight GUI.
The AI module analyzes completed tasks to:
Track productivity trends.
Use machine learning to enhance future task assignments.
Extract keywords and classify tasks into categories such as urgent, work, personal, etc.
The task manager saves task details in a MySQL database.
The AI analyzer reads the database, processes the data, and provides insights.
Communication is established through database sharing or inter-process communication (IPC).
This program allows users to add, view, and complete tasks while storing them in a MySQL database.
task_manager.cpp
#include <iostream>
#include <mysql/mysql.h>
using namespace std;
// Database connection function
MYSQL* connectDB() {
MYSQL* conn = mysql_init(nullptr);
if (conn == nullptr || !mysql_real_connect(conn, "localhost", "root", "password", "task_db", 3306, nullptr, 0)) {
cerr << "Database connection failed: " << mysql_error(conn) << endl;
exit(1);
}
return conn;
}
// Create table if it does not exist
void createTable(MYSQL* conn) {
string query = "CREATE TABLE IF NOT EXISTS tasks ("
"id INT AUTO_INCREMENT PRIMARY KEY,"
"title VARCHAR(255),"
"category VARCHAR(100),"
"completed BOOLEAN DEFAULT 0)";
mysql_query(conn, query.c_str());
}
// Add a new task
void addTask(MYSQL* conn, const string& title, const string& category) {
string query = "INSERT INTO tasks (title, category) VALUES ('" + title + "', '" + category + "')";
mysql_query(conn, query.c_str());
}
// View all tasks
void viewTasks(MYSQL* conn) {
MYSQL_RES* res;
MYSQL_ROW row;
mysql_query(conn, "SELECT * FROM tasks");
res = mysql_store_result(conn);
cout << "\nTasks:\n";
while ((row = mysql_fetch_row(res))) {
cout << "ID: " << row[0] << " | Title: " << row[1] << " | Category: " << row[2]
<< " | Completed: " << (stoi(row[3]) ? "Yes" : "No") << endl;
}
mysql_free_result(res);
}
// Mark task as completed
void completeTask(MYSQL* conn, int taskId) {
string query = "UPDATE tasks SET completed = 1 WHERE id = " + to_string(taskId);
mysql_query(conn, query.c_str());
}
int main() {
MYSQL* conn = connectDB();
createTable(conn);
int choice;
while (true) {
cout << "\n1. Add Task\n2. View Tasks\n3. Complete Task\n4. Exit\nChoice: ";
cin >> choice;
if (choice == 1) {
string title, category;
cin.ignore();
cout << "Task Title: "; getline(cin, title);
cout << "Category: "; getline(cin, category);
addTask(conn, title, category);
} else if (choice == 2) {
viewTasks(conn);
} else if (choice == 3) {
int taskId;
cout << "Enter Task ID to complete: "; cin >> taskId;
completeTask(conn, taskId);
} else {
break;
}
}
mysql_close(conn);
return 0;
}
The AI analyzer reads completed tasks from the database to analyze:
Productivity trends: Tracks how many tasks are completed daily.
Task categorization: Counts tasks in each category.
Time estimation: Uses task history to predict completion time.
ai_analyzer.cpp
#include <iostream>
#include <map>
#include <mysql/mysql.h>
using namespace std;
// Connect to MySQL\MYSQL* connectDB() {
MYSQL* conn = mysql_init(nullptr);
if (conn == nullptr || !mysql_real_connect(conn, "localhost", "root", "password", "task_db", 3306, nullptr, 0)) {
cerr << "Database connection failed: " << mysql_error(conn) << endl;
exit(1);
}
return conn;
}
// Analyze task completion trends
void analyzeProductivity(MYSQL* conn) {
MYSQL_RES* res;
MYSQL_ROW row;
map<string, int> categoryCount;
mysql_query(conn, "SELECT category FROM tasks WHERE completed = 1");
res = mysql_store_result(conn);
while ((row = mysql_fetch_row(res))) {
categoryCount[row[0]]++;
}
mysql_free_result(res);
cout << "\nCompleted Task Analysis:\n";
for (const auto& entry : categoryCount) {
cout << "Category: " << entry.first << " | Completed: " << entry.second << endl;
}
}
// Predict task completion time
void predictTaskTime(MYSQL* conn) {
MYSQL_RES* res;
MYSQL_ROW row;
int completedCount = 0;
mysql_query(conn, "SELECT COUNT(*) FROM tasks WHERE completed = 1");
res = mysql_store_result(conn);
if ((row = mysql_fetch_row(res))) {
completedCount = stoi(row[0]);
}
mysql_free_result(res);
int estimatedTime = (completedCount > 0) ? (completedCount * 2) : 5;
cout << "\nEstimated completion time for new tasks: " << estimatedTime << " minutes\n";
}
int main() {
MYSQL* conn = connectDB();
int choice;
while (true) {
cout << "\n1. Analyze Productivity\n2. Predict Task Time\n3. Exit\nChoice: ";
cin >> choice;
if (choice == 1) {
analyzeProductivity(conn);
} else if (choice == 2) {
predictTaskTime(conn);
} else {
break;
}
}
mysql_close(conn);
return 0;
}
Run the Task Manager to add and complete tasks.
Run the AI Analyzer to analyze completed tasks and predict task times.
Both programs share the same MySQL database for integration.
This project efficiently manages tasks and improves productivity using AI-driven insights.
Comments
Post a Comment