Пример #1
0
def showEffects():
    out = ''
    for effect in LEDMaster.getEffects():
        out += '<h1>' + effect['name'] + '</h1>'
        desc = LEDMaster.getDescription(effect['name'])
        desc = desc.replace('Description:', '<h4>Description</h4>')
        desc = desc.replace('Parameters:', '<h4>Parameters</h4>')
        pi = desc.find('<h4>Parameters</h4>') + len('<h4>Parameters</h4>')
        pdesc = ''
        for pname_pdesc in desc[pi:].split('\n'):
            if pname_pdesc.count(':') == 1:
                pname, pdes = pname_pdesc.split(':')
                pdesc += '<b>%s:</b> %s <br>' % (pname.strip(), pdes)
        out += desc[:pi] + pdesc
    return out
Пример #2
0
def showEffects():
    out = ''
    for effect in LEDMaster.getEffects():
        out += '<h1>' + effect['name'] + '</h1>'
        desc = LEDMaster.getDescription(effect['name'])
        desc = desc.replace('Description:', '<h4>Description</h4>')
        desc = desc.replace('Parameters:', '<h4>Parameters</h4>')
        pi = desc.find('<h4>Parameters</h4>') + len('<h4>Parameters</h4>')
        pdesc = ''
        for pname_pdesc in desc[pi:].split('\n'):
            if pname_pdesc.count(':') == 1:
                pname, pdes = pname_pdesc.split(':')
                pdesc += '<b>%s:</b> %s <br>' % (pname.strip(), pdes)
        out += desc[:pi] + pdesc
    return out
Пример #3
0
 def findObsolete(name, post, ignore=['areas', 'z', 'mergeType']):
     '''will not remove obsolete parameters, but adds a warning to the list'''
     warnings = []
     parameters = LEDMaster.getDefaultParameters(name)
     for p, v in post.items():
         if p not in parameters and p not in ignore:
             warnings.append("Parameter %s is obsolete" % p)
     validation = collections.namedtuple('validation', 'post warnings')
     validation.warnings = warnings
     validation.post = post
     return validation
Пример #4
0
 def findObsolete(name, post, ignore=['areas', 'z', 'mergeType']):
     '''will not remove obsolete parameters, but adds a warning to the list'''
     warnings = []
     parameters = LEDMaster.getDefaultParameters(name)
     for p, v in post.items():
         if p not in parameters and p not in ignore:
             warnings.append("Parameter %s is obsolete" % p)
     validation = collections.namedtuple('validation', 'post warnings')
     validation.warnings = warnings
     validation.post = post
     return validation
Пример #5
0
 def findParameters(self, words, effectname):
     ''' only check words after a parameter indicator'''
     parameters = LEDMaster.getDefaultParameters(
         effectname)  # always load default
     for i, word in enumerate(words):
         for j, p in enumerate(parameters.keys()):
             match = jellyfish.jaro_distance(unicode(p), unicode(word))
             if match > self.threshold:
                 value = self.understandParameterValue(
                     p, parameters[p], words[i+1:])
                 parameters[p] = value
     return parameters
Пример #6
0
 def findParameters(self, words, effectname):
     ''' only check words after a parameter indicator'''
     parameters = LEDMaster.getDefaultParameters(
         effectname)  # always load default
     for i, word in enumerate(words):
         for j, p in enumerate(parameters.keys()):
             match = jellyfish.jaro_distance(unicode(p), unicode(word))
             if match > self.threshold:
                 value = self.understandParameterValue(
                     p, parameters[p], words[i + 1:])
                 parameters[p] = value
     return parameters
Пример #7
0
    def addMissing(name, post):
        warnings = []
        parameters = LEDMaster.getDefaultParameters(name)
        for p, v in parameters.items():
            if p not in post:
                post[p] = v
                warnings.append(
                    "Parameter %s was missing, set to default value" % p)

        validation = collections.namedtuple('validation', 'post warnings')
        validation.warnings = warnings
        validation.post = post
        return validation
Пример #8
0
    def addMissing(name, post):
        warnings = []
        parameters = LEDMaster.getDefaultParameters(name)
        for p, v in parameters.items():
            if p not in post:
                post[p] = v
                warnings.append(
                    "Parameter %s was missing, set to default value" % p)

        validation = collections.namedtuple('validation', 'post warnings')
        validation.warnings = warnings
        validation.post = post
        return validation
Пример #9
0
def effects():
    '''list with all available effects and default parameters'''
    return jsonify(effects=LEDMaster.getEffects()), 200
Пример #10
0
 def __init__(self):
     self.threshold = 0.75
     self.parameters_indicators = [u"with", u"parameters"]
     self.gap_words = [u"and"]
     self.effect_choices = [e['name'] for e in LEDMaster.getEffects()]
     self.inpterpretation = []
Пример #11
0
 def __init__(self):
     self.threshold = 0.75
     self.parameters_indicators = [u"with", u"parameters"]
     self.gap_words = [u"and"]
     self.effect_choices = [e['name'] for e in LEDMaster.getEffects()]
     self.inpterpretation = []
Пример #12
0
def effects():
    '''list with all available effects and default parameters'''
    return jsonify(effects=LEDMaster.getEffects()), 200
Пример #13
0
from natural_language_parser import NLP


def getResponse(jsondata='', status=200):
    resp = make_response(jsondata, status)
    resp.headers['Access-Control-Allow-Origin'] = '*'
    resp.headers[
        "Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTIONS"
    resp.headers[
        'Access-Control-Allow-Headers'] = "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
    return resp


app = Flask(__name__, static_folder='../ui/static', template_folder='../ui/templates')
auto = Autodoc(app)
master = LEDMaster()

#loggers = [app.logger]
#file_handler = FileHandler('flask.log')
# file_handler.setLevel(DEBUG)
#file_handler.setFormatter(Formatter('%(asctime)s %(levelname)8s [%(filename)s/%(funcName)s:%(lineno)d] - %(message)s'))

# for logger in loggers:
#	logger.handlers = []
#	logger.addHandler(file_handler)


###############
# Development
###############