Tuesday, 22 December 2020

Chase the Pizza!

This post is, basically, a collection of random things. The first is a chart from a Google Sheet documenting the distance I've walked over 2021 for the Walk 1000 miles in 2021 challenge. What makes that fun is the way the data is collected. Unfortunately, there's no integration with Polar - my fitness tracker of choice - so I have to enter the steps from the previous day each morning. But then something cool happens. I set up URLooker to act as a webhook for IFTTT, which then slings the data from My Virtual Mission into a Google Sheet. Within the Sheet, there's a script which fires every evening and mangles the data into proper values. The following is the relevant script, and if you can see something that could be improved, please tell me:

const addFormula = () => {
  const factor = 0.62137119
  const returnSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1')
  const rowCount = returnSheet.getLastRow()
  for (let i = rowCount; i > 0; i--) {
    if (returnSheet.getRange('C' + i).getValue() === 'Removed'){
      returnSheet.deleteRow(i);
    } else {
      if(!returnSheet.getRange('F' + i).getValue()){
        const rawValue = returnSheet.getRange('D' + i).getValue()
        const rawValueNumber = Number(rawValue.toString().replace(/\D/g, ""))
        const rawValueUnit = rawValue.toString().replace(/[0-9 ]+/g, "")
        returnSheet.getRange('F' + i).setValue(rawValueNumber)
        returnSheet.getRange('G' + i).setValue(rawValueUnit)
        returnSheet.getRange('H' + i).setValue(rawValueUnit === 'km' ? rawValueNumber * factor : rawValueNumber)
      }
    }
  }
}

This is a cool way of generating an avatar. The following is mine.

And this is my first try at making a game with MakeCode, which is jolly good fun!

Proper link here.

No comments:

Post a comment