I've got an app engine app that compares values which are scrapped hourly and I'm running into high CPU usage. I'm doing a lot of calculation on the page request so I think I'm not approaching it the right way and I'm looking for suggestions.
For example, suppose I scrape Amazon's prices of electronic products on an hourly basis. I want to have a page where a user can enter an hour and it will compare the change between the current price and the price of the product X hours ago.
On the page load the following happens:
User enters 5 hours
1) curr_prices = 'select * from products where time = now'
2) prev_prices = 'select * from products where time = 5 hours ago'
3)
Is there a more efficient way to do this quicker than O(n^2)?
I can set a cron task to do this once an hour and store the values so that a client request just pulls precalculated values out the db, but since I allow the user to enter an arbitrary hour I would need to store multiple datasets (possibly of the most used values)
For example, suppose I scrape Amazon's prices of electronic products on an hourly basis. I want to have a page where a user can enter an hour and it will compare the change between the current price and the price of the product X hours ago.
On the page load the following happens:
User enters 5 hours
1) curr_prices = 'select * from products where time = now'
2) prev_prices = 'select * from products where time = 5 hours ago'
3)
Code:
for curr in curr_prices
for prev in prev_prices
if curr.product_name = prev.product_name
curr.price_diff = curr.price - prev.price
I can set a cron task to do this once an hour and store the values so that a client request just pulls precalculated values out the db, but since I allow the user to enter an arbitrary hour I would need to store multiple datasets (possibly of the most used values)