django-cube


Calculating complex aggregates on a Django queryset, Grouping them by multiple attributes, Displaying nicely the results from your templates

NOTE : this library somehow works, but it is not maintained, unfinished, very inefficient, not packaged properly and not Django-ish ...

Documentation-index

Quick-start

Some snippets

Introduction

Say I have a bookcase, with nice books on it... And I want to create a "bookcase" application with my favorite framework.

That's my model

``` from django.db import models

class Book (models.Model): title = models.CharField(max_length=100) genre = models.CharField(max_length=100) ```

I would like to calculate some statistics on my books, for example counting them :

philosophy food novels A-M how many ?? how many ?? how many ?? N-Z how many ?? how many ?? how many ??

https://django-cube.googlecode.com/hg/doc/googlecode/left-arrow.gif' width='80'> But that's such a pain, because I have to count on the whole bookcase !!!

    Book.objects.filter(genre="novels")#etc, etc ...

Even in real life that wouldn't be very practical ...

http://django-cube.googlecode.com/hg/doc/googlecode/bookcase_ordered.png' width='400'>

https://django-cube.googlecode.com/hg/doc/googlecode/left-arrow.gif' width='80'> What is much more clever is to classify my books into several boxes. So instead of counting on the whole bookcase, I can count on each box !!!

from cube.models import Cube


class BookCaseCube(Cube):

genre = Dimension('genre')
first_letter_title = Dimension('title__iregex', sample_space=[r'^[a-n].*', r'^[m-z].*'])

@staticmethod
def aggregation(queryset):
return queryset.count()

That's actually the aim of django-cube. Here, we defined :

  • 2 dimensions (genre and first_letter_title) : they actually define our "boxes"
  • the aggregation method : corresponds with the operation to apply on each "box" (count in our case), with queryset corresponding to the base queryset of the "box" !

Project Information

Labels:
django statistics cube multidimensional olap dataanalysis aggregation measures