prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  show total ever given
  Suggested [via Twitter](https://twitter.com/tripflex/status/532597015210131456):
  
  > is there no way for me to see the total I have donated?  I know I can see it weekly, but what about overall total?
  
  
  </issue>
  <code>
  [start of gratipay/utils/history.py]
  1 def iter_payday_events(db, participant):
  2     """Yields payday events for the given participant.
  3     """
  4     username = participant.username
  5     exchanges = db.all("""
  6         SELECT *
  7           FROM exchanges
  8          WHERE participant=%s
  9     """, (username,), back_as=dict)
  10     transfers = db.all("""
  11         SELECT *
  12           FROM transfers
  13          WHERE tipper=%(username)s OR tippee=%(username)s
  14     """, locals(), back_as=dict)
  15 
  16     if not (exchanges or transfers):
  17         return
  18 
  19     payday_dates = db.all("""
  20         SELECT ts_start::date
  21           FROM paydays
  22       ORDER BY ts_start ASC
  23     """)
  24 
  25     balance = participant.balance
  26     prev_date = None
  27     get_timestamp = lambda e: e['timestamp']
  28     events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)
  29     for event in events:
  30 
  31         event['balance'] = balance
  32 
  33         event_date = event['timestamp'].date()
  34         if event_date != prev_date:
  35             if prev_date:
  36                 yield dict(kind='day-close', balance=balance)
  37             day_open = dict(kind='day-open', date=event_date, balance=balance)
  38             if payday_dates:
  39                 while payday_dates and payday_dates[-1] > event_date:
  40                     payday_dates.pop()
  41                 payday_date = payday_dates[-1] if payday_dates else None
  42                 if event_date == payday_date:
  43                     day_open['payday_number'] = len(payday_dates) - 1
  44             yield day_open
  45             prev_date = event_date
  46 
  47         if 'fee' in event:
  48             if event['amount'] > 0:
  49                 kind = 'charge'
  50                 if event['status'] in (None, 'succeeded'):
  51                     balance -= event['amount']
  52             else:
  53                 kind = 'credit'
  54                 if event['status'] != 'failed':
  55                     balance -= event['amount'] - event['fee']
  56         else:
  57             kind = 'transfer'
  58             if event['tippee'] == username:
  59                 balance -= event['amount']
  60             else:
  61                 balance += event['amount']
  62         event['kind'] = kind
  63 
  64         yield event
  65 
  66     yield dict(kind='day-close', balance='0.00')
  67
  [end of gratipay/utils/history.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/gratipay/utils/history.py b/gratipay/utils/history.py
  --- a/gratipay/utils/history.py
  +++ b/gratipay/utils/history.py
  @@ -16,6 +16,13 @@
       if not (exchanges or transfers):
           return
   
  +    if transfers:
  +        yield dict(
  +            kind='totals',
  +            given=sum(t['amount'] for t in transfers if t['tipper'] == username),
  +            received=sum(t['amount'] for t in transfers if t['tippee'] == username),
  +        )
  +
       payday_dates = db.all("""
           SELECT ts_start::date
             FROM paydays
  
verification_info: {"golden_diff": "diff --git a/gratipay/utils/history.py b/gratipay/utils/history.py\n--- a/gratipay/utils/history.py\n+++ b/gratipay/utils/history.py\n@@ -16,6 +16,13 @@\n     if not (exchanges or transfers):\n         return\n \n+    if transfers:\n+        yield dict(\n+            kind='totals',\n+            given=sum(t['amount'] for t in transfers if t['tipper'] == username),\n+            received=sum(t['amount'] for t in transfers if t['tippee'] == username),\n+        )\n+\n     payday_dates = db.all(\"\"\"\n         SELECT ts_start::date\n           FROM paydays\n", "issue": "show total ever given\nSuggested [via Twitter](https://twitter.com/tripflex/status/532597015210131456):\n\n> is there no way for me to see the total I have donated?  I know I can see it weekly, but what about overall total?\n\n", "before_files": [{"content": "def iter_payday_events(db, participant):\n    \"\"\"Yields payday events for the given participant.\n    \"\"\"\n    username = participant.username\n    exchanges = db.all(\"\"\"\n        SELECT *\n          FROM exchanges\n         WHERE participant=%s\n    \"\"\", (username,), back_as=dict)\n    transfers = db.all(\"\"\"\n        SELECT *\n          FROM transfers\n         WHERE tipper=%(username)s OR tippee=%(username)s\n    \"\"\", locals(), back_as=dict)\n\n    if not (exchanges or transfers):\n        return\n\n    payday_dates = db.all(\"\"\"\n        SELECT ts_start::date\n          FROM paydays\n      ORDER BY ts_start ASC\n    \"\"\")\n\n    balance = participant.balance\n    prev_date = None\n    get_timestamp = lambda e: e['timestamp']\n    events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)\n    for event in events:\n\n        event['balance'] = balance\n\n        event_date = event['timestamp'].date()\n        if event_date != prev_date:\n            if prev_date:\n                yield dict(kind='day-close', balance=balance)\n            day_open = dict(kind='day-open', date=event_date, balance=balance)\n            if payday_dates:\n                while payday_dates and payday_dates[-1] > event_date:\n                    payday_dates.pop()\n                payday_date = payday_dates[-1] if payday_dates else None\n                if event_date == payday_date:\n                    day_open['payday_number'] = len(payday_dates) - 1\n            yield day_open\n            prev_date = event_date\n\n        if 'fee' in event:\n            if event['amount'] > 0:\n                kind = 'charge'\n                if event['status'] in (None, 'succeeded'):\n                    balance -= event['amount']\n            else:\n                kind = 'credit'\n                if event['status'] != 'failed':\n                    balance -= event['amount'] - event['fee']\n        else:\n            kind = 'transfer'\n            if event['tippee'] == username:\n                balance -= event['amount']\n            else:\n                balance += event['amount']\n        event['kind'] = kind\n\n        yield event\n\n    yield dict(kind='day-close', balance='0.00')\n", "path": "gratipay/utils/history.py"}]}