Example #1
0
 def get(self, request):
     dataX, dataY = unzip_data(Node.objects.get_eight_minutes_of_total_viewers())
     context = {
         "dataX": dataX,
         "dataY": dataY,
         "maxY": max(dataY)
     }
     return HttpResponse(json.dumps(context), content_type="application/json")
Example #2
0
def lower_resolution():
    today = get_today()
    two_months_ago = today + datetime.timedelta(days=-60)
    old_data = Node.objects.filter(timestamp__gte=two_months_ago).values_list('livetvusername', 'current_total')
    data_x, data_y = unzip_data(old_data)
    unique_users = set(data_x)

    pass
Example #3
0
def lower_resolution():
    today = get_today()
    two_months_ago = today + datetime.timedelta(days=-60)
    old_data = Node.objects.filter(timestamp__gte=two_months_ago).values_list(
        'livetvusername', 'current_total')
    data_x, data_y = unzip_data(old_data)
    unique_users = set(data_x)

    pass
Example #4
0
 def get_context_data(self, datestamp):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     day_nodes = Node.objects.filter(livetvusername=livetvusername, timestamp__contains=datetime.datetime.strptime(datestamp, "%Y-%m-%d").date())
     x_data, y_data = unzip_data(prepare_data_for_plot(day_nodes.values_list("timestamp", "current_total")))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["max_y"] = max(y_data)
     return context
Example #5
0
 def get_context_data(self):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     friend_info = Friends.objects.get_all_plottable_user_nodes(livetvusername)
     if friend_info:
         dataX, dataY = unzip_data(friend_info)
         context["friendDataX"] = dataX
         context["friendDataY"] = dataY
         context["friendMaxY"] = max(dataY)
     return context
Example #6
0
 def get_context_data(self):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     friend_info = Friends.objects.get_all_plottable_user_nodes(
         livetvusername)
     if friend_info:
         dataX, dataY = unzip_data(friend_info)
         context["friendDataX"] = dataX
         context["friendDataY"] = dataY
         context["friendMaxY"] = max(dataY)
     return context
Example #7
0
 def get_context_data(self, user_slug, datestamp):
     context = super().get_context_data()
     day_nodes = Node.objects.filter(livetvusername=user_slug, timestamp__contains=datetime.datetime.strptime(datestamp, "%Y-%m-%d").date())
     x_data, y_data = unzip_data(prepare_data_for_plot(day_nodes.values_list("timestamp", "current_total")))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["max_y"] = max(y_data)
     context["admin_viewing"] = True
     context["admin_viewing_user"] = user_slug
     return context
Example #8
0
 def get_context_data(self, datestamp):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     day_nodes = Node.objects.filter(
         livetvusername=livetvusername, timestamp__contains=datetime.datetime.strptime(datestamp, "%Y-%m-%d").date()
     )
     x_data, y_data = unzip_data(prepare_data_for_plot(day_nodes.values_list("timestamp", "current_total")))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["max_y"] = max(y_data)
     return context
Example #9
0
 def get_context_data(self):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     all_nodes = Node.objects.get_all_user_nodes(livetvusername)
     friend_info = Friends.objects.get_all_plottable_user_nodes(livetvusername)
     context["daily_breakdown"] = daily_aggregator(all_nodes)
     if friend_info:
         dataX, dataY = unzip_data(friend_info)
         context["friendDataX"] = dataX
         context["friendDataY"] = dataY
         context["friendMaxY"] = max(dataY)
     return context
Example #10
0
 def get_context_data(self, datestamp):
     context = super().get_context_data()
     day = datetime.datetime.strptime(datestamp, "%Y-%m-%d").date()
     livetvusername = self.request.user.userprofile.livetvusername
     day_nodes = Node.objects.filter(livetvusername=livetvusername, timestamp__contains=day)
     x_data, y_data = unzip_data(prepare_data_for_plot(day_nodes.values_list("timestamp", "current_total"), livetvusername))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["videos"] = [vid for generator in LiveCodingClient(livetvusername).get_user_videos() for vid in generator if datetime.datetime.strptime(vid.creation_time[:10], "%Y-%m-%d").date() == day]
     context["max_y"] = max(y_data)
     return context
Example #11
0
 def get_context_data(self):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     all_nodes = Node.objects.get_all_user_nodes(livetvusername)
     friend_info = Friends.objects.get_all_plottable_user_nodes(livetvusername)
     context["daily_breakdown"] = daily_aggregator(all_nodes)
     if friend_info:
         dataX, dataY = unzip_data(friend_info)
         context["friendDataX"] = dataX
         context["friendDataY"] = dataY
         context["friendMaxY"] = max(dataY)
     return context
Example #12
0
 def get_context_data(self, user_slug):
     context = super().get_context_data()
     all_nodes = Node.objects.get_all_user_nodes(user_slug)
     context["daily_breakdown"] = daily_aggregator(all_nodes)
     friend_info = Friends.objects.get_all_plottable_user_nodes(user_slug)
     if friend_info:
         dataX, dataY = unzip_data(friend_info)
         context["friendDataX"] = dataX
         context["friendDataY"] = dataY
         context["friendMaxY"] = max(dataY)
     context["admin_viewing"] = True
     context["admin_viewing_user"] = user_slug
     return context
Example #13
0
 def get_context_data(self):
     context = super().get_context_data()
     livetvusername = self.request.user.userprofile.livetvusername
     last_node = Node.objects.get_all_user_nodes(livetvusername).last()
     if last_node:
         if last_node.timestamp < django_timezone.now() + datetime.timedelta(minutes=-1):
             return context
         current_node = last_node
         data = Node.objects.get_plottable_eight_minutes(livetvusername)
         if data:
             dataX, dataY, siteY = unzip_data(data)
             max_viewer_count = max([_[1] for _ in data])
             context["current_node"] = current_node
             context["max_viewer_count"] = max_viewer_count
     return context
Example #14
0
 def get(self, request):
     livetvusername = request.user.userprofile.livetvusername
     dataX, dataY, siteY = unzip_data(Node.objects.get_plottable_eight_minutes(livetvusername))
     last_node = Node.objects.filter(livetvusername=livetvusername).last()
     current_count = 0
     if last_node:
         current_count = last_node.current_total
     context = {"frontpaged": request.user.userprofile.frontpaged,
                "maxY": max(dataY),
                "maxSiteY": max(siteY),
                "dataX": dataX,
                "dataY": dataY,
                "siteY": siteY,
                "current_count": current_count}
     return HttpResponse(json.dumps(context), content_type="application/json")
Example #15
0
    def get_context_data(self):
        context = super().get_context_data()
        livetvusername = self.request.user.userprofile.livetvusername
        last_node = Node.objects.get_all_user_nodes(livetvusername).last()
        if last_node:
            if last_node.timestamp < django_timezone.now() + datetime.timedelta(minutes=-1):
                return context
            current_node = last_node
            data = Node.objects.get_plottable_eight_minutes(livetvusername)
            if data:
                dataX, dataY, siteY = unzip_data(data)
                max_viewer_count = max([_[1] for _ in data])
                trending_pattern = trending(dataY)

                context["trending"] = trending_pattern
                context["current_node"] = current_node
                context["max_viewer_count"] = max_viewer_count
        return context
Example #16
0
    def get_context_data(self, user_slug, datestamp):
        context = super().get_context_data()
        day = datetime.datetime.strptime(datestamp, "%Y-%m-%d").date()
        day_nodes = Node.objects.filter(livetvusername=user_slug, timestamp__contains=datetime.datetime.strptime(datestamp, "%Y-%m-%d").date())
        x_data, y_data = unzip_data(prepare_data_for_plot(day_nodes.values_list("timestamp", "current_total"), user_slug))
        context["breakdown"] = daily_aggregator(day_nodes)[0]
        context["y_data"] = y_data
        context["x_data"] = x_data
        context["max_y"] = max(y_data)
        context["admin_viewing"] = True
        context["admin_viewing_user"] = user_slug

        # Won't work if someone hasn't authenticated with API. Fail gracefully?
        # try:
        #     context["videos"] = [vid for generator in LiveCodingClient(user_slug).get_user_videos() for vid in generator if datetime.datetime.strptime(vid.creation_time, "%Y-%m-%dT%H:%M:%S.%fZ").date() == day]
        # except ApiAccessToken.DoesNotExist:
        #     pass
        return context
Example #17
0
 def get_context_data(self, datestamp):
     context = super().get_context_data()
     day = datetime.datetime.strptime(datestamp, "%Y-%m-%d").date()
     livetvusername = self.request.user.userprofile.livetvusername
     day_nodes = Node.objects.filter(livetvusername=livetvusername,
                                     timestamp__contains=day)
     x_data, y_data = unzip_data(
         prepare_data_for_plot(
             day_nodes.values_list("timestamp", "current_total"),
             livetvusername))
     context["breakdown"] = daily_aggregator(day_nodes)[0]
     context["y_data"] = y_data
     context["x_data"] = x_data
     context["videos"] = [
         vid for generator in LiveCodingClient(
             livetvusername).get_user_videos()
         for vid in generator if datetime.datetime.strptime(
             vid.creation_time[:10], "%Y-%m-%d").date() == day
     ]
     context["max_y"] = max(y_data)
     return context
Example #18
0
    def get_context_data(self):
        context = super().get_context_data()
        livetvusername = self.request.user.userprofile.livetvusername
        all_nodes = Node.objects.get_all_user_nodes(livetvusername)
        if all_nodes:
            current_node = all_nodes.last()
            data = Node.objects.get_plottable_eight_minutes(livetvusername)
            if data:
                dataX, dataY, siteY = unzip_data(data)
                max_viewer_count = 0
                trending_pattern = False
                if data:
                    max_viewer_count = max([_[1] for _ in data])
                    trending_pattern = trending(dataY)

                context["trending"] = trending_pattern
                context["current_node"] = current_node
                context["max_viewer_count"] = max_viewer_count
                if not self.request.user.userprofile.active:
                    context["daily_breakdown"] = daily_aggregator(all_nodes)

        return context
Example #19
0
 def test_unzip_data_will_transpose_n_shaped_matrices(self):
     data = [(5, 6), (9, 0), (4, 1)]
     unzipped_data = unzip_data(data)
     self.assertEqual(unzipped_data, [[5, 9, 4], [6, 0, 1]])
Example #20
0
 def test_unzip_data_will_transpose_n_shaped_matrices(self):
     data = [(5, 6), (9, 0), (4, 1)]
     unzipped_data = unzip_data(data)
     self.assertEqual(unzipped_data, [[5, 9, 4], [6, 0, 1]])