def last_heartbeat():
    def _date_or_none(val):
        if val and val != NOT_FOUND and val != NOT_CONFIGURED:
            return datetime.strptime(val, DATE_FORMAT)
        return None
    
    from_file = _date_or_none(get_file_heartbeat())
    from_cache = _date_or_none(get_cache_heartbeat())
    if from_file and from_cache:
        return from_file if from_cache > from_file else from_cache
    elif from_file:
        return from_file
    elif from_cache:
        return from_cache
    else:
        return None
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/soil/heartbeat.py/last_heartbeat/swapped operands of `>`