Skip to content

Commit

Permalink
fix aggregation methods within mode, purpose, and transit mode stored…
Browse files Browse the repository at this point in the history
… procedures
  • Loading branch information
gregorkschroeder committed Jul 31, 2020
1 parent 8db6c77 commit 762c158
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions sql/sensitivity/sensitivity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,15 @@ BEGIN
,CASE WHEN @weight = 'persons' THEN SUM(ISNULL([person_trip].[weight_person_trip], 0))
WHEN @weight = 'trips' THEN SUM(ISNULL([person_trip].[weight_trip], 0))
ELSE NULL END AS [weight]
,CASE WHEN @metric = 'distance' THEN SUM(ISNULL([person_trip].[dist_total], 0))
WHEN @metric IN ('trips', 'share') THEN 0 -- only weight is unused if trips or share is selected
WHEN @metric = 'time' THEN SUM(ISNULL([person_trip].[time_total], 0))
,CASE WHEN @metric IN ('trips', 'share') THEN 0 -- only weight is unused if trips or share is selected
WHEN @weight = 'persons' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'trips' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'persons' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[time_total], 0))
WHEN @weight = 'trips' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[time_total], 0))
ELSE NULL END AS [metric]
FROM
[fact].[person_trip]
Expand Down Expand Up @@ -369,6 +375,8 @@ BEGIN
,SUM([metric]) AS [metric]
FROM
#aggTrips
WHERE
[model] != 'Resident Models'
GROUP BY
[mode]

Expand Down Expand Up @@ -653,10 +661,16 @@ BEGIN
,CASE WHEN @weight = 'persons' THEN SUM(ISNULL([person_trip].[weight_person_trip], 0))
WHEN @weight = 'trips' THEN SUM(ISNULL([person_trip].[weight_trip], 0))
ELSE NULL END AS [weight]
,CASE WHEN @metric = 'distance' THEN SUM(ISNULL([person_trip].[dist_total], 0))
WHEN @metric = 'share' THEN 0 -- only weight is unused if share is selected
WHEN @metric = 'time' THEN SUM(ISNULL([person_trip].[time_total], 0))
ELSE NULL END AS [metric]
,CASE WHEN @metric IN ('trips', 'share') THEN 0 -- only weight is unused if trips or share is selected
WHEN @weight = 'persons' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'trips' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'persons' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[time_total], 0))
WHEN @weight = 'trips' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[time_total], 0))
ELSE NULL END AS [metric]
FROM
[fact].[person_trip]
INNER JOIN
Expand Down Expand Up @@ -749,6 +763,8 @@ BEGIN
,SUM([metric]) AS [metric]
FROM
#aggTrips
WHERE
[model] != 'Resident Models'
GROUP BY
[purpose]

Expand Down Expand Up @@ -1061,9 +1077,15 @@ BEGIN
,CASE WHEN @weight = 'persons' THEN SUM(ISNULL([person_trip].[weight_person_trip], 0))
WHEN @weight = 'trips' THEN SUM(ISNULL([person_trip].[weight_trip], 0))
ELSE NULL END AS [weight]
,CASE WHEN @metric = 'distance' THEN SUM(ISNULL([person_trip].[dist_total], 0))
WHEN @metric IN ('trips', 'share') THEN 0 -- only weight is unused if trips or share is selected
WHEN @metric = 'time' THEN SUM(ISNULL([person_trip].[time_total], 0))
,CASE WHEN @metric IN ('trips', 'share') THEN 0 -- only weight is unused if trips or share is selected
WHEN @weight = 'persons' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'trips' AND @metric = 'distance'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[dist_total], 0))
WHEN @weight = 'persons' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_person_trip], 0) * ISNULL([person_trip].[time_total], 0))
WHEN @weight = 'trips' AND @metric = 'time'
THEN SUM(ISNULL([person_trip].[weight_trip], 0) * ISNULL([person_trip].[time_total], 0))
ELSE NULL END AS [metric]
FROM
[fact].[person_trip]
Expand Down Expand Up @@ -1143,6 +1165,8 @@ BEGIN
,SUM([metric]) AS [metric]
FROM
#aggTrips
WHERE
[model] != 'Resident Models'
GROUP BY
[mode]

Expand Down

0 comments on commit 762c158

Please sign in to comment.