Skip to content

Instantly share code, notes, and snippets.

View digitalWestie's full-sized avatar

Rory digitalWestie

View GitHub Profile
@digitalWestie
digitalWestie / clustering_scotland.md
Last active June 8, 2017 23:50
Clustering Scotland's constituencies

Using clustering to group Scotland's constituencies

A few days ago I briefly got involved in The Bureau Local's Voterpower Hack. Participants were provided with demographic and political data sourced from the Office of National Statistics, the Cabinet Office and the British Election Study.

To get started, I decided to play with some Python machine learning libraries, this was partly a learning exercise but I also wondered if I could surface any insights.

The first thing I did was run a k-means clustering algorithm on the constituency demographic & voting data.

You can see the results and the code below. In k-means clustering you input how many groups you want the algorithm to produce. Here I've provided 2,4, and 6. A '1' against a constituency means that the constituency belongs to the group in the column.

@digitalWestie
digitalWestie / a-wee-table-sorter.js
Last active July 14, 2017 21:44
A markup-light basic table sorter that uses jQuery.
var sortTable = function(tableId, columnNo, direction){
var rows = $('#'+tableId+' tbody tr').get();
rows.sort(function(a, b) {
var A = $(a).children('td').eq(columnNo).text().toUpperCase();
var B = $(b).children('td').eq(columnNo).text().toUpperCase();
if (!isNaN(parseFloat(A))){ A = parseFloat(A) }
if (!isNaN(parseFloat(B))){ B = parseFloat(B) }
@digitalWestie
digitalWestie / dundee-petitions.csv
Created March 19, 2018 11:24
Top petitions in Dundee. Date created: 18 March 2018
name id proportion total combined east west
Allow Scotland to host a second referendum for Scottish Independence. 204238 0.0475746269 1072 51 22 29
The Scottish Government should be called the Scottish Executive. 205085 0.0167115903 1855 31 12 19
Return Scottish devolved powers to UK Government and Parliament 200033 0.0129912309 3079 40 16 24
Universal Credit applicants to receive adequate payments throughout assessment. 202515 0.0125725338 1034 13 6 7
Repeal the 1939 Cancer Act so that doctors can offer alternatives to chemo 203708 0.0122169917 8922 109 55 54
Aesthetic medicine treatments only to be performed by Doctors, Nurses & Dentists 208642 0.0100917431 1090 11 8 3
To condemn the repression of democracy and freedom of speech in Catalonia 200914 0.0082359701 5221 43 21 22
Ban the sale of fireworks to the public and have only licensed displays. 203314 0.0074074074 9180 68 28 40
Support the secession of Catalonia from The Kingdom of Spain 202078 0.0067895247 2062 14 9 5
@digitalWestie
digitalWestie / italo-disco.md
Last active April 5, 2018 17:30
My Italo disco list
@digitalWestie
digitalWestie / codechall.py
Created August 8, 2018 00:52
codechallenge
def rebase(i,b):
result = []
while i > 0:
result.insert(0, i % b)
i = i // b
return ''.join(str(x) for x in result)
def perform(n,b):
k = len(n)
y = ''.join(sorted(n))
@digitalWestie
digitalWestie / kobjectCollector.js
Created August 24, 2018 09:04
Collect key object pairs into an array
// Collect key: object pairs
var processData = function(data, collectionAddress, ){
var collection = data;
for (i in collectionAddress){
collection = collection[collectionAddress[i]]
}
if (!Array.isArray(collection)){
var arrayCollection = [];
@digitalWestie
digitalWestie / open-standards-reading.md
Created February 11, 2019 12:31
Resources to help define and evaluate open standards for data

Open Standards Reading

Resources to help define and evaluate open standards for data.

ODI - Open Standards for Data

Guidebook on creating and using open standards for data. http://standards.theodi.org/

Cabinet Office - Policy paper - Open Standards principles

Policy outlook on open data standards. Good outline of how to evaluate standards.

@digitalWestie
digitalWestie / analytics_parser.py
Created February 13, 2019 12:36
Google Analytics CSV Parser for ALISS
import csv
from urllib.parse import urlparse, parse_qs
rows = []
with open('novjan_analytics.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in spamreader:
rows.append(row)
params = ["postcode", "q", "category", "location_type", "keyword_sort", "page"]
@digitalWestie
digitalWestie / scottish-localities-centres.md
Last active April 5, 2019 22:29
Scottish locality data