Anonymous avatar Anonymous committed 29cfa10

Updated to support the newest iteration of the CSV file format from Horizon Marine.

Comments (0)

Files changed (1)

maproomlib/plugin/Buoy_loader.py

     color = Line_point_layer.DEFAULT_COLORS[
         Line_point_layer.next_default_color_index
     ]
+    Line_point_layer.next_default_color_index = (
+        Line_point_layer.next_default_color_index + 1
+    ) % len( Line_point_layer.DEFAULT_COLORS )
     buoy_number_header = None
+    previous_timestamp = None
 
     for data in reader:
+        # Skip comments and blank lines.
+        if not data or data[ 0 ].startswith( "# " ): continue
+
         if len( data ) < 5:
             raise RuntimeError(
                 "The buoy file %s is invalid." % filename,
 
         if buoy_number_header is None:
             buoy_number_header = data[ 0 ]
-            if buoy_number_header not in ( "BuoyNum", "FHD" ):
+            if buoy_number_header not in ( "BuoyNum", "FHD", "#FHD_ID" ):
                 raise RuntimeError(
                     "The buoy file %s is invalid." % filename,
                 )
             continue
 
-        if buoy_number_header == "FHD":
+        if "FHD" in buoy_number_header:
             ( buoy_number, datestamp, timestamp, latitude, longitude ) = data[ 0: 5 ]
             timestamp = "%s %s" % ( datestamp, timestamp )
         else:
             color = Line_point_layer.DEFAULT_COLORS[
                 Line_point_layer.next_default_color_index
             ]
+            Line_point_layer.next_default_color_index = (
+                Line_point_layer.next_default_color_index + 1
+            ) % len( Line_point_layer.DEFAULT_COLORS )
+            labels.pop()
+            labels.append( previous_timestamp )
+            labels.append( timestamp )
+        elif last_buoy_number is None:
+            last_buoy_number = buoy_number
+            labels.append( timestamp )
+        else:
+            labels.append( None )
 
         latitude = float( latitude )
         longitude = float( longitude )
 
-        # Abuse the depth field by putting a timestamp in it. And only add
-        # every nth label so the map is actually readable.
-        if point_index == 0:
-            labels.append( timestamp )
-        else:
-            labels.append( None )
-
         lower_left = (
             longitude if lower_left[ 0 ] is None \
                       else min( longitude, lower_left[ 0 ] ),
         point_data.append( ( longitude, latitude, np.nan, color ) )
         line_data.append( ( point_index, point_index + 1, 0, color ) )
 
+        previous_timestamp = timestamp
         point_index += 1
 
     labels.pop()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.