Fixed the incorrect nightly averaging reset bug and lowered mem usage.

	The previous bug which resulted in the dates getting messed up
	when redoing the averages table at midnight or manually is now
	fixed. Previously I put the entire original data into a variable
	which at this time is roughly 50k rows, causing massive amounts
	of memory usage. Eventually it will hit the swap space, causing
	horrific slowdowns and this issue. I now get the data in batches,
	which makes the code far cleaner and mostly eliminates the memory
	usage spike when averaging the data.