version: 2

models:
  - name: dim_clip
    description: |
      Dimension table containing comprehensive metadata and attributes for all audio clips generated or uploaded to the Suno platform.
      This table serves as the central source of truth for clip information including creation details, user interactions,
      content metadata, generation parameters, and status information. This is a view that adds enhanced categorization
      and metadata on top of the intermediate int_dim_clip model.

      This model provides cleaned and enriched clip data with additional computed fields like create_mode_cleaned,
      model_category, category, history_length, is_made_in_edit, and has_augmented_tags.
    config:
      schema: PROD
      group: clips

    meta:
      dagster:
        automation_condition: hourly_cron_with_eager_historical_backfill_condition
        partitions_def:
          type: hourly
          start_date: 2023-05-12
          end_offset: 0
        backfill_policy:
          max_partitions_per_run: -1  # full backfill

    columns:
      - name: clip_id
        description: "Unique identifier for the clip (primary key)"
      - name: p_date
        description: "Partition date - date when the clip was created (used for table clustering)"
      - name: p_hour
        description: "Partition hour - hour when the clip was created (used for table clustering)"
      - name: created_at
        description: "Timestamp when the clip was created (with timezone information)"
      - name: user_id
        description: "ID of the user who created the clip"
      - name: request_id
        description: "Unique identifier for the generation request that created this clip"
      - name: s3_id
        description: "S3 object identifier for the clip's audio file"
      - name: platform
        description: "Platform where the clip was created (web, mobile, etc.)"
      - name: display_index
        description: "Index/order of the clip within a batch generation request"
      - name: initial_title
        description: "Original title assigned to the clip at creation"
      - name: time_used_sec
        description: "Time in seconds taken to generate the clip"
      - name: type
        description: "Type of clip generation (e.g., song, instrumental, remix)"
      - name: task
        description: "Specific task or mode used for clip generation"
      - name: priority
        description: "Priority level assigned to the generation request"
      - name: duration_sec
        description: "Duration of the generated clip in seconds"
      - name: is_refund_credits
        description: "Boolean indicating if credits were refunded for this clip"
      - name: is_bot
        description: "Boolean indicating if the clip was generated by a bot user"
      - name: credit_cost
        description: "Number of credits consumed to generate this clip"
      - name: lyrics_at_gen
        description: "Lyrics text that was used during clip generation"
      - name: simple_prompt
        description: "Simplified prompt description used for generation"
      - name: lyrics_final
        description: "Final lyrics text associated with the clip"
      - name: is_simple
        description: "Boolean indicating if this was generated using simple mode"
      - name: is_make_instrumental
        description: "Boolean indicating if the clip was generated as instrumental only"
      - name: style_tags
        description: "JSON array of style tags applied to the clip"
      - name: negative_style_tags
        description: "JSON array of style tags to avoid during generation"
      - name: request_models
        description: "JSON array of AI models requested for generation"
      - name: model_name
        description: "Name of the AI model actually used for generation"
      - name: experiment_inf_param
        description: "JSON object containing experimental inference parameters"
      - name: experiment_version
        description: "Version identifier for experimental features used"
      - name: history
        description: "JSON object containing generation history and iterations"
      - name: concat_history
        description: "Concatenated string representation of generation history"
      - name: error_type
        description: "Type of error if clip generation failed"
      - name: error_message
        description: "Detailed error message if clip generation failed"
      - name: upload_has_vocal
        description: "Boolean indicating if uploaded clip contains vocals"
      - name: edit_session_id
        description: "ID of the editing session if this clip was edited"
      - name: edited_clip_id
        description: "ID of the original clip if this is an edited version"
      - name: task_details
        description: "JSON object containing detailed task-specific information"
      - name: creation_source
        description: "Source or method used to create the clip"
      - name: augmented_tags
        description: "JSON array of additional tags added to the clip"
      - name: free_quota_category
        description: "Category classification for free quota usage"
      - name: lyrics_language
        description: "Language of the lyrics in the clip"
      - name: simple_lyrics_model
        description: "Model used for simple lyrics generation"
      - name: created_session_id
        description: "ID of the user session when the clip was created"
      - name: clip_uid
        description: "Unique user-facing identifier for the clip"
      - name: is_audio_watermark
        description: "Boolean indicating if audio watermarking was requested (default: false)"
      - name: is_audio_watermarked
        description: "Boolean indicating if the clip has audio watermarking applied (default: false)"
      - name: user_tier
        description: "Subscription tier of the user who created the clip"
      - name: is_deleted
        description: "Boolean indicating if the clip has been soft deleted"
      - name: create_mode
        description: "Mode or method used to create the clip"
      - name: combined_from_clip_ids
        description: "JSON array of clip IDs that were combined to create this clip (if applicable)"
      - name: create_mode_cleaned
        description: "Cleaned creation mode (simple, custom, or from create_mode field)"
      - name: model_category
        description: "Categorized model version (v3.5, v4, v4.5, v4.5+, v5, stem, older_model, no_model)"
      - name: category
        description: "Detailed clip category based on type and task (normal_gen, cover_gen, extend_gen, etc.)"
      - name: history_length
        description: "Number of steps in the creation history"
      - name: is_made_in_edit
        description: "Boolean indicating if the clip was created in edit mode"
      - name: has_augmented_tags
        description: "Boolean indicating if the clip has augmented tags"
      - name: metadata
        description: "Parsed JSON object containing all clip metadata from the raw metadata_json field"
      - name: web_client_pathname
        description: "Web client pathname from metadata, indicating the page/route where the clip was created"
      - name: is_public
        description: "Boolean indicating if the clip is public (from rds_public_clip table)"

  - name: clip_initial_metrics
    description: |
      View that provides initial interaction and satisfaction metrics on user-owned clips within a 120-minute window after creation.
      This is a view over the int_clip_initial_metrics intermediate model, which contains the actual incremental logic.
      Tracks plays, likes, dislikes, shares, downloads, and privacy toggles by the clip owner to measure early
      engagement and satisfaction. Includes both direct satisfaction (explicit user actions) and indirect
      satisfaction (play behavior) indicators.
    config:
      schema: PROD
      group: clips
    meta:
      dagster:
        automation_condition: hourly_cron_with_eager_historical_backfill_condition
        partitions_def:
          type: hourly
          start_date: 2023-05-12
          end_offset: -3
        backfill_policy:
          max_partitions_per_run: -1
        asset_key: ["clip_initial_metrics"]
    columns:
      - name: clip_id
        description: "Unique identifier for the clip (primary key)"
      - name: user_id
        description: "User ID who created the clip"
      - name: user_uid
        description: "User UID who created the clip"
      - name: clip_created_at
        description: "Timestamp when the clip was created"
      - name: window_minutes
        description: "Time window in minutes for measuring initial metrics (120 minutes)"
      - name: window_start_time
        description: "Start of the measurement window (truncated to hour of clip creation)"
      - name: window_end_time
        description: "End of the measurement window (window_start_time + window_minutes)"
      - name: play_cnt
        description: "Total number of plays by the clip owner within the time window"
      - name: play_duration_seconds
        description: "Total play duration in seconds by the clip owner within the time window"
      - name: n_like_events
        description: "Number of ClipLike events by the clip owner within the time window"
      - name: n_undolike_events
        description: "Number of ClipUndoLike events by the clip owner within the time window"
      - name: net_like_events
        description: "Net like events (n_like_events - n_undolike_events)"
      - name: n_dislike_events
        description: "Number of ClipDislike events by the clip owner within the time window"
      - name: n_undodislike_events
        description: "Number of ClipUndoDislike events by the clip owner within the time window"
      - name: net_dislike_events
        description: "Net dislike events (n_dislike_events - n_undodislike_events)"
      - name: n_share_events
        description: "Number of ClipShare events by the clip owner within the time window"
      - name: n_download_events
        description: "Number of ClipDownload events by the clip owner within the time window"
      - name: n_makepublic_events
        description: "Number of ClipMakePublic events by the clip owner within the time window"
      - name: n_makeprivate_events
        description: "Number of ClipMakePrivate events by the clip owner within the time window"
      - name: net_public_toggle_events
        description: "Net public toggle events (n_makepublic_events - n_makeprivate_events)"
      - name: net_positive_interactions
        description: |
          Combined positive interaction score (net_like_events - net_dislike_events +
          share_events + download_events + net_public_toggle_events)
      - name: is_satisfactory_indirect
        description: |
          Indirect satisfaction indicator based on play metrics (VARIANT)
          (play_cnt >= 3 AND play_duration_seconds >= 60 AND no net dislikes)
      - name: is_satisfactory_direct
        description: |
          Direct satisfaction indicator based on explicit user actions (VARIANT)
          (positive interactions without net dislikes)
      - name: is_satisfactory
        description: |
          Overall satisfaction indicator (VARIANT)
          (is_satisfactory_indirect OR is_satisfactory_direct)
      - name: metadata
        description: "Additional metadata including model_name and other clip attributes (VARIANT)"
      - name: p_date
        description: "Partition date (date of clip creation)"
      - name: p_hour
        description: "Partition hour (hour of clip creation)"

  - name: agg_play_info_hourly_v2
    description: Hourly aggregated play information on clips, from fact_play. The table is indexed by user ID/UID, clip ID, date + hour, and play duration threshold.
    config:
      schema: PROD
      on_schema_change: append_new_columns
      group: listening
      freshness_policy:
        type: time_window
    meta:
      dagster:
        partitions_def:
          type: hourly
          start_date: 2024-06-01
          end_offset: -1
        partition_mappings:
          - asset_key: fact_play
            type: identity
          - asset_key: dim_user
            type: identity
        automation_condition: hourly_cron_with_eager_historical_backfill_condition
        backfill_policy:
          max_partitions_per_run: 336 # 2 weeks
    columns:
      - name: user_id
        description: User ID (integer)
      - name: user_uid
        description: User UID (UUID)
      - name: clip_id
        description: Clip ID
      - name: is_user_song_owner
        description: Whether the user is the owner/creator of the song
      - name: platform
        description: Platform where the play occurred (web, ios, android, etc). Combines iOS and iPadOS into a single "ios" platform.
      - name: play_duration_threshold
        description: Threshold in seconds used to determine valid plays. Currently computing for 0 and 5 second thresholds.
      - name: play_duration_seconds
        description: Total duration of plays in seconds in this hour, under the play duration threshold constraint
      - name: unique_play_duration_seconds
        description: Total duration of unique plays in seconds in this hour, under the play duration threshold constraint
      - name: play_count
        description: Total number of plays in this hour, under the play duration threshold constraint
      - name: is_high_intent_listening
        description: JSON object containing breakdown of high intent listening metrics by version.
      - name: high_intent_listening_breakdown
        description: JSON object containing breakdown of high intent listening metrics by version.
      - name: p_date
        description: Partition date for the hourly aggregation
      - name: p_hour
        description: Partition hour (0-23) for the hourly aggregation.
