Skip to content

Instantly share code, notes, and snippets.

View Tafkas's full-sized avatar

Christian Stade-Schuldt Tafkas

View GitHub Profile
@Tafkas
Tafkas / trendweight.r
Last active August 31, 2018 18:09
Chart your data from http://trendweight.com/export with ggplot2 in R
#read data
tw <- read.csv(file="TrendWeightData.csv",header=T)
summary(tw)
#remove interpolated values
tw <- tw[tw$WeightIsInterpolated == "False",]
#convert strings to date and extract year
tw$Date <- as.POSIXlt(as.character(tw$Date), format="%Y-%m-%d")
tw$Year <- tw$Date$year + 1900
@Tafkas
Tafkas / rouletty.py
Created December 9, 2013 11:28
A simulation of the martingale roulette system
#!/usr/local/bin/python
# encoding: utf-8
import random
import time
import matplotlib.pyplot as plt
import numpy as np
#simulates the martingale roulette system
def simulation():
@Tafkas
Tafkas / AtlanticCity10Miler.r
Created December 9, 2013 14:27
Some charts of the St. Pat's 10 Miler and 5K 2008
data <- read.csv(file = "2008TenMiler.csv", header = TRUE, sep=",")
summary(data)
data <- na.omit(data)
#convert time to minutes
data$Nettime <- as.character(data$Nettime)
data$Nettime <- sapply(strsplit(data$Nettime, ":"),
function(x) {
x <- as.numeric(x)
x[1]*60 + x[2] + x[3]/60
@Tafkas
Tafkas / sleepdata.R
Last active April 4, 2016 14:00
A first look at the sleepdata recorded with the Sleep Cycle app for the iPhone
sleep <- read.csv(file="sleepdata.csv", header=T, sep=";")
#split end time
sleep$End <- as.character(sleep$End)
#get the date
sleep$Date <- sapply(strsplit(sleep$End, " "),"[[",1)
sleep$Date <- strptime(sleep$Date, format="%Y-%m-%d")
#fix sleep quality
@Tafkas
Tafkas / fitbitdownload.gs
Created January 28, 2014 22:41
This script will access your Fitbit data via the Fitbit API and insert it into a Google spreadsheet.
/* FitbitDownload.gs
This script will access your Fitbit data via the Fitbit API and insert it into a Google spreadsheet.
The first row of the spreadsheet will be a header row containing data element names. Subsequent rows will contain data, one day per row.
Note that Fitbit uses metric units (weight, distance) so you may wish to convert them.
Original script by loghound@gmail.com
Original instructional video by Ernesto Ramirez at http://vimeo.com/26338767
Modifications by Mark Leavitt (PDX Quantified Self organizer) www.markleavitt.com
Further Modifications by Christian Stade-Schuldt blog.tafkas.net
Here's to your (quantified) health!
@Tafkas
Tafkas / decodeLine.R
Created February 12, 2014 22:12
Decode Encoded Polylines in R
decodeLine <- function(encoded){
require(bitops)
vlen <- nchar(encoded)
vindex <- 0
varray <- NULL
vlat <- 0
vlng <- 0
while(vindex < vlen){
@Tafkas
Tafkas / sun_flight_map.R
Created May 20, 2014 14:00
Plot sun elevations along a flight path.
# sun_flight_map.R
#
# Plot sun elevations along a flight path.
#
# Airport information can be sourced from http://openflights.org/data.html.
# Note that the time zone offsets provided in their airports.dat never count
# daylight savings time.
#
# This code is for fun only, so it comes with no guarantee of accuracy and
# is not to be used for any serious purpose including making any decisions
@Tafkas
Tafkas / collect_weather.py
Created July 28, 2014 21:44
Fetch current weather from openweathermap api and save it to a sqlite database
import sqlite3
import json
import urllib
import datetime
import calendar
WEATHER_DATA_URL = 'http://api.openweathermap.org/data/2.5/weather?q=Berlin,de&units=metric'
DB_PATH = ''
def get_data():
@Tafkas
Tafkas / read_ehz.sh
Created October 27, 2014 00:17
Reading data from an eHZ-IW8E2A5 residential meter
#!/bin/bash
# read and evaluate SML output received from EMH eHZ
# set serial device
INPUT_DEV="/dev/ttyUSB0"
#set $INPUT_DEV to 9600 8N1
stty -F $INPUT_DEV 1:0:8bd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
SML_START_SEQUENCE="1B1B1B1B0101010176"
@Tafkas
Tafkas / pysml.py
Last active August 29, 2015 14:08
Script to read SML data packages from a residential meter
#!/usr/bin/env python
# encoding: utf-8
"""
pysml.py
Created by Christian Stade-Schuldt on 2014-10-25.
"""
import sys
import os
import datetime