Skip to content

Instantly share code, notes, and snippets.

@Stiivi
Created October 17, 2012 05:36
Show Gist options
  • Save Stiivi/3903870 to your computer and use it in GitHub Desktop.
Save Stiivi/3903870 to your computer and use it in GitHub Desktop.
Cubes Presenters (preliminary implementation)
# Run this script in cubes/examples/hello_world
import cubes
model = cubes.load_model("model.json")
workspace = cubes.create_workspace("sql", model,
url='sqlite:///data.sqlite')
cube = model.cube("irbd_balance")
browser = workspace.browser(cube)
cell = browser.full_cube()
# Prepare presenter
# Available presenters: simple_html_table, simple_data_table and text_table
presenter = cubes.create_presenter("simple_html_table",
create_links=False,
table_style="table table-striped table-bordered")
f = open("table.html", "w")
f.write("""<html>
<head>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
</head>
<body>""")
f.write("<h1>By Item</h1>")
result = browser.aggregate(cell, drilldown=["item"])
f.write(presenter.present(result, "item", ["amount_sum", "record_count"]))
f.write("<h1>By Year</h1>")
result = browser.aggregate(cell, drilldown=["year"])
f.write(presenter.present(result, "year", ["amount_sum", "record_count"]))
f.write("</body></html>")
f.close()
print "created table.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment