def natural_language_effect(): post = request.get_json() if not post: return getResponse() # parsing response text = post.get('text') nlp = NLP() interpretation = nlp.process(text) areas = Validator.areas({"areas": interpretation.areas}).post["areas"] z = Validator.z(interpretation.parameters).post['z'] parameters = interpretation.parameters parameters['z'] = z parameters['areas'] = areas # add effect lid = master.add(name=interpretation.effect, parameters=parameters) effectreturn = dict(id=lid, name=interpretation.effect, parameters=master.getControllerParameters(lid)) return getResponse(jsonify(interpretation={}, effect=effectreturn), 201)
def effect(name): '''Add New Effect. Name is equally to name defined in class LedEffect''' post = request.get_json() warnings = [] # do validation # validation for all for f in [Validator.areas, Validator.z]: validation = f(post) warnings += validation.warnings post = validation.post # validation for specific validations = {"color": [lambda x: Validator.color(x, ['color'])], "sequence": [lambda x: Validator.colorlist(x, ['sequence']), Validator.fadespeed]} if name in validations: for f in validations[name]: validation = f(post) warnings += validation.warnings post = validation.post else: warnings.append("No Validator defined for effect parameters") # TODO outsource the following code in validators for k in post.iterkeys(): if name == 'chase': if post.get('width') and post.get('width') < 1: pass # post['width'] = int(post['width'] * post['pos']) if post.get('soft') and post['soft'] < 1: post['soft'] = int(post['soft'] * post['width']) if name == 'pulsate': if post.get('wavelength') <= 1: pass # wavelength = int(post.get('wavelength') * length) effects = [d['name'] for d in master.getEffects()] if name not in effects: return name + ' is not valid. Please try ' + ' or '.join(effects), 500 lid = master.add(name=name, parameters=post) return jsonify(id=lid, name=name, parameters=master.getControllerParameters(lid), warnings=warnings), 201
def effect(name): '''Add New Effect. Name is equally to name defined in class LedEffect''' post = request.get_json() warnings = [] # do validation # validation for all for f in [Validator.areas, Validator.z]: validation = f(post) warnings += validation.warnings post = validation.post # validation for specific validations = {"color": [lambda x: Validator.color(x, ['color'])], "sequence": [lambda x: Validator.colorlist(x, ['sequence']), Validator.fadespeed]} if name in validations: for f in validations[name]: validation = f(post) warnings += validation.warnings post = validation.post else: warnings.append("No Validator defined for effect parameters") # TODO outsource the following code in validators for k in post.iterkeys(): if name == 'chase': if post.get('width') and post.get('width') < 1: pass # post['width'] = int(post['width'] * post['pos']) if post.get('soft') and post['soft'] < 1: post['soft'] = int(post['soft'] * post['width']) if name == 'pulsate': if post.get('wavelength') <= 1: pass # wavelength = int(post.get('wavelength') * length) print "add to master" lid = master.add(name=name, parameters=post) return jsonify(id=lid, name=name, parameters=master.getControllerParameters(lid), warnings=warnings), 201