Ejemplo n.º 1
0
    def get_ideal_series(self, times, task, direction):
        series = []
        weekday = 5

        task_per_day = float(task / (weekday * self.SPRINT_WEEK))
        remain_task = task

        for (index, time) in enumerate(times):
            if index == 0:
                series.append(remain_task)
                continue

            time = utils.add_time(time, -1)

            if utils.is_weekend(time):
                series.append(remain_task)
            else:
                remain_task -= task_per_day
                series.append(remain_task)

        if direction == "up":
            maximum = max(series)
            return list(map(lambda x: maximum - x, series))

        return series
Ejemplo n.º 2
0
    def initial_import(self):

        traced_date = utils.load_last_date(self.last_file)

        if traced_date is None:
            start_date = datetime.datetime.now() - datetime.timedelta(days=90)
        else:
            start_date = traced_date + datetime.timedelta(days=1)

        status = True
        i = 0

        # retrieve max. 90 records, if possible
        while status and (i < 90):
            print("date processing", start_date.strftime("%d-%m-%Y"), "...")

            # skip Saturday and Sunday
            if not utils.is_weekend(start_date):
                date_str = start_date.strftime("%d-%m-%Y")
                import_details = utils.retrieve_reports(
                    url=self.url,
                    market=self.market,
                    dst_file=self.file_name,
                    date_val=date_str,
                    cols=self.csv_cols)
                status = import_details.status
                utils.save_last_date(self.last_file, date_str)

                # random sleep intervals (it is good to have some to avoid banning)
                time.sleep(utils.generate_sleep_val())

                i += 1

            start_date = start_date + datetime.timedelta(days=1)
Ejemplo n.º 3
0
async def send_go(event: SimpleBotEvent):
    now = get_now()
    if is_weekend(now):
        return "В выходные поучиться захотелось?"

    percent = create_percent(user_id=event.object.object.message.from_id,
                             now=now)

    await event.answer(f"Идти на пары стоит с вероятностью {percent}%")
Ejemplo n.º 4
0
async def tomorrow(event: SimpleBotEvent):
    now = get_now()
    tomorrow_date = now + datetime.timedelta(days=1)
    if is_weekend(tomorrow_date):
        return "завтра выходной, хд"

    await event.answer(
        await create_one_day_schedule(tomorrow_date, tomorrow=True),
        dont_parse_links=True,
    )
Ejemplo n.º 5
0
    def try_fetch(self):
        cur_date = datetime.datetime.now()
        traced_date = utils.load_last_date(self.last_file)

        # skip Saturday and Sunday
        if not utils.is_weekend(cur_date) and \
                (traced_date is None or cur_date.date() > traced_date.date()):
            date_str = cur_date.strftime("%d-%m-%Y")
            _ = utils.retrieve_reports(url=self.url,
                                       market=self.market,
                                       dst_file=self.file_name,
                                       date_val=date_str,
                                       cols=self.csv_cols)
            utils.save_last_date(self.last_file, date_str)
Ejemplo n.º 6
0
async def today(event: SimpleBotEvent):
    now = get_now()
    if is_weekend(now):
        return "ниче нет"

    await event.answer(await create_one_day_schedule(now), dont_parse_links=True)
Ejemplo n.º 7
0
    def create_image(
        self,
        data,
        direction,
        total_count=0,
        x_label="Time Series",
        y_label="Task Count",
    ):
        total_count = total_count
        times = utils.get_time_series(
            start=utils.add_time(days=self.SPRINT_WEEK * -7),
            week=self.SPRINT_WEEK)

        fig, axes = plt.subplots(1)
        fig.autofmt_xdate()

        plt.grid(True, axis="x", linestyle="--")

        plt.plot(
            times,
            self.get_ideal_series(times=times,
                                  task=total_count,
                                  direction=direction),
            color="red",
            alpha=0.7,
            label="Ideal Chart",
        )

        plt.plot(
            times,
            data,
            color="grey",
            marker=".",
            alpha=0.3,
        )
        plt.plot(
            times,
            data,
            drawstyle="steps",
            color="blue",
            alpha=0.7,
            label="Actual Chart",
        )

        plt.legend()

        # 주말 영역은 색칠하기
        for time in times[:-1]:
            if utils.is_weekend(time):
                plt.axvspan(
                    time,
                    time + timedelta(days=1),
                    facecolor="0.2",
                    alpha=0.1,
                )

        plt.xlabel(x_label)
        plt.ylabel(y_label)

        date_format = mdates.DateFormatter("%m-%d")
        axes.xaxis.set_major_formatter(date_format)

        plt.savefig("burnchart.png")
def determine_home_work_places(user_id, nb_days=3, hour_threshold=3):
    home_hours = [(0, 7), (20, 23)]
    work_hours = [(9, 18)]
    home_threshold = 60 * 60 * hour_threshold * nb_days  # 4 hour threshold default
    work_threshold = 0

    places = {}

    # get all the days
    # compute the unique places visited and the time spend at these places
    days = []
    day = utils.previous_day(utils.today_string())
    for i in range(nb_days):
        days.append(day)
        day = utils.previous_day(day)

    for day in days:
        weekend = utils.is_weekend(day)
        visits = user_traces_db.load_user_visits_utc(user_id, day)

        if len(visits) == 0:
            return None, None

        if not weekend:
            work_threshold += 60 * 60 * hour_threshold

        # fix the last visit
        last_visit = visits[-1]
        utc_offset = last_visit['d_utc']

        if not utc_offset:
            return None, None

        last_visit_end = last_visit['d'] - utc_offset  # departure_utc - utc_offset
        last_visit_end = utils.end_of_day(last_visit_end)
        visits[-1]['d'] = last_visit_end + utc_offset

        for visit in visits:
            start = max(utils.start_of_day_str(day), visit['a'] - visit['d_utc'])  # arrival_utc and utc_offset
            end = visit['d'] - visit['d_utc']  # departure_utc and utc_offset
            place_id = visit['pid']

            # place = user_traces_db.load_user_place(user_id, place_id)
            # print("%s [%s %s -> %s %s] %s" % (day, utils.timestamp_to_day_str(start), utils.hm(start), utils.timestamp_to_day_str(end), utils.hm(end), place['name']))

            work_seconds = 0
            if not weekend:
                work_seconds = utils.seconds_in_hour_range(start, end, work_hours)
            home_seconds = utils.seconds_in_hour_range(start, end, home_hours)
            if place_id not in places:
                places[place_id] = [0, 0]
            places[place_id] = map(add, places[place_id], [home_seconds, work_seconds])

    new_places = {}
    for pid, p in places.items():
        new_places[pid] = list(p)

    # Determine the work and home places
    home_place = None
    home_places = [(pid, p[0]) for pid, p in new_places.items() if p[0] > home_threshold]
    if len(home_places):
        home_place = max(home_places, key=lambda x: x[1])

    # can have multiple work locations
    work_places = [pid for pid, p in new_places.items() if p[1] > work_threshold]

    return home_place[0] if home_place else None, work_places