Example #1
0
    def table_pagesize2split_OLD(cls, table, ncol_per_page):
        buffer = cls.COUNT_COLHEAD
        ncol_overlap = 1  # overlapping column 1

        n_row = len(table)
        divider = ncol_per_page - buffer - ncol_overlap

        ncol_table = iter2singleton(map(len, table))
        ncol_data = ncol_table - buffer

        n_page = (ncol_data - ncol_overlap) // divider + (
            1 if (ncol_data - ncol_overlap) % divider else 0)

        cols_header = lmap(lambda l: l[:cls.COUNT_COLHEAD], table)
        for i in range(n_page):
            start = buffer + i * divider
            end = buffer + min((i + 1) * divider + 1, ncol_data)

            cols_body = lmap(
                lambda l: SpanTool.list_span2sublist(l, (start, end)), table)

            table_partial = [
                cols_header[i] + cols_body[i] for i in range(n_row)
                if any(cols_body[i])
            ]
            yield table_partial
Example #2
0
    def test_03(self):
        logger = HenriqueLogger.func_level2logger(self.test_02, logging.DEBUG)

        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        now_seoul = datetime.now(
            tz=pytz.timezone(HenriqueLocale.lang2tzdb("ko")))
        dt_target = now_seoul - timedelta(seconds=3 * 60)
        text = "?남만 {}".format(dt_target.strftime("%I:%M %p").lstrip("0"))
        logger.debug({
            "text": text,
            "now_seoul": now_seoul,
        })

        packet = {
            KhalaPacket.Field.TEXT: text,
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }
        response = NanbanSkill.packet2response(packet)

        # pprint(text)
        # pprint(response)

        response_lines = response.splitlines()

        span = (
            len("다음 남만 시각: "),
            len("다음 남만 시각: 3:58:00 PM (KST) "),
        )

        hyp = SpanTool.list_span2sublist(response_lines[2], span).strip()
        dt_nanban = dt_target + NanbanTimedelta.period()
        ref = dt_nanban.strftime("%I:%M:00 %p (KST)").lstrip("0")
        self.assertEqual(
            hyp,
            ref,
        )
Example #3
0
 def str_span2substr(cls, str_in, span):
     return SpanTool.list_span2sublist(str_in, span)
Example #4
0
 def entity_list2entities_list_grouped(cls, text, entity_list):
     return [
         SpanTool.list_span2sublist(entity_list, span)
         for span in cls.entity_list2group_spans(text, entity_list)
     ]
Example #5
0
 def fulltext2text(_entity):
     fulltext = cls.entity2fulltext(_entity)
     span = cls.entity2span(_entity)
     return SpanTool.list_span2sublist(fulltext, span)
Example #6
0
 def gap2valid(span):
     str_span = SpanTool.list_span2sublist(text_in, span)
     return RegexTool.pattern_str2match_full(cls.pattern_colon(),
                                             str_span)