Hi so in my application I have some Employees
'Employees' : collection ['BSN'] {
'BSN' : text
'Name' : text
}
Some Ministry storing their criminal records
'Ministry of Justice Records': collection ['Employee'] {
'Employee' : text -> ^ .'Employees'[]
'Criminal history' : stategroup (
'None' { }
'Crime' { }
)
}
And an application that has a list of R&D Employees that worked on the application
'My Applications': collection ['ID'] {
can-read: user is ( > 'Creator') || user .'Type'?'Admin'
can-update: user . 'Type'?'Unknown'
'ID' : text
'Creator' : text -> ^ . 'Users'[]
'Date' : number 'date'
'type': stategroup (
'Lump Sum' { }
'Investment' { }
)
'R&D Employees': collection ['Employee'] {
'Employee' : text -> ^ ^ .'Employees'[]
}
'Number of R&D hours': number 'hours'
'Additional R&D hours': number 'hours'
'Application valid': text = switch .'Number of R&D hours' compare ( 500 ) (
| >= => "Yes"
| < => "No: Number of R&D should be at least 500h"
)
'Approval': stategroup (
'Approved' { }
'Not approved' { }
)
}
I would like to create a command that lets me check that less than 30% of the R&D employees have a positive criminal record. Here is some pseudo code that shows more or less what I am trying to do:
def check_application (application):
employees = application.get_R&D_employees()
return check_criminal_record (employees) && check_tax_profile (employees) && check_skill (employees)
// Should return the yes if less than 30% of employees have Crime in their criminal record
def check_criminal_record(employees)
// Get list of booleans (crime or none) that indicates if employees have a crime
RecordsOfEmployees = intersection (employees, MinistryOfJustice).crime
//Count how many employees have a crime
NumberOfCrimes = count(RecordsOfEmployees, Crime)
return NumberOfCrimes/Length(employees) < 0.3
// I would like to do similar things for the rest of the checks (check_tax_profile and check_skill)
I am a bit confused on where to start with I should try to obtain the intersection of R&D Employees and the Ministry but should I use a switch statement within a walk on the Ministry ? Furthermore I’m really confused how I’m going to do the count part of the code…
. This should help: