Created
October 17, 2012 05:36
-
-
Save Stiivi/3903870 to your computer and use it in GitHub Desktop.
Cubes Presenters (preliminary implementation)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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