maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_ro_overrpm(real[], integer)
Parameters
Name
Type
Mode
matrix
ARRAY
IN
rpm_limit
integer
IN
Definition
/* Returns the sum of time a unit has spent over rpm limit, out of a speedrpm matrix */ /* v20141111 */ DECLARE lower_bound int; rpm_range int := 500; i int := 0; j int := 0; total_time real :=0; /* because we're receiving columns instead of rows from the middleware */ transposed_matrix real[] := '{{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}}'; aux_array real[]; /*to hold the matrix as a simple array*/ BEGIN for i in 1..6 loop for j in 1..6 loop transposed_matrix[i][j] := matrix[j][i]; end loop; end loop; aux_array := (WITH q as (SELECT unnest(transposed_matrix) as a) SELECT array_agg(a) from q); lower_bound := ((rpm_limit / rpm_range) + 1)*5; i := 0; FOR i in lower_bound..36 LOOP total_time = total_time + aux_array[i]; END LOOP; RETURN total_time; END;