Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-9075: Remove empty line, add - in format jinja2 to remove empty l… #9091

Closed
wants to merge 9 commits into from
120 changes: 97 additions & 23 deletions app/api/custom/check_in_stats.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand from the description that this PR fixes the extra empty line on QR codes for checkin attendees. But the modifications on this file seem related to check-in stats. Just trying to understand, could you explain how this changes are related? thanks in advance!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that merge from this branch https://github.com/lthanhhieu/open-event-server/tree/lthanhhieu-tma/feature-9077 to fix issue in UT Test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is the combination of two PR/feature branches?
That is not good, please separate them or do them one by one, otherwise we cannot reasonably review code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please review the PR 9077 first, after that I will change this PR as well.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from flask import Blueprint, request
from sqlalchemy import desc
from sqlalchemy import asc, desc, func

from app.api.helpers.permissions import jwt_required
from app.api.helpers.static import STATION_TYPE
Expand Down Expand Up @@ -30,11 +30,10 @@ def get_registration_stats(event_id):
"""
# check if event is existed
event = Event.query.filter(Event.id == event_id).first()
current_time = datetime.datetime.utcnow().date()
total_attendee = TicketHolder.query.filter(TicketHolder.event_id == event_id).count()
if event is None:
return {"message": "Event can not be found."}, 404
stations = Station.query.filter(Station.event_id == event_id).all()
total_attendee = TicketHolder.query.filter(TicketHolder.event_id == event_id).count()
registration_stations = [
station.id
for station in stations
Expand All @@ -50,24 +49,94 @@ def get_registration_stats(event_id):
for station in stations
if station.station_type == STATION_TYPE.get('check out')
]
data = {
"total_attendee": total_attendee,
"registration_stations": registration_stations,
"check_in_stations": check_in_stations,
"check_out_stations": check_out_stations,
}

if request.args.get('today_only'):
results = {}
date = datetime.date.today().strftime("%Y-%m-%d")
data["date"] = date
results[date] = get_data_by_date(data)
else:
stationIds = []
for station in stations:
stationIds.append(station.id)
date_list = list(
zip(
*db.session.query(func.date(UserCheckIn.created_at))
.distinct()
.filter(
UserCheckIn.station_id.in_(stationIds),
)
.order_by(asc(func.date(UserCheckIn.created_at)))
.all()
)
)
dates = list(
map(
str,
date_list[0] if date_list else [],
)
)

if len(dates) == 0:
return {
"total_attendee": total_attendee,
"total_registered": 0,
"total_not_checked_in": total_attendee - 0,
"total_track_checked_in": 0,
"total_track_checked_out": 0,
"total_session_checked_in": 0,
"total_session_checked_out": 0,
"track_stats": [],
"session_stats": [
{
"check_in": 0,
"check_out": 0,
"manual_count": {},
"session_id": request.args.get('session_ids'),
"session_name": "",
"speakers": [],
"track_name": "",
}
],
}, 200

results = {}
for date in dates:
data["date"] = date
results[date] = get_data_by_date(data)
return results, 200


def get_data_by_date(data):
"""
Get data by date
@param data
@return: result
"""
registered_attendee = (
UserCheckIn.query.with_entities(UserCheckIn.ticket_holder_id)
.filter(
UserCheckIn.station_id.in_(registration_stations),
UserCheckIn.created_at >= current_time,
UserCheckIn.station_id.in_(data['registration_stations']),
func.date(UserCheckIn.created_at) == data['date'],
)
.group_by(UserCheckIn.ticket_holder_id)
.count()
)

check_in_attendee = UserCheckIn.query.filter(
UserCheckIn.station_id.in_(check_in_stations),
UserCheckIn.created_at >= current_time,
UserCheckIn.station_id.in_(data['check_in_stations']),
func.date(UserCheckIn.created_at) == data['date'],
)

check_out_attendee = UserCheckIn.query.filter(
UserCheckIn.station_id.in_(check_out_stations),
UserCheckIn.created_at >= current_time,
UserCheckIn.station_id.in_(data['check_out_stations']),
func.date(UserCheckIn.created_at) == data['date'],
)

session_checked_in = check_in_attendee.with_entities(
Expand All @@ -86,9 +155,9 @@ def get_registration_stats(event_id):
Session.id.in_(
[user_check_in.session_id for user_check_in in session_checked_in]
),
UserCheckIn.station_id.in_(check_in_stations),
UserCheckIn.station_id.in_(data['check_in_stations']),
Session.id == UserCheckIn.session_id,
UserCheckIn.created_at >= current_time,
func.date(UserCheckIn.created_at) == data['date'],
)

track_checked_in_count = (
Expand All @@ -101,9 +170,9 @@ def get_registration_stats(event_id):
Session.id.in_(
[user_check_in.session_id for user_check_in in session_checked_out]
),
UserCheckIn.station_id.in_(check_out_stations),
UserCheckIn.station_id.in_(data['check_out_stations']),
UserCheckIn.session_id == Session.id,
UserCheckIn.created_at >= current_time,
func.date(UserCheckIn.created_at) == data['date'],
)

track_checked_out_count = (
Expand All @@ -115,30 +184,32 @@ def get_registration_stats(event_id):
track_stat = []
if request.args.get('session_ids'):
session_stat = get_session_stats(
request.args.get('session_ids'), session_checked_in, session_checked_out
request.args.get('session_ids'),
session_checked_in,
session_checked_out,
data['date'],
)
if request.args.get('track_ids'):
track_stat = get_track_stats(
request.args.get('track_ids'),
check_in_attendee,
check_out_attendee,
current_time,
data['date'],
)

return {
"total_attendee": total_attendee,
"total_attendee": data['total_attendee'],
"total_registered": registered_attendee,
"total_not_checked_in": total_attendee - registered_attendee,
"total_not_checked_in": data['total_attendee'] - registered_attendee,
"total_track_checked_in": track_checked_in_count,
"total_track_checked_out": track_checked_out_count,
"total_session_checked_in": session_checked_in_count,
"total_session_checked_out": session_checked_out_count,
"session_stats": session_stat,
"track_stats": track_stat,
}, 200
}


def get_session_stats(session_ids, session_checked_in, session_checked_out):
def get_session_stats(session_ids, session_checked_in, session_checked_out, date):
"""
Get session stats
@param session_ids: session id to get
Expand Down Expand Up @@ -181,7 +252,10 @@ def get_session_stats(session_ids, session_checked_in, session_checked_out):

stationStorePaxs = (
db.session.query(StationStorePax)
.filter(StationStorePax.session_id == session_id)
.filter(
StationStorePax.session_id == session_id,
func.date(StationStorePax.created_at) == date,
)
.order_by(desc("created_at"))
.all()
)
Expand Down Expand Up @@ -231,7 +305,7 @@ def get_track_stats(track_ids, check_in_attendee, check_out_attendee, current_ti
),
UserCheckIn.id.in_([user_check_in.id for user_check_in in check_in_attendee]),
Session.id == UserCheckIn.session_id,
UserCheckIn.created_at >= current_time,
func.date(UserCheckIn.created_at) == current_time,
Session.track_id == track_id,
)

Expand All @@ -249,7 +323,7 @@ def get_track_stats(track_ids, check_in_attendee, check_out_attendee, current_ti
[user_check_in.id for user_check_in in check_out_attendee]
),
UserCheckIn.session_id == Session.id,
UserCheckIn.created_at >= current_time,
func.date(UserCheckIn.created_at) == current_time,
Session.track_id == track_id,
)

Expand Down
1 change: 1 addition & 0 deletions app/api/helpers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ def create_print_badge_pdf(self, attendee_id, list_field_show):
),
UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badge_form.badge_id),
identifier=badge_form.badge_id,
new_renderer=True,
)
result = {'download_url': badge_url}
ticket_holder.is_badge_printed = True
Expand Down
Loading