API Reference¶
This page is auto-generated from Python docstrings.
Early on, it may not be easy to read. It becomes more useful as we gain experience.
bizintel ¶
Bintel package.
bizintel.olap_case ¶
olap_case.py - example.
An example of OLAP reporting on a data warehouse.
OLAP stands for Online Analytical Processing. OLAP techniques help us examine business measures across different dimensions and levels of detail.
Author: Denise Case Date: 2026-07
Process: - Connect to the DuckDB data warehouse. - Create a reporting view that joins facts and dimensions. - Export a reporting-ready dataset for Power BI or Spark. - Slice sales by selecting one region. - Dice sales by selecting multiple regions and categories. - Roll up monthly sales into quarterly and annual summaries. - Drill down from annual sales to quarterly and monthly detail. - Visualize OLAP results with business charts. - Log a summary of findings.
Data Source: - artifacts/smart_sales.duckdb
Output: - data/reporting/sales_reporting_case.csv
Terminal command to run this file from the root project folder:
uv run python -m bizintel.olap_case
OBS
Don't edit this file - it should remain a working example. Copy it, rename it with your alias, and modify your copy. If you do, include your command to run it in the docstring above and in README.md.
DICE_CATEGORIES
module-attribute
¶
REPORTING_FILE
module-attribute
¶
create_reporting_view ¶
Create a reporting view that joins facts and dimensions.
WHY: The fact table stores measurable business events. Dimension tables store descriptive context such as region, product name, and category.
A reporting view joins these tables so analysts can work with one reporting-ready result without repeating the joins in every query.
A view stores the SQL query, not another copy of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/bizintel/olap_case.py
dice_sales_by_dimensions ¶
dice_sales_by_dimensions(
conn: DuckDBPyConnection,
selected_regions: tuple[str, ...],
selected_categories: tuple[str, ...],
) -> pd.DataFrame
Dice sales by selected regions and product categories.
WHY: A dice filters across two or more dimensions. Here, we select members from both the Region dimension and the Category dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
selected_regions
|
tuple[str, ...]
|
Region values to include. |
required |
selected_categories
|
tuple[str, ...]
|
Category values to include. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with Region, Category, and TotalSales columns. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selected dice has no matching rows. |
Source code in src/bizintel/olap_case.py
drilldown_sales_by_time ¶
Drill down from one year to quarters and months.
WHY: Drill-down reveals the details behind a summary value. This query begins with one selected year and then shows the quarter and month levels inside that year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
selected_year
|
int
|
Year to investigate. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with year, quarter, and month detail levels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selected year has no matching rows. |
Source code in src/bizintel/olap_case.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
export_reporting_dataset ¶
Export the reporting view to a CSV file.
WHY: Power BI and Spark can both read CSV files. Exporting one reporting-ready dataset gives both tool paths the same rows, columns, dimensions, and business measures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Reporting-ready pandas DataFrame. |
Source code in src/bizintel/olap_case.py
get_latest_sales_year ¶
Get the latest year represented in the reporting data.
WHY: Drill-down begins with a selected summary value. In an interactive BI tool, a user might click a particular year. In this example, we automatically select the latest available year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Latest sales year as an integer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the reporting data contains no sales year. |
Source code in src/bizintel/olap_case.py
main ¶
Main function to run the DuckDB OLAP reporting logic.
Source code in src/bizintel/olap_case.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
plot_bar ¶
plot_bar(
df: DataFrame,
x: str,
y: str,
title: str,
xlabel: str,
ylabel: str,
palette: str = 'Blues_d',
) -> None
Plot a vertical bar chart.
WHY: Bar charts are the most common chart in BI reporting. A reusable function ensures consistent style and labeling across all modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing the data to plot. |
required |
x
|
str
|
Column name for the x-axis (categories). |
required |
y
|
str
|
Column name for the y-axis (values). |
required |
title
|
str
|
Chart title. |
required |
xlabel
|
str
|
X-axis label. |
required |
ylabel
|
str
|
Y-axis label. |
required |
palette
|
str
|
Seaborn color palette name. |
'Blues_d'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/bizintel/utils_viz.py
plot_line ¶
Plot a line chart.
WHY: Line charts show trends over time, which is one of the most common BI use cases (weekly sales, monthly revenue, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing the data to plot. |
required |
x
|
str
|
Column name for the x-axis (time or ordered categories). |
required |
y
|
str
|
Column name for the y-axis (values). |
required |
title
|
str
|
Chart title. |
required |
xlabel
|
str
|
X-axis label. |
required |
ylabel
|
str
|
Y-axis label. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/bizintel/utils_viz.py
rollup_sales_by_time ¶
Roll up sales through the time hierarchy.
WHY: Roll-up summarizes a measure at broader hierarchy levels. Here, detailed monthly sales are summarized into quarters, years, and a grand total.
DuckDB's ROLLUP operation creates each subtotal level in one analytical query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing monthly, quarterly, yearly, |
DataFrame
|
and all-years sales totals. |
Source code in src/bizintel/olap_case.py
slice_sales_by_region ¶
Slice sales by one selected region.
WHY: A slice fixes one dimension at one selected value. Here, the Region dimension is fixed to one region. We then compare product-category sales inside that region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
selected_region
|
str
|
Region value to include in the slice. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with Region, Category, and TotalSales columns. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selected region has no matching rows. |
Source code in src/bizintel/olap_case.py
summarize ¶
summarize(
df_slice: DataFrame,
df_dice: DataFrame,
df_rollup: DataFrame,
df_drilldown: DataFrame,
selected_region: str,
selected_year: int,
) -> None
Log a brief summary of the OLAP findings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_slice
|
DataFrame
|
Slice results for one selected region. |
required |
df_dice
|
DataFrame
|
Dice results for selected regions and categories. |
required |
df_rollup
|
DataFrame
|
Time roll-up results. |
required |
df_drilldown
|
DataFrame
|
Time drill-down results. |
required |
selected_region
|
str
|
Region used in the slice. |
required |
selected_year
|
int
|
Year used in the drill-down. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/bizintel/olap_case.py
verify_warehouse ¶
Verify that the required warehouse tables exist.
WHY: Connecting to a missing DuckDB file creates a new empty database. We verify the file and required tables before running reporting queries so students receive a useful message instead of a confusing SQL error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
Open DuckDB connection. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a required warehouse table is missing. |