Ejemplo n.º 1
0
    def test_get_curr_time_diff(self):
        start = arrow.Arrow(2017, 8, 14, 12, 0)
        end = arrow.Arrow(2017, 8, 14, 13, 0)

        self.assertEqual(ArrowUtil.get_curr_time_diff(start=start, stop=end), 60)
        self.assertEqual(
            ArrowUtil.get_curr_time_diff(start=start, stop=end, base_hour=True), 1
        )
Ejemplo n.º 2
0
    def edit_attention(self, category, data, days=0):
        record = self.read_record(days=days)
        activity_data = record.get("activity", {})

        assert category in activity_data

        latest_data = activity_data[category][-1]
        task_end_time = arrow.get(latest_data["end_time"])
        current_time = data["time"]

        if ArrowUtil.get_curr_time_diff(task_end_time, current_time) < 40:
            latest_data["score"] = data["score"]
        else:
            pass

        self.edit_record(("activity", activity_data), days=days)
Ejemplo n.º 3
0
    def edit_attention(self, category, data, days=0):
        record = self.read_record(days=days)
        activity_data = record.get("activity", {})

        assert category in activity_data

        latest_data = activity_data[category][-1]
        task_end_time = arrow.get(latest_data["end_time"])
        current_time = data["time"]

        if ArrowUtil.get_curr_time_diff(task_end_time, current_time) < 40:
            latest_data["score"] = data["score"]
        else:
            pass

        self.edit_record(("activity", activity_data), days=days)
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)
Ejemplo n.º 5
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)