예제 #1
0
    def GET(self, resp=''):
        lugares = [
            'recamara_principal', 'sala', 'estudiof', 'cocina', 'hall_entrada',
            'patio', 'exterior'
        ]
        apps_mon = ['app_doorlight', 'app_autolight', 'app_doorbell']
        out = []
        for lugar in lugares:
            temp = r.hget('temperature', lugar).decode('utf-8')
            if (float(temp) != 0):
                out.append((lugar, 'Temperatura', temp))
        #for lugar in lugares:
        #    temp = r.hget('temperature', lugar).decode('utf-8')
        #    if(float(temp) != 0):
        #        out.append((lugar, 'Temperatura', temp))
        for lugar in lugares:
            humd = r.hget('humidity', lugar).decode('utf-8')
            if (float(humd) != 0):
                out.append((lugar, 'Humedad', humd))
        for lugar in lugares:
            motion = r.hget('motion', lugar).decode('utf-8')
            if (motion == 'True'):
                out.append((lugar, 'Movimiento', motion))
        kw = r.hget('power usage', 'ct kW').decode('utf-8')
        out.append(('casa', 'Consumo (kW)', kw))
        amps = r.hget('power usage', 'ct A').decode('utf-8')
        out.append(('casa', 'Consumo (A)', kw))

        riego = r.get('riego').decode('utf8')
        out.append(('patio', 'Riego por goteo', riego))
        try:
            dist = r.get('Nivel cisterna').decode('utf8')
            out.append(('cisterna', 'Nivel', dist))
        except:
            pass
        for appname in apps_mon:
            app_status = r.hget('apps', appname).decode('utf-8')
            out.append(('app', appname, app_status))

        # con2 = lite.connect('/Volumes/mmshared/bdatos/ultimas.db')
        # with con2:
        #     cur = con2.cursor()
        #     commandx = "SELECT timestamp, medicion, valor from Status WHERE lugar = 'global' ORDER BY medicion" # OR (lugar='tv' AND medicion='temperature') "
        #     #commandx = "SELECT timestamp,medicion,valor,lugar from Status  ORDER BY lugar, medicion "
        #     res = cur.execute(commandx)
        tabla = HTML.table(out).split('\n')
        tabla2 = " ".join(tabla[1:(len(tabla) - 1)])
        tabla3 = "<table class='table table-striped lead'>" + tabla2 + "</table>"
        # con2.close()
        # return tabla3
        return tabla3
예제 #2
0
def get_category():
    try:
        list_product_names = list(request.get_json())
        output_list = []

        for product_name_dict in list_product_names:
            app.logger.info("Request received {}".format(product_name_dict))
            results = {}
            results_cache = ''

            product_name = product_name_dict.get('product_name', "")
            if product_name:
                product_name_clean = (re.sub(ALPHA_NUM_REGEX, '',
                                             product_name)).lower()
                product_name_key = 'catfight:' + ':' + product_name_clean
                results_cache = r.get(product_name_key)
                if not results_cache:
                    results = predict_category(
                        product_name.encode('ascii', 'ignore'), cat_model,
                        dang_model, app.logger)
                    if results:
                        r.setex(product_name_key, json.dumps(results),
                                CACHE_EXPIRY)
                        results['cached'] = False
                else:
                    results = json.loads(results_cache)
                    results['cached'] = True
            else:
                results['invalid_product_name'] = True

            results['waybill'] = product_name_dict.get('wbn', None)

            app.logger.info("Result produced {}".format(results))

            output_list.append(results)

        return Response(json.dumps(output_list), mimetype='application/json')

    except Exception as err:
        app.logger.error('Exception {} occurred against payload: {}'.format(
            err, list_product_names))

        sentry_client.captureException(message="predict.py: Exception occured",
                                       extra={
                                           "error": err,
                                           "payload": list_product_names
                                       })
def get_category():
    try:
        list_product_names = list(request.get_json())
        output_list = []

        for product_name_dict in list_product_names:
            app.logger.info("Request received {}".format(product_name_dict))
            results = {}
            results_cache = ''
            
            product_name = product_name_dict.get('product_name', "")
            if product_name:
                product_name_clean = (re.sub(ALPHA_NUM_REGEX, '', product_name)).lower()
                product_name_key = 'catfight:' +':' + product_name_clean
                results_cache = r.get(product_name_key)
                if not results_cache:
                    results = predict_category(product_name.encode('ascii','ignore'),
                                               cat_model, dang_model, app.logger)
                    if results:
                        r.setex(product_name_key, json.dumps(results), CACHE_EXPIRY)
                        results['cached'] = False
                else:
                    results = json.loads(results_cache)
                    results['cached'] = True
            else:
                results['invalid_product_name'] = True
            
            results['waybill'] = product_name_dict.get('wbn', None)
            
            app.logger.info("Result produced {}".format(results))
    
            output_list.append(results)

        return Response(json.dumps(output_list),  mimetype='application/json')
    
    except Exception as err:
        app.logger.error(
            'Exception {} occurred against payload: {}'.format(
                err, list_product_names))

        sentry_client.captureException(
            message = "predict.py: Exception occured",
            extra = {"error" : err, "payload" : list_product_names})
def process_product(product_name_dict, cat_model, dang_model, logger):
    results = {}
    results_cache = ''

    product_name = product_name_dict.get('prd', "")
    if product_name:
        final_result = {}
        original_dict = copy.deepcopy(product_name_dict)

        product_name_clean = (re.sub(ALPHA_NUM_REGEX, '',
                                     product_name)).lower()
        product_name_key = 'catfight:' + ':' + product_name_clean
        results_cache = r.get(product_name_key)
        wbn = product_name_dict.get('wbn', "")
        if not results_cache:
            results = predict_category(product_name.encode('ascii', 'ignore'),
                                       wbn, cat_model, dang_model, logger)
            if results:
                r.setex(product_name_key, json.dumps(results), CACHE_EXPIRY)
                results['cached'] = False
        else:
            results = json.loads(results_cache)
            l_product_name = product_name.lower()
            product_words = re.findall(CLEAN_PRODUCT_NAME_REGEX,
                                       l_product_name)
            clean_product_name = " ".join(product_words)
            first_level = results['cat']
            dg_report = predict_dangerous(clean_product_name, wbn, first_level,
                                          dang_model.dg_keywords, logger)

            results['dg'] = dg_report['dangerous']
            results['cached'] = True
    else:
        results['invalid_product_name'] = True

    final_result = original_dict
    final_result['result'] = results
    return final_result
def process_product(product_name_dict, cat_model, dang_model, logger):
    results = {}
    results_cache = ''
    
    product_name = product_name_dict.get('prd', "")
    if product_name:
        final_result = {}
        original_dict = copy.deepcopy(product_name_dict)

        product_name_clean = (re.sub(ALPHA_NUM_REGEX, '', product_name)).lower()
        product_name_key = 'catfight:' +':' + product_name_clean
        results_cache = r.get(product_name_key)
        wbn = product_name_dict.get('wbn', "")
        if not results_cache:
            results = predict_category(product_name.encode('ascii','ignore'),
                                       wbn, cat_model, dang_model, logger)
            if results:
                r.setex(product_name_key, json.dumps(results), CACHE_EXPIRY)
                results['cached'] = False
        else:
            results = json.loads(results_cache)
            l_product_name = product_name.lower()
            product_words = re.findall(CLEAN_PRODUCT_NAME_REGEX, l_product_name)
            clean_product_name = " ".join(product_words)
            first_level = results['cat']
            dg_report = predict_dangerous(clean_product_name, wbn, first_level,
                                      dang_model.dg_keywords, logger)

            results['dg'] = dg_report['dangerous']
            results['cached'] = True
    else:
        results['invalid_product_name'] = True
    
    final_result = original_dict
    final_result['result'] = results
    return final_result
예제 #6
0
def redis_retrieve_split(index, ip, site):
    return r.get(index + '-' + ip + '-' + site)
예제 #7
0
def redis_get_benchmark_recent_site(config_id, mode):
    """
    Gets the cached benchmark recently made history log entry for the mode required.
    """
    return r.get(config_id + '-' + mode)
예제 #8
0
#!/usr/bin/env python3

from settings import r
import sys
import time
import redis

if __name__ == '__main__':
    r.set('lab', 'sjtu-medialab')
    print(r.get('lab'))

    job_id = 0
    socket_id = 0
    topic = "JOB_FINISH"

    while True:
        r.publish(topic, str(job_id))
        job_id += 1
        time.sleep(2)