Skip to content

Commit

Permalink
Change percent progress calculation to remove subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Aug 18, 2023
1 parent a83b664 commit 9d9fb53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion macros/get_percentage_boundaries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endfor %}

{% if 100 not in var("snowplow__percent_progress_boundaries") %}
{% do percentage_boundaries.append('100') %}
{% do percentage_boundaries.append(100) %}
{% endif %}

{{ return(percentage_boundaries) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{% macro percent_progress_col(v1_percent_progress, v1_event_type, event_name, v2_current_time, v2_duration) %}
{%- set v2_percent_progres -%}
round({{ field(
v2_current_time,
col_prefix='contexts_com_snowplowanalytics_snowplow_media_player_2'
) }} / {{ field(
v2_duration,
col_prefix='contexts_com_snowplowanalytics_snowplow_media_player_2'
) }} * 100)
{%- endset -%}
coalesce(
{% if var("snowplow__enable_media_player_v1") %}
case
Expand All @@ -24,20 +33,13 @@
col_prefix='contexts_com_snowplowanalytics_snowplow_media_player_2'
) }}, 0) > 0
then (
select max(p.pp)
from (
{% for element in get_percentage_boundaries(var("snowplow__percent_progress_boundaries")) %}
select {{ element }} as pp
{% if not loop.last %} union all {% endif %}
case
{% for element in get_percentage_boundaries(var("snowplow__percent_progress_boundaries"))|sort|reverse %}
when {{ v2_percent_progres }} >= {{ element }}
then {{ element }}
{% endfor %}
) p
where p.pp <= round({{ field(
v2_current_time,
col_prefix='contexts_com_snowplowanalytics_snowplow_media_player_2'
) }} / {{ field(
v2_duration,
col_prefix='contexts_com_snowplowanalytics_snowplow_media_player_2'
) }} * 100)
else null
end
)

else null
Expand Down

0 comments on commit 9d9fb53

Please sign in to comment.