merge training_duration and training_info into 1 view
This commit is contained in:
parent
364329dc0e
commit
cdd6418c79
23
init.sql
23
init.sql
@ -43,7 +43,7 @@ begin
|
||||
end
|
||||
$$ language plpgsql immutable;
|
||||
|
||||
create or replace view training_duration as
|
||||
create or replace view training_info as
|
||||
(
|
||||
select
|
||||
td_start.training_id as training_id,
|
||||
@ -51,9 +51,9 @@ select
|
||||
td_end.t as end_time,
|
||||
resolve_geo_location(td_start.geog) AS start_location,
|
||||
resolve_geo_location(td_end.geog) AS end_location,
|
||||
td_start.geog as start_location_point,
|
||||
td_end.geog as end_location_point,
|
||||
date_trunc('second'::text, td_end.t - td_start.t) AS duration
|
||||
date_trunc('second'::text, td_end.t - td_start.t) AS duration,
|
||||
round(((t.moving_distance)/1000)::numeric, 2) as distance,
|
||||
round(( (t.moving_distance / 1000) / (select extract(epoch from date_trunc('second'::text, td_end.t - td_start.t))/3600))::numeric, 1) as pace_kmh
|
||||
from
|
||||
(
|
||||
select distinct on (td2.training_id) *
|
||||
@ -65,19 +65,6 @@ select
|
||||
from training_data td2 order by td2.training_id, t desc
|
||||
) td_end
|
||||
on (td_start.training_id = td_end.training_id)
|
||||
join training t on (t.id = td_start.training_id)
|
||||
order by td_start.t asc
|
||||
);
|
||||
|
||||
create or replace view training_info as
|
||||
(select distinct
|
||||
td.t::date,
|
||||
training_duration.start_time as start_time,
|
||||
training_duration.end_time as end_time,
|
||||
training_duration.duration as duration,
|
||||
round(((t.moving_distance)/1000)::numeric, 2) as distance,
|
||||
round(( (t.moving_distance / 1000) / (select extract(epoch from training_duration.duration)/3600))::numeric, 1) as pace_kmh
|
||||
from training t
|
||||
join training_data td on (t.id = td.training_id)
|
||||
join training_duration on (t.id = training_duration.id)
|
||||
order by td.t::date, date_trunc('second', training_duration.start_time::time) asc
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user