The insights database
collect_insights rebuilds the insights database from your own data. It is a normal SQLite file, so you can read it with anything that speaks SQL. Here are the tables.
| Table | One row per | Main columns |
|---|---|---|
insights_app |
module with an insights.py |
uuid, module, label |
insights_counter |
counter | app_id, label, question, desc, value, trend, created_at |
insights_gauge |
gauge | the same as a counter, value is a decimal number |
insights_bucket |
chart | app_id, label, question, desc, type, xlabel, xformat, ylabel, yformat, title |
insights_bucketvalue |
point or bar of a chart | bucket_id, timestamp, xvalue, yvalue, category |
- The
labelis the name of your function and is unique per app, so two apps can both have acount_users. - The
uuidof an app is derived from its module path, so a dashboard URL stays the same when you rebuild the database. typeof a bucket is1for a time series,3for a scatter plot,4for a bar chart and5for a horizontal bar chart.trendis a JSON list with the latest 60 values of the trend, empty without atrend=function.- In
insights_bucketvaluethetimestampis only filled for a time series, and a bucket has at most one value per timestamp.
Querying #
sqlite3 db/insights.db "
select a.label, c.label, c.value
from insights_counter c join insights_app a on a.uuid = c.app_id
"
Shop|count_orders|40
The values of a chart:
sqlite3 db/insights.db "
select category, xvalue from insights_bucketvalue v
join insights_bucket b on b.id = v.bucket_id
where b.label = 'by_status' order by xvalue desc
"
From Python, the standard library is enough:
import sqlite3
with sqlite3.connect("db/insights.db") as db:
for label, value in db.execute("select label, value from insights_counter"):
print(label, value)
Or use the models of Django Insights from a shell of your project, they live on the insights database:
from django_insights.models import Counter
Counter.objects.get(label="count_orders").value
Sharing #
The file holds answers, not your data: counts, averages and the points of the charts. That is what makes it safe to share on request. Check what your insights return before you hand it out, a category can be an email address if you group by one.