[Mapbender-commits] r9856 - in trunk/mapbender: resources/db/pgsql/UTF-8/update tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Feb 1 03:46:54 PST 2018


Author: armin11
Date: 2018-02-01 03:46:54 -0800 (Thu, 01 Feb 2018)
New Revision: 9856

Modified:
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
   trunk/mapbender/tools/mod_monitorCapabilities_main.php
Log:
Fix for storing monitor counts in integral tables

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql	2018-02-01 09:08:35 UTC (rev 9855)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql	2018-02-01 11:46:54 UTC (rev 9856)
@@ -2214,3 +2214,80 @@
 ALTER FUNCTION mb_monitor_after()
   OWNER TO postgres;
 
+-- Column: monitor_count
+
+-- ALTER TABLE mb_wfs_availability DROP COLUMN monitor_count;
+
+ALTER TABLE mb_wfs_availability ADD COLUMN monitor_count integer;
+
+-- Column: monitor_count
+
+-- ALTER TABLE mb_wms_availability DROP COLUMN monitor_count;
+
+ALTER TABLE mb_wms_availability ADD COLUMN monitor_count integer;
+
+-- Function: mb_monitor_after()
+
+-- DROP FUNCTION mb_monitor_after();
+
+CREATE OR REPLACE FUNCTION mb_monitor_after()
+  RETURNS trigger AS
+$BODY$DECLARE
+   availability_new REAL;
+   average_res_cap REAL;
+   count_monitors REAL;
+    BEGIN
+     IF TG_OP = 'UPDATE' THEN
+     	IF NEW.fkey_wms_id IS NOT NULL THEN
+     		count_monitors := count(fkey_wms_id) from mb_monitor where fkey_wms_id=NEW.fkey_wms_id;
+      		--the following should be adopted if the duration of storing is changed!!!
+      		average_res_cap := ((select average_resp_time from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors+(NEW.timestamp_end-NEW.timestamp_begin))/(count_monitors+1);
+
+     		IF NEW.status > -1 THEN --service gives caps
+      			availability_new := round(cast(((select availability from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors + 100)/(count_monitors+1) as numeric),2);
+     		ELSE --service has problems with caps
+      			availability_new := round(cast(((select availability from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors)/(count_monitors+1) as numeric),2);
+     		END IF;
+      		UPDATE mb_wms_availability SET average_resp_time=average_res_cap,last_status=NEW.status, availability=availability_new, image=NEW.image, status_comment=NEW.status_comment,upload_url=NEW.upload_url,map_url=NEW.map_url, cap_diff=NEW.cap_diff, monitor_count=count_monitors::INTEGER WHERE mb_wms_availability.fkey_wms_id=NEW.fkey_wms_id;
+	ELSE
+		IF NEW.fkey_wfs_id IS NOT NULL THEN
+			count_monitors := count(fkey_wfs_id) from mb_monitor where fkey_wfs_id=NEW.fkey_wfs_id;
+      			--the following should be adopted if the duration of storing is changed!!!
+      			average_res_cap := ((select average_resp_time from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id)*count_monitors+(NEW.timestamp_end-NEW.timestamp_begin))/(count_monitors+1);
+
+     			IF NEW.status > -1 THEN --service gives caps
+      				availability_new := round(cast(((select availability from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id)*count_monitors + 100)/(count_monitors+1) as numeric),2);
+     			ELSE --service has problems with caps
+      				availability_new := round(cast(((select availability from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id)*count_monitors)/(count_monitors+1) as numeric),2);
+     			END IF;
+      			UPDATE mb_wfs_availability SET average_resp_time=average_res_cap,last_status=NEW.status, availability=availability_new, feature_content=NEW.feature_content, status_comment=NEW.status_comment,upload_url=NEW.upload_url,feature_urls=NEW.feature_urls, cap_diff=NEW.cap_diff, monitor_count=count_monitors::INTEGER WHERE mb_wfs_availability.fkey_wfs_id=NEW.fkey_wfs_id;
+		END IF;
+	END IF;
+	RETURN NEW;
+     END IF;
+
+     IF TG_OP = 'INSERT' THEN
+	IF NEW.fkey_wms_id IS NOT NULL THEN
+		IF (select count(fkey_wms_id) from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id) > 0  THEN -- service is not new
+			UPDATE mb_wms_availability set fkey_upload_id=NEW.upload_id,last_status=NEW.status,status_comment=NEW.status_comment,upload_url=NEW.upload_url, cap_diff=NEW.cap_diff where fkey_wms_id=NEW.fkey_wms_id;
+		ELSE --service has not yet been monitored
+			INSERT INTO mb_wms_availability (fkey_upload_id,fkey_wms_id,last_status,status_comment,upload_url,map_url,cap_diff,average_resp_time,availability,monitor_count) VALUES (NEW.upload_id,NEW.fkey_wms_id,NEW.status,NEW.status_comment,NEW.upload_url::text,NEW.map_url,NEW.cap_diff,0,100,count_monitor::INTEGER);
+		END IF;
+	ELSE
+		IF NEW.fkey_wfs_id IS NOT NULL THEN
+			IF (select count(fkey_wfs_id) from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id) > 0  then -- service is not new
+				UPDATE mb_wfs_availability set fkey_upload_id=NEW.upload_id,last_status=NEW.status,status_comment=NEW.status_comment,upload_url=NEW.upload_url, cap_diff=NEW.cap_diff where fkey_wfs_id=NEW.fkey_wfs_id;
+			ELSE --service has not yet been monitored
+				INSERT INTO mb_wfs_availability (fkey_upload_id,fkey_wfs_id,last_status,status_comment,upload_url,feature_urls,cap_diff,average_resp_time,availability,monitor_count) VALUES (NEW.upload_id,NEW.fkey_wfs_id,NEW.status,NEW.status_comment,NEW.upload_url::text,NEW.feature_urls,NEW.cap_diff,0,100,count_monitor::INTEGER);
+			END IF;
+		END IF;
+	END IF;	
+	RETURN NEW;	
+     END IF;
+    END;
+$BODY$
+  LANGUAGE plpgsql VOLATILE
+  COST 100;
+ALTER FUNCTION mb_monitor_after()
+  OWNER TO postgres;
+

Modified: trunk/mapbender/tools/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_main.php	2018-02-01 09:08:35 UTC (rev 9855)
+++ trunk/mapbender/tools/mod_monitorCapabilities_main.php	2018-02-01 11:46:54 UTC (rev 9856)
@@ -131,7 +131,9 @@
 $user_id_all = $userIdArray;
 echo $br ."Count of registrating users: " . count($user_id_all) . $br;
 //$e = new mb_exception("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
-
+//delete all temporary files (.xml and .png) from last monitoring
+array_map('unlink', glob(dirname(__FILE__)."/tmp/*.xml"));
+array_map('unlink', glob(dirname(__FILE__)."/tmp/*.png"));
 // loop for serviceType
 //define service types which should be monitored
 $serviceTypes = array('WMS','WFS');
@@ -141,10 +143,6 @@
 
 $time_array = array();
 
-//delete all temporary files (.xml and .png) from last monitoring
-array_map('unlink', glob(dirname(__FILE__)."/tmp/*.xml"));
-array_map('unlink', glob(dirname(__FILE__)."/tmp/*.png"));
-
 for ($iz = 0; $iz < count($user_id_all); $iz++) {
     //$e = new mb_exception("/tools/mod_monitorCapabilities_main.php: - initialize monitoring for userid: ".$user_id_all[$iz]);
     //foreach ($serviceTypes as $serviceType) {
@@ -355,7 +353,7 @@
 }
 //set time limit (mapbender.conf)
 set_time_limit(TIME_LIMIT);
-// wait until all monitoring processes are finished
+// wait until all monitoring processes are finished - each single monitoring has the same limit!!!!
 echo "please wait " . TIME_LIMIT . " seconds for the monitoring to finish...$br";
 sleep(TIME_LIMIT);
 //when time limit has ended: begin to collect results for every registrating user



More information about the Mapbender_commits mailing list