Example #1
0
def relatorio():
    transacoes = Transacao.query().fetch()
    args = flask.request.args

    query = Transacao.query()
    for key in args:
        if args[key] != '':
            if key == 'ehFraude':
                query = query.filter(Transacao.ehFraude == convert(args['ehFraude']))
            elif key == 'dataInic':
                query = query.filter(Transacao.data >= datetime.strptime(args[key], '%Y-%m-%d'))
            elif key == 'dataFim':
                query =  query = query.filter(Transacao.data < datetime.strptime(args[key], '%Y-%m-%d'))
            elif key == 'posicao':
                posicao = args['posicao'].split('k')
                if len(posicao) == 3:
                    query = query.filter(Transacao.longitude >= float(posicao[0]))
                    query = query.filter(Transacao.latitude >= float(posicao[1]))
                    query = query.filter(Transacao.longitude <= float(posicao[2]))            
                    query = query.filter(Transacao.latitude <= float(posicao[3]))

            else:
                query = query.filter(getattr(Transacao,key) == args[key])

    
    transacoes = query.fetch()

    if 'posicao' in args and args['posicao'] != '':
         posicao = args['posicao'].split('k')
         transacoes = [x for x in transacoes if x.latitude >= float(posicao[0]) and x.longitude >= float(posicao[1]) and x.latitude <= float(posicao[2]) and x.longitude <= float(posicao[3])]


    return render_template('list_transacoes.html', transacoes = transacoes , args = args)
Example #2
0
def get_max_value(transacao, conta):
	key = ndb.Key('Conta', transacao.idConta)
	transacoes = Transacao.query(Transacao.idConta == transacao.idConta, Transacao.ehFraude == False).order(-Transacao.valor)
	transacao_max = transacoes.get()
	if (transacao_max is None):
		return 0
	else:
		return transacao_max.valor
Example #3
0
def relatorio():
    transacoes = Transacao.query().fetch()
    args = flask.request.args

    query = Transacao.query()
    for key in args:
        if args[key] != '':
            if key == 'ehFraude':
                query = query.filter(
                    Transacao.ehFraude == convert(args['ehFraude']))
            elif key == 'dataInic':
                query = query.filter(
                    Transacao.data >= datetime.strptime(args[key], '%Y-%m-%d'))
            elif key == 'dataFim':
                query = query = query.filter(
                    Transacao.data < datetime.strptime(args[key], '%Y-%m-%d'))
            elif key == 'posicao':
                posicao = args['posicao'].split('k')
                if len(posicao) == 3:
                    query = query.filter(
                        Transacao.longitude >= float(posicao[0]))
                    query = query.filter(
                        Transacao.latitude >= float(posicao[1]))
                    query = query.filter(
                        Transacao.longitude <= float(posicao[2]))
                    query = query.filter(
                        Transacao.latitude <= float(posicao[3]))

            else:
                query = query.filter(getattr(Transacao, key) == args[key])

    transacoes = query.fetch()

    if 'posicao' in args and args['posicao'] != '':
        posicao = args['posicao'].split('k')
        transacoes = [
            x for x in transacoes if x.latitude >= float(posicao[0])
            and x.longitude >= float(posicao[1]) and x.latitude <= float(
                posicao[2]) and x.longitude <= float(posicao[3])
        ]

    return render_template('list_transacoes.html',
                           transacoes=transacoes,
                           args=args)
Example #4
0
def is_fraud(transacao, conta):
	#pdb.set_trace()
	ultima_transacao = Transacao.query(Transacao.idConta == transacao.idConta, Transacao.ehFraude == False).order(-Transacao.data).get()
	if (ultima_transacao is not None):
		#distancia em km
		distancia = lat_long_to_km(transacao.latitude, transacao.longitude, ultima_transacao.latitude, ultima_transacao.longitude)
		#tempo em horas
		tempo = abs(transacao.data - ultima_transacao.data).total_seconds() / 3600.0
		if (tempo == 0 or distancia/tempo > 800):
			return True
	return False
Example #5
0
def is_fraud(transacao, conta):
    #pdb.set_trace()
    ultima_transacao = Transacao.query(
        Transacao.idConta == transacao.idConta,
        Transacao.ehFraude == False).order(-Transacao.data).get()
    if (ultima_transacao is not None):
        #distancia em km
        distancia = lat_long_to_km(transacao.latitude, transacao.longitude,
                                   ultima_transacao.latitude,
                                   ultima_transacao.longitude)
        #tempo em horas
        tempo = abs(transacao.data -
                    ultima_transacao.data).total_seconds() / 3600.0
        if (tempo == 0 or distancia / tempo > 800):
            return True
    return False