Wednesday, October 19, 2016

Scraping Nissan Leaf prices: is the Leaf 2 ready, or will we have another battery upgrade?

I would like to drive an electric car and my interest was strongly increased by a lease offer from mijndomein (E399/month on a two year contract). This seems incredibly cheap for an E38.000 car, because the total costs would be E9576. Deducing some costs for insurance and the leasing company, expected deprecation would be roughly E8000 or 21% in two years. This seems rather low for an electric car, so I decided to scrape prices for second hand Nissan Leafs from autoscout24. I plotted the price versus age because most Leafs do not have all that much kilometers. I used requests to request the results, beautiful soup to extract the data and seaborn to visualize the results. The result is the following figure.

The figure shows that an effectively new Leaf is roughly E32.000. A really brand new one currently runs around E38.000, but these are mostly ex-demos and the like. After this initial deprecation (which is likely less than the discount the dealer gets), a linear approximation of the deprecation does not seem all that bad. The deprecation rate is then roughly E3700/month, closely resembling my estimation of the deprecation from the mijndomein lease deal.

Conclusion therefore, you might as well just buy one? Well, maybe. You would have to buy a Leaf at a roughly E6000 euro discount. Remarkably, a certain dealer is advertising with a E5000 discount, so that seems possible, and also seems to confirm the at least E6000 discount that dealers receive. Only thing is then that the risk of more deprecation is not for the lease company but for myself.

Finally, why is the discount so high, even for consumers. Well, it is widely believed that a 40kWh or even 45kWh Leaf (the current one is 30kWh) will arrive in January, boosting range to roughly 330/37km NEDC or 266/300 km of practical range, at the same price point. It is also rumored to have a less 'controversial' design. This will force discounts on current 30 kWh Leafs and therefore they are preferably sold before that announcement is made.

However, looking at the very short run time of the mijndomein deal, I thought that they will need an even larger discount to make that price work, so I would also not be surprised that the Leaf 2 will debut at the LA motorshow on November 15th. Consider that most car models run for 7 years and are then replaced and the current Leaf was introduced in 2010. Also consider that the Renault Zoe got a 41 kWh battery recently and now almost dwarfs the 250km range of the flagship product Leaf from the same company with a 400km range. If that introduction of the Leaf 2 happens with a 60kWh battery (as is assumed for the Leaf 2) at the current price point with deliveries starting in January, than Nissan would really crush the business case for all the 30kWh'ish current generation electric cars (BMW i3, Leaf, Zoe, Kia Soul, Hyundai Ioniq, e-Golf, etc.)! If we will only have the 45kWh upgrade, than it might still be worth the wait and discarding the current discounts, 50% range is very substantial and will put the Leaf at the front of the range battle again until the Chevy Bolt arrives. Exciting times ahead.

Sunday, October 9, 2016

Domoticz support for the NAD 7050

I happen to have an NAD 7050 Direct Digital Network Amplifier. Great product, works well with my Spotify Premium account and using an optical connection as amplifier for my television audio signal. The sound quality with my Monitor Audio Bronze 5 speakers is excellent. The amplifier comes with an Android app to mainly set the volume. Sadly, the app stopped working with the release of Android Nougat. Now, I also happen to have a home automation system based on Domoticz to operate my Hue lights, my Daikin heat pump, my blinds and what not. So, I decided to add support for the NAD 7050 to Domoticz. The reason I could was that Tom Hartley tweeted that he had figured out how to control it. I used his code with some LUA glue and a bit of clicking in Domoticz. I detailed the procedure in the NAD 7050 Domoticz wiki entry and you can discuss it on the Domoticz forum topic.

Wednesday, April 27, 2016

Building CalculiX

CalculiX is a powerful open source finite element package. Prebuild binaries are available for some distributions (e.g. Ubuntu), but many people try to build it from source. This often implies building ARPACK and SPOOLES to do the actual number crunching. The whole process is not always to trivial, though some help is available for windows and linux. I have automated the entire process using a make file and some supporting files (patches and a makefile for calculix itself). These files can be found on my github repository here.

Installing should not be fairly trivial:

  • Download the files from github and put them in ~/build_calculix
  • Fire up a terminal
  • cd ~/build_calculix
  • sh install
The script should now start downloading the required software, patches and documentation, build everything that has to be build and install the software locally in ~/calculix.

Friday, April 15, 2016

Visualizing claims from BIG cycling using python and folium

BIG cycling is a list of the 1000 cycling summits that matter in Europe. Over the past few years I rode a fair amount of them, mostly in Switzerland. There are a total of 75 climbs in region 7 (Switzerland and Liechtenstein), of which I already climbed 34, and therefore there are 41 left. I had the idea of riding the remaining ones this year.

To aid planning, I wanted to have a map with all the summits colored by claim. The site features this, though I do not like that it collapses different cols under one symbol. Furthermore, I also wanted to plot the routes in which I made the claim as-well as the routes I planned to claim them. To create this map, I first needed three data sets:
  1. My planned rides
  2. The rides in which I made a claim
  3. The latitude/longitude of the summits
I plan my rides using either strava or the Quaeldich Tourenplaner. Both have a gpx export which I use for the planned rides. The rides in which I made the claims are mostly stored in strava and therefore I made a full export of them in gpx format. To obtain the latitude/longitude of all the summits we use a small scraper in python leveraging beautifulsoup4 and store them in a text file (to avoid scraping the site over and over again, the list does not change frequently and I need to scrape almost 1000 pages).

To visualize the locations and the rides I started of using pygmaps, than switched to the pygmaps-extended fork because that could also give the locations a color (green for claimed ones, red for unclaimed ones). The maps worked wonderfully, but only on a specific computer and a specific browser, so I decided to try folium. This worked wonderfully and also provided a fantastic visualization mode, as we will see later.

Creating the visualization was then really not all that difficult anymore.

  • We first read the list we created using the scraper and scrape my own claims (this is just a single page so no real need to store this). 
  • We then loop over all files in the sub directory 'planned' to read the gpx files for all planned rides. We use xml.etree that comes with python to extract the latitude/longitude data from these files.
  • Then we loop over all files in the sub directory 'rides'. Levering the power of numpy we determine the distance of all the locations in the track to all the summits. This is a fair amount of calculation (1000 summits times roughly 3000 track points per ride times 500 rides leads to roughly 1.5 billion distance calculations, but this still takes no more than a few minutes). During this loop we keep track of the rides containing summits and the summits that we passed.
  • The only thing we then have to do is make a map object using folium, add the summits (red for unclaimed, green for claimed, blue for forgot to claim) and the rides (using a polyline, red for planned, green for ridden) and write result as html file to disk.
We use a black and white scheme called Stamen Toner, which makes for a really clear but also artistic map. You can find the results (18MB) here.