<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def positions_binning(records):
 """ Bin records by chunks of 30 minutes, returning the most prevalent position. If multiple positions have the same number of occurrences (during 30 minutes), we select the last one. """

    def get_key(d):
        return (d.year, d.day, d.hour, d.minute // 30)

    chunks = itertools.groupby(records, key=lambda r: get_key(r.datetime))

    for _, items in chunks:
        positions = [i.position for i in items]
        # Given the low number of positions per chunk of 30 minutes, and
        # the need for a deterministic value, we use max and not Counter
        yield max(positions, key=positions.count)