version: 2

models:
  - name: DATA_AVAILABILITY_SKIPS_SAVES_BY_FEED_ROLLUP_DBT
    description:
      A table containing metrics for the last 12 weeks to determine if skips & saves data is missing, incomplete,
      duplicated or as expected for a given feed / day. The source of information for this table is the dbt maintained
      table STREAMS_BY_TRACK_COUNTRY_FEED_DAILY.
    tests:
      - unique:
          column_name: "concat(feed_id, '-', download_activity_date)"
    columns:
      - name: feed_id
        description:
          The id of the feed the skips & saves data is coming from.
        tests:
          - not_null
      - name: download_activity_date
        description: The date the skips & saves data has been evaluated for.
        tests:
          - not_null
      - name: store_id
        description: The id of the store the skips & saves data is coming from.
        tests:
          - not_null
      - name: skips
        description: The total amount of skips for this day (may be `NULL` if data is missing).
      - name: saves
        description: The total amount of saves for this day (may be `NULL` if data is missing).
      - name: min_threshold_skips
        description: The minimal amount of skips required for skips not to be considered "incomplete"
        tests:
          - not_null
      - name: max_threshold_skips
        description: The maximum amount of skips required for skips not to be considered "duplicated"
        tests:
          - not_null
      - name: missing_date_skips
        description: 1 if skips are completely missing (`NULL`) for this date, `NULL` otherwise.
      - name: incomplete_date_skips
        description: 1 if skips are incomplete (< min_threshold_skips) for this date, `NULL` otherwise.
      - name: duplicated_date_skips
        description: 1 if skips are duplicated (> max_threshold_skips) for this date, `NULL` otherwise.
      - name: min_threshold_saves
        description: The minimal amount of saves required for saves not to be considered "incomplete"
      - name: max_threshold_saves
        description: The maximum amount of saves required for saves not to be considered "duplicated"
      - name: missing_date_saves
        description: 1 if saves are completely missing (`NULL`) for this date, `NULL` otherwise.
      - name: incomplete_date_saves
        description: 1 if saves are incomplete (< min_threshold_saves) for this date, `NULL` otherwise.
      - name: duplicated_date_saves
        description: 1 if saves are duplicated (> max_threshold_saves) for this date, `NULL` otherwise.
      - name: feed_high_watermark
        description: The latest date that has both skips and saves information that are believed to be accurate.

  - name: DATA_AVAILABILITY_SKIPS_SAVES_BY_FEED_SUMMARY_DBT
    description:
      A further summary of DATA_AVAILABILITY_SKIPS_SAVES_BY_FEED_ROLLUP_DBT with one row per feed_id. Represents
      the health of skips and saves data for the last 30 days and the current state.
    columns:
      - name: feed_id
        description: The feed_id the summary is for.
        tests:
          - not_null
          - unique
      - name: store_id
        description: The store_id belonging to the feed_id.
        tests:
          - not_null
      - name: missing_skip_dates_30_days
        description: The amount of days where skips data is entirely missing within the last 30 days.
        tests:
          - not_null
      - name: incomplete_skip_dates_30_days
        description: The amount of days where skips data is considered incomplete within the last 30 days.
        tests:
          - not_null
      - name: duplicated_skip_dates_30_days
        description: The amount of days where skips data is considered duplicated within the last 30 days.
        tests:
          - not_null
      - name: missing_saves_dates_30_days
        description: The amount of days where saves data is entirely missing within the last 30 days.
        tests:
          - not_null
      - name: incomplete_saves_dates_30_days
        description: The amount of days where saves data is considered incomplete within the last 30 days.
        tests:
          - not_null
      - name: duplicated_saves_dates_30_days
        description: The amount of days where saves data is considered duplicated within the last 30 days.
        tests:
          - not_null
      - name: feed_high_watermark
        description:
          The latest date that has both skips and saves information for this feed that are believed to be accurate.
      - name: feed_max_available_date
        description:
          The latest date we have any streaming data for this feed.
        tests:
          - not_null
      - name: is_up_to_date
        description:
          Indicates if we have skips & saves data for the current day. `TRUE` if the skips & saves data is considered
          correct for the date we currently have streaming data for (including other shops), `FALSE` if not.
          (`store_high_watermark = store_max_available_date`)

