NB. Script to pull out supervisors and total supervision responsibilities NB. from a csv file SuperVision.csv NB. Started SO 20210901 NB. v1.0 (first functional) clear '' 1!:44 '/home/sean/j902-user/projects/Supervision/' load 'csv' datafile =: readcsv 'SuperVision.csv' headings =: 0{datafile data =: 1}. datafile nstudents =: 0{$data NB. number of students Primaries =: 1}"1 data Joints =: 2}"1 data Secondaries =: 3}"1 data NB. General utility verbs NB. The last two are taken from the j phrases collection nub =: ~: # ] NB. unique names RotateLeading =: ] |.~ (+/)@(*./\ )@(' '&=) NB. Move leading spaces to end RemoveTrailing =: #~ ([: +./\. ' '&~:) NB. Remove trailing spaces NB. Arranging data verbs unify =: 3 : 0 tolower RotateLeading"1 > ,>(< ;._1) each ',', each y ) Primaries =: unify 1}"1 data Joints =: unify 2}"1 data Secondaries =: unify 3}"1 data NB. Now work on the data. NB. Collections of unique supervisor lists and supervision numbers NB. for each category of Primary, Joint and Secondary supervisors GradeNub =: (/: { ])@nub PrimNub =: GradeNub Primaries PrimNum =: (+/"1) -. (<"1 PrimNub) (i."0 _) <"1 Primaries JointNub =: GradeNub Joints JointNum =: (+/"1) -. (<"1 JointNub) (i."0 _) <"1 Joints SecNub =: GradeNub Secondaries SecNum =: (+/"1) -. (<"1 SecNub) (i."0 _) <"1 Secondaries NB. Now make a list of the unique names with NB. numbers of primary, joint and secondary supervisions for each NB. First, generate the unique list and sort in alphabetical order TotalNames =: RemoveTrailing each <"1 GradeNub PrimNub,JointNub,SecNub NB. Now generate the numbers of each category of supervisions NB. Note we add a 0 to the list of numbers because NB. if a name does not show up, the index 1 beyond the end NB. is generated, which corresponds to the name not being NB. on the list of primaries. NumPrimNub =: ((RemoveTrailing each <"1 PrimNub) i. TotalNames){PrimNum,0 NumJointNub =: ((RemoveTrailing each <"1 JointNub) i. TotalNames){JointNum,0 NumSecNub =: ((RemoveTrailing each <"1 SecNub) i. TotalNames){SecNum,0 NB. Now produce the Summary Tables Score =: +/"1 (|: NumPrimNub,NumJointNub,:NumSecNub) (*"1) 1, 0.5,0 SupervisionMatrix =: (|: NumPrimNub,NumJointNub,:NumSecNub),"1 0 Score Labels =: 'Name'; 'Primary'; 'Joint'; 'Secondary'; 'Score' AlphaTable =: }. (TotalNames),"0 1 (<"0 SupervisionMatrix) LeagueTable =: AlphaTable \: }. Score AlphaSummary =: Labels,AlphaTable LeagueSummary =: Labels,LeagueTable WriteSummary =: 3 : 0 FileName =. y LeagueSummary writecsv FileName ) ('Number of students';'Number of primary supervisors'; 'Total staff involved in supervision'),:"1 <"0 nstudents,(# PrimNub),(# TotalNames) - 1