From b22b30ba4415da04819e60cc20a4ff916307c9d9 Mon Sep 17 00:00:00 2001 From: shreddd Date: Thu, 4 Jul 2013 16:14:22 +1200 Subject: [PATCH] mean sightings as a standalone script --- python/testing/mean_sightings | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 python/testing/mean_sightings diff --git a/python/testing/mean_sightings b/python/testing/mean_sightings new file mode 100755 index 0000000..5863179 --- /dev/null +++ b/python/testing/mean_sightings @@ -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) -- 2.26.2