Permalink
Browse files

uuid is added as result of execquote and insertorder

  • Loading branch information...
1 parent a669a81 commit 53e884d072546060433279b1b42ade1fba0e346c @olivierch committed Aug 10, 2012
View
BIN doc/doc-ob.odt
Binary file not shown.
View
BIN doc/doc-ob.pdf
Binary file not shown.
View
BIN doc/paper-ob.odt
Binary file not shown.
View
BIN doc/paper-ob.pdf
Binary file not shown.
View
32 simu/testopt.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+# -*- coding: utf8 -*-
+
+
+
+from optparse import OptionParser
+
+def main():
+ usage = "usage: %prog [options] arg"
+ parser = OptionParser(usage)
+ parser.add_option("-f", "--file", dest="filename",
+ help="read data from FILENAME")
+ parser.add_option("-v", "--verbose",
+ action="store_true", dest="verbose")
+ parser.add_option("-q", "--quiet",
+ action="store_false", dest="verbose")
+ parser.add_option("-r", "--reset",action="store_true", dest="reset",help="database is reset",default=False)
+ parser.add_option("--MAXTRY",type="int",dest="MAXTRY",help="reset MAXTRY")
+
+ (options, args) = parser.parse_args()
+ if len(args) != 1:
+ parser.error("incorrect number of arguments")
+ if options.verbose:
+ print "reading %s..." % options.filename
+ print options.reset
+ print options.MAXTRY
+ print "args %s" % args
+
+if __name__ == "__main__":
+ main()
+
+
View
4 src/expected/testflow_1.out
@@ -123,8 +123,8 @@ SET client_min_messages = warning;
(1 row)
-psql:sql/model.sql:2105: INFO: market_status INITIALIZING->OPENED
-psql:sql/model.sql:2105: INFO: The market is now opened for clients
+psql:sql/model.sql:2132: INFO: market_status INITIALIZING->OPENED
+psql:sql/model.sql:2132: INFO: The market is now opened for clients
fchangestatemarket
--------------------
OPENED
View
28 src/expected/testflow_2.out
@@ -24,19 +24,19 @@ INFO: The market is opened for this user
select * from finsertorder('u',fq('b'),1000,1000,fq('a'));
INFO: owner u created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 1 | 1 | 2 | 1000 | 1 | 1000 | 0 | 0 | {} | |
+PL/pgSQL function "finsertorder" line 20 at assignment
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 1 | 1-1 | 1 | 2 | 1000 | 1 | 1000 | 0 | 0 | {}
(1 row)
select * from finsertorder('v',fq('c'),1000,1000,fq('b'));
INFO: owner v created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 2 | 2 | 1 | 1000 | 3 | 1000 | 0 | 0 | {} | |
+PL/pgSQL function "finsertorder" line 20 at assignment
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 2 | 1-2 | 2 | 1 | 1000 | 3 | 1000 | 0 | 0 | {}
(1 row)
select id,nr,qtt_requ,np,qtt_prov,qtt_in,qtt_out,flows from fgetquote('w',fq('a'),1000,1000,fq('c'));
@@ -69,15 +69,15 @@ select * from fremoveagreement(1);
(1 row)
select * from finsertorder('u',fq('b'),2000,1000,fq('a'));
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 4 | 1 | 2 | 1000 | 1 | 2000 | 0 | 0 | {} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 4 | 1-4 | 1 | 2 | 1000 | 1 | 2000 | 0 | 0 | {}
(1 row)
select * from finsertorder('v',fq('c'),2000,1000,fq('b'));
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 5 | 2 | 1 | 1000 | 3 | 2000 | 0 | 0 | {} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 5 | 1-5 | 2 | 1 | 1000 | 3 | 2000 | 0 | 0 | {}
(1 row)
select id,nr,qtt_requ,np,qtt_prov,qtt_in,qtt_out,flows from fgetquote('w',fq('a'),500,2000,fq('c'));
View
60 src/expected/testflow_4.out
@@ -2,28 +2,28 @@
select * from finsertorder('x','b',160,40,'a');
INFO: owner x created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 8 | 4 | 5 | 40 | 4 | 160 | 0 | 0 | {} | |
+PL/pgSQL function "finsertorder" line 20 at assignment
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 8 | 1-8 | 4 | 5 | 40 | 4 | 160 | 0 | 0 | {}
(1 row)
select * from finsertorder('y','c',160,80,'b');
INFO: owner y created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 9 | 5 | 4 | 80 | 6 | 160 | 0 | 0 | {} | |
+PL/pgSQL function "finsertorder" line 20 at assignment
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 9 | 1-9 | 5 | 4 | 80 | 6 | 160 | 0 | 0 | {}
(1 row)
select * from finsertorder('t','c',100,100,'a');
INFO: owner t created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 10 | 6 | 5 | 100 | 6 | 100 | 0 | 0 | {} | |
+PL/pgSQL function "finsertorder" line 20 at assignment
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 10 | 1-10 | 6 | 5 | 100 | 6 | 100 | 0 | 0 | {}
(1 row)
select * from fgetquote('z','a',20,0,'c'); -- expected (qtt_prov,qtt_requ)= (20,160)
@@ -68,9 +68,9 @@ select * from fgetquote('z','a',100,0,'c'); -- expected (qtt_in,qtt_out)= (100,1
(1 row)
select * from finsertorder('z','a',100,100,'c'); -- one agreements
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-----------------------------------------------------------------+---------+---------
- 12 | 7 | 6 | 100 | 5 | 100 | 100 | 100 | {"[(10, 6, 5, 100, 6, 100, 100),(12, 7, 6, 100, 5, 100, 100)]"} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-----------------------------------------------------------------
+ 12 | 1-12 | 7 | 6 | 100 | 5 | 100 | 100 | 100 | {"[(10, 6, 5, 100, 6, 100, 100),(12, 7, 6, 100, 5, 100, 100)]"}
(1 row)
select * from fgetagr(12) where _own='z'; -- expected as first quote
@@ -80,21 +80,21 @@ select * from fgetagr(12) where _own='z'; -- expected as first quote
(1 row)
select * from finsertorder('x','b2',160,40,'a2');
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 13 | 4 | 8 | 40 | 7 | 160 | 0 | 0 | {} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 13 | 1-13 | 4 | 8 | 40 | 7 | 160 | 0 | 0 | {}
(1 row)
select * from finsertorder('y','c2',160,80,'b2');
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 14 | 5 | 7 | 80 | 9 | 160 | 0 | 0 | {} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 14 | 1-14 | 5 | 7 | 80 | 9 | 160 | 0 | 0 | {}
(1 row)
select * from finsertorder('t','c2',90,10,'a2');
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-------+---------+---------
- 15 | 6 | 8 | 10 | 9 | 90 | 0 | 0 | {} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-------
+ 15 | 1-15 | 6 | 8 | 10 | 9 | 90 | 0 | 0 | {}
(1 row)
select * from fgetquote('z','a2',10,0,'c2');-- expected (qtt_in,qtt_out)= (90,10)
@@ -104,9 +104,9 @@ select * from fgetquote('z','a2',10,0,'c2');-- expected (qtt_in,qtt_out)= (90,10
(1 row)
select * from finsertorder('z','a2',10,90,'c2');
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+-----------------------------------------------------------+---------+---------
- 16 | 7 | 9 | 90 | 8 | 10 | 90 | 10 | {"[(15, 6, 8, 10, 9, 90, 90),(16, 7, 9, 90, 8, 10, 10)]"} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+-----------------------------------------------------------
+ 16 | 1-16 | 7 | 9 | 90 | 8 | 10 | 90 | 10 | {"[(15, 6, 8, 10, 9, 90, 90),(16, 7, 9, 90, 8, 10, 10)]"}
(1 row)
select * from fgetagr(14) where _own='z'; -- expected as first quote
@@ -122,9 +122,9 @@ select * from fgetquote('z','a2',20,0,'c2'); -- expected (qtt_in,qtt_out)= (160,
(1 row)
select * from finsertorder('z','a2',20,160,'c2');
- id | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows | created | removed
-----+-----+----+----------+----+----------+--------+---------+------------------------------------------------------------------------------------------+---------+---------
- 17 | 7 | 9 | 160 | 8 | 20 | 160 | 20 | {"[(13, 4, 8, 40, 7, 160, 160),(14, 5, 7, 80, 9, 160, 160),(17, 7, 9, 160, 8, 20, 20)]"} | |
+ id | uuid | own | nr | qtt_requ | np | qtt_prov | qtt_in | qtt_out | flows
+----+------+-----+----+----------+----+----------+--------+---------+------------------------------------------------------------------------------------------
+ 17 | 1-17 | 7 | 9 | 160 | 8 | 20 | 160 | 20 | {"[(13, 4, 8, 40, 7, 160, 160),(14, 5, 7, 80, 9, 160, 160),(17, 7, 9, 160, 8, 20, 20)]"}
(1 row)
select * from fgetagr(16) where _own='z'; -- expected as first quote
View
40 src/expected/testflow_5.out
@@ -68,19 +68,19 @@ set role client;
select finsertorder('u','b',1000,1000,'a');
INFO: owner u created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
-------------------------------
- (1,1,2,1000,1,1000,0,0,{},,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+--------------------------------
+ (1,2-1,1,2,1000,1,1000,0,0,{})
(1 row)
select finsertorder('v','c',1000,1000,'b');
INFO: owner v created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
-------------------------------
- (2,2,1,1000,3,1000,0,0,{},,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+--------------------------------
+ (2,2-2,2,1,1000,3,1000,0,0,{})
(1 row)
select qtt_in,qtt_out from fgetquote('w','a',1000,0,'c');
@@ -93,9 +93,9 @@ PL/pgSQL function "fgetquote" line 36 at assignment
(1 row)
select finsertorder('w','a',1000,1000,'c');
- finsertorder
-----------------------------------------------------------------------------------------------------------------------------------------
- (3,3,3,1000,2,1000,1000,1000,"{""[(1, 1, 2, 1000, 1, 1000, 1000),(2, 2, 1, 1000, 3, 1000, 1000),(3, 3, 3, 1000, 2, 1000, 1000)]""}",,)
+ finsertorder
+------------------------------------------------------------------------------------------------------------------------------------------
+ (3,2-3,3,3,1000,2,1000,1000,1000,"{""[(1, 1, 2, 1000, 1, 1000, 1000),(2, 2, 1, 1000, 3, 1000, 1000),(3, 3, 3, 1000, 2, 1000, 1000)]""}")
(1 row)
select id,nb,oruuid,grp,provider,quality,qtt,receiver from vmvt;
@@ -121,15 +121,15 @@ select id,qtt from tquality;
(3 rows)
select finsertorder('u','b',2000,1000,'a');
- finsertorder
-------------------------------
- (4,1,2,1000,1,2000,0,0,{},,)
+ finsertorder
+--------------------------------
+ (4,2-4,1,2,1000,1,2000,0,0,{})
(1 row)
select finsertorder('v','c',2000,1000,'b');
- finsertorder
-------------------------------
- (5,2,1,1000,3,2000,0,0,{},,)
+ finsertorder
+--------------------------------
+ (5,2-5,2,1,1000,3,2000,0,0,{})
(1 row)
select qtt_in,qtt_out from fgetquote('w','a',500,0,'c');
@@ -172,9 +172,9 @@ select fgetquote('w','a',500,0,'b');
(1 row)
select finsertorder('w','a',500,1000,'b');
- finsertorder
------------------------------------------------------------------------------------------------------
- (7,3,1,1000,2,500,1000,500,"{""[(4, 1, 2, 1000, 1, 2000, 1000),(7, 3, 1, 1000, 2, 500, 500)]""}",,)
+ finsertorder
+-------------------------------------------------------------------------------------------------------
+ (7,2-7,3,1,1000,2,500,1000,500,"{""[(4, 1, 2, 1000, 1, 2000, 1000),(7, 3, 1, 1000, 2, 500, 500)]""}")
(1 row)
set role admin;
View
32 src/expected/testflow_6.out
@@ -71,31 +71,31 @@ INFO: The market is reset and opened
select finsertorder('A','z',200 ,200 ,'x');
INFO: owner A created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
-----------------------------
- (1,1,2,200,1,200,0,0,{},,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+------------------------------
+ (1,4-1,1,2,200,1,200,0,0,{})
(1 row)
-- path (a)
-- select finsertorder('B','x',25 ,200 ,'y');
select finsertorder('B','y',200 ,25 ,'x');
INFO: owner B created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
----------------------------
- (2,2,2,25,3,200,0,0,{},,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+-----------------------------
+ (2,4-2,2,2,25,3,200,0,0,{})
(1 row)
--select finsertorder('C','y',100 ,100 ,'z');
select finsertorder('C','z',100 ,100 ,'y');
INFO: owner C created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
-----------------------------
- (3,3,3,100,1,100,0,0,{},,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+------------------------------
+ (3,4-3,3,3,100,1,100,0,0,{})
(1 row)
-- no exchange
@@ -108,10 +108,10 @@ select id,nb,oruuid,grp,provider,quality,qtt,receiver from vmvt;
select finsertorder('D','x',250 ,250 ,'z');
INFO: owner D created
CONTEXT: PL/pgSQL function "fgetowner" line 10 at assignment
-PL/pgSQL function "finsertorder" line 19 at assignment
- finsertorder
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- (4,4,1,250,2,250,300,250,"{""[(2, 2, 2, 25, 3, 200, 200),(3, 3, 3, 100, 1, 100, 100),(4, 4, 1, 250, 2, 250, 250)]"",""[(1, 1, 2, 200, 1, 200, 200),(4, 4, 1, 250, 2, 250, 200)]""}",,)
+PL/pgSQL function "finsertorder" line 20 at assignment
+ finsertorder
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ (4,4-4,4,1,250,2,250,300,250,"{""[(2, 2, 2, 25, 3, 200, 200),(3, 3, 3, 100, 1, 100, 100),(4, 4, 1, 250, 2, 250, 250)]"",""[(1, 1, 2, 200, 1, 200, 200),(4, 4, 1, 250, 2, 250, 200)]""}")
(1 row)
--two exchanges in a single transaction
View
89 src/sql/model.sql
@@ -903,6 +903,7 @@ CREATE TABLE tquoteremoved (
removed timestamp
);
SELECT _grant_read('tquoteremoved');
+
--------------------------------------------------------------------------------
-- (id,own,qtt_in,qtt_out,flows) = fgetquote(owner,qltprovided,qttprovided,qttrequired,qltprovided)
/* if qttrequired == 0,
@@ -1092,28 +1093,40 @@ $$ LANGUAGE PLPGSQL SECURITY DEFINER;
GRANT EXECUTE ON FUNCTION fgetprequote(text,text,int8,text) TO client_opened_role;
--------------------------------------------------------------------------------
---
+-- -- id,uuid,own,nr,qtt_requ,np,qtt_prov,qtt_in,qtt_out,flows
+CREATE TYPE yresorder AS (
+ id int,
+ uuid text,
+ own int,
+ nr int,
+ qtt_requ int8,
+ np int,
+ qtt_prov int8,
+ qtt_in int8,
+ qtt_out int8,
+ flows yflow[]
+);
--------------------------------------------------------------------------------
-- torder id,uuid,yorder,created,updated
-- yorder: qtt,nr,np,qtt_prov,qtt_requ,own
CREATE FUNCTION
fexecquote(_owner text,_idquote int)
- RETURNS tquote AS $$
+ RETURNS yresorder AS $$
DECLARE
_wid int;
_o torder%rowtype;
_idd int;
- _expected tquote%rowtype;
_q tquote%rowtype;
- _pivot torder%rowtype;
+ _ro yresorder%ROWTYPE;
_flows yflow[];
- _ypatmax yflow;
+ _ypatmax yflow;
_res int8[];
_qtt_prov int8;
_qtt_requ int8;
_first_mvt int;
+
BEGIN
_idd := fverifyquota();
@@ -1135,23 +1148,30 @@ BEGIN
_o := finsert_toint(_qtt_prov,_q.nr,_q.np,_qtt_requ,_q.own);
- _q.id := _o.id;
- _q.qtt_in := 0;
- _q.qtt_out := 0;
- _q.flows := ARRAY[]::yflow[];
+ -- id,uuid,own,nr,qtt_requ,np,qtt_prov,qtt_in,qtt_out,flows
+ _ro.id := _o.id;
+ _ro.uuid := _o.uuid;
+ _ro.own := _q.own;
+ _ro.nr := _q.nr;
+ _ro.qtt_requ := _q.qtt_requ;
+ _ro.np := _q.np;
+ _ro.qtt_prov := _q.qtt_prov;
+ _ro.qtt_in := 0;
+ _ro.qtt_out := 0;
+ _ro.flows := ARRAY[]::yflow[];
FOR _ypatmax IN SELECT _patmax FROM finsertflows(_o) LOOP
_first_mvt := fexecute_flow(_ypatmax);
_res := yflow_qtts(_ypatmax);
- _q.qtt_in := _q.qtt_in + _res[1];
- _q.qtt_out := _q.qtt_out + _res[2];
- _q.flows := array_append(_q.flows,_ypatmax);
+ _ro.qtt_in := _ro.qtt_in + _res[1];
+ _ro.qtt_out := _ro.qtt_out + _res[2];
+ _ro.flows := array_append(_ro.flows,_ypatmax);
END LOOP;
- IF ( (_q.qtt_in = 0) OR (_qtt_requ = 0) OR
- ((_q.qtt_out::double precision) /(_q.qtt_in::double precision)) >
- ((_qtt_prov::double precision) /(_qtt_requ::double precision))
+ IF ( (_ro.qtt_in = 0) OR (_qtt_requ = 0) OR
+ ((_ro.qtt_out::double precision) /(_ro.qtt_in::double precision)) >
+ ((_qtt_prov::double precision) /(_qtt_requ::double precision))
) THEN
RAISE NOTICE 'Omega of the flows obtained is not limited by the order';
RAISE EXCEPTION USING ERRCODE='YA003';
@@ -1160,12 +1180,12 @@ BEGIN
PERFORM fremovequote_int(_idquote);
PERFORM finvalidate_treltried();
- RETURN _q;
+ RETURN _ro;
EXCEPTION WHEN SQLSTATE 'YU001' THEN
-- PERFORM fremovequote_int(_idquote);
-- RAISE INFO 'Abort; Quote removed';
- RETURN _q;
+ RETURN _ro;
END;
$$ LANGUAGE PLPGSQL SECURITY DEFINER;
@@ -1213,15 +1233,16 @@ $$ LANGUAGE PLPGSQL;
-- yorder: qtt,nr,np,qtt_prov,qtt_requ,own
CREATE FUNCTION
finsertorder(_owner text,_qualityprovided text,_qttprovided int8,_qttrequired int8,_qualityrequired text)
- RETURNS tquote AS $$
+ RETURNS yresorder AS $$
DECLARE
_wid int;
_o torder%rowtype;
_idd int;
- _expected tquote%rowtype;
+ -- _expected tquote%rowtype;
_q tquote%rowtype;
- _pivot torder%rowtype;
+ _ro yresorder%rowTYPE;
+ -- _pivot torder%rowtype;
_qua text[];
_flows yflow[];
@@ -1255,22 +1276,28 @@ BEGIN
_o := finsert_toint(_qttprovided,_q.nr,_q.np,_qttrequired,_q.own);
- _q.id := _o.id;
- _q.qtt_in := 0;
- _q.qtt_out := 0;
- _q.flows := ARRAY[]::yflow[];
+ _ro.id := _o.id;
+ _ro.uuid := _o.uuid;
+ _ro.own := _q.own;
+ _ro.nr := _q.nr;
+ _ro.qtt_requ := _q.qtt_requ;
+ _ro.np := _q.np;
+ _ro.qtt_prov := _q.qtt_prov;
+ _ro.qtt_in := 0;
+ _ro.qtt_out := 0;
+ _ro.flows := ARRAY[]::yflow[];
FOR _ypatmax IN SELECT _patmax FROM finsertflows(_o) LOOP
_first_mvt := fexecute_flow(_ypatmax);
_res := yflow_qtts(_ypatmax);
- _q.qtt_in := _q.qtt_in + _res[1];
- _q.qtt_out := _q.qtt_out + _res[2];
- _q.flows := array_append(_q.flows,_ypatmax);
+ _ro.qtt_in := _ro.qtt_in + _res[1];
+ _ro.qtt_out := _ro.qtt_out + _res[2];
+ _ro.flows := array_append(_ro.flows,_ypatmax);
END LOOP;
- IF ( (_q.qtt_in != 0) AND
- ((_q.qtt_out::double precision) /(_q.qtt_in::double precision)) >
+ IF ( (_ro.qtt_in != 0) AND
+ ((_ro.qtt_out::double precision) /(_ro.qtt_in::double precision)) >
((_qttprovided::double precision) /(_qttrequired::double precision))
) THEN
RAISE NOTICE 'Omega of the flows obtained is not limited by the order';
@@ -1279,11 +1306,11 @@ BEGIN
PERFORM finvalidate_treltried();
- RETURN _q;
+ RETURN _ro;
EXCEPTION WHEN SQLSTATE 'YU001' THEN
RAISE INFO 'Abort';
- RETURN _q;
+ RETURN _ro;
END;
$$ LANGUAGE PLPGSQL SECURITY DEFINER;
View
4 src/yflow.c
@@ -640,6 +640,8 @@ Datum yflow_flr_omega(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(_Omega);
}
/******************************************************************************
+returns a matrix int8[i][j] of i lines of nodes, where a node is:
+ [id,own,nr,qtt_requ,np,qtt_prov,qtt,flowr]
******************************************************************************/
Datum yflow_to_matrix(PG_FUNCTION_ARGS)
{
@@ -672,7 +674,7 @@ Datum yflow_to_matrix(PG_FUNCTION_ARGS)
_datum_out = palloc(sizeof(Datum) * _dim * DIMELTRESULT);
_null_out = palloc(sizeof(bool) * _dim * DIMELTRESULT);
- //id,nr,qtt_prov,qtt_requ,sid,own,qtt,np
+ // id,own,nr,qtt_requ,np,qtt_prov,qtt,flowr
obMRange(_i,_dim) {
int _j = _i * DIMELTRESULT;
_null_out[_j+0] = false; _datum_out[_j+0] = Int64GetDatum((int64) box->x[_i].id);

0 comments on commit 53e884d

Please sign in to comment.