Ejemplo n.º 1
0
def episode_status_icon(action):
    if not action or not action.action:
        s = '<img src="/media/nothing.png" alt="nothing" title="%s" />' % _('Unplayed episode')

    else:
        date_string   = (_(' on %s') % (action.timestamp)) if action.timestamp else ''
        device_string = (_(' on %s') % (action.device.name)) if action.device else ''

        if action.action == 'new':
            s = '<img src="/media/new.png" alt="new" title="%s" />' % ('%s%s%s' % (_('This episode has been marked new'),date_string, device_string))
        elif action.action == 'download':
            s = '<img src="/media/download.png" alt="downloaded" title="%s" />' % ('%s%s%s' % (_('This episode has been downloaded'),date_string, device_string))
        elif action.action == 'play':
            if action.playmark is not None:
                if getattr(action, 'started', None) is not None:
                    playback_info = _(' from %(start)s to %(end)s') % { \
                            'start': utils.format_time(action.started), \
                            'end': utils.format_time(action.playmark)}
                else:
                    playback_info = _(' to position %s') % (\
                            utils.format_time(action.playmark),)
            else:
                playback_info = ''
            s = '<img src="/media/playback.png" alt="played" title="%s" />' % ('%s%s%s%s' % (_('This episode has been played'),date_string, device_string, playback_info))
        elif action.action == 'delete':
            s = '<img src="/media/delete.png" alt="deleted" title="%s"/>' % ('%s%s%s' % (_('This episode has been deleted'),date_string, device_string))
        else:
            return action.action #this is not marked safe by intention

    return mark_safe(s)
Ejemplo n.º 2
0
def episode_status_icon(action):
    if not action or not action.action:
        s = '<img src="%s" alt="nothing" title="%s" />' % \
            (staticfiles_storage.url('nothing.png'), _('Unplayed episode'))

    else:
        date_string   = (_(' on %s') % (action.timestamp)) if action.timestamp else ''
        device_string = (_(' on %s') % (action.client.name)) if action.client else ''

        if action.action == 'flattr':
            s = '<img src="https://flattr.com/_img/icons/flattr_logo_16.png" alt="flattr" title="%s" />' % (_("The episode has been flattr'd"),)

        elif action.action == 'new':
            s = '<img src="%s" alt="new" title="%s" />' % (staticfiles_storage.url('new.png'), '%s%s%s' % (_('This episode has been marked new'),date_string, device_string))
        elif action.action == 'download':
            s = '<img src="%s" alt="downloaded" title="%s" />' % (staticfiles_storage.url('download.png'), '%s%s%s' % (_('This episode has been downloaded'),date_string, device_string))
        elif action.action == 'play':
            if action.stopped is not None:
                if getattr(action, 'started', None) is not None:
                    playback_info = _(' from %(start)s to %(end)s') % { \
                            'start': utils.format_time(action.started), \
                            'end': utils.format_time(action.stopped)}
                else:
                    playback_info = _(' to position %s') % (\
                            utils.format_time(action.stopped),)
            else:
                playback_info = ''
            s = '<img src="%s" alt="played" title="%s" />' % (staticfiles_storage.url('playback.png'), '%s%s%s%s' % (_('This episode has been played'),date_string, device_string, playback_info))
        elif action.action == 'delete':
            s = '<img src="%s" alt="deleted" title="%s"/>' % (staticfiles_storage.url('delete.png'), '%s%s%s' % (_('This episode has been deleted'),date_string, device_string))
        else:
            return action.action  # this is not marked safe by intention

    return mark_safe(s)
Ejemplo n.º 3
0
def episode_status_icon(action):
    if not action or not action.action:
        s = '<img src="%s" alt="nothing" title="%s" />' % \
            (staticfiles_storage.url('nothing.png'), _('Unplayed episode'))

    else:
        date_string = (_(' on %s') %
                       (action.timestamp)) if action.timestamp else ''
        device_string = (_(' on %s') %
                         (action.client.name)) if action.client else ''

        if action.action == 'flattr':
            s = '<img src="https://flattr.com/_img/icons/flattr_logo_16.png" alt="flattr" title="%s" />' % (
                _("The episode has been flattr'd"), )

        elif action.action == 'new':
            s = '<img src="%s" alt="new" title="%s" />' % (
                staticfiles_storage.url('new.png'), '%s%s%s' %
                (_('This episode has been marked new'), date_string,
                 device_string))
        elif action.action == 'download':
            s = '<img src="%s" alt="downloaded" title="%s" />' % (
                staticfiles_storage.url('download.png'), '%s%s%s' %
                (_('This episode has been downloaded'), date_string,
                 device_string))
        elif action.action == 'play':
            if action.stopped is not None:
                if getattr(action, 'started', None) is not None:
                    playback_info = _(' from %(start)s to %(end)s') % { \
                            'start': utils.format_time(action.started), \
                            'end': utils.format_time(action.stopped)}
                else:
                    playback_info = _(' to position %s') % (\
                            utils.format_time(action.stopped),)
            else:
                playback_info = ''
            s = '<img src="%s" alt="played" title="%s" />' % (
                staticfiles_storage.url('playback.png'), '%s%s%s%s' %
                (_('This episode has been played'), date_string, device_string,
                 playback_info))
        elif action.action == 'delete':
            s = '<img src="%s" alt="deleted" title="%s"/>' % (
                staticfiles_storage.url('delete.png'), '%s%s%s' %
                (_('This episode has been deleted'), date_string,
                 device_string))
        else:
            return action.action  # this is not marked safe by intention

    return mark_safe(s)
Ejemplo n.º 4
0
def episode_heatmap_visualization(heatmap):
    """
    display a visual heatmap using the Google Charts API

    heatmap_data is expected as an array of numbers of users that have
    played this part part of the episode. the length of the parts is
    indicated by step_length; the duration of the whole episode is
    therefore approximated by len(heatmap_data) * step_length
    """
    label_steps = 2

    max_plays = heatmap.max_plays

    if max_plays == 1:
        #              light blue       dark blue
        colours = ( (198, 217, 253), (77, 137, 249) )
    else:
        #               red            yellow         green
        colours = ( (210, 54, 28), (239, 236, 22), (15, 212, 18) )

    WIDTH=760

    # maximum number of labels that will be placed on the visualization
    MAX_LABELS=20

    axis_pos = []
    axis_label = []
    part_colours = []
    widths = []
    duration = max(heatmap.borders, default=0)

    last_label = None
    for start, end, plays in heatmap.sections:

        if last_label is None or (end-last_label) > (duration/MAX_LABELS):
            axis_pos.append(end)
            axis_label.append(format_time(end))
            last_label = end

        rgb = colour_repr(plays, max_plays, colours)
        part_colours.append('%02x%02x%02x' % rgb)
        start = start or 0
        widths.append( end-start )

    parts = [
        'cht=bhs',                            # bar chart
        'chco=%s' % ','.join(part_colours),   # colors
        'chs=%dx50' % WIDTH,                  # width corresponds to length, arbitrary height
        'chds=0,%s' % duration,               # axis scaling from 0 to maximum duration
        'chd=t:%s' % '|'.join([repr(w) for w in widths]),  # all block have the same width
        'chxt=x',                             # visible axes
        'chxr=0,0,%s' % duration,             # axis range for axis 0 (x): 0 - duration
        'chxl=0:|%s' % '|'.join(axis_label),  # axis labels
        'chxp=0,%s' % ','.join([repr(x) for x in axis_pos]),   # axis label positions
        ]

    s = '<img src="http://chart.apis.google.com/chart?%s" />' % '&'.join(parts)

    return mark_safe(s)
Ejemplo n.º 5
0
def convert_position(action):
    """ convert position parameter for API 1 compatibility """
    pos = getattr(action, "position", None)
    if pos is not None:
        action.position = format_time(pos)
    return action
Ejemplo n.º 6
0
def convert_position(action):
    """ convert position parameter for API 1 compatibility """
    pos = getattr(action, 'position', None)
    if pos is not None:
        action.position = format_time(pos)
    return action
Ejemplo n.º 7
0
def episode_status_icon(action):
    if not action or not action.action:
        s = '<img src="%s" alt="nothing" title="%s" />' % (
            staticfiles_storage.url("nothing.png"),
            _("Unplayed episode"),
        )

    else:
        date_string = (_(" on %s") %
                       (action.timestamp)) if action.timestamp else ""
        device_string = (_(" on %s") %
                         (action.client.name)) if action.client else ""

        if action.action == "flattr":
            s = (
                '<img src="https://flattr.com/_img/icons/flattr_logo_16.png" alt="flattr" title="%s" />'
                % (_("The episode has been flattr'd"), ))

        elif action.action == "new":
            s = '<img src="%s" alt="new" title="%s" />' % (
                staticfiles_storage.url("new.png"),
                "%s%s%s" % (_("This episode has been marked new"), date_string,
                            device_string),
            )
        elif action.action == "download":
            s = '<img src="%s" alt="downloaded" title="%s" />' % (
                staticfiles_storage.url("download.png"),
                "%s%s%s" % (_("This episode has been downloaded"), date_string,
                            device_string),
            )
        elif action.action == "play":
            if action.stopped is not None:
                if getattr(action, "started", None) is not None:
                    playback_info = _(" from %(start)s to %(end)s") % {
                        "start": utils.format_time(action.started),
                        "end": utils.format_time(action.stopped),
                    }
                else:
                    playback_info = _(" to position %s") % (utils.format_time(
                        action.stopped), )
            else:
                playback_info = ""
            s = '<img src="%s" alt="played" title="%s" />' % (
                staticfiles_storage.url("playback.png"),
                "%s%s%s%s" % (
                    _("This episode has been played"),
                    date_string,
                    device_string,
                    playback_info,
                ),
            )
        elif action.action == "delete":
            s = '<img src="%s" alt="deleted" title="%s"/>' % (
                staticfiles_storage.url("delete.png"),
                "%s%s%s" % (_("This episode has been deleted"), date_string,
                            device_string),
            )
        else:
            return action.action  # this is not marked safe by intention

    return mark_safe(s)
Ejemplo n.º 8
0
def episode_heatmap_visualization(heatmap):
    """
    display a visual heatmap using the Google Charts API

    heatmap_data is expected as an array of numbers of users that have
    played this part part of the episode. the length of the parts is
    indicated by step_length; the duration of the whole episode is
    therefore approximated by len(heatmap_data) * step_length
    """
    label_steps = 2

    max_plays = heatmap.max_plays

    if max_plays == 1:
        #              light blue       dark blue
        colours = ((198, 217, 253), (77, 137, 249))
    else:
        #               red            yellow         green
        colours = ((210, 54, 28), (239, 236, 22), (15, 212, 18))

    WIDTH = 760

    # maximum number of labels that will be placed on the visualization
    MAX_LABELS = 20

    axis_pos = []
    axis_label = []
    part_colours = []
    widths = []
    duration = max(heatmap.borders, default=0)

    last_label = None
    for start, end, plays in heatmap.sections:

        if last_label is None or (end - last_label) > (duration / MAX_LABELS):
            axis_pos.append(end)
            axis_label.append(format_time(end))
            last_label = end

        rgb = colour_repr(plays, max_plays, colours)
        part_colours.append('%02x%02x%02x' % rgb)
        start = start or 0
        widths.append(end - start)

    parts = [
        'cht=bhs',  # bar chart
        'chco=%s' % ','.join(part_colours),  # colors
        'chs=%dx50' % WIDTH,  # width corresponds to length, arbitrary height
        'chds=0,%s' % duration,  # axis scaling from 0 to maximum duration
        'chd=t:%s' %
        '|'.join([repr(w) for w in widths]),  # all block have the same width
        'chxt=x',  # visible axes
        'chxr=0,0,%s' % duration,  # axis range for axis 0 (x): 0 - duration
        'chxl=0:|%s' % '|'.join(axis_label),  # axis labels
        'chxp=0,%s' % ','.join([repr(x)
                                for x in axis_pos]),  # axis label positions
    ]

    s = '<img src="http://chart.apis.google.com/chart?%s" />' % '&'.join(parts)

    return mark_safe(s)