> For the complete documentation index, see [llms.txt](https://openup.gitbook.io/wazi-ng-technical/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openup.gitbook.io/wazi-ng-technical/system-architecture/database-models.md).

# Database Models

![Entity-Relationship Diagram for Wazimap-NG](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjOAjs7aD731-14p-G%2F-MGjOWY4dKpxJhHzfJl6%2Ferd.png?alt=media\&token=51c484fd-10b0-4ace-a6b7-ac8142a76a08)

The Django apps and database models are divided into roughly two groups: models that store data, and models that are used to present information to the end-user.

## Datasets App

![Entity Relationship Diagram for the Datasets App](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjbdC-Ycyh_26tyCZU%2Fdatasets.svg?alt=media\&token=a7cd23e5-5130-4ff9-8d59-4f0f7a49386f)

### Dataset and DatasetData

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjcX9HAKblNiafyye2%2Fdatasetdata.svg?alt=media\&token=edc74de6-f53e-497e-82a0-95a87ca359f3)

Data models can be found in the **datasets** app. The central model is **Dataset.** It represents a dataset that was uploaded by the [**Data Administrator**](broken://pages/-MGjU06AzMAtA43bJIfP)**.** Each dataset is associated with a [Geography Hierarchy](/wazi-ng-technical/system-architecture/geography-hierarchies.md). Data files uploaded to the system are expected to have the following structure:

| Geography | Group 1 | Group 2 | ... | Group N | Count         |
| --------- | ------- | ------- | --- | ------- | ------------- |
| geography | Value 1 | Value 2 |     | Value N | #observations |

Only the **Geography**, **Count**, and at least one additional column are required.  An example table might look as follows:

| Geography | Gender | Age | Count |
| --------- | ------ | --- | ----- |
| ZA        | Male   | 20  | 10    |
| ZA        | Male   | 21  | 12    |
| ZA        | Female | 20  | 15    |
| ZA        | Female | 21  | 13    |
| ...       |        |     |       |
| WC        | Male   | 20  | 5     |
| ...       |        |     |       |

&#x20;When this file is uploaded, a new **Dataset** object is created. Each row is stored in a **DatasetData** object. A typical DatasetData object might look as follows:

```
{
    Geography: ZA # Geography is actually stored in its own field and not in the JSON field. 
    Gender: Male,
    Age: 20,
    Count: 10
}
```

All groups and the **Count** column are stored in a JSONField.&#x20;

### Indicators and IndicatorData

Another key concept is an **Indicator**. **Indicators** represent saved aggregations and filters on a dataset. For example, the above Dataset can be used to create an Indicator containing population per geography disaggregated by gender. The equivalent query in SQL would look something like this:

```
Select
    Geography,
    Gender,
    Sum(Count)
From 
    Dataset d
Where
    d.id = XXX
Group by
    Geography,
    Gender
```

Similarly, another indicator can be created to return population disaggregated by age.

```
Select
    Geography,
    Age,
    Sum(Count)
From 
    Dataset d
Where
    d.id = XXX
Group by
    Geography,
    Age
```

When a new indicator is created, data from **DatasetData** is processed to create an IndicatorData object, one per geography.  A simplified version of and **IndicatorData** would like something like this:

```
{
  Geography: ZA,
  subindicators: {
   Male: 22,
   Female: 28
  }
  ... # other information is stored here and is described elsewhere in this manual.
}
```

The actual structure of IndicatorData objects is a little more complicated. More detail can be found here: [IndicatorData](/wazi-ng-technical/system-architecture/indicatordata.md).

![Relationship between Indicator and IndicatorData](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MIM1nTJKNQIgSPXVK0U%2F-MIM2ltl_hK_XcbfuuQU%2Findicatordata.svg?alt=media\&token=16a6dd52-a2d6-4d4d-9e81-e1502f29dbf6)

### Universe

**Universes** represent saved filters on queries and enable the Data Administrator to run a query on a subset of the database. The default **Universe** is the total of all the distinct observations in a geography (e.g. the total population of the geography). It is possible to create a custom **Universe** and apply it to an **Indicator.**&#x20;

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjaHXrSx4X-peJ5OSN%2Funiverse.svg?alt=media\&token=cacbb0f2-ff1a-493c-b1b3-9f303d90b0e7)

A **Universe** which creates a filter on gender can enable queries on Female exclusively. PseudoSQL to represent this operation

```
Select
    Geography,
    Age,
    Sum(Count)
From 
    Dataset d
Where
    d.id = XXX
    and Gender = Female
Group by
    Geography,
    Age
```

The **Universe** filters field contains a dictionary that will be used in a Django ORM filter method. Below is an example filter to extract adults 60 and older.

```
{
    'Age Group__in': ['60-64', '65-69', '70-74', '75-79', '80-84', '85+']
}
```

This filter is then passed to the Django ORM as follows:

```
Dataset.objects.filter(**universe.filters) # pseudocode
```

Other noteworthy models are Geography and GeographyHierarchy. These are discussed in more detail here: [Geography Hierarchies](/wazi-ng-technical/system-architecture/geography-hierarchies.md).&#x20;

## Profile App

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjeOB6sKBuN4AA5G2S%2Fprofile.svg?alt=media\&token=693b87e2-9219-415c-9b1d-1a87ba27f051)

Whereas models in the Datasets app focus on data, Profile App models are for presentation to end-users. The key model is **Profile**. A **profile** is a view of the data curated by the [Profile Administrator](broken://pages/-MGjU06AzMAtA43bJIfP). Each profile can be considered to be a complete Wazimap instance. A **profile** organises tabular data in Categories (**IndicatorCategory**) and Subcategories (**IndicatorSubcategory**). This data can be presented using three different models:

**ProfileIndicator**, **ProfileKeyMetrics**, and **ProfileHighlight. ProfileIndicator** is the most commonly used of the three. &#x20;

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjhsQwHyLPWjNGn8xn%2Fprofileindicators.svg?alt=media\&token=7ba43360-5bd5-4cd7-9ebe-69017d34b3f2)

**ProfileIndicators** present Indicators. They provide explanatory text, a custom label, and other attributes that control presentation. They are used in the Rich Data Panel in the form of graphs and the Data Mapper Panel in the form of [choropleth maps](/wazi-ng-technical/system-architecture/choropleth-maps.md).

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjihJO3KVT5tJNKtIw%2FScreen%20Shot%202020-09-08%20at%2023.58.04.png?alt=media\&token=cd8e3013-494d-4255-bac0-7ff858ea6656)

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjjNZesy37br9HdwUV%2FScreen%20Shot%202020-09-09%20at%2000.00.10.png?alt=media\&token=89dbeaca-88f0-41b2-8ba5-e123b09da8ad)

**ProfileKeyMetrics** display only a single value from an Indicator. For instance, the number of youth between 15-24 living in the area.

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjk0hRSkkVDJabM4CV%2FScreen%20Shot%202020-09-09%20at%2000.04.23.png?alt=media\&token=1d846af3-5f59-4028-abe3-51f1c7003bca)

ProfileHighlights are similar to ProfileKeyMetrics in that they display a single value from an Indicator, but are displayed in the Map View rather than the Rich Data View.

![Example of how ProfileHighlights are displayed on the frontend. ](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3zapxOsLjq_qKRcmH8%2F-MGjU5hEbybdLVpIIrR1%2F-MGjktMg1NVRWwxsRrRv%2FScreen%20Shot%202020-09-09%20at%2000.08.33.png?alt=media\&token=1e22e47e-518f-4f6c-abba-257a8d59d08a)

## Points App
