From: shreddd Date: Thu, 4 Jul 2013 04:14:22 +0000 (+1200) Subject: mean sightings as a standalone script X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=refs%2Fheads%2Ftest-kitzes-shreyas;p=swc-testing-nose.git mean sightings as a standalone script --- 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)