def _log_task(self, task):
        """ Logs task record to file.

            `task`
                ``Task`` instance.
            """
        if not task.duration:
            return

        self._setup_dir(task.base_dir)
        stats_dir = self._sdir(task.base_dir)
        duration = task.duration

        while duration > 0:
            # build filename
            date = (datetime.datetime.now() -
                    datetime.timedelta(minutes=duration))
            date_str = date.strftime('%Y%m%d')
            filename = os.path.join(stats_dir, '{0}.json'.format(date_str))

            with open(filename, 'a+') as file_:
                # fetch any existing data
                try:
                    file_.seek(0)
                    data = json.loads(file_.read())
                except (ValueError, OSError):
                    data = {}

                if not task.name in data:
                    data[task.name] = 0

                # how much total time for day
                try:
                    total_time = sum(int(x) for x in data.values())
                    if total_time > MINS_IN_DAY:
                        total_time = MINS_IN_DAY

                except __HOLE__:
                    total_time = 0

                # constrain to single day
                amount = duration
                if amount + total_time > MINS_IN_DAY:
                    amount = MINS_IN_DAY - total_time

                    # invalid or broken state, bail
                    if amount <= 0:
                        break

                data[task.name] += amount
                duration -= amount

                # write file
                try:
                    file_.seek(0)
                    file_.truncate(0)
                    file_.write(json.dumps(data))
                except (ValueError, OSError):
                    pass
dataset/ETHPy150Open xtrementl/focus/focus/plugin/modules/stats.py/Stats._log_task