new data endpoints and support for non-binary genders in admin stats (way overdue)

This commit is contained in:
matticoli 2022-01-11 23:37:05 -05:00
parent 10e623f899
commit 198f56f2c4
2 changed files with 18 additions and 5 deletions

View file

@ -18,6 +18,7 @@ from werkzeug.utils import secure_filename
from config_hackWPI import (api_keys, SERVER_LISTEN_ADDR, SERVER_PORT, WAITLIST_LIMIT, HACKATHON_TIME,
ALLOWED_EXTENSIONS, REGISTRATION_OPEN, MCE_API_KEY)
from mail import send_message
from admin import json_to_csv
app = Flask(__name__)
app.config.from_pyfile('config.py')
@ -274,6 +275,12 @@ def send():
send_message(to, subject, html, text)
return "Message sent successfully to {0} recipients".format(len(to))
@app.route('/hackers.csv', methods=['GET'])
def hackers_csv():
if not is_admin():
return redirect(url_for('register'))
return json_to_csv(admin(True))
@app.route('/hackers', methods=['GET'])
def hackers():
if not is_admin():
@ -294,6 +301,7 @@ def admin(return_hackers=False):
shirt_count = {'xxs': 0, 'xs': 0, 's': 0, 'm': 0, 'l': 0, 'xl': 0, 'xxl': 0}
male_count = 0
female_count = 0
nb_count = 0
schools = {}
majors = {}
@ -317,8 +325,10 @@ def admin(return_hackers=False):
if hacker['gender'] == 'Male':
male_count += 1
else:
elif hacker['gender'] == 'Female':
female_count += 1
else:
nb_count += 1
total_count += 1
if not 'school' in hacker:
@ -356,7 +366,7 @@ def admin(return_hackers=False):
return hackers
return render_template('admin.html', hackers=hackers, total_count=total_count, waitlist_count=waitlist_count,
check_in_count=check_in_count, shirt_count=shirt_count, female_count=female_count,
check_in_count=check_in_count, shirt_count=shirt_count, female_count=female_count, nb_count=nb_count,
male_count=male_count, schools=schools, majors=majors,
mlh_url='https://my.mlh.io/api/v3/users.json?client_id=' + api_keys['mlh'][
'client_id'] + '&secret=' + api_keys['mlh'][

View file

@ -40,7 +40,10 @@
<div class="contact-section" style="height: auto; background-repeat: repeat; background-size: contain;">
<div class="container-fluid" style="margin-left: 3%; margin-right: 3%;">
<div class="row" style="margin-top: 10%;">
<h2><a href="{{ mlh_url }}">Get JSON object of users from MLH. <b>Do NOT share this URL.</b></a></h2>
<h5>JSON object of users from MLH (Including dropped applications):</h5>
<p><a href="{{ mlh_url }}"><b>Do NOT share this URL.</b></a></p>
<h5>Get registered hackers only:</h5>
<p><a href="/hackers">JSON</a> <a href="/hackers.csv">CSV</a></p>
</div>
<div class="row">
<div class="col-md-4">
@ -51,10 +54,10 @@
let genderChart = new Chart(genderCtx, {
type: 'doughnut',
data: {
labels: ['Female', 'Male'],
labels: ['Female', 'Male', 'Non-Binary/Other'],
datasets: [
{
data: [{{ female_count }}, {{ male_count }}]
data: [{{ female_count }}, {{ male_count }}, {{ nb_count }}]
}
]
},