Skip to content

Commit

Permalink
Changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya-vastare committed Oct 9, 2024
1 parent ba17ab7 commit c48ea15
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 202 deletions.
195 changes: 30 additions & 165 deletions Backend/SQLFILE.sql
Original file line number Diff line number Diff line change
@@ -1,170 +1,35 @@
-- Create a new database for the SPROCTOR project
CREATE DATABASE SPROCTOR;

-- Use the new database
USE SPROCTOR;

-- Create the Exams table
CREATE TABLE Exams (
exam_id INT AUTO_INCREMENT PRIMARY KEY, -- Unique identifier for each exam
exam_name VARCHAR(255) NOT NULL, -- Name or title of the exam
exam_date DATE NOT NULL, -- Date of the exam
duration INT NOT NULL, -- Duration of the exam in minutes
subject VARCHAR(100) NOT NULL -- Subject associated with the exam
CREATE TABLE HeadMovements (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id VARCHAR(50) NOT NULL,
session_id VARCHAR(50) NOT NULL,
look_up FLOAT DEFAULT 0,
look_down FLOAT DEFAULT 0,
look_left FLOAT DEFAULT 0,
look_right FLOAT DEFAULT 0,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert sample data into the Exams table
-- Insert new sample data into the Exams table
-- Insert 100 new sample data into the Exams table
INSERT INTO Exams (exam_name, exam_date, duration, subject) VALUES
('Algebra Midterm', '2024-09-01', 40, 'Mathematics'),
('Calculus Final', '2024-09-02', 60, 'Mathematics'),
('Geometry Quiz', '2024-09-03', 30, 'Mathematics'),
('Statistics Assignment', '2024-09-04', 50, 'Mathematics'),
('Trigonometry Test', '2024-09-05', 45, 'Mathematics'),
('Physics Basics', '2024-09-06', 55, 'Physics'),
('Advanced Physics', '2024-09-07', 70, 'Physics'),
('Thermodynamics', '2024-09-08', 80, 'Physics'),
('Quantum Mechanics', '2024-09-09', 90, 'Physics'),
('Nuclear Physics', '2024-09-10', 75, 'Physics'),
('Organic Chemistry', '2024-09-11', 30, 'Chemistry'),
('Inorganic Chemistry', '2024-09-12', 40, 'Chemistry'),
('Physical Chemistry', '2024-09-13', 50, 'Chemistry'),
('Biochemistry Exam', '2024-09-14', 60, 'Chemistry'),
('Analytical Chemistry', '2024-09-15', 70, 'Chemistry'),
('Cell Biology', '2024-09-16', 55, 'Biology'),
('Genetics Exam', '2024-09-17', 65, 'Biology'),
('Ecology Quiz', '2024-09-18', 45, 'Biology'),
('Microbiology Test', '2024-09-19', 50, 'Biology'),
('Botany Exam', '2024-09-20', 60, 'Biology'),
('World History', '2024-09-21', 75, 'History'),
('Modern History', '2024-09-22', 80, 'History'),
('Ancient Civilizations', '2024-09-23', 70, 'History'),
('US History Exam', '2024-09-24', 85, 'History'),
('European History', '2024-09-25', 90, 'History'),
('Shakespeare Studies', '2024-09-26', 50, 'English'),
('Poetry Analysis', '2024-09-27', 45, 'English'),
('Prose Exam', '2024-09-28', 60, 'English'),
('Grammar Test', '2024-09-29', 30, 'English'),
('Creative Writing', '2024-09-30', 40, 'English'),
('Programming Basics', '2024-10-01', 75, 'Computer Science'),
('Data Structures', '2024-10-02', 85, 'Computer Science'),
('Algorithms', '2024-10-03', 90, 'Computer Science'),
('Software Engineering', '2024-10-04', 70, 'Computer Science'),
('Database Management', '2024-10-05', 60, 'Computer Science'),
('Microeconomics', '2024-10-06', 80, 'Economics'),
('Macroeconomics', '2024-10-07', 90, 'Economics'),
('Econometrics', '2024-10-08', 100, 'Economics'),
('International Economics', '2024-10-09', 70, 'Economics'),
('Behavioral Economics', '2024-10-10', 60, 'Economics'),
('Calculus Review', '2024-10-11', 50, 'Mathematics'),
('Discrete Mathematics', '2024-10-12', 55, 'Mathematics'),
('Linear Algebra', '2024-10-13', 60, 'Mathematics'),
('Probability Theory', '2024-10-14', 45, 'Mathematics'),
('Mathematical Modelling', '2024-10-15', 70, 'Mathematics'),
('Electricity and Magnetism', '2024-10-16', 80, 'Physics'),
('Wave Dynamics', '2024-10-17', 75, 'Physics'),
('Optics', '2024-10-18', 60, 'Physics'),
('Classical Mechanics', '2024-10-19', 70, 'Physics'),
('Astrophysics', '2024-10-20', 90, 'Physics'),
('Environmental Chemistry', '2024-10-21', 45, 'Chemistry'),
('Chemical Kinetics', '2024-10-22', 50, 'Chemistry'),
('Thermodynamic Processes', '2024-10-23', 55, 'Chemistry'),
('Coordination Chemistry', '2024-10-24', 65, 'Chemistry'),
('Chemical Engineering', '2024-10-25', 80, 'Chemistry'),
('Anatomy', '2024-10-26', 55, 'Biology'),
('Physiology', '2024-10-27', 60, 'Biology'),
('Botany and Ecology', '2024-10-28', 70, 'Biology'),
('Molecular Biology', '2024-10-29', 75, 'Biology'),
('Genomics', '2024-10-30', 80, 'Biology'),
('Philosophy of History', '2024-10-31', 60, 'History'),
('Sociology Exam', '2024-11-01', 50, 'Social Science'),
('Political Science', '2024-11-02', 70, 'Social Science'),
('International Relations', '2024-11-03', 80, 'Social Science'),
('Psychology Basics', '2024-11-04', 75, 'Social Science'),
('Social Research Methods', '2024-11-05', 60, 'Social Science'),
('American Literature', '2024-11-06', 55, 'English'),
('Literary Criticism', '2024-11-07', 65, 'English'),
('Modernist Literature', '2024-11-08', 70, 'English'),
('Postcolonial Literature', '2024-11-09', 60, 'English'),
('Shakespearean Tragedy', '2024-11-10', 75, 'English'),
('Web Development Basics', '2024-11-11', 70, 'Computer Science'),
('Mobile App Development', '2024-11-12', 75, 'Computer Science'),
('Software Testing', '2024-11-13', 80, 'Computer Science'),
('Cloud Computing', '2024-11-14', 90, 'Computer Science'),
('Machine Learning', '2024-11-15', 100, 'Computer Science'),
('Behavioral Economics Review', '2024-11-16', 80, 'Economics'),
('Market Structures', '2024-11-17', 70, 'Economics'),
('Economic Policies', '2024-11-18', 90, 'Economics'),
('Finance Basics', '2024-11-19', 75, 'Economics'),
('Investment Strategies', '2024-11-20', 85, 'Economics');
('Biology Midterm', '2024-11-21', 65, 'Biology'),
('Chemistry Final', '2024-11-22', 75, 'Chemistry'),
('Physics Quiz', '2024-11-23', 35, 'Physics'),
('Statistics Project', '2024-11-24', 40, 'Mathematics'),
('Calculus Exam', '2024-11-25', 50, 'Mathematics'),
('Computer Networks', '2024-11-26', 70, 'Computer Science'),
('Discrete Structures', '2024-11-27', 60, 'Computer Science'),
('Operating Systems', '2024-11-28', 80, 'Computer Science'),
('Database Systems', '2024-11-29', 75, 'Computer Science'),
('Web Programming', '2024-11-30', 85, 'Computer Science'),
('Algebra II', '2024-12-01', 50, 'Mathematics'),
('Calculus III', '2024-12-02', 65, 'Mathematics'),
('Vector Calculus', '2024-12-03', 55, 'Mathematics'),
('Graph Theory', '2024-12-04', 60, 'Mathematics'),
('Statistical Inference', '2024-12-05', 70, 'Mathematics'),
('Thermodynamics Midterm', '2024-12-06', 80, 'Physics'),
('Electromagnetism Final', '2024-12-07', 90, 'Physics'),
('Quantum Physics Quiz', '2024-12-08', 40, 'Physics'),
('Classical Mechanics Assignment', '2024-12-09', 50, 'Physics'),
('Astrophysics Test', '2024-12-10', 60, 'Physics'),
('Organic Chemistry Midterm', '2024-12-11', 70, 'Chemistry'),
('Physical Chemistry Final', '2024-12-12', 80, 'Chemistry'),
('Analytical Chemistry Quiz', '2024-12-13', 45, 'Chemistry'),
('Biochemistry Assignment', '2024-12-14', 60, 'Chemistry'),
('Chemical Engineering Test', '2024-12-15', 75, 'Chemistry'),
('Microbiology Midterm', '2024-12-16', 65, 'Biology'),
('Cell Biology Final', '2024-12-17', 70, 'Biology'),
('Genetics Quiz', '2024-12-18', 50, 'Biology'),
('Ecology Assignment', '2024-12-19', 40, 'Biology'),
('Evolutionary Biology Test', '2024-12-20', 60, 'Biology'),
('History of Science', '2024-12-21', 55, 'History'),
('American History', '2024-12-22', 80, 'History'),
('World History Final', '2024-12-23', 90, 'History'),
('Contemporary History Quiz', '2024-12-24', 70, 'History'),
('Historical Analysis Test', '2024-12-25', 85, 'History'),
('Creative Writing Midterm', '2024-12-26', 45, 'English'),
('Literary Analysis Final', '2024-12-27', 55, 'English'),
('American Literature Quiz', '2024-12-28', 60, 'English'),
('Shakespeare Studies Assignment', '2024-12-29', 50, 'English'),
('Poetry Workshop Test', '2024-12-30', 70, 'English'),
('Philosophy Basics', '2024-12-31', 65, 'Philosophy'),
('Ethics in Science', '2025-01-01', 75, 'Philosophy'),
('Political Philosophy', '2025-01-02', 80, 'Philosophy'),
('Philosophy of Mind', '2025-01-03', 70, 'Philosophy'),
('Existentialism', '2025-01-04', 90, 'Philosophy'),
('Fundamentals of Economics', '2025-01-05', 75, 'Economics'),
('Behavioral Economics Exam', '2025-01-06', 80, 'Economics'),
('International Trade', '2025-01-07', 85, 'Economics'),
('Economic Theory', '2025-01-08', 90, 'Economics'),
('Development Economics', '2025-01-09', 100, 'Economics'),
('Software Engineering Principles', '2025-01-10', 70, 'Computer Science'),
('Agile Methodologies', '2025-01-11', 75, 'Computer Science'),
('Software Design Patterns', '2025-01-12', 80, 'Computer Science'),
('User Experience Design', '2025-01-13', 90, 'Computer Science'),
('Artificial Intelligence Basics', '2025-01-14', 100, 'Computer Science'),
('Psychology Basics', '2025-01-15', 60, 'Social Science'),
('Cognitive Psychology', '2025-01-16', 70, 'Social Science'),
('Social Psychology', '2025-01-17', 80, 'Social Science'),
('Developmental Psychology', '2025-01-18', 75, 'Social Science'),
('Research Methods in Psychology', '2025-01-19', 65, 'Social Science'),
('Sociology of Families', '2025-01-20', 50, 'Social Science'),
('Urban Sociology', '2025-01-21', 60, 'Social Science'),
('Sociology of Education', '2025-01-22', 70, 'Social Science'),
('Sociology of Work', '2025-01-23', 75, 'Social Science'),
('Sociological Theory', '2025-01-24', 80, 'Social Science'),
('Modern World History', '2025-01-25', 90, 'History'),
('Cultural Anthropology', '2025-01-26', 70, 'Social Science'),
('Introduction to Sociology', '2025-01-27', 55, 'Social Science'),
('Globalization and Society', '2025-01-28', 65, 'Social Science'),
('Social Issues and Policy', '2025-01-29', 75, 'Social Science'),
('World Geography', '2025-01-30', 85, 'Social Science');
-- Continue inserting the rest of the sample records
INSERT INTO HeadMovements (student_id, session_id, look_up, look_down, look_left, look_right)
VALUES
('STU092', 'SESSION010', 2.0, 3.0, 1.5, 2.5),
('STU093', 'SESSION010', 1.0, 2.5, 3.0, 1.5),
('STU094', 'SESSION010', 3.0, 1.0, 2.5, 2.0),
('STU095', 'SESSION010', 2.5, 2.0, 1.0, 3.5),
('STU096', 'SESSION010', 3.0, 1.5, 3.5, 2.0),
('STU097', 'SESSION010', 1.5, 2.5, 2.0, 1.5),
('STU098', 'SESSION010', 2.0, 3.0, 1.5, 3.0),
('STU099', 'SESSION010', 3.5, 2.5, 1.0, 2.0),
('STU100', 'SESSION010', 1.0, 1.5, 2.5, 3.5);
('STU102', 'SESSION010', 3.0, 1.5, 2.5, 1.0),
('STU103', 'SESSION010', 1.0, 3.5, 2.0, 2.5),
('STU104', 'SESSION010', 2.0, 1.0, 3.0, 2.5),
('STU105', 'SESSION010', 3.5, 2.0, 1.5, 1.0),
('STU106', 'SESSION010', 1.5, 3.0, 2.5, 3.0),
('STU107', 'SESSION010', 2.0, 2.5, 3.5, 1.0),
('STU108', 'SESSION010', 3.0, 1.0, 1.0, 2.5),
('STU109', 'SESSION010', 1.0, 2.0, 2.0, 3.5),
('STU110', 'SESSION010', 2.5, 3.5, 1.5, 1.5);
95 changes: 58 additions & 37 deletions Backend/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,94 @@

# Connect to the database
db = mysql.connector.connect(
host="localhost", # Replace with your host, usually 'localhost'
user="root", # Replace with your database username
password="ananyavastare2345", # Replace with your database password
database="SPROCTOR", # Database name
host="localhost", # Your database host
user="root", # Your database username
password="ananyavastare2345", # Your database password
database="SPROCTOR", # Your database name
)

cursor = db.cursor()

# Query to retrieve exam durations
cursor.execute("SELECT duration FROM Exams")
durations = cursor.fetchall()
# Query to retrieve look_up, look_down, look_left, and look_right values from HeadMovements
cursor.execute("SELECT look_up, look_down, look_left, look_right FROM HeadMovements")
head_movement_values = cursor.fetchall() # Retrieve all values

# Close the cursor and database connection
cursor.close()
db.close()

# Prepare heatmap data
heatmap_data = np.zeros((10, 10)) # Create a 10x10 grid
heatmap_data = np.zeros((10, 10, 4)) # Create a 10x10 grid for RGBA channels

# Populate heatmap data based on durations
for index, (duration,) in enumerate(durations):
# Populate heatmap data based on head movement values
for index, (look_up, look_down, look_left, look_right) in enumerate(
head_movement_values
):
row = index // 10 # Determine row index
col = index % 10 # Determine column index
if row < 10 and col < 10: # Check bounds
heatmap_data[row, col] = duration # Use duration as heatmap value
# Assign values to different channels
heatmap_data[row, col] = [look_up, look_down, look_left, look_right]

# Ensure first row has different colors (values)
first_row_values = np.random.rand(10) * 10 # Random values for the first row
heatmap_data[0] = first_row_values
# Normalize the heatmap data to the range [0, 1]
heatmap_data_normalized = heatmap_data / np.max(heatmap_data)

# Create the combined heatmap by averaging the channels
combined_heatmap = np.mean(
heatmap_data_normalized, axis=2
) # Average across the channels

# Initialize the figure
plt.ion() # Turn on interactive mode
fig, ax = plt.subplots() # Create a subplot


# Declare heatmap_data as global to modify it within the function
def update_heatmap():
global heatmap_data # Declare as global variable
# Lighten the heatmap data by adding random small changes
heatmap_data[1:] += np.random.uniform(
0, 1, size=heatmap_data[1:].shape
) # Random small increments
heatmap_data = np.clip(
heatmap_data, 0, np.max(heatmap_data)
) # Keep values within bounds
heatmap.set_data(heatmap_data) # Update heatmap data


# Create the heatmap
heatmap = ax.imshow(
heatmap_data,
cmap="YlOrRd",
combined_heatmap,
cmap="YlOrRd", # Choose a color map
interpolation="nearest",
vmin=0,
vmax=np.max(heatmap_data),
vmax=1, # Set the range for color normalization
)
plt.colorbar(heatmap) # Add a colorbar to indicate scale
plt.title("Heatmap of Exam Durations")
plt.title("Combined Heatmap of Look Directions")

# Loop to update heatmap every 5 seconds
# Add labels for each direction without overlap
for i, direction in enumerate(["Look Up", "Look Down", "Look Left", "Look Right"]):
ax.text(
0.5,
-0.15 - (i * 0.05), # Adjust this value to position the labels appropriately
direction,
transform=ax.transAxes,
ha="center",
va="top",
fontsize=10,
color="black",
fontweight="bold",
)

# Loop to update heatmap every second
for _ in range(10): # Run the loop 10 times
update_heatmap() # Update the heatmap
plt.draw() # Redraw the updated heatmap
plt.pause(1) # Pause for 5 seconds
# Lightly modify the heatmap data for demonstration (this simulates transition)
heatmap_data_normalized += np.random.uniform(0, 0.1, heatmap_data_normalized.shape)
heatmap_data_normalized = np.clip(
heatmap_data_normalized, 0, 1
) # Keep values within [0, 1]

# Create a new combined heatmap by averaging the updated data
combined_heatmap = np.mean(
heatmap_data_normalized, axis=2
) # Average across the channels

# Update the heatmap
heatmap.set_array(combined_heatmap) # Update heatmap data
plt.draw() # Redraw the heatmap
plt.pause(1) # Pause for 1 second

# Save the figure
plt.savefig(f"heatmap_{time.strftime('%Y%m%d_%H%M%S')}.png") # Save with timestamp
plt.savefig(
f"heatmap_combined_{time.strftime('%Y%m%d_%H%M%S')}.png"
) # Save with timestamp

# Keep the plot window open at the end
plt.ioff() # Turn off interactive mode
Expand Down
Binary file added heatmap_combined_20241009_144503.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c48ea15

Please sign in to comment.