PRIYANSHUDHAKED commited on
Commit
6568643
·
verified ·
1 Parent(s): 98db480

Update record_attendance.py

Browse files
Files changed (1) hide show
  1. record_attendance.py +13 -10
record_attendance.py CHANGED
@@ -8,18 +8,19 @@ def record_attendance_new(present_students: list, subject: str, max_roll_number=
8
  date = datetime.now().strftime("%Y-%m-%D")
9
  length = len(present_students)
10
  ty = type(present_students).__name__ # Get the name of the type as a string
11
- st.success(f"{length} students' attendance is going to complete {ty}.")
12
-
13
  # Convert present_students to integers
14
  present_students = list(map(int, present_students))
15
  print("Present Students:", present_students) # Debugging line
16
  length = len(present_students)
17
  ty = type(present_students).__name__ # Get the name of the type as a string
18
- st.success(f"{length} students' attendance is going to complete {ty}.")
 
19
  # Get the path of the uploaded CSV file
20
  csv_file_path = f'{subject}.csv'
21
  print("CSV File Path:", csv_file_path) # Debugging line
22
-
23
  # Read the existing CSV file
24
  if os.path.exists(csv_file_path):
25
  with open(csv_file_path, 'r', newline='') as csvfile:
@@ -28,7 +29,7 @@ def record_attendance_new(present_students: list, subject: str, max_roll_number=
28
  else:
29
  # If file doesn't exist, create a new one with header and roll numbers
30
  rows = [['Roll Number']]
31
- for roll_number in range(1, 26 + 1):
32
  rows.append([str(roll_number)])
33
 
34
  # Add the new date column
@@ -36,15 +37,16 @@ def record_attendance_new(present_students: list, subject: str, max_roll_number=
36
  date_col_index = len(rows[0]) - 1
37
 
38
  # Create a list to hold the attendance status for each roll number
39
- attendance_status = ['Absent'] * 26
40
- for i in range(1, 26 + 1):
41
- if i in present_students:
42
  attendance_status[i - 1] = 'Present'
43
 
44
  # Update the attendance status in the CSV data
45
  for i, row in enumerate(rows[1:]):
46
  roll_number = int(row[0])
47
- row[date_col_index] = attendance_status[roll_number - 1]
 
48
 
49
  # Write the updated data back to the CSV file
50
  with open(csv_file_path, 'w', newline='') as csvfile:
@@ -54,7 +56,7 @@ def record_attendance_new(present_students: list, subject: str, max_roll_number=
54
  # Create a download button
55
  with open(csv_file_path, 'r') as file:
56
  csv_contents = file.read()
57
-
58
  st.download_button(
59
  label="Download updated attendance file",
60
  data=csv_contents,
@@ -63,4 +65,5 @@ def record_attendance_new(present_students: list, subject: str, max_roll_number=
63
  )
64
 
65
  print(f"Attendance recorded for {len(present_students)} students on {date} in {subject}.")
 
66
 
 
8
  date = datetime.now().strftime("%Y-%m-%D")
9
  length = len(present_students)
10
  ty = type(present_students).__name__ # Get the name of the type as a string
11
+ st.success(f"{length} students' attendance is going to complete {ty}.")
12
+
13
  # Convert present_students to integers
14
  present_students = list(map(int, present_students))
15
  print("Present Students:", present_students) # Debugging line
16
  length = len(present_students)
17
  ty = type(present_students).__name__ # Get the name of the type as a string
18
+ st.success(f"{length} students' attendance is going to complete {ty}.")
19
+
20
  # Get the path of the uploaded CSV file
21
  csv_file_path = f'{subject}.csv'
22
  print("CSV File Path:", csv_file_path) # Debugging line
23
+
24
  # Read the existing CSV file
25
  if os.path.exists(csv_file_path):
26
  with open(csv_file_path, 'r', newline='') as csvfile:
 
29
  else:
30
  # If file doesn't exist, create a new one with header and roll numbers
31
  rows = [['Roll Number']]
32
+ for roll_number in range(1, max_roll_number + 1):
33
  rows.append([str(roll_number)])
34
 
35
  # Add the new date column
 
37
  date_col_index = len(rows[0]) - 1
38
 
39
  # Create a list to hold the attendance status for each roll number
40
+ attendance_status = ['Absent'] * max_roll_number
41
+ for i in present_students:
42
+ if 1 <= i <= max_roll_number:
43
  attendance_status[i - 1] = 'Present'
44
 
45
  # Update the attendance status in the CSV data
46
  for i, row in enumerate(rows[1:]):
47
  roll_number = int(row[0])
48
+ if 1 <= roll_number <= max_roll_number:
49
+ row[date_col_index] = attendance_status[roll_number - 1]
50
 
51
  # Write the updated data back to the CSV file
52
  with open(csv_file_path, 'w', newline='') as csvfile:
 
56
  # Create a download button
57
  with open(csv_file_path, 'r') as file:
58
  csv_contents = file.read()
59
+
60
  st.download_button(
61
  label="Download updated attendance file",
62
  data=csv_contents,
 
65
  )
66
 
67
  print(f"Attendance recorded for {len(present_students)} students on {date} in {subject}.")
68
+
69