From 7eb9f5d12389df0ef7440a82df0be9bd1119847e Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 May 2013 00:22:54 +0000 Subject: Lots of changes around users --- wqflask/utility/formatting.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'wqflask/utility') diff --git a/wqflask/utility/formatting.py b/wqflask/utility/formatting.py index 52173417..e53dda22 100644 --- a/wqflask/utility/formatting.py +++ b/wqflask/utility/formatting.py @@ -10,6 +10,14 @@ def numify(number, singular=None, plural=None): >>> numify(9, 'book', 'books') 'nine books' + You can add capitalize to change the capitalization + >>> numify(9, 'book', 'books').capitalize() + 'Nine books' + + Or capitalize every word using title + >>> numify(9, 'book', 'books').title() + 'Nine Books' + >>> numify(15) '15' @@ -107,3 +115,8 @@ def commify(n): if cents: out += '.' + cents return out + + +if __name__ == '__main__': + import doctest + doctest.testmod() -- cgit v1.2.3 From 0c5e75b42fb02faa2f2735aa4e188d32b9691101 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Thu, 20 Jun 2013 21:47:59 +0000 Subject: Added file corr_result_helpers.py that includes the function that normalizes the lists of sample values --- wqflask/utility/corr_result_helpers.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 wqflask/utility/corr_result_helpers.py (limited to 'wqflask/utility') diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py new file mode 100644 index 00000000..edf32449 --- /dev/null +++ b/wqflask/utility/corr_result_helpers.py @@ -0,0 +1,30 @@ +def normalize_values(a_values, b_values): + """ + Trim two lists of values to contain only the values they both share + + Given two lists of sample values, trim each list so that it contains + only the samples that contain a value in both lists. Also returns + the number of such samples. + + >>> normalize_values([2.3, None, None, 3.2, 4.1, 5], [3.4, 7.2, 1.3, None, 6.2, 4.1]) + ([2.3, 4.1, 5], [3.4, 6.2, 4.1], 3) + + """ + + min_length = min(len(a_values), len(b_values)) + a_new = [] + b_new = [] + for counter in range(min_length): + if a_values[counter] and b_values[counter]: + a_new.append(a_values[counter]) + b_new.append(b_values[counter]) + + num_overlap = len(a_new) + assert num_overlap == len(b_new), "Lengths should be the same" + + return a_new, b_new, num_overlap + + +if __name__ == '__main__': + import doctest + doctest.testmod() \ No newline at end of file -- cgit v1.2.3