commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/geas/examples/python neil_methods_test.py


From: Neil Tiffin
Subject: gnue/geas/examples/python neil_methods_test.py
Date: Fri, 21 Sep 2001 11:21:13 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Neil Tiffin <address@hidden>    01/09/21 11:21:13

Modified files:
        geas/examples/python: neil_methods_test.py 

Log message:
        Add query test.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/examples/python/neil_methods_test.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gnue/geas/examples/python/neil_methods_test.py
diff -u gnue/geas/examples/python/neil_methods_test.py:1.2 
gnue/geas/examples/python/neil_methods_test.py:1.3
--- gnue/geas/examples/python/neil_methods_test.py:1.2  Thu Sep 20 18:12:42 2001
+++ gnue/geas/examples/python/neil_methods_test.py      Fri Sep 21 11:21:13 2001
@@ -3,11 +3,12 @@
 # a test file: relies on GEAS being run from gnue/geas/src
 # and this from gnue/geas/examples/python
 
-# $Id: neil_methods_test.py,v 1.2 2001/09/20 22:12:42 ntiffin Exp $
+# $Id: neil_methods_test.py,v 1.3 2001/09/21 15:21:13 ntiffin Exp $
 
 import sys
 import md5
 import time
+import whrandom
 from string import * 
 
 try:
@@ -33,7 +34,34 @@
 except GEAS.ServerError,ex:
     print "error? " + ex.detail
 
-num_loops = 100
+def zip_query(start_zip, end_zip):
+   try:
+      query = con.newQuery()
+      query.classname = "location::post_code"
+      query.orderby = "zip_code"
+      query.reverse = CORBA.FALSE
+      query.logic = GEAS.Query.AND
+      f1 = GEAS.Query.Field( field="zip_code",test=GEAS.Query.greaterthan,
+         invert=CORBA.FALSE,casesensitive=CORBA.FALSE,value=str(start_zip))
+      query.addField(f1)
+      f2 = GEAS.Query.Field( field="zip_code",test=GEAS.Query.lessthan,
+         invert=CORBA.FALSE,casesensitive=CORBA.FALSE,value=str(end_zip))
+      query.addField(f2)
+      obj_list = con.executeQuery(query)
+      query.release()
+      
+   except GEAS.ServerError,ex:
+      # TODO
+      print "ServerError: " + ex.detail
+   except GEAS.UnknownClass,ex:
+      # TODO
+      print "Unknown Class error: " + ex.detail
+   if obj_list == None:
+      return []   
+   return obj_list
+
+
+num_loops = 50
 print "neil_methods_test.py"
 print time.asctime(time.gmtime()), "UTC"
 print "loop count = %i" % num_loops
@@ -53,6 +81,8 @@
 create_and_set_time = (time_end - time_start) / x
 print "time to create object and set one field = ", "%.3f" % 
(create_and_set_time*1000), " milliseconds."
 
+print "This query test requires the zip code database be loaded into GEAS.  
Email"
+print "address@hidden if you do not have a copy of it."
 x = 0
 a = "a"
 b = "b"
@@ -68,9 +98,7 @@
             print ex.detail
         except GEAS.MethodError,ex:
             print ex.detail
-    
         obj.delete()
-    
     except GEAS.ServerError,ex:
         print ex.detail
     x = x+1
@@ -78,3 +106,28 @@
 create_and_set_method_time = (time_end - time_start) / x
 print "time to create object, set one field, and call method = ", "%.3f" % 
(create_and_set_method_time*1000), " milliseconds."
 print "time to call a method only = ", "%.3f" % ((create_and_set_method_time - 
create_and_set_time)*1000), " milliseconds."
+
+num_loops = 10
+x = 0
+num_records = 0
+total_time_start = time.time()
+while (x < num_loops):
+    start_time = time.time()
+    zip1 = whrandom.randint(10000, 99999)
+    zip2 = whrandom.randint(10000, 99999)
+    if (zip1 <= zip2):
+        result = zip_query( zip1, zip2)
+    else:
+        result = zip_query( zip2, zip1)
+    x = x+1
+    end_time = time.time()
+    query_time = end_time - start_time
+    if query_time > 60.0:
+        print "query found %i results between zip codes %i - %i, in %.3f 
minutes." % (result.length, zip1, zip2, query_time/60.0)
+    else:
+        print "query found %i results between zip codes %i - %i, in %.3f 
seconds." % (result.length, zip1, zip2, query_time)
+    num_records = num_records + result.length
+total_time_end = time.time()
+query1_time = (total_time_end - total_time_start) / num_records
+print "time to query zip file = ", "%.3f" % (query1_time), " seconds."
+print "number of items returned = %i" % num_records



reply via email to

[Prev in Thread] Current Thread [Next in Thread]