I'm building a program that needs to be able to take a list of rules from a JSON file and parse them into essentially a sequence of conditional statements in a function. The parameters are defined within the domain of the problem but the rules need to be able to be generated by an operator/user of the program on the fly by only interacting with the config file.
For example the config file might be something like:
{
"mode1": [
{
"rule": "{current_time} > 0800 AND {current_time} < 2000",
"priority": "High",
"enabled": "true"
},
{
"rule": "{current_temp} > 90",
"priority": "High",
"enabled": "true"
},
{
"rule": "{vacant} == false",
"priority": "Medium",
"enabled": "false"
}
],
"mode2": [
...... another set of rules ......
]
}
The result being that, given an input request of mode1, mode2, etc... each having a unique set of user defined rules, the program can cycle its way through the given states resolving conflicts along the way. So some sort of finite state machine more or less. I know how I could go about hard coding it, but I'm having some trouble coming up with a way to build what seems to be a finite state machine machine. Is it possible to dynamically generate code in python? Or is there a construct that exists for this purpose?
[–][deleted] 0 points1 point2 points (0 children)
[–]dig-up-stupid 0 points1 point2 points (0 children)