Ejemplo n.º 1
0
 def test_summary(self):
     data = {
             "Color": "RED",
             "Total": "90"
             }
     attachments = MsgTemplate.make_summary_template(data)
     self.assertEqual(isinstance(attachments, list), True)
Ejemplo n.º 2
0
    def total_score(self):
        today_data = self.__get_total_score()
        self.data_handler.edit_summary(today_data)

        color = MsgResource.SCORE_COLOR(today_data["total"])
        today_data["Color"] = color

        yesterday_data = self.__get_total_score(-1)
        for k, v in today_data.items():
            if isinstance(v, float):
                y_point = yesterday_data.get(k, False)
                if not y_point:
                    continue
                else:
                    diff = v - float(y_point)
                    diff = round(diff * 100) / 100

                if diff > 0:
                    diff = "+" + str(diff)
                else:
                    diff = str(diff)
                today_data[k] = str(v) + " (" + diff + ")"
            elif isinstance(v, bool):
                if v:
                    today_data[k] = "O"
                else:
                    today_data[k] = "X"

        record = self.data_handler.read_record()
        activity = record.get("activity", {})

        # Sleep Time
        go_to_bed = activity.get("go_to_bed", None)
        wake_up = activity.get("wake_up", None)

        if go_to_bed is not None and wake_up is not None:
            go_to_bed_time = arrow.get(go_to_bed)
            wake_up_time = arrow.get(wake_up)

            sleep_hour = ArrowUtil.get_curr_time_diff(start=go_to_bed_time,
                                                      stop=wake_up_time,
                                                      base_hour=True)
            today_data["Sleep"] = (go_to_bed_time.format("HH:mm") + " ~ " +
                                   wake_up_time.format("HH:mm") + " : " +
                                   str(sleep_hour) + "h (" +
                                   str(today_data["Sleep"]) + ")")

        # Working Hour
        in_company = activity.get("in_company", None)
        out_company = activity.get("out_company", None)

        if in_company is not None and out_company is not None:
            in_company_time = arrow.get(in_company)
            out_company_time = arrow.get(out_company)

            working_hour = ArrowUtil.get_curr_time_diff(start=in_company_time,
                                                        stop=out_company_time,
                                                        base_hour=True)
            today_data["Working Hour"] = (in_company_time.format("HH:mm") +
                                          " ~ " +
                                          out_company_time.format("HH:mm") +
                                          " : " + str(working_hour) + "h")

        attachments = MsgTemplate.make_summary_template(today_data)
        self.slackbot.send_message(attachments=attachments)
 def test_summary(self):
     data = {"Color": "RED", "total": "90"}
     attachments = MsgTemplate.make_summary_template(data)
     self.assertEqual(isinstance(attachments, list), True)
Ejemplo n.º 4
0
    def total_score(self):
        today_data = self.__get_total_score()
        self.data_handler.edit_summary(today_data)

        color = MsgResource.SCORE_COLOR(today_data["total"])
        today_data["Color"] = color

        yesterday_data = self.__get_total_score(-1)
        for k, v in today_data.items():
            if isinstance(v, float):
                y_point = yesterday_data.get(k, False)
                if not y_point:
                    continue
                else:
                    diff = v - float(y_point)
                    diff = round(diff * 100) / 100

                if diff > 0:
                    diff = "+" + str(diff)
                else:
                    diff = str(diff)
                today_data[k] = str(v) + " (" + diff + ")"
            elif isinstance(v, bool):
                if v:
                    today_data[k] = "O"
                else:
                    today_data[k] = "X"

        record = self.data_handler.read_record()
        activity = record.get("activity", {})

        # Sleep Time
        go_to_bed = activity.get("go_to_bed", None)
        wake_up = activity.get("wake_up", None)

        if go_to_bed is not None and wake_up is not None:
            go_to_bed_time = arrow.get(go_to_bed)
            wake_up_time = arrow.get(wake_up)

            sleep_hour = ArrowUtil.get_curr_time_diff(
                start=go_to_bed_time, stop=wake_up_time, base_hour=True
            )
            today_data["Sleep"] = (
                go_to_bed_time.format("HH:mm")
                + " ~ "
                + wake_up_time.format("HH:mm")
                + " : "
                + str(sleep_hour)
                + "h ("
                + str(today_data["Sleep"])
                + ")"
            )

        # Working Hour
        in_company = activity.get("in_company", None)
        out_company = activity.get("out_company", None)

        if in_company is not None and out_company is not None:
            in_company_time = arrow.get(in_company)
            out_company_time = arrow.get(out_company)

            working_hour = ArrowUtil.get_curr_time_diff(
                start=in_company_time, stop=out_company_time, base_hour=True
            )
            today_data["Working Hour"] = (
                in_company_time.format("HH:mm")
                + " ~ "
                + out_company_time.format("HH:mm")
                + " : "
                + str(working_hour)
                + "h"
            )

        attachments = MsgTemplate.make_summary_template(today_data)
        self.slackbot.send_message(attachments=attachments)