Esempio n. 1
0
    def get(self, request, *args, **kwargs):
        # `kwargs` will be used as `nav_param` so extract chcoll_oid from `kwargs` instead of creating param.

        # `chcoll_oid` may be misformatted.
        # If so, `safe_cast` will yield `None` while the original parameter needs to be kept for the case of not found.
        chcoll_oid_str = kwargs.get("chcoll_oid", "")
        chcoll_oid = safe_cast(chcoll_oid_str, ObjectId)

        chcoll_data: Optional[
            ChannelCollectionModel] = ChannelCollectionManager.get_chcoll_oid(
                chcoll_oid)

        if not chcoll_data:
            return WebsiteErrorView.website_error(
                request,
                WebsiteError.CHANNEL_COLLECTION_NOT_FOUND,
                {"chcoll_oid": chcoll_oid_str},
                nav_param=kwargs)

        msgdata_1d = MessageStatsDataProcessor.get_user_chcoll_messages(
            chcoll_data, hours_within=24)
        msgdata_7d = MessageStatsDataProcessor.get_user_chcoll_messages(
            chcoll_data, hours_within=168)

        return render_template(
            self.request,
            _("Channel Collection Info - {}").format(chcoll_oid),
            "info/chcoll/main.html", {
                "chcoll_data":
                chcoll_data,
                "chcoll_cch_data":
                InfoProcessor.collate_child_channel_data(
                    get_root_oid(request), chcoll_data.child_channel_oids),
                "user_message_data1d":
                msgdata_1d,
                "user_message_data7d":
                msgdata_7d
            },
            nav_param=kwargs)
Esempio n. 2
0
def _chcoll_msg_count_list_section_(e: TextMessageEventObject, limit):
    ret = []

    if e.chcoll_model:
        mem_stats_chcoll = MessageStatsDataProcessor.get_user_chcoll_messages(
            e.chcoll_model, hours_within=168).member_stats[:limit]

        ret.append("")
        ret.append(
            _("Top {} Message Count in 7 Days in this channel collection:").
            format(limit))
        ret.append("```")
        ret.append("\n".join([
            f"{entry.total_count:>6} ({_('Ratio %')} {entry.total_count_ratio:>7.02%}) - {entry.user_name}"
            for entry in mem_stats_chcoll
        ]))
        ret.append("```")

    return ret