示例#1
0
def get_order_yesterday_today_statistic():
    all_orders = Order.query.filter(Order.confirmed == True).all()
    yesterday = date.convert_utc_to_asia_tz(datetime.utcnow() -
                                            timedelta(days=1))
    yesterday_start = datetime(yesterday.year,
                               yesterday.month,
                               yesterday.day,
                               tzinfo=yesterday.tzinfo)
    yesterday_end = datetime(yesterday.year,
                             yesterday.month,
                             yesterday.day,
                             23,
                             59,
                             59,
                             tzinfo=yesterday.tzinfo)
    today = date.convert_utc_to_asia_tz(datetime.utcnow())
    today_start = datetime(today.year,
                           today.month,
                           today.day,
                           tzinfo=today.tzinfo)
    yesterday_orders_count = len([
        o for o in all_orders if yesterday_start <=
        date.convert_utc_to_asia_tz(o.confirmation_date) <= yesterday_end
    ])
    today_orders_count = len([
        o for o in all_orders if today_start <= date.convert_utc_to_asia_tz(
            o.confirmation_date) <= today
    ])
    return yesterday_orders_count, today_orders_count
示例#2
0
def get_bot_users_yesterday_today_statistic():
    all_users = get_all_bot_users()
    yesterday = date.convert_utc_to_asia_tz(datetime.utcnow() -
                                            timedelta(days=1))
    yesterday_start = datetime(yesterday.year,
                               yesterday.month,
                               yesterday.day,
                               tzinfo=yesterday.tzinfo)
    yesterday_end = datetime(yesterday.year,
                             yesterday.month,
                             yesterday.day,
                             23,
                             59,
                             59,
                             tzinfo=yesterday.tzinfo)
    yesterday_bot_users_count = len([
        u for u in all_users if yesterday_start <= date.convert_utc_to_asia_tz(
            u.registration_date) <= yesterday_end
    ])
    today = date.convert_utc_to_asia_tz(datetime.utcnow())
    today_start = datetime(today.year,
                           today.month,
                           today.day,
                           tzinfo=today.tzinfo)
    today_bot_users_count = len([
        u for u in all_users if today_start <= date.convert_utc_to_asia_tz(
            u.registration_date) <= today
    ])
    return yesterday_bot_users_count, today_bot_users_count
示例#3
0
def get_yesterday_orders():
    all_orders = get_all_confirmed_orders()
    yesterday = date.convert_utc_to_asia_tz(datetime.utcnow() - timedelta(days=1))
    yesterday_start = datetime(yesterday.year, yesterday.month, yesterday.day, tzinfo=yesterday.tzinfo)
    yesterday_end = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59, tzinfo=yesterday.tzinfo)
    yesterday_orders = [o for o in all_orders if yesterday_start <= date.convert_utc_to_asia_tz(o.confirmation_date) <= yesterday_end]
    return yesterday_orders
示例#4
0
def order(order_id: int):
    current_order = orderservice.get_order_by_id(order_id)
    order_date = date.convert_utc_to_asia_tz(
        current_order.confirmation_date).strftime('%d.%m.%Y %H:%M:%S')
    total_sum = _total_order_sum(current_order.order_items.all())
    return render_template('admin/order.html',
                           title="Заказ от {}".format(order_date),
                           area='orders',
                           order=current_order,
                           total_sum=total_sum)
示例#5
0
 def to_dict(self):
     return {
         'id':
         self.id,
         'userId':
         self.user_id,
         'testId':
         self.test_id,
         'points':
         self.points,
         'is_right':
         self.is_right,
         'createdAt':
         dateutils.convert_utc_to_asia_tz(
             self.created_at).strftime('%d.%m.%Y'),
         'channelId':
         self.channel_id,
         'quizId':
         self.quiz_id
     }
示例#6
0
def answers_processor(test_id, option_id, user: User, channel_chat_id,
                      query: CallbackQuery):
    """
    Processor which process user answers
    :param test_id: The test id which the user given an answer
    :param option_id: The answer id
    :param user: The user
    :param channel_chat_id: Telegram chat id of channel
    :param query: Telegram Callback query
    :return: void
    """
    channel = Channel.get_by_chat_id(channel_chat_id)
    if not channel:
        # if channel is not registered just stop processing
        return
    # if user given answer in first time, add him to channel members
    current_user = BotUser.add_user(user.id, user.first_name, user.last_name,
                                    user.username)
    channel.add_member(current_user)
    test = Test.get_by_id(test_id)
    if not test:
        message = strings.get_string('answer.test_not_found')
        _answer_callback_query_safely(query.id, message)
        return
    # Check if user given an answer for current quiz
    now_utc = datetime.utcnow()
    quiz_date = test.quiz.end_date
    local_date = date.convert_utc_to_asia_tz(now_utc)
    if datetime(local_date.year, local_date.month, local_date.day) > datetime(
            quiz_date.year, quiz_date.month, quiz_date.day):
        message = strings.get_string('answer.quiz_already_ended')
        _answer_callback_query_safely(query.id, message, show_alert=True)
        return
    if test.user_given_right_answer(user_id=current_user.id):
        # if user already given the right answer send message to him and stop processing
        message = strings.get_string('answer.already_given')
        _answer_callback_query_safely(query.id, message, show_alert=True)
        return
    right_answer = test.get_right_answer()
    # if user given right answer
    if int(option_id) == right_answer.id:
        answer_right = True
        answers_count = test.get_count_user_answers(user.id)
        # If user given right answer on first try
        if answers_count == 0:
            # If user not in top 10, but answered on first try
            answer_points = settings.get_right_answer_points()
            message = strings.get_string(
                'answer.right_answer_on_the_first_try').format(answer_points)
        else:
            # if user answered not on first try
            answer_points = 0
            message = strings.get_string(
                'answer.right_answer_on_the_not_first_try').format(
                    answers_count + 1, answer_points)
    else:
        answer_right = False
        answer_points = 0
        message = strings.get_string('answer.wrong_answer')
    answer = Answer(user_id=user.id,
                    points=answer_points,
                    channel_id=channel.id,
                    is_right=answer_right,
                    quiz_id=test.quiz.id)
    test.add_answer(answer)
    _answer_callback_query_safely(query.id, message, show_alert=True)