Exemplo n.º 1
0
def evaluate_non_themp():
    mappings = get_mappings()
    table = RuleTable(
        "Non thermostat rules",
        mappings,
        "RegexParser",
        #rawfile,
        "RAWFile",
        None)
    table.setPolicy(False)
    for rule in Rule.objects.filter(active=True, thermostat=False).order_by("pk"):
        table.addRule(rule.to_pypelib())
    if settings.DEBUG:
        table.dump(logger)
    try:
        table.evaluate({})
        logger.debug("Table NONTHERM evaluated True")
    except Exception as ex:
        logger.debug("Table NONTHERM evaluated False")
Exemplo n.º 2
0
table = RuleTable(
    "Calecfaccion Invierno laborables",
    mappings,
    "RegexParser",
    #rawfile,
    "RAWFile",
    None)

start_time = gen_comparing_time(19, 00, 00)
print "estar time: %s" % start_time
end_time = gen_comparing_time(22, 00, 00)

print "end time: %s " % end_time
print "current day of week: %s" % mappings["current_day_of_week"]()
print "current temp %s" % mappings["current_temperature"]()
table.setPolicy(False)
#table.addRule("if (current_day_of_week != Sat ) && ( current_day_of_week != Sun) then accept ")
table.addRule("if ((current_day_of_week != Sat ) && ( current_day_of_week != Sun)) && ((current_hour > %f) && (current_hour < %f)) && (current_temperature < confort_temperature) then accept" % (start_time, end_time))
table.addRule("if current_temperature < economic_temperature then accept")



#table.addRule(Rule(Condition("vm.memory","2000",">"),"Memory", "Action forbbiden: You requested more that 2GB of RAM" ,Rule.NEGATIVE_TERMINAL))
#table.addRule(Rule(Condition("project.vms","4",">="),"VMs","Action forbidden: you have 4 VMs already in the project",Rule.NEGATIVE_TERMINAL))
#table.addRule(Rstrptime("30 Nov 00", "%d %b %y")rint ule(Condition("projec t.string","try","!="),"String","Action forbidden: String",Rule.NEGATIVE_TERMINAL))
print "DUMP *******************************"
table.dump()

print "END DUMP *******************************"
#table.save(fileName="rules.txt")
Exemplo n.º 3
0
def evaluate():

    mappings = get_mappings()
    table = RuleTable(
        "Decide tunned temp",
        mappings,
        "RegexParser",
        #rawfile,
        "RAWFile",
        None)


    logger.debug("current time: %s " % mappings["current_time"]())
    logger.debug("current day of week: %s" % mappings["current_day_of_week"]())
    logger.debug("current temp %s" % mappings["current_internal_temperature"]())
    logger.debug("economic %s" % mappings["economic_temperature"]())
    logger.debug("confort %s" % mappings["confort_temperature"]())
    logger.debug("tuned %s" % mappings["tuned_temperature"]())
    logger.debug("flame %s" % mappings["flame_on"]())
    logger.debug("heat on %s" % mappings["heater_on"]())

    table.setPolicy(False)

    table.addRule("if heater_manual = 1 then ACCEPT")

    for rule in Rule.objects.filter(active=True, thermostat=True).order_by("pk"):
        table.addRule(rule.to_pypelib())

    if settings.DEBUG:
        table.dump(logger)

    metaObj = {}

    try:
        table.evaluate(metaObj)
        logger.debug("Table THERM1 evaluated True")
        mappings["tune_to_confort"]()
    except Exception:
        logger.debug("Table THERM1 evaluated False")
        mappings["tune_to_economic"]()

    table1 = RuleTable(
        "Decide flame status",
        mappings,
        "RegexParser",
        #rawfile,
        "RAWFile",
        None)
    table1.addRule("if heater_on = 0 then deny")
    table1.addRule("if current_internal_temperature < tuned_temperature then accept")
    if settings.DEBUG:
        table1.dump(logger)
        
    try:
        table1.evaluate(metaObj)
        logger.debug("Table THERM2 evaluated True")
        try:
            mappings["start_flame"]()
        except Exception as ex:
            logger.critical("ERROR: Cant start flame: %s" % ex)
    except Exception as e:
        logger.debug("Table THERM2 evaluated False")
        try:
            mappings["stop_flame"]()
        except Exception as ex:
            logger.critical("ERROR: Cant stop flame: %s" % ex)