-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from jairus-m/refactor/dbt-models
Refactor/dbt models
- Loading branch information
Showing
11 changed files
with
60 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
select | ||
id | ||
, name | ||
, has_heartrate | ||
, private | ||
, visibility | ||
, case | ||
when sport_type in ('VirtualRide', 'Ride', 'MountainBikeRide') then 'Cycling' | ||
when sport_type = 'Run' then 'Running' | ||
else 'Other' | ||
end as sport_type | ||
from {{ ref('obt_clean_activities') }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,26 @@ | ||
with activities as ( | ||
select | ||
date, | ||
time, | ||
distance_miles, | ||
moving_time_minutes, | ||
elapsed_time_minutes, | ||
total_elevation_gain_feet, | ||
sport_type, | ||
id, | ||
achievement_count, | ||
kudos_count, | ||
comment_count, | ||
athlete_count, | ||
private, | ||
visibility, | ||
average_speed_mph, | ||
max_speed_mph, | ||
has_heartrate, | ||
pr_count, | ||
average_cadence, | ||
average_temp, | ||
average_watts, | ||
max_watts, | ||
weighted_average_watts, | ||
kilojoules, | ||
average_heartrate, | ||
max_heartrate, | ||
elev_high_feet, | ||
elev_low_feet | ||
from {{ ref('obt_clean_activities') }} | ||
|
||
), | ||
|
||
dates as ( | ||
select * from {{ ref('dim_dates') }} | ||
), | ||
|
||
sport_type as ( | ||
select * from {{ ref('dim_sport_type') }} | ||
), | ||
|
||
privacy as ( | ||
select * from {{ ref('dim_privacy') }} | ||
), | ||
|
||
has_heartrate as ( | ||
select * from {{ ref('dim_has_heartrate') }} | ||
) | ||
|
||
select | ||
a.id as id_pk, | ||
d.date_id, | ||
a.time, | ||
s.sport_type_pk as sport_type_fk, | ||
p.visibility_pk as visibility_fk, | ||
a.distance_miles, | ||
a.moving_time_minutes, | ||
a.elapsed_time_minutes, | ||
a.total_elevation_gain_feet, | ||
a.achievement_count, | ||
a.kudos_count, | ||
a.comment_count, | ||
a.athlete_count, | ||
a.average_speed_mph, | ||
a.max_speed_mph, | ||
a.pr_count, | ||
a.average_cadence, | ||
a.average_temp, | ||
a.average_watts, | ||
a.max_watts, | ||
a.weighted_average_watts, | ||
a.kilojoules, | ||
a.average_heartrate, | ||
a.max_heartrate, | ||
a.elev_high_feet, | ||
a.elev_low_feet, | ||
h.has_heartrate_pk as has_heartrate_fk, | ||
from activities as a | ||
left join dates as d | ||
on d.date = a.date and d.time = a.time | ||
left join sport_type as s | ||
on a.sport_type = s.sport_type | ||
left join privacy as p | ||
on a.private = p.private | ||
left join has_heartrate as h | ||
on a.has_heartrate = h.has_heartrate | ||
id | ||
, date | ||
, time | ||
, distance_miles | ||
, moving_time_minutes | ||
, elapsed_time_minutes | ||
, total_elevation_gain_feet | ||
, achievement_count | ||
, kudos_count | ||
, comment_count | ||
, athlete_count | ||
, average_speed_mph | ||
, max_speed_mph | ||
, pr_count | ||
, average_cadence | ||
, average_temp | ||
, average_watts | ||
, max_watts | ||
, weighted_average_watts | ||
, kilojoules | ||
, average_heartrate | ||
, max_heartrate | ||
, elev_high_feet | ||
, elev_low_feet | ||
from {{ ref('obt_clean_activities') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
select | ||
date_trunc('week', strptime(fa.date, '%m-%d-%Y')) AS week_start | ||
, da.sport_type | ||
, sum(distance_miles) as distance_miles | ||
, sum(moving_time_minutes) as moving_time_minutes | ||
, sum(elapsed_time_minutes) as elapsed_time_minutes | ||
, sum(total_elevation_gain_feet) as total_elevation_gain_feet | ||
, sum(achievement_count) as achievement_count | ||
, sum(kudos_count) as kudos_count | ||
, sum(comment_count) as comment_count | ||
, sum(pr_count) as pr_count | ||
from {{ ref('fct_activities') }} as fa | ||
left join {{ ref('dim_activities') }} as da | ||
on fa.id = da.id | ||
group by week_start, sport_type | ||
order by week_start desc |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.