Skip to content

Instantly share code, notes, and snippets.

View pudo's full-sized avatar

Friedrich Lindenberg pudo

View GitHub Profile
import os.path
from pkg_resources import resource_listdir, resource_stream
from pymongo import Connection, errors
from pymongo.objectid import ObjectId, InvalidId
from bson import DBRef
connection = None
db = None
import csv
from StringIO import StringIO
# National statistics for tax paid per household income decile, 2008/9.
# Taken from Table 14 in http://www.statistics.gov.uk/CCI/article.asp?ID=2440
# Row 1 is average gross income per decile - including benefits, pensions etc
# Row 2 is average direct taxation - income tax, employee NI and council tax
# Row 3 is average total indirect taxation MINUS VAT, tobacco, alcohol, & car costs
# Row 4 is average total VAT paid
# Row 5 is average total tobacco tax paid
import csv
from StringIO import StringIO
# National statistics for tax paid per household income decile, 2008/9.
# Taken from Table 14 in http://www.statistics.gov.uk/CCI/article.asp?ID=2440
# Row 1 is average gross income per decile - including benefits, pensions etc
# Row 2 is average direct taxation - income tax, employee NI and council tax
# Row 3 is average total indirect taxation MINUS VAT, tobacco, alcohol, & car costs
# Row 4 is average total VAT paid
# Row 5 is average total tobacco tax paid
{
"dataset": {
"model_rev": 1,
"name": "bg-budget",
"label": "Приходна част на бюджета за 2011 година",
"description": "Визуализация на приходната част на Бюджета на Република България за 2011 година",
"currency": "BGN"
},
"mapping": {
"from": {
/* Proposed OpenSpending data model, v2 */
/* Core issues we want to address:
*
* - Merge "entities" and "classifiers".
* - Use better terminology.
* - Decide whether to still have value dimensions.
* - Handle time better (no "end_column")
*
* Secondary but long-term goals:
/* Proposed OpenSpending data model, v2 */
/* Core issues we want to address:
*
* - Merge "entities" and "classifiers".
* - Use better terminology.
* - Decide whether to still have value dimensions.
* - Handle time better (no "end_column")
*
* Secondary but long-term goals:
class DateAttributeType(AttributeType):
""" Date parsing. """
# TODO: simplify this, its hell!
SUFFIX = ('in the format "yyyy-mm-dd", "yyyy-mm" or "yyyy", '
'e.g. "2011-12-31".')
def test(self, row, meta):
value = unicode(self._column_or_default(row, meta))
end_value = row.get(meta.get('end_column'))
for value, is_end in [(value, False), (end_value, True)]:

Proposed data model changes in OpenSpending 0.11

We've decided to move OpenSpending away from MongoDB in 0.11 and to move back to a relational database backend, presumably supporting both SQLite and PostgreSQL.

The following feature requests and reasons are behind this decision:

CREATE TABLE bund_bund (
id INTEGER NOT NULL, name TEXT, label TEXT, color TEXT, pdf_url TEXT, source_url TEXT, bund_kapitel TEXT, description TEXT, bund_titel TEXT, bund_titelgruppe TEXT,
PRIMARY KEY (id)
);
CREATE TABLE bund_entity (
id INTEGER NOT NULL, label TEXT, name TEXT, color TEXT, pdf_url TEXT, source_url TEXT, bund_ep TEXT,
PRIMARY KEY (id)
);
CREATE TABLE bund_entry (
id INTEGER NOT NULL, hauptgruppe_id INTEGER, kapitel_id INTEGER, from_id INTEGER, titel_id INTEGER, funktion_id INTEGER, gruppe_id INTEGER, flow TEXT, data_year TEXT, financial_type TEXT, to_id INTEGER, hauptfunktion_id INTEGER, titelgruppe_id INTEGER, time TEXT, remarks TEXT, flexible TEXT, oberfunktion_id INTEGER, obergruppe_id INTEGER, amount FLOAT,
from openspending.model import meta as db
from openspending.model.attribute import Attribute
from openspending.model.common import TableHandler
class Dimension(object):
""" A base class for dimensions. """
def __init__(self, dataset, name, data):
self._data = data