We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Show how many total fundees and the donation amount they're in for.
As a reciever of money I'd like to know how diversified my $13/wk is so that I know how volatile my income is likely to be.

How I see this working is a Histogram similar to:

 $1 [---]  1
 $3 []
 $6 []
$12 [---]  1
$24 []

which shows that I have 2 funders, one in for $1 and one in for $12.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gittip/__init__.py`
Content:
```
1 import datetime
2 import locale
3 import os
4 from decimal import Decimal
5 
6 
7 try:  # XXX This can't be right.
8     locale.setlocale(locale.LC_ALL, "en_US.utf8")
9 except locale.Error:
10     locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
11 
12 
13 BIRTHDAY = datetime.date(2012, 6, 1)
14 CARDINALS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
15 MONTHS = [None, 'January', 'February', 'March', 'April', 'May', 'June', 'July',
16           'August', 'September', 'October', 'November', 'December']
17 
18 def age():
19     today = datetime.date.today()
20     nmonths = today.month - BIRTHDAY.month
21     plural = 's' if nmonths != 1 else ''
22     if nmonths < 10:
23         nmonths = CARDINALS[nmonths]
24     else:
25         nmonths = str(nmonths)
26     return "%s month%s" % (nmonths, plural)
27 
28 
29 db = None # This global is wired in wireup. It's an instance of
30           # gittip.postgres.PostgresManager.
31 
32 # Not sure we won't want this for something yet. Prune if you don't find it in
33 # the codebase in a month.
34 OLD_OLD_AMOUNTS= [Decimal(a) for a in ('0.00', '0.08', '0.16', '0.32', '0.64', '1.28')]
35 OLD_AMOUNTS= [Decimal(a) for a in ('0.25',)]
36 
37 AMOUNTS= [Decimal(a) for a in ('0.00', '1.00', '3.00', '6.00', '12.00', '24.00')]
38 
39 
40 __version__ = "~~VERSION~~"
41 
42 
43 def get_tip(tipper, tippee):
44     """Given two user ids, return a Decimal.
45     """
46     TIP = """\
47 
48         SELECT amount
49           FROM tips
50          WHERE tipper=%s
51            AND tippee=%s
52       ORDER BY mtime DESC
53          LIMIT 1
54 
55     """
56     rec = db.fetchone(TIP, (tipper, tippee))
57     if rec is None:
58         tip = Decimal(0.00)
59     else:
60         tip = rec['amount']
61     return tip
62 
63 
64 def get_backed_amount(participant_id):
65     """Given a unicode, return a Decimal.
66     """
67 
68     BACKED = """\
69 
70         SELECT sum(amount) AS backed
71           FROM ( SELECT DISTINCT ON (tipper)
72                         amount
73                       , tipper
74                    FROM tips
75                    JOIN participants p ON p.id = tipper
76                   WHERE tippee=%s
77                     AND last_bill_result = ''
78                ORDER BY tipper
79                       , mtime DESC
80                 ) AS foo
81 
82     """
83     rec = db.fetchone(BACKED, (participant_id,))
84     if rec is None:
85         amount = None
86     else:
87         amount = rec['backed']  # might be None
88 
89     if amount is None:
90         amount = Decimal(0.00)
91 
92     return amount
93 
94 
95 def get_number_of_backers(participant_id):
96     """Given a unicode, return an int.
97     """
98 
99     BACKED = """\
100 
101         SELECT count(amount) AS nbackers
102           FROM ( SELECT DISTINCT ON (tipper)
103                         amount
104                       , tipper
105                    FROM tips
106                    JOIN participants p ON p.id = tipper
107                   WHERE tippee=%s
108                     AND last_bill_result = ''
109                ORDER BY tipper
110                       , mtime DESC
111                 ) AS foo
112          WHERE amount > 0
113 
114     """
115     rec = db.fetchone(BACKED, (participant_id,))
116     if rec is None:
117         nbackers = None
118     else:
119         nbackers = rec['nbackers']  # might be None
120 
121     if nbackers is None:
122         nbackers = 0
123 
124     return nbackers
125 
126 
127 def get_tips_and_total(tipper, for_payday=False, db=None):
128     """Given a participant id and a date, return a list and a Decimal.
129 
130     This function is used to populate a participant's page for their own
131     viewing pleasure, and also by the payday function. If for_payday is not
132     False it must be a date object.
133 
134     A half-injected dependency, that's what db is.
135 
136     """
137     if db is None:
138         from gittip import db
139 
140     if for_payday:
141 
142         # For payday we want the oldest relationship to be paid first.
143         order_by = "ctime ASC"
144 
145 
146         # This is where it gets crash-proof.
147         # ==================================
148         # We need to account for the fact that we may have crashed during
149         # Payday and we're re-running that function. We only want to select
150         # tips that existed before Payday started, but haven't been processed
151         # as part of this Payday yet.
152         #
153         # It's a bug if the paydays subselect returns > 1 rows.
154         #
155         # XXX If we crash during Payday and we rerun it after a timezone
156         # change, will we get burned? How?
157 
158         ts_filter = """\
159 
160                AND mtime < %s
161                AND ( SELECT id
162                        FROM transfers
163                       WHERE tipper=t.tipper
164                         AND tippee=t.tippee
165                         AND timestamp >= %s
166                     ) IS NULL
167 
168         """
169         args = (tipper, for_payday, for_payday)
170     else:
171         order_by = "amount DESC"
172         ts_filter = ""
173         args = (tipper,)
174 
175     TIPS = """\
176 
177         SELECT * FROM (
178             SELECT DISTINCT ON (tippee)
179                    amount
180                  , tippee
181                  , t.ctime
182                  , p.claimed_time
183               FROM tips t
184               JOIN participants p ON p.id = t.tippee
185              WHERE tipper = %%s
186                %s
187           ORDER BY tippee
188                  , t.mtime DESC
189         ) AS foo
190         ORDER BY %s
191                , tippee
192 
193     """ % (ts_filter, order_by)  # XXX, No injections here, right?!
194     tips = list(db.fetchall(TIPS, args))
195 
196 
197     # Compute the total.
198     # ==================
199     # For payday we only want to process payments to tippees who have
200     # themselves opted into Gittip. For the tipper's profile page we want to
201     # show the total amount they've pledged (so they're not surprised when
202     # someone *does* start accepting tips and all of a sudden they're hit with
203     # bigger charges.
204 
205     if for_payday:
206         to_total = [t for t in tips if t['claimed_time'] is not None]
207     else:
208         to_total = tips
209     total = sum([t['amount'] for t in to_total])
210 
211     if not total:
212         # If to_total is an empty list then total is int 0. We want a Decimal.
213         total = Decimal('0.00')
214 
215     return tips, total
216 
217 
218 # canonizer
219 # =========
220 # This is an Aspen hook to ensure that requests are served on a certain root
221 # URL, even if multiple domains point to the application.
222 
223 class X: pass
224 canonical_scheme = None
225 canonical_host = None
226 
227 def canonize(request):
228     """Enforce a certain scheme and hostname. Store these on request as well.
229     """
230     scheme = request.headers.get('X-Forwarded-Proto', 'http') # per Heroku
231     host = request.headers['Host']
232     bad_scheme = scheme != canonical_scheme
233     bad_host = bool(canonical_host) and (host != canonical_host)
234                 # '' and False => ''
235     if bad_scheme or bad_host:
236         url = '%s://%s' % (canonical_scheme, canonical_host)
237         if request.line.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
238             # Redirect to a particular path for idempotent methods.
239             url += request.line.uri.path.raw
240             if request.line.uri.querystring:
241                 url += '?' + request.line.uri.querystring.raw
242         else:
243             # For non-idempotent methods, redirect to homepage.
244             url += '/'
245         request.redirect(url, permanent=True)
246 
247 
248 def configure_payments(request):
249     # Work-around for https://github.com/balanced/balanced-python/issues/5
250     import balanced
251     balanced.configure(os.environ['BALANCED_API_SECRET'])
252
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gittip/__init__.py b/gittip/__init__.py
--- a/gittip/__init__.py
+++ b/gittip/__init__.py
@@ -215,6 +215,17 @@
     return tips, total
 
 
+def get_histogram_of_giving(user):
+    SQL = """
+    SELECT amount, count(amount) num_contributing FROM tips t WHERE
+    tippee=%s GROUP BY (amount)
+    """
+    results = dict()
+    for amount_dict in db.fetchall(SQL, (user,)):
+        results[amount_dict['amount']] = amount_dict['num_contributing']
+    return results
+
+
 # canonizer
 # =========
 # This is an Aspen hook to ensure that requests are served on a certain root

{"golden_diff": "diff --git a/gittip/__init__.py b/gittip/__init__.py\n--- a/gittip/__init__.py\n+++ b/gittip/__init__.py\n@@ -215,6 +215,17 @@\n     return tips, total\n \n \n+def get_histogram_of_giving(user):\n+    SQL = \"\"\"\n+    SELECT amount, count(amount) num_contributing FROM tips t WHERE\n+    tippee=%s GROUP BY (amount)\n+    \"\"\"\n+    results = dict()\n+    for amount_dict in db.fetchall(SQL, (user,)):\n+        results[amount_dict['amount']] = amount_dict['num_contributing']\n+    return results\n+\n+\n # canonizer\n # =========\n # This is an Aspen hook to ensure that requests are served on a certain root\n", "issue": "Show how many total fundees and the donation amount they're in for.\nAs a reciever of money I'd like to know how diversified my $13/wk is so that I know how volatile my income is likely to be.\n\nHow I see this working is a Histogram similar to:\n\n $1 [---]  1\n $3 []\n $6 []\n$12 [---]  1\n$24 []\n\nwhich shows that I have 2 funders, one in for $1 and one in for $12.\n\n", "before_files": [{"content": "import datetime\nimport locale\nimport os\nfrom decimal import Decimal\n\n\ntry:  # XXX This can't be right.\n    locale.setlocale(locale.LC_ALL, \"en_US.utf8\")\nexcept locale.Error:\n    locale.setlocale(locale.LC_ALL, \"en_US.UTF-8\")\n\n\nBIRTHDAY = datetime.date(2012, 6, 1)\nCARDINALS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']\nMONTHS = [None, 'January', 'February', 'March', 'April', 'May', 'June', 'July',\n          'August', 'September', 'October', 'November', 'December']\n\ndef age():\n    today = datetime.date.today()\n    nmonths = today.month - BIRTHDAY.month\n    plural = 's' if nmonths != 1 else ''\n    if nmonths < 10:\n        nmonths = CARDINALS[nmonths]\n    else:\n        nmonths = str(nmonths)\n    return \"%s month%s\" % (nmonths, plural)\n\n\ndb = None # This global is wired in wireup. It's an instance of\n          # gittip.postgres.PostgresManager.\n\n# Not sure we won't want this for something yet. Prune if you don't find it in\n# the codebase in a month.\nOLD_OLD_AMOUNTS= [Decimal(a) for a in ('0.00', '0.08', '0.16', '0.32', '0.64', '1.28')]\nOLD_AMOUNTS= [Decimal(a) for a in ('0.25',)]\n\nAMOUNTS= [Decimal(a) for a in ('0.00', '1.00', '3.00', '6.00', '12.00', '24.00')]\n\n\n__version__ = \"~~VERSION~~\"\n\n\ndef get_tip(tipper, tippee):\n    \"\"\"Given two user ids, return a Decimal.\n    \"\"\"\n    TIP = \"\"\"\\\n\n        SELECT amount\n          FROM tips\n         WHERE tipper=%s\n           AND tippee=%s\n      ORDER BY mtime DESC\n         LIMIT 1\n\n    \"\"\"\n    rec = db.fetchone(TIP, (tipper, tippee))\n    if rec is None:\n        tip = Decimal(0.00)\n    else:\n        tip = rec['amount']\n    return tip\n\n\ndef get_backed_amount(participant_id):\n    \"\"\"Given a unicode, return a Decimal.\n    \"\"\"\n\n    BACKED = \"\"\"\\\n\n        SELECT sum(amount) AS backed\n          FROM ( SELECT DISTINCT ON (tipper)\n                        amount\n                      , tipper\n                   FROM tips\n                   JOIN participants p ON p.id = tipper\n                  WHERE tippee=%s\n                    AND last_bill_result = ''\n               ORDER BY tipper\n                      , mtime DESC\n                ) AS foo\n\n    \"\"\"\n    rec = db.fetchone(BACKED, (participant_id,))\n    if rec is None:\n        amount = None\n    else:\n        amount = rec['backed']  # might be None\n\n    if amount is None:\n        amount = Decimal(0.00)\n\n    return amount\n\n\ndef get_number_of_backers(participant_id):\n    \"\"\"Given a unicode, return an int.\n    \"\"\"\n\n    BACKED = \"\"\"\\\n\n        SELECT count(amount) AS nbackers\n          FROM ( SELECT DISTINCT ON (tipper)\n                        amount\n                      , tipper\n                   FROM tips\n                   JOIN participants p ON p.id = tipper\n                  WHERE tippee=%s\n                    AND last_bill_result = ''\n               ORDER BY tipper\n                      , mtime DESC\n                ) AS foo\n         WHERE amount > 0\n\n    \"\"\"\n    rec = db.fetchone(BACKED, (participant_id,))\n    if rec is None:\n        nbackers = None\n    else:\n        nbackers = rec['nbackers']  # might be None\n\n    if nbackers is None:\n        nbackers = 0\n\n    return nbackers\n\n\ndef get_tips_and_total(tipper, for_payday=False, db=None):\n    \"\"\"Given a participant id and a date, return a list and a Decimal.\n\n    This function is used to populate a participant's page for their own\n    viewing pleasure, and also by the payday function. If for_payday is not\n    False it must be a date object.\n\n    A half-injected dependency, that's what db is.\n\n    \"\"\"\n    if db is None:\n        from gittip import db\n\n    if for_payday:\n\n        # For payday we want the oldest relationship to be paid first.\n        order_by = \"ctime ASC\"\n\n\n        # This is where it gets crash-proof.\n        # ==================================\n        # We need to account for the fact that we may have crashed during\n        # Payday and we're re-running that function. We only want to select\n        # tips that existed before Payday started, but haven't been processed\n        # as part of this Payday yet.\n        #\n        # It's a bug if the paydays subselect returns > 1 rows.\n        #\n        # XXX If we crash during Payday and we rerun it after a timezone\n        # change, will we get burned? How?\n\n        ts_filter = \"\"\"\\\n\n               AND mtime < %s\n               AND ( SELECT id\n                       FROM transfers\n                      WHERE tipper=t.tipper\n                        AND tippee=t.tippee\n                        AND timestamp >= %s\n                    ) IS NULL\n\n        \"\"\"\n        args = (tipper, for_payday, for_payday)\n    else:\n        order_by = \"amount DESC\"\n        ts_filter = \"\"\n        args = (tipper,)\n\n    TIPS = \"\"\"\\\n\n        SELECT * FROM (\n            SELECT DISTINCT ON (tippee)\n                   amount\n                 , tippee\n                 , t.ctime\n                 , p.claimed_time\n              FROM tips t\n              JOIN participants p ON p.id = t.tippee\n             WHERE tipper = %%s\n               %s\n          ORDER BY tippee\n                 , t.mtime DESC\n        ) AS foo\n        ORDER BY %s\n               , tippee\n\n    \"\"\" % (ts_filter, order_by)  # XXX, No injections here, right?!\n    tips = list(db.fetchall(TIPS, args))\n\n\n    # Compute the total.\n    # ==================\n    # For payday we only want to process payments to tippees who have\n    # themselves opted into Gittip. For the tipper's profile page we want to\n    # show the total amount they've pledged (so they're not surprised when\n    # someone *does* start accepting tips and all of a sudden they're hit with\n    # bigger charges.\n\n    if for_payday:\n        to_total = [t for t in tips if t['claimed_time'] is not None]\n    else:\n        to_total = tips\n    total = sum([t['amount'] for t in to_total])\n\n    if not total:\n        # If to_total is an empty list then total is int 0. We want a Decimal.\n        total = Decimal('0.00')\n\n    return tips, total\n\n\n# canonizer\n# =========\n# This is an Aspen hook to ensure that requests are served on a certain root\n# URL, even if multiple domains point to the application.\n\nclass X: pass\ncanonical_scheme = None\ncanonical_host = None\n\ndef canonize(request):\n    \"\"\"Enforce a certain scheme and hostname. Store these on request as well.\n    \"\"\"\n    scheme = request.headers.get('X-Forwarded-Proto', 'http') # per Heroku\n    host = request.headers['Host']\n    bad_scheme = scheme != canonical_scheme\n    bad_host = bool(canonical_host) and (host != canonical_host)\n                # '' and False => ''\n    if bad_scheme or bad_host:\n        url = '%s://%s' % (canonical_scheme, canonical_host)\n        if request.line.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):\n            # Redirect to a particular path for idempotent methods.\n            url += request.line.uri.path.raw\n            if request.line.uri.querystring:\n                url += '?' + request.line.uri.querystring.raw\n        else:\n            # For non-idempotent methods, redirect to homepage.\n            url += '/'\n        request.redirect(url, permanent=True)\n\n\ndef configure_payments(request):\n    # Work-around for https://github.com/balanced/balanced-python/issues/5\n    import balanced\n    balanced.configure(os.environ['BALANCED_API_SECRET'])\n", "path": "gittip/__init__.py"}], "after_files": [{"content": "import datetime\nimport locale\nimport os\nfrom decimal import Decimal\n\n\ntry:  # XXX This can't be right.\n    locale.setlocale(locale.LC_ALL, \"en_US.utf8\")\nexcept locale.Error:\n    locale.setlocale(locale.LC_ALL, \"en_US.UTF-8\")\n\n\nBIRTHDAY = datetime.date(2012, 6, 1)\nCARDINALS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']\nMONTHS = [None, 'January', 'February', 'March', 'April', 'May', 'June', 'July',\n          'August', 'September', 'October', 'November', 'December']\n\ndef age():\n    today = datetime.date.today()\n    nmonths = today.month - BIRTHDAY.month\n    plural = 's' if nmonths != 1 else ''\n    if nmonths < 10:\n        nmonths = CARDINALS[nmonths]\n    else:\n        nmonths = str(nmonths)\n    return \"%s month%s\" % (nmonths, plural)\n\n\ndb = None # This global is wired in wireup. It's an instance of\n          # gittip.postgres.PostgresManager.\n\n# Not sure we won't want this for something yet. Prune if you don't find it in\n# the codebase in a month.\nOLD_OLD_AMOUNTS= [Decimal(a) for a in ('0.00', '0.08', '0.16', '0.32', '0.64', '1.28')]\nOLD_AMOUNTS= [Decimal(a) for a in ('0.25',)]\n\nAMOUNTS= [Decimal(a) for a in ('0.00', '1.00', '3.00', '6.00', '12.00', '24.00')]\n\n\n__version__ = \"~~VERSION~~\"\n\n\ndef get_tip(tipper, tippee):\n    \"\"\"Given two user ids, return a Decimal.\n    \"\"\"\n    TIP = \"\"\"\\\n\n        SELECT amount\n          FROM tips\n         WHERE tipper=%s\n           AND tippee=%s\n      ORDER BY mtime DESC\n         LIMIT 1\n\n    \"\"\"\n    rec = db.fetchone(TIP, (tipper, tippee))\n    if rec is None:\n        tip = Decimal(0.00)\n    else:\n        tip = rec['amount']\n    return tip\n\n\ndef get_backed_amount(participant_id):\n    \"\"\"Given a unicode, return a Decimal.\n    \"\"\"\n\n    BACKED = \"\"\"\\\n\n        SELECT sum(amount) AS backed\n          FROM ( SELECT DISTINCT ON (tipper)\n                        amount\n                      , tipper\n                   FROM tips\n                   JOIN participants p ON p.id = tipper\n                  WHERE tippee=%s\n                    AND last_bill_result = ''\n               ORDER BY tipper\n                      , mtime DESC\n                ) AS foo\n\n    \"\"\"\n    rec = db.fetchone(BACKED, (participant_id,))\n    if rec is None:\n        amount = None\n    else:\n        amount = rec['backed']  # might be None\n\n    if amount is None:\n        amount = Decimal(0.00)\n\n    return amount\n\n\ndef get_number_of_backers(participant_id):\n    \"\"\"Given a unicode, return an int.\n    \"\"\"\n\n    BACKED = \"\"\"\\\n\n        SELECT count(amount) AS nbackers\n          FROM ( SELECT DISTINCT ON (tipper)\n                        amount\n                      , tipper\n                   FROM tips\n                   JOIN participants p ON p.id = tipper\n                  WHERE tippee=%s\n                    AND last_bill_result = ''\n               ORDER BY tipper\n                      , mtime DESC\n                ) AS foo\n         WHERE amount > 0\n\n    \"\"\"\n    rec = db.fetchone(BACKED, (participant_id,))\n    if rec is None:\n        nbackers = None\n    else:\n        nbackers = rec['nbackers']  # might be None\n\n    if nbackers is None:\n        nbackers = 0\n\n    return nbackers\n\n\ndef get_tips_and_total(tipper, for_payday=False, db=None):\n    \"\"\"Given a participant id and a date, return a list and a Decimal.\n\n    This function is used to populate a participant's page for their own\n    viewing pleasure, and also by the payday function. If for_payday is not\n    False it must be a date object.\n\n    A half-injected dependency, that's what db is.\n\n    \"\"\"\n    if db is None:\n        from gittip import db\n\n    if for_payday:\n\n        # For payday we want the oldest relationship to be paid first.\n        order_by = \"ctime ASC\"\n\n\n        # This is where it gets crash-proof.\n        # ==================================\n        # We need to account for the fact that we may have crashed during\n        # Payday and we're re-running that function. We only want to select\n        # tips that existed before Payday started, but haven't been processed\n        # as part of this Payday yet.\n        #\n        # It's a bug if the paydays subselect returns > 1 rows.\n        #\n        # XXX If we crash during Payday and we rerun it after a timezone\n        # change, will we get burned? How?\n\n        ts_filter = \"\"\"\\\n\n               AND mtime < %s\n               AND ( SELECT id\n                       FROM transfers\n                      WHERE tipper=t.tipper\n                        AND tippee=t.tippee\n                        AND timestamp >= %s\n                    ) IS NULL\n\n        \"\"\"\n        args = (tipper, for_payday, for_payday)\n    else:\n        order_by = \"amount DESC\"\n        ts_filter = \"\"\n        args = (tipper,)\n\n    TIPS = \"\"\"\\\n\n        SELECT * FROM (\n            SELECT DISTINCT ON (tippee)\n                   amount\n                 , tippee\n                 , t.ctime\n                 , p.claimed_time\n              FROM tips t\n              JOIN participants p ON p.id = t.tippee\n             WHERE tipper = %%s\n               %s\n          ORDER BY tippee\n                 , t.mtime DESC\n        ) AS foo\n        ORDER BY %s\n               , tippee\n\n    \"\"\" % (ts_filter, order_by)  # XXX, No injections here, right?!\n    tips = list(db.fetchall(TIPS, args))\n\n\n    # Compute the total.\n    # ==================\n    # For payday we only want to process payments to tippees who have\n    # themselves opted into Gittip. For the tipper's profile page we want to\n    # show the total amount they've pledged (so they're not surprised when\n    # someone *does* start accepting tips and all of a sudden they're hit with\n    # bigger charges.\n\n    if for_payday:\n        to_total = [t for t in tips if t['claimed_time'] is not None]\n    else:\n        to_total = tips\n    total = sum([t['amount'] for t in to_total])\n\n    if not total:\n        # If to_total is an empty list then total is int 0. We want a Decimal.\n        total = Decimal('0.00')\n\n    return tips, total\n\n\ndef get_histogram_of_giving(user):\n    SQL = \"\"\"\n    SELECT amount, count(amount) num_contributing FROM tips t WHERE\n    tippee=%s GROUP BY (amount)\n    \"\"\"\n    results = dict()\n    for amount_dict in db.fetchall(SQL, (user,)):\n        results[amount_dict['amount']] = amount_dict['num_contributing']\n    return results\n\n\n# canonizer\n# =========\n# This is an Aspen hook to ensure that requests are served on a certain root\n# URL, even if multiple domains point to the application.\n\nclass X: pass\ncanonical_scheme = None\ncanonical_host = None\n\ndef canonize(request):\n    \"\"\"Enforce a certain scheme and hostname. Store these on request as well.\n    \"\"\"\n    scheme = request.headers.get('X-Forwarded-Proto', 'http') # per Heroku\n    host = request.headers['Host']\n    bad_scheme = scheme != canonical_scheme\n    bad_host = bool(canonical_host) and (host != canonical_host)\n                # '' and False => ''\n    if bad_scheme or bad_host:\n        url = '%s://%s' % (canonical_scheme, canonical_host)\n        if request.line.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):\n            # Redirect to a particular path for idempotent methods.\n            url += request.line.uri.path.raw\n            if request.line.uri.querystring:\n                url += '?' + request.line.uri.querystring.raw\n        else:\n            # For non-idempotent methods, redirect to homepage.\n            url += '/'\n        request.redirect(url, permanent=True)\n\n\ndef configure_payments(request):\n    # Work-around for https://github.com/balanced/balanced-python/issues/5\n    import balanced\n    balanced.configure(os.environ['BALANCED_API_SECRET'])\n", "path": "gittip/__init__.py"}]}