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
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
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
def test_daily_aggregator_returns_list_of_namedtuples_given_one_day_of_data(self): self.create_node(self.day_one, total=6) self.create_node(self.day_one, total=1) self.create_node(self.day_one, total=3) self.create_node(self.day_one, total=0) qs = Node.objects.filter(livetvusername="******") aggregate_total = daily_aggregator(qs) self.assertEqual(len(aggregate_total), 1) self.assertEqual(aggregate_total[0].mean, 2.5) self.assertEqual(aggregate_total[0].max, 6) self.assertEqual(aggregate_total[0].day, '2015-11-25') self.assertEqual(aggregate_total[0].minutes, 0.33)
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
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
def test_daily_aggregator_returns_list_of_namedtuples_given_one_day_of_data( self): self.create_node(self.day_one, total=6) self.create_node(self.day_one, total=1) self.create_node(self.day_one, total=3) self.create_node(self.day_one, total=0) qs = Node.objects.filter(livetvusername="******") aggregate_total = daily_aggregator(qs) self.assertEqual(len(aggregate_total), 1) self.assertEqual(aggregate_total[0].mean, 2.5) self.assertEqual(aggregate_total[0].max, 6) self.assertEqual(aggregate_total[0].day, '2015-11-25') self.assertEqual(aggregate_total[0].minutes, 0.33)
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
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
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
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