[GRASS-SVN] r60019 - grass/branches/releasebranch_7_0/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 1 12:27:07 PDT 2014


Author: martinl
Date: 2014-05-01 12:27:07 -0700 (Thu, 01 May 2014)
New Revision: 60019

Modified:
   grass/branches/releasebranch_7_0/lib/python/temporal/abstract_space_time_dataset.py
   grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py
Log:
Fix for #2264 and #2264
    (merge r59916 from trunk)


Modified: grass/branches/releasebranch_7_0/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/abstract_space_time_dataset.py	2014-05-01 19:18:28 UTC (rev 60018)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/abstract_space_time_dataset.py	2014-05-01 19:27:07 UTC (rev 60019)
@@ -14,6 +14,7 @@
 @author Soeren Gebbert
 """
 import sys
+import uuid
 from abstract_dataset import *
 from temporal_granularity import *
 from spatio_temporal_relationships import *
@@ -44,18 +45,19 @@
         """!Create the name of the map register table of this space time
             dataset
 
-            The name, mapset and the map type are used to create the table name
+            A uuid and the map type are used to create the table name
 
             ATTENTION: It must be assured that the base object has selected its
             content from the database.
 
             @return The name of the map register table
         """
+        
+        uuid_rand = str(uuid.uuid4()).replace("-",  "")
+        
+        table_name = self.get_new_map_instance(None).get_type() + "_map_register_" + uuid_rand
+        return table_name
 
-        return self.base.get_name() + "_" + \
-                self.base.get_mapset() + "_" + \
-                self.get_new_map_instance(None).get_type() + "_register"
-
     @abstractmethod
     def get_new_map_instance(self, ident=None):
         """!Return a new instance of a map which is associated
@@ -343,12 +345,9 @@
             sql = open(os.path.join(sql_path,
                                     "stds_map_register_table_template.sql"),
                                     'r').read()
-            map_type = self.get_new_map_instance(None).get_type()
-            stds_name = self.get_name() + "_" + self.get_mapset()
 
             # Create a raster, raster3d or vector tables
-            sql = sql.replace("GRASS_MAP", map_type)
-            sql = sql.replace("SPACETIME_NAME", stds_name)
+            sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
             statement += sql
 
             if dbif.dbmi.__name__ == "sqlite3":
@@ -2123,7 +2122,6 @@
             sql = "INSERT INTO " + stds_register_table + \
                 " (id) " + "VALUES (%s);\n"
 
-
         statement += dbif.mogrify_sql_statement((sql, (map_id,)))
 
         # Now execute the insert transaction
@@ -2230,7 +2228,7 @@
         self.msgr.verbose(_("Update metadata, spatial and temporal extent from "
                        "all registered maps of <%s>") % (self.get_id()))
 
-        # Nothing to do if the register is not present
+        # Nothing to do if the map register is not present
         if not self.get_map_register():
             return
 
@@ -2244,6 +2242,7 @@
         stds_name = self.base.get_name()
         stds_mapset = self.base.get_mapset()
         sql_path = get_sql_template_path()
+        stds_register_table = self.get_map_register()
 
         #We create a transaction
         sql_script = ""
@@ -2255,7 +2254,7 @@
                    'r').read()
         sql = sql.replace(
             "GRASS_MAP", self.get_new_map_instance(None).get_type())
-        sql = sql.replace("SPACETIME_NAME", stds_name + "_" + stds_mapset)
+        sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
         sql = sql.replace("SPACETIME_ID", self.base.get_id())
         sql = sql.replace("STDS", self.get_type())
 
@@ -2265,11 +2264,8 @@
         # Update type specific metadata
         sql = open(os.path.join(sql_path, "update_" +
             self.get_type() + "_metadata_template.sql"), 'r').read()
-        sql = sql.replace(
-            "GRASS_MAP", self.get_new_map_instance(None).get_type())
-        sql = sql.replace("SPACETIME_NAME", stds_name + "_" + stds_mapset)
+        sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
         sql = sql.replace("SPACETIME_ID", self.base.get_id())
-        sql = sql.replace("STDS", self.get_type())
 
         sql_script += sql
         sql_script += "\n"
@@ -2293,19 +2289,17 @@
             if self.is_time_absolute():
                 sql = """SELECT max(start_time) FROM GRASS_MAP_absolute_time
                          WHERE GRASS_MAP_absolute_time.id IN
-                        (SELECT id FROM SPACETIME_NAME_GRASS_MAP_register);"""
+                        (SELECT id FROM SPACETIME_REGISTER_TABLE);"""
                 sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
                     None).get_type())
-                sql = sql.replace("SPACETIME_NAME",
-                    stds_name + "_" + stds_mapset)
+                sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
             else:
                 sql = """SELECT max(start_time) FROM GRASS_MAP_relative_time
                          WHERE GRASS_MAP_relative_time.id IN
-                        (SELECT id FROM SPACETIME_NAME_GRASS_MAP_register);"""
+                        (SELECT id FROM SPACETIME_REGISTER_TABLE);"""
                 sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
                     None).get_type())
-                sql = sql.replace("SPACETIME_NAME",
-                    stds_name + "_" + stds_mapset)
+                sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
 
             dbif.cursor.execute(sql)
             row = dbif.cursor.fetchone()
@@ -2337,24 +2331,22 @@
                 sql = """UPDATE STDS_absolute_time SET end_time =
                (SELECT max(start_time) FROM GRASS_MAP_absolute_time WHERE
                GRASS_MAP_absolute_time.id IN
-                        (SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
+                        (SELECT id FROM SPACETIME_REGISTER_TABLE)
                ) WHERE id = 'SPACETIME_ID';"""
                 sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
                     None).get_type())
-                sql = sql.replace("SPACETIME_NAME",
-                    stds_name + "_" + stds_mapset)
+                sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
                 sql = sql.replace("SPACETIME_ID", self.base.get_id())
                 sql = sql.replace("STDS", self.get_type())
             elif self.is_time_relative():
                 sql = """UPDATE STDS_relative_time SET end_time =
                (SELECT max(start_time) FROM GRASS_MAP_relative_time WHERE
                GRASS_MAP_relative_time.id IN
-                        (SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
+                        (SELECT id FROM SPACETIME_REGISTER_TABLE)
                ) WHERE id = 'SPACETIME_ID';"""
                 sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
                     None).get_type())
-                sql = sql.replace("SPACETIME_NAME",
-                    stds_name + "_" + stds_mapset)
+                sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
                 sql = sql.replace("SPACETIME_ID", self.base.get_id())
                 sql = sql.replace("STDS", self.get_type())
 

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py	2014-05-01 19:18:28 UTC (rev 60018)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/univar_statistics.py	2014-05-01 19:27:07 UTC (rev 60019)
@@ -82,6 +82,13 @@
         elif type == "str3ds":
             stats = core.parse_command("r3.univar", map=id, flags=flag)
 
+        if not stats:
+            if type == "strds":
+                core.warning(_("Unable to get statistics for raster map <%s>") % id)
+            elif type == "str3ds":
+                core.warning(_("Unable to get statistics for 3d raster map <%s>") % id)
+            continue
+        
         string += str(id) + fs + str(start) + fs + str(end)
         string += fs + str(stats["mean"]) + fs + str(stats["min"])
         string += fs + str(stats["max"]) + fs + str(stats["mean_of_abs"])
@@ -178,40 +185,44 @@
                                    type=type, flags=flags)
 
         string = ""
-        if stats:
-            string += str(id) + fs + str(start) + fs + str(end)
-            string += fs + str(stats["n"]) + fs + str(stats[
-                "nmissing"]) + fs + str(stats["nnull"])
-            if "min" in stats:
-                string += fs + str(stats["min"]) + fs + str(
-                    stats["max"]) + fs + str(stats["range"])
-            else:
-                string += fs + fs + fs
 
-            if type == "point" or type == "centroid":
-                if "mean" in stats:
-                    string += fs + str(stats["mean"]) + fs + \
-                    str(stats["mean_abs"]) + fs + \
-                    str(stats["population_stddev"]) + fs + \
-                    str(stats["population_variance"])
+        if not stats:
+            core.warning(_("Unable to get statistics for vector map <%s>") % id)
+            continue
+        
+        string += str(id) + fs + str(start) + fs + str(end)
+        string += fs + str(stats["n"]) + fs + str(stats[
+            "nmissing"]) + fs + str(stats["nnull"])
+        if "min" in stats:
+            string += fs + str(stats["min"]) + fs + str(
+                stats["max"]) + fs + str(stats["range"])
+        else:
+            string += fs + fs + fs
 
-                    string += fs + str(stats["population_coeff_variation"]) + \
-                    fs + str(stats["sample_stddev"]) + fs + \
-                    str(stats["sample_variance"])
+        if type == "point" or type == "centroid":
+            if "mean" in stats:
+                string += fs + str(stats["mean"]) + fs + \
+                str(stats["mean_abs"]) + fs + \
+                str(stats["population_stddev"]) + fs + \
+                str(stats["population_variance"])
 
-                    string += fs + str(stats["kurtosis"]) + fs + \
-                    str(stats["skewness"])
+                string += fs + str(stats["population_coeff_variation"]) + \
+                fs + str(stats["sample_stddev"]) + fs + \
+                str(stats["sample_variance"])
+
+                string += fs + str(stats["kurtosis"]) + fs + \
+                str(stats["skewness"])
+            else:
+                string += fs + fs + fs + fs + fs + fs + fs + fs + fs
+            if extended == True:
+                if "first_quartile" in stats:
+                    string += fs + str(stats["first_quartile"]) + fs + \
+                    str(stats["median"]) + fs + \
+                    str(stats["third_quartile"]) + fs + \
+                    str(stats["percentile_90"])
                 else:
-                    string += fs + fs + fs + fs + fs + fs + fs + fs + fs
-                if extended == True:
-                    if "first_quartile" in stats:
-                        string += fs + str(stats["first_quartile"]) + fs + \
-                        str(stats["median"]) + fs + \
-                        str(stats["third_quartile"]) + fs + \
-                        str(stats["percentile_90"])
-                    else:
-                        string += fs + fs + fs + fs
+                    string += fs + fs + fs + fs
 
-            print string
+        print string
 
     dbif.close()



More information about the grass-commit mailing list