Commit 22b7d198 authored by Azat Khuziyakhmetov's avatar Azat Khuziyakhmetov
Browse files

initial commit of the recommendation system

parent 160f55cd
# this file contains attributs wich are used to build rules
# the attributes can be build using the instance of Aggregator class.
# each attribute should have finite number of values
from db.aggrstruct import *
DEBUG = False
def printd(*args, **kargs):
if DEBUG:
print(*args, **kargs)
def rcmattr(func):
'''Function decorator. Checks and sets arguments'''
def wrapper(Aggr, *args, **kwargs):
if type(Aggr) != Aggregator:
raise TypeError("argument of attribute should be Aggregator")
printd(" - evaluation of the attribute {:s} - ".format(func.__name__))
res = func(Aggr, *args, **kwargs)
printd(" - finished the attribute {:s} - ".format(func.__name__))
return res
return wrapper
class Attributes:
@rcmattr
def cpu_usage(Aggr):
cpu_usage = 0
cpu_usage_sum = 0
cpu_requested = Aggr.job.requested_cu
for node in Aggr.nodes:
cpu_usage_sum += node.proc.cpu_usage
cpu_fact = cpu_usage_sum / cpu_requested / 100
printd("{} = {} (total cpu_usage) / {} (requested cores) / {}".
format(cpu_fact, cpu_usage_sum, cpu_requested, 100))
res = "MED"
if cpu_fact > 1.1:
res = "HIGH"
elif cpu_fact < 0.7:
res = "LOW"
return res
from .rules import RULES
from rcm import attributes
attributes.DEBUG = True
def attributes_match(attrs, Aggr):
matches = True
for rule_attr, attr_value in attrs.items():
try:
attr_func = getattr(attributes.Attributes, rule_attr)
except AttributeError:
raise AttributeError("there is no attribute " + rule_attr)
if attr_func(Aggr) != attr_value:
matches = False
break
return matches
def get_recommendations(Aggr):
rcms = []
for rule in RULES:
if attributes_match(rule["attrs"], Aggr):
rcms.append(rule["msg"])
return rcms
RULES = [
{"attrs": {"cpu_usage": "HIGH"}, "msg": "request more compute units"},
{"attrs": {"cpu_usage": "LOW"}, "msg": "request less compute units"}
]
#! /usr/bin/env python3
import db.aggregator as aggregator
from rcm import rcm
aggr = aggregator.get_aggregator("2368599", "pdf")
rcms = rcm.get_recommendations(aggr)
print(rcms)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment