I am looking to design a system that will essentially need to make decisions based on input. The input will be a person.
class Person:
def __init__(self, name, age, sex, weight, height, nationality):
self.name = name
self.age = age
self.sex = sex
self.weight = weight
self.height = height
self.nationality = nationality
We want to assign each person to a school class based on certain rules.
For example:
Women from the UK between 22-25 should go to class B. Men over 75 should go to class A. Women over 6ft should go to class C.
We will have approximately 400 different rules and the first rule that is met should be applied - we need to maintain the order of the rules.
I am thinking about how to store/represent the rules here. Obviously, you could just have a veeeery long if, elif, elif
statement but this isn't efficient. Another option would be storing the rules in a database and maybe having an in memory table.
I would like to be able to edit the rules without doing a release - possibly having a front end to allow non tech people to add, remove and reorder rules.
Everything is on the table here - the only certain requirement is the actually programming language must be Python.
Added for further context
I suppose my question is how to store the rules. At the moment it is one huge long if elif elif
statement so anytime there is a change to the business logic the PM does up the new rules and I then convert them to the if statement.
All inputs to the system will be sent through the same list of rules and the first rule that matches will be applied. Multiple rules can apply to each input but it's always the first that is applied.
e.g.
Women over 25 go to Class B
Women go to Class A.
Any women over 25 will be sent to class B even though the second rule also applies.
Input will always contain the same format input - haven't decided where it will be an object or a dict but some of the values may be None
. Some Persons may not have a weight associated with them.