PEP8 all the things!

see http://legacy.python.org/dev/peps/pep-0008/
Remove unused imports
Remove obvious comment, and move constants

Constants generally go before any "real" code
Pre-calculate filenames and loop better

In python you almost never use range when looping over a list. It's
faster and easier to read to just go "for x in y:".

See: https://www.youtube.com/watch?v=OSGv2VnC0go
Use a context manager to ensure closing file

This will ensure that the resource is always closed, even if there
is an exception. Normal files support this out of the box, but urlopen
doesn't (until python 3), so we have to wrap it.

See https://docs.python.org/2/library/contextlib.html
Use enumerate instead of counting manually

Faster, more pythonic, easier to read, less bookkeeping
Ahh, so we set one hash value per row...

Which means we can:

1. Use DictReader (https://docs.python.org/2/library/csv.html#csv.DictReader)
This will automatically use the first line of the file as a header so
we don't have to match it up manually.

2. Use redis method hmset (http://redis-py.readthedocs.org/en/latest/#redis.StrictRedis.hmset)
Then we only send shit to redis once, since we populate the entire key
in one fell swoop.
Don't use cgi and cgitb

They're never needed when using flask... That was the 90's way of doing
web
Set up logging first

Logging setup should almost always be the first thing to set up, after
importing stuff and specifying a couple of constants
Usually stuff is imported from datetime.

Like "from datetime import datetime, date, timedelta"... Makes code
shorter and easier to read
Clean up templates

Use inheritance, and don't set title from python. Also, since we want
the timestamp everywhere let's make it a default context processor, and
also disregard the intermediary "now" variable.

I changed it to an "isoformat()" instead. It was pretty close, and it
gets the job done for debug stuff like this.
Don't check for true on debug

Debug is either true (in which case "if debug" will be ok) or not. Also,
bonus tip:

Never do "x == True", "x == False" or "x == None". When dealing with
True, False and None, you always want to use "x is False" etc.
This is a console-only script, so just use globals

It's ok to have global connections sometime. This is one of those times
Rename redis and neo connections to be clearer.

And now that they're global, there's no point in passing them around
Use a named tuple for the data points

Named tuples are very lightweight classes with named attributes.
Whenever you have a class that's just a container for some values
with no real methods, it's a good bet you want a named tuple.

They take less code AND less memory
Redis already supports matching keys

No reason to keep our own set and reimplement. It's potentially a little
slower, but should be ok in this case.
Move key outside of point... This will break stuff

Readis structure should probably be re-thought a little. Seems like
we're spending an awful lot of energy dissasembling and assembling keys.
Use debug logging instead of print statements.

No need to pass around a debug param, and we can turn it on/off globally
instead.
Add some logical grouping comments

Always a good idea
Go up one level of abstraction.

My math is bad right now (i'm tired) so the weights are probably off.
Anyway, the idea is solid. It's basically about moving up a level of
abstraction.

So first off, there shouldn't be different average functions for
different number of elements. That's just silly.

Second, instead of doing this:

avg(p1.x, p2.x, p3.x)

lets try and do this:

avg('x', [p1, p2, p3])

i.e. specify the points and the dimension independently. Then we can
shorten our code because the points don't change.

Also, once we do that, we can create a function which gives us the sum
each dimension, so you can say:

ax, ay, az = allavg([p1, p2, p3])

For weighted averages, we should have a set of functions that work the
same way, but also takes a list of weights, i.e.:

ax, ay, az = allwavg([p1, p2, p3], [1, 2, 1])

and boom, we've removed a bunch of very long lines of code.