Thursday 28 October 2010

MapMyFitness JSON API Example




function loadMaps() {
var type = 2; //bike ride
var radius = 10;
$.ajax({
type: 'GET',
url: "http://api.mapmyfitness.com/3/routes/search_routes?&o=json&user_id=&user_key=&keyword=&min_latitude=51.08786&max_latitude=51.38786&min_longitude=-0.3013&max_longitude=-0.3013&center_longitude=51.38786&center_latitude=-0.3013&center_geocode=&radius=" + radius + "&route_type_id=" + type + "&city=&state=&country_code=&zip=&start_record=0&limit=25&sort_by=featured_flag%20desc,%20average_rating%20desc,%20route_name",
data: "id=" + "&lang=en-us&format=json&jsoncallback=?",
success: function(feed) {
// Create an empty array to store images
var thumbs = [];

// Loop through the items
for (var i = 0, l = feed.result.output.routes.length; i < l && i < 16; ++i) {
var routename = feed.result.output.routes[i].route_name;
// Add the new element to the array
thumbs.push(routename);
}

// Display the routes on the page
$('#feed').html(thumbs.join(''));

var show_user = tmpl("item_tmpl"), html = "";

for (var ii = 0; ii < feed.result.output.routes.length; ii++) {
html += show_user(feed.result.output.routes[ii]);
}
//var results = document.getElementById("results");
$('#vcalendar').html(html);
},
dataType: 'jsonp'
});
}

Flickr API - JQuery Javascript Example


function loadFlickr(flickrid) {
// Display a loading icon in our display element
$('#feed').html('');

// Request the JSON and process it
$.ajax({
type: 'GET',
url: "http://api.flickr.com/services/feeds/photos_public.gne",
data: "id=" + flickrid + "&lang=en-us&format=json&jsoncallback=?",
success: function(feed) {
// Create an empty array to store images
var thumbs = [];

// Loop through the items
for (var i = 0, l = feed.items.length; i < l && i < 16; ++i) {
// Manipulate the image to get thumb and medium sizes
var img = feed.items[i].media.m.replace(
/^(.*?)_m\.jpg$/,
''
);

// Add the new element to the array
thumbs.push(img);
}

// Display the thumbnails on the page
$('#feed').html(thumbs.join(''));

// A function to add a lightbox effect
addLB();
},
dataType: 'jsonp'
});
}

Wednesday 13 October 2010

Basic Netduino HL1606 driver port.


Straight port of Arduino library to interface with RGB LED strips built with the HL1606 driver chip.

This hasnt even been tested yet, I just converted the code without even analysing it.

[EDIT] OK I've had a chance to look at the code and what its suppose to do. The HL1606 is basically 2* shift register and 2* LED driver. The code below is Bit Bashing it's way through, which is a pretty basic way of controlling, especially since there should be some hardware support which can do the job for us (e.g. SPI).

I'm going to have a go a writing a driver which is a bit more efficient than the below code. I'll keep you posted!



http://code.google.com/p/ledstrip/



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

using System.IO;
using System.Text;

namespace NetduinoLEDSriptDriver
{
class HL1606Driver
{
enum BitOrder
{
LSBFirst,
MSBFirst
}

enum LEDState
{
OFF, // 0b00
ON, // 0b01
UP, // 0b10
DOWN, // 0b11

};

//#define _BV(bit) (1 << (bit)) //#include
//Converts a bit number into a byte value.
private const uint NONCMD = 0xFF;
private const uint LATCH = 0x07;
private const uint SPEED2X = 0x06;
private const bool LOW = false;
private const bool HIGH = true;

static OutputPort _dPin;
private OutputPort _sPin;
private OutputPort _latchPin;
private OutputPort _clkPin;

private bool _faderEnabled;
private uint _faderPulseNextEdge;

//System Function
protected void digitalWrite(OutputPort port, bool state)
{
port.Write(state);
}

protected bool digitalRead(OutputPort port)
{
return port.Read();
}

//public void pinMode(uint port, uint state)
//{

//}

public HL1606Driver(Cpu.Pin dPin, Cpu.Pin sPin, Cpu.Pin latchPin, Cpu.Pin clkPin)
{

//Setup Ports
try
{
_dPin = new OutputPort(dPin, false);
_sPin = new OutputPort(sPin, false); ;
_latchPin = new OutputPort(latchPin, false);
_clkPin = new OutputPort(clkPin, false);

}
catch (Exception)
{

throw;
}

_faderEnabled = false;

//Setup Port Inital States
wakeup();

}

void wakeup()
{
digitalWrite(_dPin, LOW);
digitalWrite(_sPin, LOW);
digitalWrite(_latchPin, LOW);
digitalWrite(_clkPin, LOW);
}


void faderCrank()
{
short mymillis;

if (!_faderEnabled) return;
SystemTime t = new SystemTime();

mymillis = t.Milliseconds;

// Give us 250ms slop in case we don't exactly catch our edge.
if (mymillis >= _faderPulseNextEdge && mymillis < _faderpulsehalfwidth =" _faderPulseNewHalfWidth;" _faderpulsenextedge =" (uint)mymillis" myvar =" value;" myvar ="=" _faderenabled =" false;" _faderpulsehalfwidth =" 0;" _faderpulsenewhalfwidth =" 0;" _faderpulsenewhalfwidth =" myVar;" _faderenabled =" true;" _faderpulsehalfwidth =" myVar;" t =" new" _faderpulsenextedge =" (uint)t.Milliseconds" value ="=" _faderenabled =" false;" _faderpulsehalfwidth =" 0;" _faderpulsenewhalfwidth =" 0;" _faderpulsenewhalfwidth =" value;" _faderenabled =" true;" _faderpulsehalfwidth =" value;" t =" new" _faderpulsenextedge =" (uint)t.Milliseconds" cmd =" 0;" flags =" LATCH;">= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;

cmd |= (greencmd << cmd =" 0;" flags =" LATCH">= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;

cmd |= (greencmd << i =" 0;" _bitorder ="=" mask =" (byte)(1" mask =" (byte)(1" ms =" (int)delay">

Monday 11 October 2010

Training Peaks Webservice

<script language='javascript'>
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>



Dim sUserName As String = "username"
Dim sPassword As String = "password"
Dim nUserId As Integer = 115133
Dim bData() As Byte

Dim ws As trainingpeaksWS.Service = New trainingpeaksWS.Service()
Dim p() As trainingpeaksWS.PersonBase = ws.GetAccessibleAthletes("username", "password", trainingpeaksWS.AthleteAccountTypes.SharedSelfCoachedPremium)


Dim v As String = ws.Version()

Dim dt As DateTime = DateTime.Now()
dt = dt.AddDays(-30)

Dim v3 As Object = ws.GetWorkoutsForAthlete("username", "password", dt, DateTime.Now)
Dim v2 As Object = ws.GetWorkoutsForAccessibleAthlete("username", "password", nUserId, dt, DateTime.Now)
Dim v4 As Object = ws.GetExtendedWorkoutDataForAccessibleAthlete("username", "password", nUserId, 40760637)

Dim workout As trainingpeaksWS.Workout = New trainingpeaksWS.Workout()


ws.ImportFileForUser(sUserName, sPassword, bData)



Wednesday 10 March 2010

Surrey League Alfold Crossways 7th march 2010


I rode the Alfold race a the weekend and saw a couple of the Twickenham CC guys. As previously mentioned I was in stealth mode so I was riding in a plain jersey.
I've only been back training since 1st Feb so I didn't have high expectations of this race, it was more of a training day for me.

My goals for the race were open:
  • I expected to finish
  • I wanted to get in a break or cause a bit of damage
  • I wanted to work on bunch positioning
  • Test my basic sprinting
  • Overall I wanted a good workout with a TSS of 250->300

Course Overview (6 laps = 72 miles)

Alfold is a great circuit and suits a strong rider, you don't have to be a climber for this course.
There are 2 small drags which are the ideal place to attack; one coming into Alfold and a longer shallower one on the back of the course which drags all the way up to near the village of Plaistow before dropping into ifold and the finish. There are also some semi technical corners which can be taken very fast and can cause gaps to open up.
By staying near the front at these sections it should be easier to go with any move.
*Lots of potholes at the moment so it pays to be aware especially when the sun is low in the sky.

Race Report
The race was good, lots of action, lots of attacks, but probably 15 miles too long for most of the guys there, this caused the race to be more of a survival exercise for some riders.

I was convinced that a break would get away and stay away, especially with some very strong 2nd cat riders.

The race split and reformed for quite a while with lots of riders trying their luck. I was doing what you do and following wheels having digs and generally getting to know the riders and course.
On the Plaistow drag Matt Melville(AW Cycles) attacked hard, I've know Matt for a number of years he's the strong rider who can wring himself out in a break, so it's a wheel to follow. We got a nice gap and after a short time were joined by more riders... that's were it fell apart, too many riders in the break and too many fresh legs in the bunch... it came back. This seemed to be the start of the race for real.

Over the next 20-30 miles a few breaks did go but none really stuck.

A break finally floated off the front... 2 riders, theys were Matt Melville (again!) and eventual winner Andy Bryson(DHCyclesport.co.uk). They worked well and once it had >20 seconds I knew we might be in trouble. The break hung about at 20 seconds for a while and eventually Matt Blew (He'd only brought 1 bottle and was bonking, I gave him the rest of mine and gave him a quick push, he soon recovered enough to hang in and attack again).

Legs were getting tired, mine included, the bunch slowed for a few miles allowing the lone breakaway to get a good gap.

Eventually the bunch started rolling again, one rider in particular was on the front a lot! Ben Instone (Torq Racing) rode hard keeping the tempo and detering any breaks. Its a bit of a shame that he didnt rest for a lap and try to get in a break rather than towing the bunch around lap after lap... ah well, each to their own.

Personally, I decided to hang around the front 10 riders and follow wheels for a bit.


The sharp end
By the last lap I was convinced(again!) that there would be no more attacks, we had passed all the difficult parts of the circuit and it was basically a run into the flat headwind finish, perfect for me.

So as I settled into the remains of the bunch I dropped my guard, as did quite a few other riders. The bunch split, some riders lost wheels and by the time we reacted there was a 10 second gap. Matt, Rob Enslin and some other good riders were in the back group and we were all slightly lethargic after 67 miles of racing.

At the end of races it CAN get like this, either you all get it on, or you end up in a group who will not work cohesively at all.

What's the best situation?
  • Attack and hope no one will chase
  • Try to organise a chase
  • Do nothing and wait for the sprint
What did happen?
Rob attacked and got 5 then 10 seconds. As a sprinter I wanted to hedge my bets, I knew if we could peg them back without too much energy then I could get a result in the sprint. So I rolled through trying to encourage others to do the same. Some riders rolled through, enough to bring Rob back but not enough to catch the lead bunch.

Do I attack, do I hope some riders are waiting to attack? By now the break had a good gap and we were coming into the last couple of Km, it was time to settle in and practice my sprinting.

So, what do we know about the finish?
  • Straight
  • Head wind
  • Group of ~10 riders
What to do in a sprint
  • Watch the riders
  • Who looks strong, who is built like a sprinter
  • Who is positioning themselves

Position yourself
  • Dont get boxed
  • Stay out of the wind
  • Use your type of sprint

I picked a rider who was hovering on the outside looking like he was going to jump, he went with about 200 to go on the outside of the bunch. Being on his wheel sheltered me from the wind and as he hit his top speed and pulled to left slightly I totally committed and accelerated off his wheel hard to the right. Gaining a gap of just 1 bike length over other riders can cause enough of a reduce in shelter that they cant get back on your wheel. Job done I could ease down for the last 50 meters, bunch sprint taken.

10th Place. OK I'm happy with that.

Well done to all the riders, some great efforts and Andy did a great ride for the win.

Lessons Learnt
  • Don't be convinced always be adaptable to race situations. Keep multiple strategies
  • The winning break came from a small group where no teams chased at the point where people were getting tired.
  • Most people at 2nd cat attack when they are feeling good or at easy section of the course, maybe they should attack at the hard sections and when they are feeling on the limit?
Some stats from the Alfold Crossways race:
  • 72 Miles
  • 3 hours @ 300watt average
  • Max 20 minutes 333 watts (Normalized)
  • Max Power 1588watts
  • ~3000Kcal
  • Lots of Potholes = Bent Handlebars
  • BUT No Punctures

Thursday 11 February 2010

New Look

Just a little note.

I decided to spruce up the look of the blog and found a nice free example over at Lawnys Templates

Quick and easy, and I added the code highlighter in about 2 minutes.

Thanks Lawny


Tuesday 9 February 2010

May Flyer Short Route- South Western Road Club Sportive

Here is a ride from Surbiton including the SWRC Cyclo Sportive May Flyer Short route. It takes in some great surrey roads and even comes back through peaslake so you can grab a cheese straw from the peaslake store!