def sync_profile(request): user_id = settings.WHAT_USER_ID interval = settings.WHAT_PROFILE_SNAPSHOT_INTERVAL snapshots = WhatUserSnapshot.objects.order_by('-datetime')[:1] if len(snapshots) == 0 or (timezone.now() - snapshots[0].datetime).total_seconds() >= interval - 30: what = get_what_client(request) WhatUserSnapshot.get(what, user_id).save()
def sync_profile(request): user_id = settings.WHAT_USER_ID interval = settings.WHAT_PROFILE_SNAPSHOT_INTERVAL try: last_snap = WhatUserSnapshot.get_last() if (timezone.now() - last_snap.datetime).total_seconds() < interval - 30: return except WhatUserSnapshot.DoesNotExist: pass what = get_what_client(request) WhatUserSnapshot.get(what, user_id).save()
def profile(request): try: data = { "delta_hour": WhatUserSnapshot.buffer_delta(datetime.timedelta(hours=1)), "delta_day": WhatUserSnapshot.buffer_delta(datetime.timedelta(days=1)), "delta_week": WhatUserSnapshot.buffer_delta(datetime.timedelta(days=7)), "delta_month": WhatUserSnapshot.buffer_delta(datetime.timedelta(days=30)), "buffer": WhatUserSnapshot.get_last().buffer_105, } except WhatUserSnapshot.DoesNotExist: data = {"delta_hour": "-", "delta_day": "-", "delta_week": "-", "delta_month": "-", "buffer": "-"} return render(request, "what_profile/profile.html", data)
def profile_history(request): since = timezone.now() - timedelta(days=1) input_snapshots = [ WhatUserSnapshot.get_closest_snapshot(when) for when in [since + timedelta(hours=h) for h in range(0, 25)] ] snapshots = [] prev = None for snapshot in input_snapshots: if prev: snapshots.append({ 'datetime': snapshot.datetime, 'uploaded': snapshot.uploaded - prev.uploaded, 'total_uploaded': snapshot.uploaded, 'downloaded': snapshot.downloaded - prev.downloaded, 'total_downloaded': snapshot.downloaded, 'buffer': snapshot.buffer_105 - prev.buffer_105, 'total_buffer': snapshot.buffer_105, 'ratio': snapshot.ratio - prev.ratio, 'total_ratio': snapshot.ratio, }) prev = snapshot else: prev = snapshot data = {'snapshots': snapshots} return render(request, 'what_profile/part_ui/profile_history.html', data)
def auto_pop(request): front = QueueItem.get_front() if not front: LogEntry.add(request.user, u'info', 'Auto pop: queue is empty.') return { 'success': False, 'error': 'Queue is empty.' } try: ratio_delta = get_auto_pop_ratio_delta(WhatUserSnapshot.get_last()) except WhatUserSnapshot.DoesNotExist: LogEntry.add(request.user, u'info', 'Auto pop: User profile not updated, skipping pop.') return { 'success': False, 'error': u'User profile not updated, skipping pop.' } if ratio_delta >= front.torrent_size: return do_pop(request) else: message = u'Auto pop: ratio delta {0} < {1}, skipping pop.'.format( filesizeformat(ratio_delta), filesizeformat(front.torrent_size) ) LogEntry.add(request.user, u'info', message) return { 'success': False, 'error': u'Buffer is {0}, skipping pop.'.format(message) }
def profile_history(request): since = timezone.now() - timedelta(days=1) input_snapshots = [ WhatUserSnapshot.get_closest_snapshot(when) for when in [since + timedelta(hours=h) for h in range(0, 25)] ] snapshots = [] prev = None for snapshot in input_snapshots: if prev: snapshots.append({ 'datetime': snapshot.datetime, 'uploaded': snapshot.uploaded - prev.uploaded, 'total_uploaded': snapshot.uploaded, 'downloaded': snapshot.downloaded - prev.downloaded, 'total_downloaded': snapshot.downloaded, 'buffer': snapshot.buffer_105 - prev.buffer_105, 'total_buffer': snapshot.buffer_105, 'ratio': snapshot.ratio - prev.ratio, 'total_ratio': snapshot.ratio, }) prev = snapshot else: prev = snapshot data = { 'snapshots': snapshots } return render(request, 'what_profile/part_ui/profile_history.html', data)
def profile(request): try: WhatUserSnapshot.objects.first() data = { 'delta_hour': WhatUserSnapshot.buffer_delta(datetime.timedelta(hours=1)), 'delta_day': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=1)), 'delta_week': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=7)), 'delta_month': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=30)), 'buffer': WhatUserSnapshot.get_last().buffer_105, } except (WhatUserSnapshot.DoesNotExist, IndexError): data = { 'delta_hour': '-', 'delta_day': '-', 'delta_week': '-', 'delta_month': '-', 'buffer': '-', } return render(request, 'what_profile/profile.html', data)
def torrent_stats(request): what_buffer = 0 try: what_buffer = WhatUserSnapshot.get_last().buffer_105 except WhatUserSnapshot.DoesNotExist: pass data = { 'master': ReplicaSet.get_what_master(), 'buffer': what_buffer, } return render(request, 'home/part_ui/torrent_stats.html', data)
def queue_stats(request): ratio_delta = '-' try: ratio_delta = get_auto_pop_ratio_delta(WhatUserSnapshot.get_last()) except (WhatUserSnapshot.DoesNotExist, IndexError): pass data = { 'item_count': QueueItem.objects.count(), 'total_size': QueueItem.objects.aggregate(Sum('torrent_size'))['torrent_size__sum'], 'auto_pop_ratio_delta': ratio_delta, } return render(request, 'queue/part_ui/queue_stats.html', data)
def profile(request): try: data = { 'delta_hour': WhatUserSnapshot.buffer_delta(datetime.timedelta(hours=1)), 'delta_day': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=1)), 'delta_week': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=7)), 'delta_month': WhatUserSnapshot.buffer_delta(datetime.timedelta(days=30)), 'buffer': WhatUserSnapshot.get_last().buffer_105, } except WhatUserSnapshot.DoesNotExist: data = { 'delta_hour': '-', 'delta_day': '-', 'delta_week': '-', 'delta_month': '-', 'buffer': '-', } return render(request, 'what_profile/profile.html', data)