def ping(request): get_dict, query, date = _get_query(request) _, history = live_stream_query_manager(get_dict, request.user, return_type="list") username = request.GET.get("username", "") if username: objs = EyeHistory.objects.filter(user__username=username) else: objs = EyeHistory.objects.all() try: user = User.objects.get(username=username) except User.DoesNotExist: user = None return { 'history': history, 'num_history': objs.count(), 'num_online': online_user_count(), 'is_online': online_user(user), }
def ping(request): get_dict, query, date = _get_query(request) _, history = live_stream_query_manager(get_dict, request.user, return_type="list") username = request.GET.get("username", "") if username: objs = EyeHistory.objects.filter(user__username=username) else: objs = EyeHistory.objects.all() try: user = User.objects.get(username=username) except User.DoesNotExist: user = None return { 'history' : history, 'num_history' : objs.count(), 'num_online' : online_user_count(), 'is_online' : online_user(user), }
def live_stream(request): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') tot_time, num_history, num_online = _get_stats(user) get_dict, query, date = _get_query(request) hist, history_stream = live_stream_query_manager(get_dict, user) following_count = user.profile.follows.count() follower_count = UserProfile.objects.filter(follows=user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter(start_time__gt=today).values('url', 'title').annotate(num_urls=Count('id')).order_by('-num_urls')[:3] day_domains = hist.filter(start_time__gt=today).values('domain').annotate(num_domains=Count('id')).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter(start_time__gt=last_week).values('url', 'title').annotate(num_urls=Count('id')).order_by('-num_urls')[:3] week_domains = hist.filter(start_time__gt=last_week).values('domain').annotate(num_domains=Count('id')).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': user.username, 'following_count': following_count, 'follower_count': follower_count, 'query' : query, 'date' : date, 'history_stream' : history_stream, 'tot_time' : tot_time, 'num_history' : num_history, 'num_online' : num_online, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="live stream", navbar="nav_home", sub_navbar=_get_subnav(request), **template_dict)
def viz_page(request): user = request.user get_dict, query, date, sort, filter = _get_query(request) get_dict["orderBy"] = "end_time" get_dict["direction"] = "hl" get_dict["filter"] = "" get_dict["page"] = request.GET.get("page", 1) get_dict["sort"] = "time" hist, history_stream = live_stream_query_manager(get_dict, user) if user.is_authenticated(): following_count = user.profile.follows.count() follower_count = UserProfile.objects.filter(follows=user.profile).count() tot_time, num_history = _get_stats(user, filter=filter) else: following_count = 0 follower_count = 0 tot_time = None num_history = None # stats template_dict = { 'visualization': True, 'username': user.username, "history_stream": history_stream, "start_time": get_dict["start_time"], "end_time": get_dict["end_time"], "query": query, "date": date, 'following_count': following_count, 'follower_count': follower_count, 'sort': '', 'filter': filter, 'tot_time': tot_time, 'num_history': num_history, 'num_online': online_user_count(), } return template_dict
def live_stream(request): user = request.user get_dict, query, date, sort, filter = _get_query(request) hist, history_stream = live_stream_query_manager(get_dict, user) if user.is_authenticated(): following_count = user.profile.follows.count() follower_count = UserProfile.objects.filter( follows=user.profile).count() tot_time, num_history = _get_stats(user, filter=filter) else: following_count = 0 follower_count = 0 tot_time = None num_history = None template_dict = { 'username': user.username, 'following_count': following_count, 'follower_count': follower_count, 'query': query, 'date': date, 'sort': sort, 'filter': filter, 'history_stream': history_stream, 'tot_time': tot_time, 'num_history': num_history, 'num_online': online_user_count(), } return _template_values(request, page_title="live stream", navbar="nav_home", sub_navbar=_get_subnav(request), **template_dict)
def live_stream(request): user = request.user get_dict, query, date, sort, filter = _get_query(request) hist, history_stream = live_stream_query_manager(get_dict, user) if user.is_authenticated(): following_count = user.profile.follows.count() follower_count = UserProfile.objects.filter(follows=user.profile).count() tot_time, num_history = _get_stats(user, filter=filter) else: following_count = 0 follower_count = 0 tot_time = None num_history = None template_dict = { 'username': user.username, 'following_count': following_count, 'follower_count': follower_count, 'query': query, 'date': date, 'sort': sort, 'filter': filter, 'history_stream': history_stream, 'tot_time': tot_time, 'num_history': num_history, 'num_online': online_user_count(), } return _template_values(request, page_title="live stream", navbar="nav_home", sub_navbar=_get_subnav(request), **template_dict)
def live_stream(request): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') tot_time, num_history, num_online = _get_stats(user) get_dict, query, date = _get_query(request) hist, history_stream = live_stream_query_manager(get_dict, user) following_count = user.profile.follows.count() follower_count = UserProfile.objects.filter(follows=user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter(start_time__gt=today).values( 'url', 'title').annotate(num_urls=Count('id')).order_by('-num_urls')[:3] day_domains = hist.filter(start_time__gt=today).values('domain').annotate( num_domains=Count('id')).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter(start_time__gt=last_week).values( 'url', 'title').annotate(num_urls=Count('id')).order_by('-num_urls')[:3] week_domains = hist.filter( start_time__gt=last_week).values('domain').annotate( num_domains=Count('id')).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': user.username, 'following_count': following_count, 'follower_count': follower_count, 'query': query, 'date': date, 'history_stream': history_stream, 'tot_time': tot_time, 'num_history': num_history, 'num_online': num_online, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="live stream", navbar="nav_home", sub_navbar=_get_subnav(request), **template_dict)
def profile_data(request, username=None): if request.user.is_authenticated(): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') else: user = None userprof = None """ Own profile page """ username, follows, profile_user, empty_search_msg, nav_bar = _profile_info( user, username) get_dict, query, date, sort, filter = _get_query(request) get_dict["orderBy"] = "end_time" get_dict["direction"] = "hl" get_dict["filter"] = "" get_dict["page"] = request.GET.get("page", 1) get_dict["username"] = profile_user.username get_dict["sort"] = "time" hist, history_stream = live_stream_query_manager(get_dict, request.user, empty_search_msg=empty_search_msg) # stats tot_time, item_count = profile_stat_gen(profile_user) fav_data = FavData.objects.get(user=profile_user) num_history = EyeHistory.objects.filter(user=profile_user).count() is_online = online_user(user=profile_user) following_count = profile_user.profile.follows.count() follower_count = UserProfile.objects.filter( follows=profile_user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter( start_time__gt=today ).values('url', 'title').annotate( num_urls=Sum('total_time') ).order_by('-num_urls')[:3] day_domains = hist.filter( start_time__gt=today ).values('domain' ).annotate(num_domains=Sum('total_time') ).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter( start_time__gt=last_week ).values('url', 'title' ).annotate(num_urls=Sum('total_time') ).order_by('-num_urls')[:3] week_domains = hist.filter( start_time__gt=last_week ).values('domain' ).annotate(num_domains=Sum('total_time') ).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': profile_user.username, 'following_count': following_count, 'follower_count': follower_count, "profile_user": profile_user, "history_stream": history_stream, "empty_search_msg": empty_search_msg, "follows": str(follows), "is_online": is_online, "num_history": num_history, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, "query": query, "date": date, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="profile history", navbar=nav_bar, sub_navbar="subnav_data", **template_dict)
def profile_data(request, username=None): if request.user.is_authenticated(): user = get_object_or_404(User, username=request.user.username) userprof = UserProfile.objects.get(user=user) confirmed = userprof.confirmed if not confirmed: return redirect('/consent') else: user = None userprof = None """ Own profile page """ username, follows, profile_user, empty_search_msg, nav_bar = _profile_info( user, username) get_dict, query, date, sort, filter = _get_query(request) get_dict["orderBy"] = "end_time" get_dict["direction"] = "hl" get_dict["filter"] = "" get_dict["page"] = request.GET.get("page", 1) get_dict["username"] = profile_user.username get_dict["sort"] = "time" hist, history_stream = live_stream_query_manager( get_dict, request.user, empty_search_msg=empty_search_msg) # stats tot_time, item_count = profile_stat_gen(profile_user) fav_data = FavData.objects.get(user=profile_user) num_history = EyeHistory.objects.filter(user=profile_user).count() is_online = online_user(user=profile_user) following_count = profile_user.profile.follows.count() follower_count = UserProfile.objects.filter( follows=profile_user.profile).count() today = datetime.now() - timedelta(hours=24) day_count = hist.filter(start_time__gt=today).values( 'url', 'title').annotate(num_urls=Sum('total_time')).order_by('-num_urls')[:3] day_domains = hist.filter(start_time__gt=today).values('domain').annotate( num_domains=Sum('total_time')).order_by('-num_domains')[:5] day_chart = {} for domain in day_domains: day_chart[domain['domain']] = domain['num_domains'] last_week = today - timedelta(days=7) week_count = hist.filter(start_time__gt=last_week).values( 'url', 'title').annotate(num_urls=Sum('total_time')).order_by('-num_urls')[:3] week_domains = hist.filter( start_time__gt=last_week).values('domain').annotate( num_domains=Sum('total_time')).order_by('-num_domains')[:5] week_chart = {} for domain in week_domains: week_chart[domain['domain']] = domain['num_domains'] template_dict = { 'username': profile_user.username, 'following_count': following_count, 'follower_count': follower_count, "profile_user": profile_user, "history_stream": history_stream, "empty_search_msg": empty_search_msg, "follows": str(follows), "is_online": is_online, "num_history": num_history, "tot_time": tot_time, "item_count": item_count, "fav_data": fav_data, "query": query, "date": date, 'day_articles': day_count, 'week_articles': week_count, 'day_chart': json.dumps(day_chart), 'week_chart': json.dumps(week_chart), } return _template_values(request, page_title="profile history", navbar=nav_bar, sub_navbar="subnav_data", **template_dict)