Skip to content

Instantly share code, notes, and snippets.

import requests
import re
import datetime
import time
import os
# function to build form data given date and time
def get_form_data(date, time):
return { 'Type': 'Observation',
'PredictionSiteID': 'ALL',
@willycs40
willycs40 / SeatingPlan.R
Last active August 29, 2015 14:18
Optimising Seating Plans with Simulated Annealing
source('Seating_Plan_Functions.R')
# Example run:
N <- c('Bill','Sandra','Frank','Jane','Henry','Sarah','Jeremy','John','Rich','Geoff','Smithy','Neil','Arthur','Sophie','Emmet','Andy')
# Community matrix (which guests know which guests)
C <- matrix(c( 1,50,10,10,10,10,0,10,10,10,10,10,10,0,10,10,
50,1,10,10,10,10,0,10,0,10,10,10,10,0,10,0,
10,10,1,50,10,10,0,0,0,0,0,10,0,0,0,0,
10,10,50,1,10,10,0,0,0,0,0,0,0,0,0,0,
@willycs40
willycs40 / extract_station_info_create_kdtree.py
Created April 14, 2015 22:16
Link Weather Data to Geospatial / Temporal Data
import pandas as pd
from sqlalchemy import create_engine # database connection
import numpy as np
import pyproj
from scipy import spatial
# connect to the database, and query for all the unique weather station names and locations:
disk_engine = create_engine('sqlite:///WeatherData.db')
@willycs40
willycs40 / cygwin_combine.sh
Created April 15, 2015 10:00
Using Cygwin to combine csvs
# Get the row names and put them in a new file called combined.csv
head -4 firstFile.txt | tail -1 > combined.csv
# Get the data from all files and append to combined.csv
# The more complicated 'find, while, do, done' is there because my file names had spaces in
find ./*.txt | while read file; do awk 'NR>5' "$file"; done >> combined.csv
# Finally do a row count reconcilisation
wc -l *.txt && wc -l combined.csv
@willycs40
willycs40 / sessionize.sql
Created April 15, 2015 10:07
Break Timeseries into Sessions
--Test Data
CREATE TABLE #Log
( UserID int, [Timestamp] datetime)
INSERT INTO #Log
VALUES
(1, '2014-10-26 10:51:18'), (1, '2014-10-26 10:52:18'), (1, '2014-10-26 10:55:18'), (1, '2014-10-26 10:59:18'), (1, '2014-10-26 15:01:18'), (1, '2014-10-26 15:01:21'), (1, '2014-10-27 21:22:19'),
(2, '2014-10-15 12:19:01'), (2, '2014-10-15 12:19:12'), (2, '2014-10-15 12:19:45'), (2, '2014-10-15 12:20:03'), (2, '2014-10-17 14:55:13'), (2, '2014-10-17 14:55:19'),
(3, '2014-10-22 14:55:19')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willycs40
willycs40 / Simulate GPS Problem 2.ipynb
Last active August 29, 2015 14:20
Simulate GPS Grid Problems
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willycs40
willycs40 / Weather_Effect.ipynb
Last active August 29, 2015 14:20
Looking at the Effects of Weather
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willycs40
willycs40 / Glastonbury Sampler Playlist.ipynb
Created May 26, 2015 19:40
Create Glastonbury Sampler Playlist
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.