Example #1
0
def _user_ranking_section_(e: TextMessageEventObject):
    ret = []

    rk_ch_1d = MessageStatsDataProcessor.get_user_channel_ranking(
        e.channel_model, e.user_model.id, hours_within=24)
    if rk_ch_1d.available:
        ret.append(
            _("Current Channel Message Count Ranking in 1 Day - {}").format(
                str(rk_ch_1d)))

    rk_ch_7d = MessageStatsDataProcessor.get_user_channel_ranking(
        e.channel_model, e.user_model.id, hours_within=168)
    if rk_ch_7d.available:
        ret.append(
            _("Current Channel Message Count Ranking in 7 Days - {}").format(
                str(rk_ch_7d)))

    if e.chcoll_model:
        rk_ccoll_1d = MessageStatsDataProcessor.get_user_chcoll_ranking(
            e.chcoll_model, e.user_model.id, hours_within=24)
        if rk_ccoll_1d.available:
            ret.append(
                _("Channel Collection Message Count Ranking in 1 Day - {}").
                format(str(rk_ccoll_1d)))

        rk_ccoll_7d = MessageStatsDataProcessor.get_user_chcoll_ranking(
            e.chcoll_model, e.user_model.id, hours_within=168)
        if rk_ccoll_7d.available:
            ret.append(
                _("Channel Collection Message Count Ranking in 7 Days - {}").
                format(str(rk_ccoll_7d)))

    return ret
Example #2
0
    def get(self, request, *args, **kwargs):
        channel_data = self.get_channel_data(*args, **kwargs)
        chcoll_data: Optional[ChannelCollectionModel] = \
            ChannelCollectionManager.get_chcoll_child_channel(channel_data.model.id)

        root_oid = get_root_oid(request)
        channel_name = channel_data.model.get_channel_name(root_oid)

        msgdata_1d = MessageStatsDataProcessor.get_user_channel_messages(channel_data.model, hours_within=24)
        msgdata_7d = MessageStatsDataProcessor.get_user_channel_messages(channel_data.model, hours_within=168)
        member_info = InfoProcessor.get_member_info(channel_data.model)

        return render_template(
            self.request, _("Channel Info - {}").format(channel_name), "info/channel/main.html",
            {
                "channel_name": channel_name,
                "channel_data": channel_data.model,
                "chcoll_data": chcoll_data,
                "user_message_data1d": msgdata_1d,
                "user_message_data7d": msgdata_7d,
                "member_info": member_info,
                "manageable": bool(ProfileManager.get_user_profiles(channel_data.model.id, root_oid)),
                "bot_usage_7d": BotFeatureUsageDataManager.get_channel_usage(channel_data.model.id, hours_within=168),
                "bot_usage_all": BotFeatureUsageDataManager.get_channel_usage(channel_data.model.id)
            },
            nav_param=kwargs)
Example #3
0
def _content_recent_msgs_(e: TextMessageEventObject, limit: int):
    limit = min(Bot.RecentActivity.DefaultLimitCountDirect, limit)

    ctnt = []

    recent_messages = MessageStatsDataProcessor.get_recent_messages(
        e.channel_model, limit, e.user_model.config.tzinfo)

    for data in recent_messages.data:
        ctnt.append(f"{data.timestamp} - {data.model.message_content}")

    return HandledMessageEventText(content="\n".join(ctnt))
Example #4
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)
Example #5
0
def _channel_msg_count_list_section_(e: TextMessageEventObject, limit):
    ret = []

    mem_stats = MessageStatsDataProcessor.get_user_channel_messages(
        e.channel_model, hours_within=168).member_stats[:limit]

    ret.append(
        _("Top {} Message Count in 7 Days in this channel:").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
    ]))
    ret.append("```")

    return ret
Example #6
0
    def get(self, request, *args, **kwargs):
        channel_data = self.get_channel_data(*args, **kwargs)

        # Check if the user is in the channel
        root_oid = get_root_oid(request)
        profs = ProfileManager.get_user_profiles(channel_data.model.id,
                                                 root_oid)
        if not profs or profs == ChannelProfileConnectionModel.ProfileOids.none_obj(
        ):
            return WebsiteErrorView.website_error(
                request,
                WebsiteError.NOT_IN_THE_CHANNEL,
                {"channel_oid": channel_data.oid_org},
                nav_param=kwargs)

        # Process the necessary data
        channel_name = channel_data.model.get_channel_name(root_oid)

        limit = get_limit(request.GET, Website.RecentActivity.MaxMessageCount)

        ctxt = {
            "channel_name":
            channel_name,
            "channel_data":
            channel_data.model,
            "recent_msg_limit":
            limit or "",
            "recent_msg_limit_max":
            Website.RecentActivity.MaxMessageCount,
            "recent_msg_data":
            MessageStatsDataProcessor.get_recent_messages(
                channel_data.model, limit)
        }

        return render_template(self.request,
                               _("Recent Messages - {}").format(channel_name),
                               "info/recent/message.html",
                               ctxt,
                               nav_param=kwargs)
Example #7
0
def _channel_user_msg_(channel_data, available_only, *, hours_within=None, start=None, end=None):
    return KEY_MSG_USER_CHANNEL, MessageStatsDataProcessor.get_user_channel_messages(
        channel_data, hours_within=hours_within, start=start, end=end, available_only=available_only)
Example #8
0
def _msg_user_daily_(channel_data, tzinfo, available_only, *, hours_within=None, start=None, end=None):
    return KEY_MSG_DAILY_USER, MessageStatsDataProcessor.get_user_daily_message(
        channel_data, tz=tzinfo, hours_within=hours_within, start=start, end=end, available_only=available_only)
Example #9
0
def _msg_intv_count_(
        channel_data, tzinfo, available_only, *, hours_within=None, start=None, end=None, period_count=None):
    return KEY_MSG_INTV_COUNT, MessageStatsDataProcessor.get_user_channel_message_count_interval(
        channel_data, hours_within=hours_within, start=start, end=end,
        period_count=period_count, tz=tzinfo, available_only=available_only)