1
I am finishing developing a web application but I have a problem. All my application was developed in Python, Restful, Angularjs and Chartjs. I am importing information from the database via python and saving in a vector according to the code below:
def consumoKwhLampadaData():
fabrica.cursorExecucao.execute("SELECT round(SUM(kwh),2) AS 'Semanal',IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 1, 'domingo',IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 2, (......), IF(dayofweek(DATE_FORMAT(`data`, '%y/%m/%d'))<> 7, 'Sabado','Dia da semana nao definido'))))))) FROM energia WHERE Dispositivo NOT IN ('LAM') AND `data` BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() GROUP BY DATE_FORMAT(`data`, '%d/%m')")
resultado = fabrica.cursorExecucao.fetchall()
consumoKwhLampadaData = []
for data_out in resultado:
consumoKwhLampadaData.append(str(data_out[1]))
return ('%s') % (consumoKwhLampadaData)
I’m having the problem of "$http:baddata Bad JSON Data" at the angle because it is returning the contents of the "Sunday" vector, the vector has other similar data (Monday, Tuesday...), I couldn’t identify what might be happening, can anyone help me? I need the information of the days of the week to be displayed on a graph in HTML. This is Restfull’s code:
@app.route('/consumoKwhLampadaData', methods=['GET'])
def consumoKwhLampadaData():
return app.response_class(Servico.consumoKwhLampadaData(), mimetype='text/json')
This error indicates that the result is not being issued in JSON format. You could post an example returned by the call to endpoint
/consumoKwhLampadaData
, Wendell?– OnoSendai
Hi Erlon, then, when the data is returned from the database, I want him to change the format to string, as well as when I request to fetch the power consumption value, convert to int. In the case of the vector that is giving problem, I believe it is the content of it, since the others are working.
– Wendell Mosquini Pozzatti
This is the part of the code that receives the vector at the angle.
function obterConsumoEmKwhDoVentiladorData() {
 service.consumoKwhVentiladorData = [];
 return $http.get(link.host + link.consumoKwhVentiladorData).then(function (resposta) {
 service.consumoKwhVentiladorData = resposta.data; //retorna a reposta direto para o vetor.
 })
 }
– Wendell Mosquini Pozzatti
I’ll make a comment q is not directly linked to this issue, but honestly, I think for python developers your code frightens, I recommend you take a look at PEP8 https://www.python.org/dev/peps/pep-0008/
– Sidon
In time: I was the first to edit your msg to try to make it more "palatable", but still totally at odds with PEP8
– Sidon
What do you mean: '...due to be returning the contents of the vector "Sunday"...' - for the other days there is no mistake?
– Daniel
Sidon, it may be that the python code is not in the best way, but I’m getting the result I need, I’m beginner in python programming. The big issue of my python code posted (part of it) is that I use encapsulation.
– Wendell Mosquini Pozzatti
Daniel, I don’t know exactly why the error occurs, when I wanted to say '...due to be returning the content of the vector "Sunday"...' would be due to the content of the vector being a string. Sunday is in the first position of the vector, due to the error, I believe that the angular does not read the other positions of the vector.
– Wendell Mosquini Pozzatti
Solved that question? Oh, and for people to be notified when you answer them, use
@nomedapessoa
.– Daniel