Skip to content

Instantly share code, notes, and snippets.

View Stiivi's full-sized avatar

Stefan Urbanek Stiivi

View GitHub Profile
# Demo:
#
# Aggregate population per independence type for every year
# Sources: Population and Country Codes datasets
#
from bubbles import Pipeline
# List of stores with datasets. In this example we are using the "datapackage"
# store
@Stiivi
Stiivi / eu-budget-dataaudit.py
Last active August 29, 2015 13:57
Basic Data Audit of a datapackage for EU Budget data using Bubbles
# -*- coding: utf8 -*-
from bubbles import Pipeline
stores = {
"package": {"type": "datapackages", "url": "data" }
}
p = Pipeline(stores=stores)
@Stiivi
Stiivi / cubes-hello_world-output
Created March 17, 2014 11:40
Output from cubes hello world
Total
----------------------
Record count: 62
Total amount: 1116860
Drill Down by Category (top-level Item hierarchy)
=================================================
Category Count Total
----------------------------------------
Assets 32 558430
class CreateTableAsSelect(Executable, ClauseElement):
def __init__(self, table, select):
self.table = table
self.select = select
@compiles(CreateTableAsSelect)
def visit_create_table_as_select(element, compiler, **kw):
preparer = compiler.dialect.preparer(compiler.dialect)
full_name = preparer.format_table(element.table)
from sqlalchemy import create_engine, MetaData, Table, Integer, Date, Column
import sqlalchemy.sql as sql
engine = create_engine("sqlite://")
md = MetaData(bind=engine)
table = Table("data", md)
table.append_column(Column("id", Integer))
table.append_column(Column("adate", Date))
table.append_column(Column("value", Integer))
@Stiivi
Stiivi / bubbles-p3.py
Created September 8, 2014 21:56
Bubbles 0.3 (prototype 3) feature preview
from bubbles import Pipeline, ExecutionEngine
from bubbles import operation, datasource
# New implicit iterator operations
@datasource(fields=["i"])
def generator(context, count=10):
for i in range(count):
yield [i]
@Stiivi
Stiivi / simple_upsert.py
Created November 26, 2014 21:33
Simple table → table UPSERT with mapping (using SQLAlchemy)
from sqlalchemy import sql
from collections import OrderedDict
def simple_upsert(source, target, source_key, target_key, mapping):
"""Simple transformative upsert from `source` table into `target` table
where `source_key` is unique key in the `source` table amd `target_key`
is its equivalend in the `target` table. `mapping` is a dictionary that
maps between target's column names and source column names.
Returns a tuple of two statements (`update`, `insert`).
@Stiivi
Stiivi / sql.hs
Last active August 29, 2015 14:20
{-# LANGUAGE MultiParamTypeClasses #-}
import Text.Printf
data SQLLiteral
= SQLFloatLiteral Float
| SQLIntLiteral Integer
| SQLStringLiteral String
deriving (Show, Eq)
@Stiivi
Stiivi / gist:1205736
Created September 9, 2011 08:11
Brewery leak
import brewery.streams
import brewery.nodes
import time
class FunctionSubstituteNode(brewery.nodes.Node):
"""Manipulate a field using a function.
This is a simpler version of DeriveNode(); a single field is passed in
rather than the entire record.
"""
@Stiivi
Stiivi / gist:1388739
Created November 23, 2011 14:05
Brewery server app w. backbone
$(function(){ /* jQuery.ready */
var Stream = Backbone.Model.extend({
initialize: function() { /* do nothing */ },
});
window.streamsCollection = Backbone.Collection.extend({
model: Stream,
url: "http://localhost:5000/streams",