How do I do math with data from my SQL before displaying on my website?

Viewed 27

I'm working on a project with Python and SQL but i really need some ideas right now.

I use Python to scrap some information from websites and save them on my SQL. After that, I have to take a few rows from this SQL using a filter and do some math with them (like taking the mean, applying weights, creating a score...) and dispose them on a graph or a table.

My problem is: I can do this on python, but I need to make this available on my website (people should choose the filters they want and then all the math is done behind the scene).

Do you guys have any idea how I could do it? Is it possible to be done only with Python?

1 Answers

Because SQL and Python are both Turing-complete languages, you could you use either or both in any combination, and will get advice across the gamut.

My advice: use SQL to do all computation, and Python to schlepp the data between the database and the website. Don't worry about performance. Because database work is dominated by I/O, any computation inside the DBMS is almost invisible.

The great advantage of this approach is its reliability and simplicity. To verify any result, just run the query and look at the results, independent and apart from the application. If the result posted on the web page is wrong, it's easy to see if the computed answer produced by SQL is wrong, or if something got munged in transit.

Related