Project Cover Page (AutoRecovered)
Project Cover Page (AutoRecovered)
Name: _______________________________________
Grade: _______________________________________
Roll no: ______________________________________
Page | 1
Acknowledgement
Page | 2
COMPUTER SCIENCE
CERTIFICATE
_______________ ______________
_______________ ______________
Page | 3
Index
1. Aim of the project Page No.
Page | 4
Aim of the project:
The aim of this project is to develop a Python-based system using SQLite3 and
Pandas that tracks the repair status of machines. The system organizes the
machines into two categories: repaired and unrepaired, and exports the sorted
data into two separate Excel sheets. The system also ensures data integrity by
preventing duplicate entries
Page | 5
System Requirements Hardware:
1.A computer with at least 4 GB of RAM.
2.Hard disk with 500 MB of free space.
3.Software: Operating System: Windows 10/11, macOS, or Linux.
4.Python 3.6 or later. SQLite3.
5.Pandas library.
6. Openpyxl or XlsxWriter for Excel file handling
Page | 6
Installation Procedure Install
Python:
Download and install Python from python.org. Ensure you add
Python to your PATH during installation. Install Required Python
Packages:
1.pip install sqlite3
2.pip install pandas
3.pip install openpyxl
# Optional: Required for Excel file handling RUN THE SCRIPT:
1.python machine_tracker.py
Page | 7
System Layout Database:
The system uses an SQLite3 database (machines.db) to store
machine data, ensuring each machine entry is unique.
Data Management: Data is inserted, queried, and
manipulated using SQL commands through SQLite3.
Data Export: Pandas library is used to sort the data and export it to
Excel files, categorized by
Page | 8
Functions and Modules Used Modules:
sqlite3: For database operations like creating tables, inserting data,
and querying.
pandas: For data manipulation, querying the database results, and
exporting to Excel.
openpyxl (optional): For handling Excel file creation (can also use
XlsxWriter)
Page | 9
Functions:
Database Setup:
CREATE TABLE IF NOT EXISTS: Creates the table structure with a
primary key to avoid duplicates.
Data Insertion:
INSERT INTO: Inserts new machine records into the database.
Catches sqlite3.IntegrityError to avoid duplicates.
Data Querying: pd.read_sql_query: Retrieves data from the database
based on repair status.
Excel Export: pd.ExcelWriter: Writes the sorted data into two
separate Excel sheets.
Page | 10
C0DE
import sqlite3
import pandas as pd
cursor.execute('''
CREATE TABLE IF NOT EXISTS
repaired_machines (
Name TEXT,
Page | 11
SerialNumber TEXT PRIMARY KEY,
Nationality TEXT,
Repaired TEXT,
CashSpent REAL
)
''')
Page | 12
{serial_number} added successfully.")
except sqlite3.IntegrityError:
print(f"Entry with Serial Number
{serial_number} already exists.")
def export_data_to_excel():
# Query repaired machines
cursor.execute('''
SELECT * FROM machines WHERE
Repaired = 'Yes'
''')
repaired_data = cursor.fetchall()
if repaired_data:
# Convert to DataFrame and export to
Excel
df_repaired =
pd.DataFrame(repaired_data,
columns=['Name', 'SerialNumber',
'Nationality', 'Repaired', 'CashSpent'])
df_repaired.to_excel('repaired_machines.xlsx',
index=False)
Page | 13
print("Repaired machines exported to
'repaired_machines.xlsx'.")
''')
conn.commit()
Page | 14
else:
print("No repaired machines found.")
if unrepaired_data:
df_unrepaired.to_excel('unrepaired_machines.
xlsx', index=False)
print("Unrepaired machines exported to
'unrepaired_machines.xlsx'.")
else:
Page | 15
print("No unrepaired machines found.")
def main():
while True:
print("\nOptions:")
print("1. Add a new entry")
print("2. Export data to Excel and sort
repaired machines")
print("3. Exit")
if choice == '1':
name = input("Enter Name: ").strip()
serial_number = input("Enter Serial
Number: ").strip()
Page | 16
repaired = input("Is it repaired?
(Yes/No): ").strip()
cash_spent = input("Enter Cash Spent:
").strip()
try:
cash_spent = float(cash_spent)
add_entry(name, serial_number,
nationality, repaired, cash_spent)
except ValueError:
print("Invalid cash spent value. Please
enter a numeric value.")
else:
print("Invalid choice. Please try again.")
Page | 17
conn.close()
if __name__ == "__main__":
main()
Page | 18
Output
Database:
A SQLite database file (machines.db) containing the machine
records. Excel Sheets: An Excel file (machines_report.xlsx) with two
sheets: 1. Repaired Machines: Contains all machines that have
been repaired. Unrepaired Machines: Contains all machines that
are not yet repaired.
Page | 19
Errors Identified
Duplicate Entries:
If a duplicate machine ID is inserted, the script raises an
sqlite3.IntegrityError, which is handled gracefully by ignoring the
duplicate entry.
Page | 20
Future Modifications
User Interface:
Develop a graphical user interface (GUI) for easier data entry and
report generation.
Detailed Reports:
Add more detailed filtering options, such as filtering by machine
type, repair date, or technician.
Page | 21
Bibliography Python documentation:
https://docs.python.org/3/ Pandas documentation:
https://pandas.pydata.org/ SQLite3 documentation:
https://www.sqlite.org/docs.html OpenPyXL documentation:
https://openpyxl.readthedocs.io/ en/stable/
Page | 22