• Cardio Grapher Beta

    As hinted at in my previous post, I’ve been working on an Android application in my spare time for the last month or so.

    As a result of me no longer being a student I can no longer go cycling so easily during the middle of the day when there is daylight and the roads are quieter. When winter has passed so I don’t end up cycling back in the dark (multiply the distance by the number of working days the journey would be in the dark for and take into account the fact it would be at rush hour and on busy roads and that’s quite a lot of risk to accumulate) I’ll get around this by cycling to and from work (I did a few times before winter set in). But for now I’ve bought a turbo trainer for my bike and have it set it up in my flat.

    Now, necessity is the mother of invention and as with many of the things I’ve built this was the case here; when cycling out on roads I’ve used Google My Tracks a lot (and even added a small feature at one point), but when inside it becomes a lot less useful – obviously all distance and speed data (derived from the GPS) become meaningless. Now, I could setup a standard magnet based cycle computer on the rear wheel, but even then the data are not so meaningful – knowing that you’re doing e.g. 20 mph when stationary doesn’t really give you any idea how you’d be doing out on roads. So heart rate really does become the metric of real interest.

    Of course there are numerous applications out there already that will connect to the Zephyr HxM (the Bluetooth heart rate monitoring strap I bought) – for example, My Tracks itself has support for a wide range of sensors – but the majority of them share the problem that displaying heart rate is only one the things they do and as such little emphasis is placed on doing things with that metric other than graphing it and giving the current value.

    Enter Cardio Grapher: While it doesn’t yet do that much more than the existing solutions, my intention with it (as you may guess from the name) is for it to solely work with heart rate data. As such, I intend over time to explore a number of ideas for metrics that can be used to gauge the quality of a workout and to track progress.

    Today I’ve released version 1.0, which I consider to be beta quality. The features:

    • Live graphs of your heart rate over the last 1, 10 and 120 minutes.
    • User specific heart rate training zones, helping you get the most you can from your training (based on formulae from http://www.machinehead-software.co.uk/bike/heart_rate/heart_rate_calculator.html).
    • Audio alerts when entering and exiting training zones.
    • Can be set to keep the phone’s screen on when in use.
    • Can be set to automatically switch the phone’s Bluetooth adapter off and on again when connecting to the HxM times out (this is a work around for a bug in the Bluetooth implementation on some phones).
    • Reports the remaining battery charge level of the HxM.

    View it on the Android market here: https://market.android.com/details?id=net.cardiographer

    Screenshots:

    Connecting Autoscaling Training zones Details About EULA Preferences Menu

  • Source Lines Of Code with Munin and SLOCCount

    Pretty much exactly a year ago I wrote a plugin for Munin that scrapes the current temperature in Cambridge as recorded by the University Computer Laboratory.

    The plugin is unlikely to be of much use to anyone else if used exactly as is, given that it only provides information for Cambridge. Posting the code here serves two purposes:

    1. It serves as a backup of the plugin for my own reference – full blown version control for snippets like this is overkill.
    2. Mutating something that already works to make it do what you want is often easier than writing something from scratch, so it may be of use to other Munin plugin developers just getting started.

    It doesn’t take any configuration, and has no comments – the code should be self explanatory:

    #!/bin/sh
    
    case $1 in
    config)
    cat <<'EOM'
    graph_title Cambridge Weather
    graph_args --base 1000 -l 0
    graph_vlabel Celsius
    graph_category sensors
    temperature.label Computer Laboratory
    EOM
    exit 0;;
    esac
    
    echo -n "temperature.value "
    wget http://www.cl.cam.ac.uk/research/dtg/weather/current-obs.txt \
    -O - 2> /dev/null | awk '/Temperature/ {print $2}'
    

    Installing this plugin is as simple as writing the above source to

    /usr/share/munin/plugins/weather

    and making a symbolic link to it in

    /etc/munin/plugins

    - not forgetting to restart munin-node having done so.

    The graphs can be viewed at penguin.piggott.me.uk.

    The temperature over the course of the last year, at the time of writing, follows:

     

    If you do happen to look around at the rest of the graphs at the above link, you’ll notice that all the others are currently looking very bare, and that the weather graph is missing a chunk of the last week. There are two reasons for this:

    1. I’ve recently migrated away from a fixed-price-per-month VDS (it was slightly overpowered in terms of CPU and underproviding in terms of disk capacity) to an Amazon EC2 micro instance, which is more flexible in terms of cost (but also seems to be fairly erratic in terms of performance, to the point that I’m having second thoughts). It wouldn’t have been very meaningful to migrate the server-specific statistics of one server over to another.
    2. In the process of developing my SLOCCount plugin, I managed to make a bit of a mess of the freshly installed Munin configuration on the new EC2 instance, and had to revert to a backup of the RRD file that I’d copied over from the previous VDS.

    Anyway, one year on and I’m just starting up a small side project for fun outside of work (which I will hopefully be making a post about soon), and as I don’t have a dissertation to write alongside it – which served well as a planning tool – I’m putting a bit of initial time in to setting up some tools like Trac for the project. As well as that, I thought it would be neat to have a graph of the number of lines of code over time as the project develops (this would have been interesting for my dissertation, but alas, I was – quite appropriately – focused only on the bits that really mattered; graphing lines of code is just a bit of fun).

    So, before allowing myself to do any more development on the project itself, I hacked up a quick and dirty Munin plugin that shows lines of code by language as stacked graphs:

    #!/bin/sh
    
    case $1 in
    config)
    printf "graph_title $PROJECT_NAME\n"
    printf "graph_args --base 1000 -l 0\n"
    printf "graph_vlabel Lines of code\n"
    printf "graph_category projects\n"
    sloccount $PROJECT_PATH 2>/dev/null | awk \
    'BEGIN{FS="[:]?[ ]*[(]?[%)]?"}; \
    /Totals grouped by language/ {resultLine=NR}; \
    /Total Physical Source Lines of Code/ {resultLine=0}; \
    resultLine>0 && NF==5 {print $1 "_lines.label " $1; \
    if(NR==resultLine+1) print $1 "_lines.draw AREA"; \
    else print $1 "_lines.draw STACK"}'
    exit 0;;
    esac
    
    sloccount $PROJECT_PATH 2>/dev/null | awk \
    'BEGIN{FS="[:]?[ ]*[(]?[%)]?"}; \
    /Totals grouped by language/ {resultLine=NR}; \
    /Total Physical Source Lines of Code/ {resultLine=0}; \
    resultLine>0 && NF==5 {print $1 "_lines.value " $2}'
    

    Because you may wish to run multiple instances of the plugin – e.g. if you have several distinct projects that you want code analysis running on – I suggest you write the above code to

    /usr/share/munin/plugins/sloccount

    and then make symbolic links of the form

    /etc/munin/plugins/sloccount_cardiographer

    The plugin does require configuration: the single entry I currently have in

    /etc/munin/plugin-conf.d/munin-node

    is:

    [sloccount_cardiographer]
    env.PROJECT_NAME Cardio Grapher
    env.PROJECT_PATH /home/dhpiggott/Workspace/CardioGrapher
    user dhpiggott
    

    With this configuration, the config output at the time of writing is:

    $ sudo munin-run sloccount_cardiographer config
    graph_title Cardio Grapher
    graph_args --base 1000 -l 0
    graph_vlabel Lines of code
    graph_category projects
    java_lines.label java
    java_lines.draw AREA
    xml_lines.label xml
    xml_lines.draw STACK
    

    and the value output is:

    java_lines.value 887
    xml_lines.value 37
    

    PROJECT_NAME and PROJECT_PATH do what they say on the tin. The user is a bit more interesting; sloccount tries to cache the results of its analysis to

    ~/.slocdata

    and fails if it can’t write this data. The directory it uses is configurable with

    --datadir

    but the point here is that Munin plugins by default run as the munin user and thus cannot write this slocdata. To make it work, configure the plugin to run as any user that will allow slocdata to be written to its home directory.

    Of course, the user will also need permission to read PROJECT_PATH and you will need to have SLOCCount installed.

    At the time of writing this post, the resulting graphs are pretty bare – as they would be. Here’s a snapshot anyway:

    References

    In creating this plugin I found the following resources useful. I won’t repeat the content to be found in them, except to say that if you’re struggling to grok awk, the key concept that everything else will follow from is the idea of patterns and actions (though I don’t claim to have grokked it!).


  • Inferring Transportation Mode using Smartphone Sensor Data

    Now that The End (of The Beginning) is complete, one of the various things that it is appropriate to do is to post a bit about my dissertation, which I had fleetingly mentioned in previous cycling posts.

    You can download a copy here: Inferring Transportation Mode using Smartphone Sensor Data (213)

    The inspiration and motivation behind the project was from the UROP I did last year summer. I had envisioned my Energy Meter application accounting for peoples’ day to day energy usage in three ways:

    1. Scanning QR codes that point to modified Atom feeds that contain cumulative energy consumption figures for regularly used “facilities”, for example, home and workplace HVAC systems. See the video below for a full description of this; I successfully prototyped it in the UROP.
    2. Scanning barcodes from consumable items (e.g. a ream of paper), using the barcode to look up the consumable in question in a crowd sourced database mapping consumable items to their embodied energy.
    3. Using GPS and accelerometer data on the smartphone to infer when the user is travelling, and what sort of vehicle (if any) they are using. This data, along with a record of their mileage for the trip (measured using the GPS) could then be used to calculate an estimate of the energy used and hence the carbon dioxide released as a result of the activity.

    As with so many projects, these goals turned out (as I had suspected) to be too much for one summer, and I settled for making a good go of the QR code system.

    Still keen to develop the system at the end of the summer, I decided to continue my work and develop the third metering approach. The dissertation investigates the use of sensors not tried  by other research (orientation, light level, magnetic field strength and GPS satellite data) as well as the more tried and tested accelerometer data and GPS location data. Within this scope, various features (ways of analysing the raw sensor data) for classification are compared.

    Part of doing this required that I construct a representative data-set for classifier training and evaluation purposes, which first of all meant creating Route Tracer [1] [2], an Android application which records accelerometer, GPS location, GPS satellite light level, magnetic field strength and orientation data, along with the (user supplied) transportation mode label to the SD card. I used this to collect (with the aid of volunteers) 3000+km (100 hours/200 journeys) of data spanning eight cities in four countries.

    Saying much more here would just mean repeating what I have said in the introduction and conclusion of the dissertation itself, so I’ll wrap up with two concluding paragraphs:

    “The accuracy of the best resulting classifier (recall of 97.8%) is very promising and it would really be good to develop a standalone Android application for personal transportation energy metering. Better yet would be to automate the personal transportation energy metering component of the Energy Meter application I created as part of my Undergraduate Research Opportunities Program (UROP).”

    “In addition to testing approaches from existing literature, I have been able to confirm my original hypotheses that magnetic field strength and GPS satellite information are useful data sources. Finally, I found that orientation sensor information is a strong data source.”

    The mark I received was 81.2/100, resulting in it being one of eight dissertations to be highly commended! Better yet is the fact that the organisers of the UROP projects have set somebody working this year to develop an Android application that uses the findings of my dissertation to further the energy metering work that started all of this.

    This is the presentation I gave at the end of my UROP last summer, explaining Energy Meter:

    You can also download the slides: Personal Energy Meter UROP Presentation Slides (93) (Note: the email address on the cover slide has now expired, and most of the URLs seen in the examples are no longer around).


  • Easter Term 2011 – Part 2 – The End (of The Beginning)

    OK, so this post is a little late arriving – let that speak only of just how busy the last several months have been!

    Rough timeline from the end of the previous post (May 29th) to the present day (July 15th), in terms of week start-dates and the main activity:

    May 30th: My final week of planned revision.

    June 6th: Exam week plus Download Festival (exams on Tuesday 7th, Wednesday 8th and Thursday 9th) followed by Download Festival on Friday 10th, Saturday 11th and Sunday 12th – a huge change of circumstances in the space of a few days, from being very tightly wound to relatively carefree.

    June 13th: The first part was spent doing pretty much nothing (it’s important to do that sometimes) – I was a bit ill after Download, though Download probably wasn’t the cause – more likely it was the culmination of having worked so hard, for so long, with so little rest. Very quickly I had to stop doing nothing, as I realised that with exams out of the way I could no longer defer finding somewhere to live (in the build up to exams, *everything* went on hold aside from revision and cycling). So the second half of the week saw me view a few potential houseshares, the official end of Easter Term, a birthday formal, and the Third Annual Cambridge University Cardboard Boat Race…

    June 20th: May Week! At last! The main event for me was Downing May Ball on Tuesday 21st, though I also viewed another houseshare the day after. There was also the final Fitz Comp Sci Wine and Cheese social on the Monday, a missed punting trip on the Thursday, and a birthday meal on the Thursday. And on the Friday, a NatSci dinner, preceded first of all by results! They appeared on CamSis at around 2pm as I recall: I got a 2.i, which needless to say I am very pleased with.

    June 27th: Grad week. At this point I was fed up of being messed around by potential housemates, and had intended to start the week by arranging viewings of apartments/flats. The daily Spareroom email flagged up a new houseshare that was to be available on Friday 1st (which was the date I’d need to move in if I was to avoid moving home for a few days first – which I was intent on doing). So instead I viewed that in the afternoon, liked what I saw, and went back to meet the other housemates in the evening. All was going well; we arranged to go to the letting agents the next day and do all the paperwork. Then I got a text later that evening saying they were going to let a few more people view it first, and could we do Wednesday. After previous experiences, this was enough to make me change my mind. Thursday saw me view two flats, one a studio and the other with one bedroom. I liked the former, and would have submitted an application on the Thursday had it not been for the fact I had one more viewing lined up for the Friday morning. But at 6:30pm that evening the agents for that viewing called to cancel, as it had been let. At this point my mind was made, and I would submit an application for the studio flat as soon as possible; complicated by the fact that the graduation dinner started at 7pm that evening. I elected to remain a bit more sober than I might otherwise have done, and went to sleep at a relatively early 2:30am; I later learnt that the partying continued until 4:30am. I was up at 7am or so, and at the letting agent for just after 9am, where I learned that somebody else had already submitted an online application overnight – which, had it not been for the graduation dinner, is what I would have done. I submitted mine anyway, as they would both be given to the landlord. About midday I got a call to let me know the landlord had picked mine – great, I now had somewhere to live! The rest of the day saw me arrange the move in date; July 8th, and then was spent with family, who had come down for the graduation weekend. Saturday was the actual grad day itself. It was a pretty awesome day. I probably don’t need to write much more – I can’t see myself forgetting it easily. Dare I say it, it was also pretty emotional – this was compounded by the fact that Fitz kicked grads out by 7pm, so half of the afternoon was spent loading the car up – which was no easy task, given the bulk of my computer, speakers & stands, and bikes. We stayed in a hotel overnight and traveled back on the Sunday morning.

    July 4th: I finally bought Portal 2 on the Monday, having deferred doing so until after exams and then just being too busy to do so, and between playing that and lounging around doing nothing, had finished it by the end of Tuesday. Wednesday was a day of nothing, as also was Thursday. Friday saw me pack everything up and load it into a car once more, but this time for good; I drove down to Cambridge, picked up my keys, and moved into my own place. Friday and Saturday were mostly spent stocking the kitchen and unpacking. On Sunday I went swimming in Jesus Green pool.

    11th July – present day: More flat-related admin; sorting out utilities, including internet, inventories and parking permits. Also various other things like getting my degree certificate framed, and finally customising my phone to my satisfaction; something I just had not had time for until now.

    Tomorrow I drive back home, to go to Carcassonne with family for two weeks. This’ll be my first real holiday in two years, and I really need it!

    [large gap due to more busy-ness - I didn't publish this post when I got to end of that last sentence]

    [the date is now August 25th]

    The second two weeks of July were, as I said they would be, spent in Carcassonne enjoying a very nice and much needed holiday.

    August 1st – present day and beyond: Working as a software developer, which is pretty cool, given that it’s what I’ve wanted to do for the last six years or so. Up until last weekend my flat didn’t have an office chair nor a good desk, and so although on the evenings that I’d sit down at the computer with every intention of doing productive things (like finishing blog posts), I’d just end up playing games, watching films, or reading books. I now have a decent desk and chair (bought from Ikea last weekend) and hence am now able to slowly but surely bring order to my life once again – and once that is done, I might start doing cooler creative stuff.

    A large fraction of this post would be better as photographs, not prose, but in recent years I’ve stopped taking so many good photos as I prefer to focus on enjoying whatever the activity is that I would otherwise be photographing. Despite that, if I posted one I’d have to post an entire album, because there are so many that – although not good photographically –  do capture good memories.

    Following on from the previous Easter Term 2011 – Part 1 post, here is the second half of Easter Term cycling.

    RouteDateCommentsCateyeMyTracksCL Weather
    North Cambridgeshire 1201/06/11Time: 1:27:28
    Dst: 26.80m
    Av: 18.4mph
    Mx: 28.6mph
    Av 30.31km/h~18°C
    North Cambridgeshire 1303/06/11Time: 1:26:01
    Dst: 26.80m
    Av: 18.6mph
    Mx: 32.8mph
    Av 30.58km/h~23°C
    North Cambridgeshire 1420/06/11There's a 17 day gap between this and the last because in between I've had:
    1) Three consecutive days of exams (finals!)
    followed immediately by:
    2) Three consecutive days on a not ideal diet at Download 2011
    followed immediately by:
    3) A week of cold-symptoms - presumably bought about by Download - and catching up on various bits of deferred admin.

    The result is a clear and significant reduction in average and maximum speed.
    Time: 1:31:37
    Dst: 26.88m
    Av: 17.6mph
    Mx: 24.9mph
    Av 28.69km/h~20°C
    North Cambridgeshire 1525/06/11Time: 1:28:23
    Dst: 26.73m
    Av: 18.1mph
    Mx: 27.0mph
    Av 29.65km/h~22°C
    North Cambridgeshire 1626/06/11Phenomenal weather; the hottest day of the year by far. Took 1.6L of water and had run out by Cottenham. Average as far as Swavesy/Willingham was hovering around 20mph; it came down a lot after that due to wind from the south (and possibly insufficient prior eating).Time: 1:31:32
    Dst: 26.88m
    Av: 17.6mph
    Mx: 27.1mph
    Av 28.74km/h~28°C

    Here is the Google Doc with all the stats:
    http://spreadsheets.google.com/ccc?
    key=0At0EKwdiLZmYdFg4Mk9fdHltdWlGeWpQTHMzM3RjU3c&hl=en_GB


  • Easter Term 2011 – Part 1

    Posted on by Dave Comment

    405.23 miles so far:

    RouteDateCommentsCateyeMyTracksCL Weather
    North Cambridgeshire (Variant) 223/04/11Time: 1:28:08
    Dst: 26.91m
    Av: 18.3mph
    Mx: 26.9mph
    It failed to record many parts27.80°C peak
    Cambridge Semi Orbital 4325/04/11Time: 1:17:12
    Dst: 22.88m
    Av: 17.7mph
    Mx: 25.2mph
    Av 28.8km/h~10°C
    North Cambridgeshire (Variant) 327/04/11A new personal best! I'm going to drop the "Variant" from this and make it the normal route. It's longer than semi orbital and avoids the traffic lights and roundabouts of Cambridge itself.Time: 1:24:43
    Dst: 26.81m
    Av: 18.7mph
    Mx: 27.1mph
    Av 30.53km/h~12°C
    North Cambridgeshire 428/04/11Time: 1:26:43
    Dst: 26.81m
    Av: 18.5mph
    Mx: 25.1mph
    Av 29.82km/h

    Route:


    View North Cambridgeshire 4 in a larger map
    ~12°C
    North Cambridgeshire 529/04/11Time: 1:28:08
    Dst: 26.79m
    Av: 18.2mph
    Mx: 25.7mph
    Av 29.6km/h~18°C
    North Cambridgeshire (Variant) 630/04/11I went the longer way back, through Landbeach, Waterbeach, Horningsea and Fen Ditton. The wind was fierce!Time: 1:51:33
    Dst: 32.29m
    Av: 17.3mph
    Mx: 31.1mph
    Av 27.96km/h~18°C
    North Cambridgeshire 706/05/11Another personal best! There's quite a gap between this ride and the last: I did another dissertation sprint, this time for the second draft.Time: 1:25:26
    Dst: 26.82m
    Av: 18.8mph
    Mx: 28.7mph
    Av 31.92km/h~22°C
    North Cambridgeshire 807/05/11Time: 1:26:33
    Dst: 26.84m
    Av: 18.6mph
    Mx: 31.0mph
    Av 26.89km/h (it failed to record half of the ride)
    ~24°C (it rained in the morning but had cleared up by the time I left)
    Cambridge Orbital 5 (slight deviation from the normal orbital; the rail crossing in Great Shelford was closed so I had to take a diversion)08/05/11I made a minor saddle adjustment (brought it forward and down) and it seems to have almost solved the back pain I was having. Now I just need to upgrade the saddle itself and with a bit of luck the only thing that will limit my range is the amount of drink I can carry.Time: 2:47:36
    Dst: 49.19m
    Av: 17.6mph
    Mx: 34.3mph
    Av 26.41km/h (it failed to record the first eighth or so of the ride)

    Route:


    View Cambridge Orbital 5 in a larger map
    ~20°C (it rained in the morning again but had cleared up by the time I left)
    North Cambridgeshire 918/05/11New personal best, and on the same day I submitted my dissertation (two days early, which is nice)!Time: 1:24:02
    Dst: 26.75m
    Av: 19.1mph
    Mx: 25.2mph
    Av 30.97km/h~14°C (it rained just before I left and the forecast was threatening thunderstorms – nearly didn’t go at all but for the duration I was out not a drop fell!)
    North Cambridgeshire 1019/05/11Time: 1:27:09
    Dst: 26.74m
    Av: 18.4mph
    Mx: 25.2mph
    Av 29.94km/h~16°C
    North Cambridgeshire 1125/05/11Time: 1:25:05
    Dst: 26.79m
    Av: 18.9mph
    Mx: 28.4mph
    Av 31.01km/h~18°C
    Cambridge, Cambourne, St Ives, Ely29/05/11There was a very strong wind from the south; my average speed all the way up to Ely was 19.3mph (and I'd done 40+ miles by the time I got there). It really slowed me down on the way back down though!Time: 3:26:42
    Dst: 59.61m
    Av: 17.3mph
    Mx: 39.8mph
    Av 27.97km/h


    View Cambridge, Cambourne, St Ives, Ely in a larger map
    ~19°C

    I found something almost worthy of being called a hill, and it seemed to be asking for a picture:

    2011-05-29 12.37.58

    Here is the Google Doc with all the stats:
    http://spreadsheets.google.com/ccc?
    key=0At0EKwdiLZmYdFg4Mk9fdHltdWlGeWpQTHMzM3RjU3c&hl=en_GB



  • dinamic_sidebar 4 none

©2012 piggott.me.uk Entries (RSS) and Comments (RSS)  Raindrops Theme