First stab at some driving statistics

This still hardcodes the capacity of the car. Need to parse this from the
initial response from the Tesla server.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove debug output that made it into an earlier commit

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add charging and temperature details to the database

This causes load on the Tesla server - so be very careful with the timeout
used for the calls to getAux()

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix stupid bug that caused more and more getAux() calls to get scheduled

initialize() is called every time the credentials expire. So every time
that happened, we scheduled another round of getAux() calls. So the number
of API calls per hour keeps going up. Like crazy.

With this commit we a) no longer add more setInterval calls and b) check
inside getAux() if at least 30 seconds have passed since the last time the
API calls have been made.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
First use of the charging data from the aux table

For now we just get the maxima for current / voltage and charge rate.

We should also graph those (at least with shorter time frames).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Show data for the last day of the stats page

We didn't add this to the output variables before.

This commit also includes a bug fix where incorrect JS was created if the
first day of a stats range had a distance of 0.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Deliver fewer data points to the browser in energy mode

Previously we delivered all available data, which could be many megabytes
and millions of values - even though the browser window has no way of
actually plotting all these. This made the response times slow and wasted
bandwidth.

With thie commit we summarize the values delivered in the server process
and only deliver up to 10000 values for speed and SOC and 20000 values for
energy (this way we show both maximum energy used and maximum regen).

This also fixes a bug where parsing of the to/from parameter was too
inflexible (when switching from stats to energy we don't get hh-mm-ss).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Make switching between different displays more consistent

Previously we would sometimes create invalid from / to parameters.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix yet another boundary condition

If charging "across" midnight, that last charge of the day wasn't added to
the total for the day.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Increase margin for end of map update

2 seconds is too short if the car is parked. Let's try with 2 minutes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove last hard coded URL

The MAGIC_UPDATE_URL was still hardcoding localhost. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix map drawing issues

We were drawing way too many "lines" were the car didn't move at all. And we
occasionally drew incorrect lines from the last to the first location of a time
series.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Improve energy graph

- seperate y scales for speed and energy
- fix calculations for max energy / max regen
- draw speed with lower opacity to be able to see both speed and energy when
  displaying longer time series

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Rewrite visualize.js to use existing url parser

This also changes the nesting of the checking for the different supported paths
(the old version had some at the top level, and some in the catch all "else"
branch - very strange).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we have no datasets for the requested timeframe, skip it.

Otherwise the update could simply 'hang'.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Make streaming.js more robust

The test for existance appears to cause database issues. I need to investigate
why, but for now let's just store multiples.

Also avoid a few more potential errors when the servers are down.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Improve the robustnes of the AJAX updates

Report failures, prevent infinite looping if there are gaps in the data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Merge pull request #11 from dirkhh/fromto

Major changes to visualization tools