Example #1
0
    def test_get_least_square_slope(self):
        eq_(VidlySubmission.get_least_square_slope(), None)

        event = Event.objects.get(title='Test event')
        event.duration = 300
        event.save()

        now = timezone.now()
        VidlySubmission.objects.create(
            event=event,
            submission_time=now,
            finished=now + datetime.timedelta(seconds=event.duration * 2.1)
        )
        other_event = Event.objects.create(
            duration=450,
            slug='other',
            start_time=event.start_time,
        )
        VidlySubmission.objects.create(
            event=other_event,
            submission_time=now,
            finished=now + datetime.timedelta(
                seconds=other_event.duration * 1.9
            )
        )
        eq_(VidlySubmission.get_least_square_slope(), 1.5)
Example #2
0
def vidly_media_timings_data(request):
    points = VidlySubmission.get_points(100)
    slope = VidlySubmission.get_least_square_slope(points=points)
    context = {
        'points': points,
        'slope': slope,
    }
    return context
Example #3
0
def get_video_tagged(event, request, autoplay=False, tag=None):
    def poster_url(geometry='896x504', crop='center'):
        image = event.picture and event.picture.file or event.placeholder_img
        return thumbnail(image, geometry, crop=crop).url

    context = {
        'md5': lambda s: hashlib.md5(s).hexdigest(),
        'event': event,
        'request': request,
        'datetime': datetime.datetime.utcnow(),
        'vidly_tokenize': vidly.tokenize,
        'edgecast_tokenize': edgecast_tokenize,
        'akamai_tokenize': akamai_tokenize,
        'popcorn_url': event.popcorn_url,
        'autoplay': autoplay and 'true' or 'false',  # javascript
        'poster_url': poster_url,
    }
    if isinstance(event.template_environment, dict):
        context.update(event.template_environment)
    if tag:
        submissions = VidlySubmission.objects.filter(tag=tag, event=event)
        if not submissions.exists():
            raise VidlySubmission.DoesNotExist(tag)
        context['tag'] = tag
    template = engines['backend'].from_string(event.template.content)
    try:
        template_tagged = template.render(context)
    except vidly.VidlyTokenizeError, msg:
        template_tagged = '<code style="color:red">%s</code>' % msg
Example #4
0
def vidly_media_timings_data(request):
    points = VidlySubmission.get_recent_points(100)
    slope_and_intercept = VidlySubmission.get_general_least_square_slope(
        points=points)
    if slope_and_intercept is None:
        # This is the bootstrapping case when you don't have enough data.
        # It only applies if you have an empty database.
        slope, intercept = None, None
    else:
        slope, intercept = slope_and_intercept
    context = {
        'points': points,
        'slope': slope,
        'intercept': intercept,
    }
    return context
Example #5
0
def vidly_media_timings_data(request):
    points = VidlySubmission.get_recent_points(100)
    slope_and_intercept = VidlySubmission.get_general_least_square_slope(
        points=points
    )
    if slope_and_intercept is None:
        # This is the bootstrapping case when you don't have enough data.
        # It only applies if you have an empty database.
        slope, intercept = None, None
    else:
        slope, intercept = slope_and_intercept
    context = {
        'points': points,
        'slope': slope,
        'intercept': intercept,
    }
    return context
Example #6
0
def get_video_tagged(event, request, autoplay=False, tag=None):
    context = {
        'md5': lambda s: hashlib.md5(s).hexdigest(),
        'event': event,
        'request': request,
        'datetime': datetime.datetime.utcnow(),
        'vidly_tokenize': vidly.tokenize,
        'edgecast_tokenize': edgecast_tokenize,
        'akamai_tokenize': akamai_tokenize,
        'popcorn_url': event.popcorn_url,
        'autoplay': autoplay and 'true' or 'false',  # javascript
    }
    if isinstance(event.template_environment, dict):
        context.update(event.template_environment)
    if tag:
        submissions = VidlySubmission.objects.filter(tag=tag, event=event)
        if not submissions.exists():
            raise VidlySubmission.DoesNotExist(tag)
        context['tag'] = tag
    template = Template(event.template.content)
    try:
        template_tagged = template.render(context)
    except vidly.VidlyTokenizeError, msg:
        template_tagged = '<code style="color:red">%s</code>' % msg