mean sightings as a standalone script test-kitzes-shreyas
authorshreddd <shreyas@gmail.com>
Thu, 4 Jul 2013 04:14:22 +0000 (16:14 +1200)
committerW. Trevor King <wking@tremily.us>
Fri, 8 Nov 2013 16:59:07 +0000 (08:59 -0800)
python/testing/mean_sightings [new file with mode: 0755]

diff --git a/python/testing/mean_sightings b/python/testing/mean_sightings
new file mode 100755 (executable)
index 0000000..5863179
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+import matplotlib.mlab as ml
+import numpy as np
+import sys
+
+def get_sightings(filename, focusanimal):
+
+    # # Load table
+    # tab = ml.csv2rec(filename)
+
+    # focusanimal = focusanimal.capitalize()
+
+    # # Find number of records and total count of animals seen
+    # isfocus = (tab['animal'] == focusanimal)
+    # totalrecs = np.sum(isfocus)
+    # if totalrecs == 0:
+    #     meancount = 0
+    # else:
+    #     meancount = np.mean(tab['count'][isfocus])
+
+    # # Return num of records and animals seen
+    # return totalrecs, meancount
+
+
+    # Load table
+    tab = ml.csv2rec(filename)
+
+
+    # Loop through all records, countings recs and animals
+    totalrecs = 0.
+    totalcount = 0.
+    focusanimal = focusanimal.capitalize()
+
+    for rec in tab:
+        if rec['animal'] == focusanimal:
+            totalrecs += 1
+            totalcount += rec['count']
+
+    if totalrecs == 0:
+        meancount = 0
+    else:
+        meancount = totalcount/totalrecs
+    # Return num of records and animals seen
+    return totalrecs, meancount
+
+
+filename = sys.argv[1]
+animal = sys.argv[2]
+
+print get_sightings(filename, animal)