scouts_training_reports/appointments_training_reports.py
2022-05-31 12:36:32 +01:00

527 lines
39 KiB
Python

#! python3
#Appointments_Training_Reports.py
#A tool to process Compass Records and produce something human readable using the appointments report
#Licence: GPL-3.0-or-later
#Written by Stuart Griffiths, stuart.griffiths@birminghamscouts.org.uk
#Started 19/05/2022
#Version:0.3
#Released: 31/05/2022
#Status: Working - outputs to 2 seperate CSV files
#Inputs: CSV
#Outputs: multiple CSV and 1 x text file
#Next Steps: upload to Drive?, retrive automatically, send e-mails, working directory selection,
#Issues:
#Background IP: https://automatetheboringstuff.com/, Chapter 16
#Notes - CSV Column Numbers
#Membership_Number = 0
#Surname = 2
#Known_As = 3
#Email = 4
#Telephone = 5
#Member_Role = 8
#Roll_Status = 11
#Roll_Start_Date = 9
#Line_Manager = 13
#Review_Date = 14
#County Section = 18
#District = 19
#District section = 20
#Scout_Group = 21
#CE check = 23
#Advisory committee approval = 24
#commissioner approval = 25
#Committee approval = 26
#References = 27
#Wood badge = 35
#Safety Completed = 36
#Safety Due = 37
#Safeguarding completed = 38
#Safeguarding due = 39
#First Aid Completed = 40
#First Aid Due = 41
#Libraries
import os #Enables file IO
from pathlib import Path #to work out current working directory
import csv #required to handle csv files
import datetime #required to deal with dates for due items
from dateutil.relativedelta import relativedelta #required to calculate 6 months later
#1. Set up Output files
#CSV files
late_mandatory_file = open('late_mandatory_training.csv', 'w', newline='')
late_mandatory = csv.writer(late_mandatory_file)
late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
due_mandatory_file = open('due_mandatory_training.csv', 'w', newline='')
due_mandatory = csv.writer(due_mandatory_file)
due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
#text files
statistics_file = open('_total_training_statistics.txt', 'w')
#Modules
def training_report():
#2. Open the file
file_name = str(Path.cwd()) + '/' + str('County Appointments Report (Beta).csv')
input_file = open(file_name) #assumes file is in working directory
#Create a list using the CSV file
input_data_reader = csv.reader(input_file)
input_data = list(input_data_reader)
#2.1 Set months variable
due_months = 3
#3. Process the data
#Start at row 1 for the OSM output
line_num = int(1) #strips header out
#Ensure we start writing at row 2
row_num_missing = 2
row_num_late = 2
row_num_due = 2
row_num_started = 2
#create lists to process
due_list = []
late_list = []
#create lists for counting purposes
safety_missing_list = []
safeguarding_missing_list = []
firstaid_missing_list = []
safety_due_list = []
safeguarding_due_list = []
firstaid_due_list = []
#to avoid errors
safety_status = False
safeguarding_status = False
firstaid_status = False
safety_due_status = False
safeguarding_due_status = False
firstaid_due_status = False
role_training = False
firstaid_required = False
while line_num < (len(input_data)-1): #while there is an entry to handle, do this
#3.0 Test 0 - Is this the last entry for the person?
#Required to ensure only the primary role is being processed
line_num_next = line_num + 1
current_line_membership = input_data[line_num][0]
try:
next_line_membership = input_data[line_num_next][0]
except:
a= 1
#If membership numbers are equal, we are not at primary role so want to skip to next line
#if they are not equal, we are at primary role and so want to process
if next_line_membership != current_line_membership:
#3.1 acquire dates
#Get today's date
today1 = str(datetime.date.today())
today = datetime.datetime.strptime(today1, "%Y-%m-%d") #dodgy work around comparing datetime to date object error
#Establish comparative date - set by variable
Xmonths_later = datetime.datetime.now() + relativedelta(months=+due_months)
#3.2 Does the role require mandatory training?
#Grab the role type
role = input_data[line_num][8]
role_list = ['Group Occasional Helper', 'District Occasional Helper', 'County Occasional Helper', 'County President', 'County Vice President', 'District President', 'District Vice President', 'Group President', 'Group Vice President', 'County TSA Council - Nominated Representative', 'County Sub-Committee Member', 'County Supporter', 'District Supporter', 'Group Supporter', 'County Award Certificate Recipient', 'County Chair', 'District Chair', 'Group Chair', 'Retired Member', 'Group Chairman', 'Scout Network Member']
if role not in role_list:
role_training = True
#Of course some roles do need safety and safeguarding but not first aid....
role_list_first_aid = ['County Treasurer', 'District Treasurer', 'Group Treasurer', 'Section Assistant', 'Group Section Assistant', 'District Section Assistant', 'County Section Assistant', 'County Secretary', 'District Secretary', 'Group Secretary', 'County Treasurer', 'District Treasurer', 'Group Treasurer', 'County Executive Committee Member', 'District Executive Committee Member', 'Group Executive Committee Member', 'Group Executive Committee Member - Elected Member', 'County Appointments Advisory Committee Member', 'District Appointments Advisory Committee Member', 'District Skills Instructor', 'County Skills Instructor', 'Group Skills Instructor', 'County Administrator', 'District Administrator', 'Group Administrator', 'County Badge Secretary', 'District Badge Secretary', 'Group Badge Secretary', 'Scout Active Support Member', 'District Training Administrator', 'County Training Administrator', 'County Chaplain', 'District Chaplain' 'Section Assistant - Squirrel Scouts', 'Section Assistant - Beaver Scouts', 'Section Assistant - Cub Scouts', 'Section Assistant - Scouts', 'District Section Assistant - Explorer Scouts', 'Assistant Section Leader', 'Assistant Section Leader - Beaver Scouts', 'Assistant Section Leader - Cub Scouts', 'Assistant Section Leader - Scouts', 'County Scout Active Support Co-ordinator', 'County Scout Active Support Member', 'District Scout Active Support Member', 'Group Scout Active Support Member', 'County Training Adviser', 'County Scout Active Support Manager', 'District Scout Active Support Manager' ]
if role not in role_list_first_aid:
firstaid_required = True
#3.3 late to complete testing
#3.3.1 safety
#Read the column
safety = input_data[line_num][36]
#print(safety)
#print(input_data[line_num][37])
#Check is it late?
#If date is blank, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if safety == "" and role_training == True:
safety_status = True #marker that safety is late
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safety_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safety_missing_list.append(member_number)
if input_data[line_num][37] != "" and role_training == True:
#Convert string to date object, has to be done here for the blanks!
safety = datetime.datetime.strptime(input_data[line_num][37], "%d/%m/%Y")
#Check is it late?
#If date is less than today when program is ran, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if safety < today:
safety_status = True #marker that safety is late
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safety_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safety_missing_list.append(member_number)
#3.3.2 Safeguarding
#Read the column
safeguarding = input_data[line_num][38]
#Check is it late?
#If date is less than today when program is ran, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if safeguarding == "" and role_training == True:
safeguarding_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safeguarding_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safeguarding_missing_list.append(member_number)
if input_data[line_num][39] != "" and role_training == True:
#Convert string to date object, has to be done here for the blanks!
safeguarding = datetime.datetime.strptime(input_data[line_num][39], "%d/%m/%Y")
#Check is it late?
#If date is less than today when program is ran, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if safeguarding < today:
safeguarding_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safeguarding_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safeguarding_missing_list.append(member_number)
#3.3.3 First Aid
#Read the column
firstaid = input_data[line_num][40]
#Check is it late?
#If date is blank, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if firstaid == "" and role_training == True and firstaid_required == True:
firstaid_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = firstaid_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
firstaid_missing_list.append(member_number)
if input_data[line_num][41] != "" and role_training == True and firstaid_required == True:
#Convert string to date object, has to be done here for the blanks!
firstaid = datetime.datetime.strptime(input_data[line_num][41], "%d/%m/%Y")
#Check is it late?
#If date is less than today when program is ran, add to list using membership no, known_name, surname, email, telephone, member_role, manager, group, district, safety due, safeguarding due, first aid due
if firstaid < today:
firstaid_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = firstaid_missing_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
firstaid_missing_list.append(member_number)
#3.4 Due training
#3.4.1 Safety
if input_data[line_num][37]:
#Convert string to date object, has to be done here for the blanks!
safety = datetime.datetime.strptime(input_data[line_num][37], "%d/%m/%Y")
#If date is less than 6 momths from when program is ran, add to list using known_name, surname, email, member_role, group, district, training module
if safety < Xmonths_later and safety >= today:
safety_due_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safety_due_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safety_due_list.append(member_number)
#3.4.2 Safeguarding
if input_data[line_num][39] != "":
#Convert string to date object, has to be done here for the blanks!
safeguarding = datetime.datetime.strptime(input_data[line_num][39], "%d/%m/%Y")
#If date is less than 6 months from when program is ran, add to list using known_name, surname, email, member_role, group, district, training module
if safeguarding < Xmonths_later and safeguarding >= today:
safeguarding_due_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = safeguarding_due_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
safeguarding_due_list.append(member_number)
#3.4.3 First Aid
if input_data[line_num][41] != "":
#Convert string to date object, has to be done here for the blanks!
firstaid = datetime.datetime.strptime(input_data[line_num][41], "%d/%m/%Y")
#If date is less than 6 months from when program is ran, add to list using known_name, surname, email, member_role, group, district, training module
if firstaid < Xmonths_later and firstaid >= today:
firstaid_due_status = True
member_number = input_data[line_num][0]
#check whether membership number is in the index and add it if not
try:
x = firstaid_due_list.index(member_number)
#if it is, nothing happens
except:
#this executes if the membership number is not in the list
firstaid_due_list.append(member_number)
#4: Construct the file outputs
#Late or missing training
#single one only
if safety_status == True and safeguarding_status != True and firstaid_status != True and role_training == True:
#write only with the safety status
if input_data[line_num][36] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], 'Never Completed', '', ''])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], '', ''])
if safety_status != True and safeguarding_status == True and firstaid_status != True and role_training == True:
#write only with the safeguarding status
if input_data[line_num][38] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', 'Never Completed', ''])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', input_data[line_num][39], ''])
if safety_status != True and safeguarding_status != True and firstaid_status == True and role_training == True and firstaid_required == True:
#write only with the first aid status
if input_data[line_num][40]:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', '', 'Never Completed'])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', '', input_data[line_num][41]])
# x2 combo only
if safety_status == True and safeguarding_status == True and firstaid_status != True and role_training == True:
#write safety and safeguarding status
if input_data[line_num][36] == '' and input_data[line_num][38] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], 'Never Completed', 'Never Completed', ''])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], input_data[line_num][39], ''])
if safety_status == True and safeguarding_status != True and firstaid_status == True and role_training == True and firstaid_required == True:
#write safety and first aid status
if input_data[line_num][36] == '' and input_data[line_num][40] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], 'Never Completed' , '', 'Never Completed'])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37] , '', input_data[line_num][41]])
if safety_status != True and safeguarding_status == True and firstaid_status == True and role_training == True and firstaid_required == True:
#write safeguarding and first aid status
if input_data[line_num][38] == '' and input_data[line_num][40] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', 'Never Completed', 'Never Completed'])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', input_data[line_num][39], input_data[line_num][41]])
# all 3
if safety_status == True and safeguarding_status == True and firstaid_status == True and role_training == True and firstaid_required == True:
#write safety, safeguarding and first aid status
if input_data[line_num][36] == '' and input_data[line_num][38] == '' and input_data[line_num][40] == '':
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], 'Never Completed', 'Never Completed', 'Never Completed'])
else:
late_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], input_data[line_num][39], input_data[line_num][41]])
#Due training
#single one only
if safety_due_status == True and safeguarding_due_status != True and firstaid_due_status != True and role_training == True:
#write only with the safety status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], "", ""])
if safety_due_status != True and safeguarding_due_status == True and firstaid_due_status != True and role_training == True:
#write only with the safeguarding status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', input_data[line_num][39], ""])
if safety_due_status != True and safeguarding_due_status != True and firstaid_due_status == True and role_training == True:
#write only with the first aid status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', '', input_data[line_num][41]])
# x2 combo only
if safety_due_status == True and safeguarding_due_status == True and firstaid_due_status != True and role_training == True:
#write safety and safeguarding status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], input_data[line_num][39], ""])
if safety_due_status == True and safeguarding_due_status != True and firstaid_due_status == True and role_training == True:
#write safety and first aid status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37] , '', input_data[line_num][41]])
if safety_due_status != True and safeguarding_due_status == True and firstaid_due_status == True and role_training == True:
#write safeguarding and first aid status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], '', input_data[line_num][39], input_data[line_num][41]])
# all 3
if safety_due_status == True and safeguarding_due_status == True and firstaid_due_status == True and role_training == True:
#write safety, safeguarding and first aid status
due_mandatory.writerow([input_data[line_num][0], input_data[line_num][3], input_data[line_num][2], input_data[line_num][4], input_data[line_num][5], input_data[line_num][8], input_data[line_num][13], input_data[line_num][21], input_data[line_num][19], input_data[line_num][37], input_data[line_num][39], input_data[line_num][41]])
# Clear everything up to avoid printing same old stuff again and again
safety_status = False
safeguarding_status = False
firstaid_status = False
safety_due_status = False
safeguarding_due_status = False
firstaid_due_status = False
role_training = False
firstaid_required = False
line_num = line_num + 1 #continues the loop
#print(input_data[line_num][0])
#4: Statistics Generation Time
statistics_file.write('Statistics File for Training Reports\n')
statistics_file.write('====================================\n')
statistics_file.write('\n')
statistics_file.write('Leaders who are late with Safety module: ' + str(len(safety_missing_list))+'\n')
statistics_file.write('Leaders who need to complete the Safety module within ' + str(due_months) + ' months: ' + str(len(safety_due_list))+'\n')
statistics_file.write('Leaders who are late with Safeguarding module: ' + str(len(safeguarding_missing_list))+'\n')
statistics_file.write('Leaders who need to complete the Safeguarding module within ' + str(due_months) + ' months: ' + str(len(safeguarding_due_list))+'\n')
statistics_file.write('Leaders who are late with First Aid module: ' + str(len(firstaid_missing_list))+'\n')
statistics_file.write('Leaders who need to complete the First Aid module within ' + str(due_months) + ' months: ' + str(len(firstaid_due_list))+'\n')
#5: Close files to show they are done
late_mandatory_file.close()
due_mandatory_file.close()
print("Finished the County part!")
def districts_reports():
#Runs after missing and soon due training has been listed. Produces district reports
#County
county_late_mandatory_file = open('county_late_mandatory_training.csv', 'w', newline='')
county_late_mandatory = csv.writer(county_late_mandatory_file)
county_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
county_due_mandatory_file = open('county_due_mandatory_training.csv', 'w', newline='')
county_due_mandatory = csv.writer(county_due_mandatory_file)
county_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
#Districts
CVS_late_mandatory_file = open('CVS_late_mandatory_training.csv', 'w', newline='')
CVS_late_mandatory = csv.writer(CVS_late_mandatory_file)
CVS_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
CVS_due_mandatory_file = open('CVS_due_mandatory_training.csv', 'w', newline='')
CVS_due_mandatory = csv.writer(CVS_due_mandatory_file)
CVS_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
spitfire_late_mandatory_file = open('spitfire_late_mandatory_training.csv', 'w', newline='')
spitfire_late_mandatory = csv.writer(spitfire_late_mandatory_file)
spitfire_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
spitfire_due_mandatory_file = open('spitfire_due_mandatory_training.csv', 'w', newline='')
spitfire_due_mandatory = csv.writer(spitfire_due_mandatory_file)
spitfire_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
SCE_late_mandatory_file = open('SCE_late_mandatory_training.csv', 'w', newline='')
SCE_late_mandatory = csv.writer(SCE_late_mandatory_file)
SCE_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
SCE_due_mandatory_file = open('SCE_due_mandatory_training.csv', 'w', newline='')
SCE_due_mandatory = csv.writer(SCE_due_mandatory_file)
SCE_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
SCW_late_mandatory_file = open('SCW_late_mandatory_training.csv', 'w', newline='')
SCW_late_mandatory = csv.writer(SCW_late_mandatory_file)
SCW_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
SCW_due_mandatory_file = open('SCW_due_mandatory_training.csv', 'w', newline='')
SCW_due_mandatory = csv.writer(SCW_due_mandatory_file)
SCW_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
rea_late_mandatory_file = open('rea_late_mandatory_training.csv', 'w', newline='')
rea_late_mandatory = csv.writer(rea_late_mandatory_file)
rea_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
rea_due_mandatory_file = open('rea_due_mandatory_training.csv', 'w', newline='')
rea_due_mandatory = csv.writer(rea_due_mandatory_file)
rea_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
tame_late_mandatory_file = open('tame_late_mandatory_training.csv', 'w', newline='')
tame_late_mandatory = csv.writer(tame_late_mandatory_file)
tame_late_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
tame_due_mandatory_file = open('tame_due_mandatory_training.csv', 'w', newline='')
tame_due_mandatory = csv.writer(tame_due_mandatory_file)
tame_due_mandatory.writerow(['Membership Number', 'Known_Name', 'Surname', 'E-Mail', 'Telephone', 'Role', 'Line Manager', 'Group', 'District', 'Safety', 'Safeguarding', 'First Aid'])
#6. late reports
#Open the file
file_name = str(Path.cwd()) + '/' + str('late_mandatory_training.csv')
input_file = open(file_name) #assumes file is in working directory
#Create a list using the CSV file
input_data_reader = csv.reader(input_file)
input_data = list(input_data_reader)
#6.2 Process the data
#start at row 2 to strip header out
line_num = int(1)
while line_num < (len(input_data)-1): #While there is an entry to handle, do something
#read District info (8)
district = input_data[line_num][8]
if district == '':
#If no district, must be county
county_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Cole Valley South':
CVS_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Birmingham Spitfire District Scout Association':
spitfire_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Sutton Coldfield East':
SCE_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Sutton Coldfield West':
SCW_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Rea Valley':
rea_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Tame Valley Birmingham':
tame_late_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
line_num = line_num + 1
#7. late reports
#Open the file
file_name = str(Path.cwd()) + '/' + str('due_mandatory_training.csv')
input_file = open(file_name) #assumes file is in working directory
#Create a list using the CSV file
input_data_reader = csv.reader(input_file)
input_data = list(input_data_reader)
#7.2 Process the data
#start at row 2 to strip header out
line_num = int(1)
while line_num < (len(input_data)-1): #While there is an entry to handle, do something
#read District info (8)
district = input_data[line_num][8]
if district == '':
#If no district, must be county
county_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Cole Valley South':
CVS_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Birmingham Spitfire District Scout Association':
spitfire_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Sutton Coldfield East':
SCE_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Sutton Coldfield West':
SCW_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Rea Valley':
rea_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
if district == 'Tame Valley Birmingham':
tame_due_mandatory.writerow([input_data[line_num][0], input_data[line_num][1], input_data[line_num][2], input_data[line_num][3], input_data[line_num][4], input_data[line_num][5], input_data[line_num][6], input_data[line_num][7], input_data[line_num][8], input_data[line_num][9], input_data[line_num][10], input_data[line_num][11]])
line_num = line_num + 1 #continues the loop
#8: Close the files
county_late_mandatory_file.close()
county_due_mandatory_file.close()
CVS_late_mandatory_file.close()
CVS_due_mandatory_file.close()
spitfire_late_mandatory_file.close()
spitfire_due_mandatory_file.close()
SCE_late_mandatory_file.close()
SCE_due_mandatory_file.close()
SCW_late_mandatory_file.close()
SCW_due_mandatory_file.close()
rea_late_mandatory_file.close()
rea_due_mandatory_file.close()
tame_late_mandatory_file.close()
tame_due_mandatory_file.close()
print("District reports finised!")
#Program
training_report()
districts_reports()