fix mean_sightings
authorshreddd <shreyas@gmail.com>
Wed, 3 Jul 2013 09:21:19 +0000 (21:21 +1200)
committerW. Trevor King <wking@tremily.us>
Fri, 8 Nov 2013 16:59:06 +0000 (08:59 -0800)
python/mean_sightings-full.py

index a76c416ce756e5caf34e3dbc00acf95c46a91004..55c51484b571ae52d4f61f6bf0891b88017d0e24 100755 (executable)
@@ -40,14 +40,17 @@ def get_sightings_loop(filename, focusanimal):
     focusanimal = focusanimal.capitalize()
 
     # Loop through all records, countings recs and animals
-    totalrecs = 0
-    totalcount = 0
+    totalrecs = 0.
+    totalcount = 0.
     for rec in tab:
         if rec['animal'] == focusanimal:
             totalrecs += 1
             totalcount += rec['count']
 
-    meancount = totalcount/totalrecs
+    if totalrecs==0:
+        meancount = 0
+    else:
+        meancount = totalcount/totalrecs
 
     # Return num of records and animals seen
     return totalrecs, meancount