-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path304.do.update--ov-indv-rat.fn.sql
More file actions
97 lines (90 loc) · 1.51 KB
/
304.do.update--ov-indv-rat.fn.sql
File metadata and controls
97 lines (90 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
create or replace function update_ov_coindv_rat() returns numeric as $$
declare
pe record;
cel_rot numeric(10,9) := 0.0;
svpth_rot numeric(10,9) := 0.0;
ov_rat numeric := 0.00;
tar_gras record;
manw int := 60;
weis int := 40;
begin
--
-- reset
--
update
thlogepen
set
ov_coindv_rat = 0;
--
-- retrieve gnars for individual calculations relative to gnars
--
select
max(svpth) - min(svpth) as svpth_gra,
max(cel) - min(cel) as cel_gra
from
thlogepen
where
otc = 'LV2'
into
tar_gras;
--
-- now set the ov value in a loop
--
for pe in
select
cel,
svpth,
thlogepen_id,
otc
from
thlogepen pe
loop
--
-- non-lafs involve c_l
--
if
pe.otc = 'LV2'
then
-- c_l relative to tar
cel_rot :=
pe.cel
/
tar_gras.cel_gra;
-- sv of event relatoive to tar
svpth_rot :=
pe.svpth
/
tar_gras.svpth_gra;
-- ov rating using wgts
ov_rat :=
(
svpth_rot
*
weis
)
+
(
cel_rot
*
manw
);
end if;
--
-- lafs are simpler, just the sv itself for them, no weig
--
if
pe.otc = 'LV1'
then
ov_rat := pe.svpth;
end if;
-- finish with the update
update
thlogepen
set
ov_coindv_rat = ov_rat
where
thlogepen_id = pe.thlogepen_id;
end loop;
return ov_rat;
end;
$$ language plpgsql;