Esempio n. 1
0
    def handle(self, *args, **options):

        if len(options['cod_secao']) == 0:
            materiais = Material.objects.all()
        else:
            materiais = Material.objects.filter(secoes_possiveis__cod_secao__in=options['cod_secao'])

        efg = ElasticFilesGenerator(ES_FAMILIAS_INDEX,ES_FAMILIAS_DOC_TYPE,ES_FAMILIAS_INDEX)

        for m in materiais:
            efg.add(m.index_dict(), m.index_key())
Esempio n. 2
0
def read(filename):

    lineNum = 0
    efg = ElasticFilesGenerator("clima","clima","clima")

    with open(filename, 'r') as f:
        for line in f:
            lineNum = lineNum + 1
            if lineNum < 2:
                continue

            line = line.strip()
            try:
                clima = parse(line)
                efg.add(clima,'%(ano)s-%(pais)s-%(visao)s-%(conceito)s-%(item)s' % clima)

            except NoDataRecordException:
                pass
Esempio n. 3
0
def read(filename):

    lineNum = 0
    efg = ElasticFilesGenerator("usrtrx","usrtrx","usrtrx")

    with open(filename, 'r') as f:
        for line in f:
            lineNum = lineNum + 1

            line = line.strip()
            line = line.decode("utf8","replace")
            try:
                usrtrx = parse(line)
                usrtrx['fecha'] = str(usrtrx['fecha'])
                efg.add(usrtrx)

            except NoDataRecordException as e:
                print(e)
Esempio n. 4
0
def read(filename):

    lineNum = 0
    efg = ElasticFilesGenerator(INDEX, TYPE, FILE_NAME_PREFIX)

    with open(filename, "r") as f:
        for line in f:
            lineNum = lineNum + 1
            if lineNum <= 1:
                continue

            line = line.strip()
            line = line.decode("utf8", "replace")
            try:
                register = parse(line)
                efg.add(register, register["mac_address"])

            except NoDataRecordException:
                pass
Esempio n. 5
0
def read(filename):

    lineNum = 0
    efg = ElasticFilesGenerator("skuhier","skuhier","skuhier")

    with open(filename, 'r') as f:
        for line in f:
            print line
            lineNum = lineNum + 1
            if lineNum <= 1:
                continue

            line = line.strip()
            #line = line.decode("utf8","replace")
            try:
                skuhier = parse(line)
                efg.add(skuhier,skuhier['cod_familia'])

            except NoDataRecordException:
                pass
Esempio n. 6
0
def read(filename, GPTW):

    lineNum = 0
    efg = ElasticFilesGenerator("nomina","nomina","nomina")

    with open(filename, 'r') as f:
        for line in f:

            line = line.strip()
            #line = line.decode("utf8","replace")
            try:
                nominas = toGPTW(parse(line), GPTW)
                for n in nominas:
                    nomina['admissao'] = str(nomina['admissao'])
                    nomina['nascimento'] = str(nomina['nascimento'])
                    efg.add(nomina, nomina['matricula'])

            except NoDataRecordException:
                pass
            except AprendizException:
                pass
Esempio n. 7
0
def read(filename):

    efg = ElasticFilesGenerator(INDEX, TYPE, filename)

    with open(filename, 'r') as f:
        for line in f:

            line = line.strip()
            line = line.decode("utf8","replace")

            try:
                register = parse(line)
                register[L.secao] = materiales.get_seccion(register[L.material])
                register[L.descricao_secao] = secciones.get_descripcion(register[L.secao])
                matid = "%s%s" % (register[L.loja], register[L.material])
                register.update({L.matid: matid})

                efg.add(register, "%s%s%s" % (matid, register[L.tipo_movimento], str(register[L.data][0:10]).replace('-','')))


            except NoDataRecordException:
                pass
Esempio n. 8
0
def read(filename):

    lineNum = 0
    head, tail = ntpath.split(filename)
    data = datetime.datetime(
             int(tail[0:4]), int(tail[5:7]), int(tail[8:10]), 12
             ) - datetime.timedelta(days=1)
    efg = ElasticFilesGenerator(INDEX,TYPE,filename)
    data = str(data)

    with open(filename, 'r') as f:
        for line in f:
            lineNum = lineNum + 1
            if lineNum <= 10:
                continue

            line = line.strip()
            line = line.decode("utf8","replace")
            try:
                register = parse(line)
                if register[L.loja][0] <> 'B':
                    register[L.loja] = 'B' + register[L.loja]
                if register[L.loja] not in LOJAS_PADRINHOS:
                    continue
                register[L.data] = data
                register[L.ruptura] = 1
                register[L.perda] = - register['venda_ultimos_90_dias'] / 90 
                register[L.matid] = '%s%s' % (register[L.loja], register[L.material])
                register[L.secao] = materiales.get_seccion(register[L.material])
                register[L.descricao_secao] = secciones.get_descripcion(register[L.secao])
                register.pop('venda_ultimos_90_dias')

                efg.add(register, "%s%s" % (register[L.matid], str(register[L.data][0:10]).replace('-','')))

            except NoDataRecordException:
                pass
Esempio n. 9
0
def read(filename, GPTW):

    lineNum = 0
    efg = ElasticFilesGenerator("nomina","nomina","nomina")

    with open(filename, 'r') as f:
        for line in f:

            line = line.strip()
            #line = line.decode("utf8","replace")
            try:
                nominas = toGPTW(parse(line), GPTW)
                for n in nominas:
                    n['admissao'] = str(int(n['admissao'].timestamp())*1000)
                    n['nascimento'] = str(int(n['nascimento'].timestamp())*1000)
                    n['data_avaliacao'] = str(int(n['data_avaliacao'].timestamp())*1000)
                    #del n['data_avaliacao']
                    id = '%s-%s-%s-%s' % (n['ano'], n['visao'], n['num_item'], n['matricula'])
                    efg.add(n, id)

            except NoDataRecordException:
                pass
            except AprendizException:
                pass
Esempio n. 10
0
def top_variance(desde=date.today()-timedelta(days=30),hasta=date.today(), cantidad_top=9999999, tipoCondicion=None, toleranciaIndice=2, iv_tienda=None):

    command_line = {
        "index": {
            "_index":"precios",
            "_type":"venta",
            "_id":None
        }}

    conn = psycopg2.connect("dbname='precios'")

    cur = conn.cursor()

    query = """select tienda, material, unidadMedida, avg(precio) as media,
            sqrt(abs(avg(precio*precio)- avg(precio)*avg(precio))) as varianza,
            CASE WHEN avg(precio) = 0 THEN 0 else sqrt(abs(avg(precio*precio)- avg(precio)*avg(precio))) * 100 / avg(precio) end as porcentaje
        from precio_dia
        where
            precio > 0"""

    if tipoCondicion is not None:
        query = query + """ and tipoCondicion = %(tipoCondicion)s """

    if iv_tienda is not None:
        query = query + """ and tienda = %(tienda)s """

    query = query + """ group by tienda, material, unidadMedida
        limit %(cantidad_top)s"""

    cur.execute(
        query,
        {
         'cantidad_top':cantidad_top,
         'tipoCondicion':tipoCondicion,
         'tienda': iv_tienda})

    analisis = {}

    for register in cur:

        tienda, material, unidadMedida, media, desvio, indiceVariacion = register

        if indiceVariacion <= toleranciaIndice:
            continue

        if tienda not in analisis:
            analisis[tienda] = {}
        if material not in analisis[tienda]:
            analisis[tienda][material] = {}
        if unidadMedida not in analisis[tienda][material]:
            analisis[tienda][material][unidadMedida] = {}

        analisis[tienda][material][unidadMedida][L.media] = media
        analisis[tienda][material][unidadMedida][L.desvio] = desvio
        analisis[tienda][material][unidadMedida][L.indice_variacion] = indiceVariacion

    query = """
        select tienda, material, unidadMedida, fecha, precio, tipoCondicion, rankvartot, rankvarabs
        from precio_dia
        where
            fecha >= %(desde)s and
            fecha <= %(hasta)s and
            precio > 0
        """

    if tipoCondicion is not None:
        query = query + """ and tipoCondicion = %(tipoCondicion)s """

    if iv_tienda is not None:
        query = query + """ and tienda = %(tienda)s """

    cur.execute(query,
                     { 'desde':desde,
                      'hasta':hasta,
                      'tipoCondicion':tipoCondicion,
                      'tienda':iv_tienda})

    efg = ElasticFilesGenerator("precos", "venda", "precios-venta.%s" % iv_tienda)

    for reg in cur:

        tienda, material, unidadMedida, fecha, precio, tipoCondicionPrecioDia, rankvartot, rankvarabs = reg
        register = {
            L.loja: tienda.strip(),
            L.material: material,
            L.unidade_medida: unidadMedida.strip(),
            L.data: datetime.datetime(fecha.year,
                fecha.month,fecha.day,12).strftime("%Y-%m-%d %H:%M:%S"),
            L.preco: precio,
            L.tipo_condicao: tipoCondicionPrecioDia,
            L.rankvarabs: rankvarabs,
            L.rankvartot: rankvartot,
        }

        register[L.descricao_material] = materiales.get_descricao(material)
        register[L.secao] = materiales.get_seccion(register[L.material])
        register[L.descricao_secao] = secciones.get_descripcion(register[L.secao])

        try:
            register.update(analisis[tienda][material][unidadMedida])
        except KeyError:
            print "ERROR: Analisis material %s no encontrado" % material
            continue

        matid_com_um = "%s%s%s" % (register[L.loja],
            register[L.unidade_medida], register[L.material])
        register[L.matid_com_um] = matid_com_um

        matid = "%s%s" % (register[L.loja], register[L.material])
        register[L.matid] = matid

        efg.add(register, "%s%s" % (matid_com_um, str(register[L.data][0:10]).replace('-','')))
Esempio n. 11
0
                desition[option][criterion] = self.criteria[criterion] * (float(scores[criterion][option]) / criterion_score_sum )
                desition[option]["total"] = ( desition[option]["total"] + desition[option][criterion])

        desition = [ desition[option] for option in desition ]
        return sorted(desition,key = lambda x: x['total'], reverse=True)

with open(sys.argv[1],'r') as f:
    config = json.load(f)

decider = Decider(config)

if len(sys.argv) == 3:
    with open(sys.argv[2],'r') as f:
        scores = json.load(f)
    desition = decider.decide(scores)
    efg = ElasticFilesGenerator("wdecide", "wdecide", "wdecide")
    for i in range(len(desition)):
        
        # stdout
        print("(%s) [%s]: %s" % (i+1, desition[i]['description'], desition[i]['total']))

        # elastic search bulk file
        for criteria in desition[i]:
            if criteria == 'description' or criteria == 'total':
                continue
            efg.add({
               'option': desition[i]["description"],
               'criteria': criteria,
               'value': desition[i][criteria],
               },"%s-%s" %(desition[i]["description"], criteria))
else: