2023-09-13 11:49:08 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
import os
|
|
|
|
|
2023-09-13 11:49:08 +01:00
|
|
|
import flask
|
2023-09-21 04:59:17 +01:00
|
|
|
from sqlalchemy import func, or_, update
|
2023-09-15 19:04:41 +01:00
|
|
|
from werkzeug.wrappers import Response
|
2023-09-13 11:49:08 +01:00
|
|
|
|
2023-09-25 15:20:01 +01:00
|
|
|
from confarchive import database, model, wikidata, query, utils
|
2023-09-13 11:49:08 +01:00
|
|
|
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
app.debug = True
|
|
|
|
|
|
|
|
app.config.from_object("config.default")
|
|
|
|
database.init_app(app)
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
@app.route("/person/<int:person_id>", methods=["GET", "POST"])
|
|
|
|
def person(person_id: int) -> str | Response:
|
|
|
|
item = model.Person.query.get(person_id)
|
2023-09-24 22:19:09 +01:00
|
|
|
if flask.request.method == "POST" and check_admin_mode():
|
2023-09-22 21:00:56 +01:00
|
|
|
qid = flask.request.form["wikidata_qid"] or None
|
2023-09-15 19:04:41 +01:00
|
|
|
item.name = flask.request.form["name"]
|
2023-09-22 21:00:56 +01:00
|
|
|
|
|
|
|
if qid and qid != item.wikidata_qid:
|
|
|
|
item.wikidata_qid = qid
|
|
|
|
wd_item = wikidata.get_item(qid)
|
|
|
|
if "P18" in wd_item["claims"]:
|
|
|
|
claim_p18 = wd_item["claims"]["P18"]
|
|
|
|
wikidata_photo = [
|
2023-09-25 15:20:01 +01:00
|
|
|
utils.drop_start(s["mainsnak"]["datavalue"]["value"], "-")
|
2023-09-22 21:00:56 +01:00
|
|
|
for s in claim_p18
|
|
|
|
]
|
|
|
|
for filename in wikidata_photo:
|
|
|
|
print(filename)
|
|
|
|
wikidata.get_photo(filename)
|
|
|
|
item.wikidata_photo = wikidata_photo
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
database.session.commit()
|
|
|
|
assert flask.request.endpoint
|
|
|
|
return flask.redirect(
|
|
|
|
flask.url_for(flask.request.endpoint, person_id=person_id)
|
|
|
|
)
|
|
|
|
|
2023-09-22 21:00:56 +01:00
|
|
|
wikidata_hits: list[dict[str, str]] = []
|
|
|
|
if False and item.wikidata_qid is None:
|
2023-09-24 21:41:30 +01:00
|
|
|
q = item.name + " haswbstatement:P31=Q5"
|
|
|
|
search_hits = wikidata.search(q)
|
2023-09-22 21:00:56 +01:00
|
|
|
print(len(search_hits))
|
|
|
|
for search_hit in search_hits:
|
|
|
|
qid = search_hit["title"]
|
|
|
|
wd_item = wikidata.get_item(qid)
|
|
|
|
if "en" in wd_item["labels"]:
|
|
|
|
label = wd_item["labels"]["en"]["value"]
|
|
|
|
else:
|
|
|
|
label = "[no english label]"
|
|
|
|
|
|
|
|
if "en" in wd_item["descriptions"]:
|
|
|
|
description = wd_item["descriptions"]["en"]["value"]
|
|
|
|
else:
|
|
|
|
description = "[no english description]"
|
|
|
|
|
|
|
|
wikidata_hits.append(
|
|
|
|
{
|
|
|
|
"qid": qid,
|
|
|
|
"label": label,
|
|
|
|
"description": description,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
return flask.render_template(
|
2023-09-22 21:00:56 +01:00
|
|
|
"person.html",
|
|
|
|
item=item,
|
|
|
|
Event=model.Event,
|
2023-09-25 15:20:01 +01:00
|
|
|
plural=utils.plural,
|
2023-09-22 21:00:56 +01:00
|
|
|
wikidata_hits=wikidata_hits,
|
2023-09-24 22:19:09 +01:00
|
|
|
is_admin=check_admin_mode,
|
2023-09-21 04:59:17 +01:00
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
|
2023-09-25 15:45:53 +01:00
|
|
|
@app.route("/person/<int:person_id>/split", methods=["GET", "POST"])
|
|
|
|
def split_person(person_id: int) -> str | Response:
|
|
|
|
"""Split person."""
|
|
|
|
item = model.Person.query.get(person_id)
|
|
|
|
assert not item.wikidata_qid
|
|
|
|
if flask.request.method == "GET":
|
|
|
|
return flask.render_template(
|
|
|
|
"person/split.html",
|
|
|
|
item=item,
|
|
|
|
)
|
|
|
|
|
|
|
|
names = flask.request.form["names"].strip().splitlines()
|
|
|
|
print(names)
|
|
|
|
assert len(names) > 1
|
|
|
|
|
|
|
|
item.name = names[0]
|
|
|
|
for cp in item.conferences_association:
|
|
|
|
cp.named_as = names[0]
|
|
|
|
|
|
|
|
for num, name in enumerate(names[1:], start=2):
|
|
|
|
person = model.Person(name=name)
|
|
|
|
database.session.add(person)
|
|
|
|
|
|
|
|
for cp0 in item.conferences_association:
|
|
|
|
cp = model.ConferencePerson(
|
|
|
|
person=person, named_as=name, conference_id=cp0.conference_id
|
|
|
|
)
|
|
|
|
database.session.add(cp)
|
|
|
|
|
|
|
|
for event0 in item.events_association:
|
|
|
|
ep = model.EventPerson(
|
|
|
|
person=person, event_id=event0.event_id, position=num
|
|
|
|
)
|
|
|
|
database.session.add(ep)
|
|
|
|
|
|
|
|
database.session.commit()
|
|
|
|
|
|
|
|
return flask.redirect(flask.url_for("person", person_id=person_id))
|
|
|
|
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
@app.route("/event/<int:event_id>")
|
|
|
|
def event_page(event_id: int) -> str:
|
|
|
|
item = model.Event.query.get(event_id)
|
|
|
|
return flask.render_template("event.html", item=item)
|
|
|
|
|
|
|
|
|
2023-09-25 13:05:12 +01:00
|
|
|
@app.route("/conference/<short_name>", methods=["GET", "POST"])
|
|
|
|
def conference_page(short_name: str) -> str | Response:
|
2023-09-15 19:04:41 +01:00
|
|
|
item = model.Conference.query.filter_by(short_name=short_name).one_or_none()
|
|
|
|
if item is None:
|
|
|
|
flask.abort(404)
|
2023-09-25 13:05:12 +01:00
|
|
|
|
|
|
|
if flask.request.method == "POST" and check_admin_mode():
|
|
|
|
item.short_name = flask.request.form["short_name"]
|
|
|
|
item.title = flask.request.form["title"]
|
|
|
|
database.session.commit()
|
|
|
|
|
|
|
|
assert flask.request.endpoint
|
|
|
|
return flask.redirect(
|
|
|
|
flask.url_for(flask.request.endpoint, short_name=item.short_name)
|
|
|
|
)
|
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
return flask.render_template(
|
2023-09-25 13:05:12 +01:00
|
|
|
"conference.html",
|
|
|
|
item=item,
|
|
|
|
person_image_filename=person_image_filename,
|
|
|
|
is_admin=check_admin_mode,
|
2023-09-21 04:59:17 +01:00
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/people")
|
|
|
|
def search_people() -> str:
|
|
|
|
search_for = flask.request.args["q"]
|
|
|
|
assert search_for
|
|
|
|
search_for = search_for.strip()
|
|
|
|
q = model.Person.query.filter(model.Person.name.ilike(f"%{search_for}%")).order_by(
|
|
|
|
model.Person.name
|
|
|
|
)
|
2023-09-25 16:51:29 +01:00
|
|
|
return flask.render_template(
|
|
|
|
"search_people.html", q=q, search_for=search_for, is_admin=check_admin_mode
|
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/merge", methods=["GET", "POST"])
|
|
|
|
def merge() -> str | Response:
|
2023-09-25 15:14:05 +01:00
|
|
|
"""Merge speakers."""
|
|
|
|
assert check_admin_mode()
|
2023-09-24 09:21:16 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
if flask.request.method == "GET":
|
|
|
|
search_for = flask.request.args["q"]
|
|
|
|
assert search_for
|
|
|
|
search_for = search_for.strip()
|
|
|
|
q = query.search_for_people(search_for)
|
|
|
|
return flask.render_template("merge_people.html", q=q, search_for=search_for)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
assert flask.request.method == "POST"
|
|
|
|
search_for = flask.request.form["q"]
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
item_ids_str = flask.request.form.getlist("person_id")
|
|
|
|
item_ids: list[int] = [int(i) for i in item_ids_str]
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
merge_to_id: int = min(item_ids)
|
|
|
|
other_ids = [i for i in item_ids if i != merge_to_id]
|
2023-09-21 04:59:17 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
name_from_person_id = int(flask.request.form["name"])
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
print(other_ids, "->", merge_to_id)
|
2023-09-21 04:59:17 +01:00
|
|
|
|
2023-09-25 17:35:21 +01:00
|
|
|
conference_people = model.ConferencePerson.query.filter(
|
|
|
|
model.ConferencePerson.person_id.in_(other_ids)
|
|
|
|
)
|
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
with database.session.begin():
|
2023-09-25 17:35:21 +01:00
|
|
|
merge_to = model.Person.query.get(merge_to_id)
|
|
|
|
existing_conferences = {conf.id for conf in merge_to.conferences}
|
|
|
|
to_delete = [
|
|
|
|
cp for cp in conference_people if cp.conference_id in existing_conferences
|
|
|
|
]
|
|
|
|
for cp in to_delete:
|
|
|
|
database.session.delete(cp)
|
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
if merge_to_id != name_from_person_id:
|
|
|
|
name_from_person = model.Person.query.get(name_from_person_id)
|
|
|
|
merge_to.name = name_from_person.name
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
print("update ConferencePerson")
|
|
|
|
database.session.execute(
|
|
|
|
update(model.ConferencePerson)
|
|
|
|
.where(model.ConferencePerson.person_id.in_(other_ids))
|
|
|
|
.values(person_id=merge_to_id)
|
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
print("update EventPerson")
|
|
|
|
database.session.execute(
|
|
|
|
update(model.EventPerson)
|
|
|
|
.where(model.EventPerson.person_id.in_(other_ids))
|
|
|
|
.values(person_id=merge_to_id)
|
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
print("delete people")
|
|
|
|
for person_id in other_ids:
|
|
|
|
item = model.Person.query.get(person_id)
|
|
|
|
database.session.delete(item)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-25 15:14:05 +01:00
|
|
|
endpoint = flask.request.endpoint
|
|
|
|
assert endpoint
|
|
|
|
return flask.redirect(flask.url_for(endpoint, q=search_for))
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/events")
|
|
|
|
def events_page() -> str:
|
2023-09-25 15:14:05 +01:00
|
|
|
"""Events page."""
|
2023-09-15 19:04:41 +01:00
|
|
|
search_for = flask.request.args.get("q")
|
2023-09-25 15:14:05 +01:00
|
|
|
if search_for:
|
|
|
|
q = query.search_for_events(search_for)
|
|
|
|
return flask.render_template("search_events.html", q=q, search_for=search_for)
|
|
|
|
else:
|
|
|
|
return flask.render_template("top_events.html", top_events=query.top_events())
|
2023-09-15 19:04:41 +01:00
|
|
|
|
2023-09-13 11:49:08 +01:00
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index() -> str:
|
|
|
|
"""Start page."""
|
2023-09-15 19:04:41 +01:00
|
|
|
q = model.Conference.query.order_by(model.Conference.start.desc())
|
|
|
|
|
|
|
|
count = {
|
|
|
|
"conference": model.Conference.query.count(),
|
|
|
|
"event": model.Event.query.count(),
|
|
|
|
"person": model.Person.query.count(),
|
2023-09-21 04:59:17 +01:00
|
|
|
"country": model.Country.query.count(),
|
|
|
|
"venue": model.Venue.query.count(),
|
2023-09-15 19:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return flask.render_template("index.html", items=q, count=count)
|
|
|
|
|
|
|
|
|
2023-09-25 14:25:04 +01:00
|
|
|
@app.route("/series")
|
|
|
|
def list_series() -> str:
|
|
|
|
"""Page showing list of conference series."""
|
|
|
|
items = model.Series.query
|
|
|
|
|
|
|
|
return flask.render_template("series/list.html", items=items)
|
|
|
|
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
@app.route("/speakers")
|
|
|
|
def top_speakers_page() -> str:
|
|
|
|
"""Top speakers page."""
|
2023-09-25 15:20:01 +01:00
|
|
|
top = query.top_speakers().having(func.count() > 4)
|
2023-09-22 21:00:56 +01:00
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
return flask.render_template(
|
|
|
|
"top_speakers.html",
|
2023-09-22 21:00:56 +01:00
|
|
|
top_speakers=top,
|
2023-09-25 15:14:05 +01:00
|
|
|
speaker_counts=query.speaker_counts(),
|
2023-09-25 15:20:01 +01:00
|
|
|
plural=utils.plural,
|
2023-09-22 21:00:56 +01:00
|
|
|
person_image_filename=person_image_filename,
|
2023-09-21 04:59:17 +01:00
|
|
|
)
|
2023-09-15 19:04:41 +01:00
|
|
|
|
|
|
|
|
2023-09-17 05:16:33 +01:00
|
|
|
@app.route("/country")
|
|
|
|
def country_list() -> str:
|
|
|
|
"""Country list."""
|
|
|
|
return flask.render_template("country_list.html", items=model.Country.query)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/city/<int:city_id>/venue/new", methods=["GET", "POST"])
|
|
|
|
def add_venue(city_id: int) -> str | Response:
|
|
|
|
"""Add new venue."""
|
|
|
|
city = model.City.query.get(city_id)
|
|
|
|
if flask.request.method != "POST":
|
|
|
|
return flask.render_template("add_venue.html", city=city)
|
|
|
|
|
|
|
|
name = flask.request.form["name"]
|
|
|
|
wikidata_qid = flask.request.form["wikidata_qid"]
|
|
|
|
venue = model.Venue(name=name, city=city, wikidata_qid=wikidata_qid)
|
|
|
|
database.session.add(venue)
|
|
|
|
database.session.commit()
|
|
|
|
|
|
|
|
endpoint = flask.endpoint
|
|
|
|
return flask.redirect(flask.url_for(endpoint))
|
|
|
|
|
|
|
|
|
2023-09-15 19:04:41 +01:00
|
|
|
@app.route("/wikidata")
|
|
|
|
def link_to_wikidata() -> str:
|
|
|
|
items = []
|
2023-09-25 15:14:05 +01:00
|
|
|
top = (
|
|
|
|
query.top_speakers()
|
|
|
|
.filter(model.Person.name.like("% %"), model.Person.wikidata_qid.is_(None))
|
|
|
|
.having(func.count() > 2)
|
|
|
|
)
|
|
|
|
for person, num in top:
|
|
|
|
search_hits = wikidata.search(person.name + " haswbstatement:P31=Q5")
|
2023-09-15 19:04:41 +01:00
|
|
|
if not search_hits:
|
|
|
|
continue
|
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
if len(search_hits) > 14:
|
2023-09-15 19:04:41 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
hits = []
|
|
|
|
|
|
|
|
for search_hit in search_hits:
|
|
|
|
qid = search_hit["title"]
|
2023-09-24 21:41:30 +01:00
|
|
|
item = wikidata.get_item(qid)
|
2023-09-15 19:04:41 +01:00
|
|
|
if "en" in item["labels"]:
|
|
|
|
label = item["labels"]["en"]["value"]
|
|
|
|
else:
|
|
|
|
label = "[no english label]"
|
|
|
|
|
|
|
|
if "en" in item["descriptions"]:
|
|
|
|
description = item["descriptions"]["en"]["value"]
|
|
|
|
else:
|
|
|
|
description = "[no english description]"
|
|
|
|
|
|
|
|
hits.append(
|
|
|
|
{
|
|
|
|
"qid": qid,
|
|
|
|
"label": label,
|
|
|
|
"description": description,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
items.append((person, num, hits))
|
|
|
|
|
|
|
|
return flask.render_template("wikidata.html", items=items)
|
2023-09-13 11:49:08 +01:00
|
|
|
|
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
@app.route("/search")
|
|
|
|
def search_everything() -> str:
|
2023-09-22 21:00:56 +01:00
|
|
|
search_for = flask.request.args.get("q")
|
2023-09-21 04:59:17 +01:00
|
|
|
if not search_for:
|
|
|
|
return flask.render_template("search_everything.html")
|
|
|
|
|
|
|
|
search_for = search_for.strip()
|
|
|
|
like = f"%{search_for}%"
|
|
|
|
|
|
|
|
people = model.Person.query.filter(model.Person.name.ilike(like)).order_by(
|
|
|
|
model.Person.name
|
|
|
|
)
|
|
|
|
|
|
|
|
events = model.Event.query.filter(
|
|
|
|
or_(model.Event.abstract.ilike(like), model.Event.description.ilike(like))
|
|
|
|
).order_by(model.Event.event_date)
|
|
|
|
|
|
|
|
return flask.render_template(
|
|
|
|
"search_everything.html", people=people, events=events, search_for=search_for
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/person/<int:person_id>/delete", methods=["POST"])
|
|
|
|
def delete_person(person_id: int) -> str | Response:
|
2023-09-24 09:21:16 +01:00
|
|
|
assert app.config["ADMIN_MODE"]
|
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
item = model.Person.query.get(person_id)
|
|
|
|
|
|
|
|
for cp in item.conferences_association:
|
|
|
|
database.session.delete(cp)
|
|
|
|
|
|
|
|
for ep in item.events_association:
|
|
|
|
database.session.delete(ep)
|
|
|
|
database.session.delete(item)
|
|
|
|
|
|
|
|
database.session.commit()
|
|
|
|
|
|
|
|
return flask.redirect(flask.url_for("index"))
|
|
|
|
|
|
|
|
|
2023-09-24 21:41:30 +01:00
|
|
|
def person_image_filename(person_id: int) -> str:
|
|
|
|
"""Filename for speaker photo."""
|
2023-09-21 04:59:17 +01:00
|
|
|
person = model.Person.query.get(person_id)
|
|
|
|
return os.path.join("wikidata_photo", "thumb", person.wikidata_photo[0])
|
2023-09-22 21:00:56 +01:00
|
|
|
|
2023-09-21 04:59:17 +01:00
|
|
|
for filename in person.wikidata_photo:
|
|
|
|
face_crop = "face_1_" + filename
|
|
|
|
full = os.path.join("static", "wikidata_photo", "face_cropped", face_crop)
|
|
|
|
if os.path.exists(full):
|
|
|
|
return os.path.join("wikidata_photo", "face_cropped", face_crop)
|
|
|
|
|
|
|
|
return os.path.join("wikidata_photo", "thumb", person.wikidata_photo[0])
|
|
|
|
|
|
|
|
|
2023-09-24 22:19:09 +01:00
|
|
|
@app.route("/login", methods=["GET", "POST"])
|
|
|
|
def login() -> str | Response:
|
|
|
|
"""Login page."""
|
|
|
|
if flask.request.method == "GET":
|
|
|
|
return flask.render_template("login.html")
|
|
|
|
password = flask.request.form["password"]
|
|
|
|
if password != app.config["ADMIN_PASSWORD"]:
|
|
|
|
endpoint = flask.endpoint
|
|
|
|
return flask.redirect(endpoint)
|
|
|
|
|
|
|
|
flask.session["admin_password"] = password
|
|
|
|
return flask.redirect(flask.url_for("index"))
|
|
|
|
|
|
|
|
|
|
|
|
def check_admin_mode() -> bool:
|
|
|
|
"""User is an admin."""
|
|
|
|
return bool(flask.session.get("admin_password") == app.config["ADMIN_PASSWORD"])
|
|
|
|
|
|
|
|
|
2023-09-22 21:00:56 +01:00
|
|
|
@app.route("/github_wikidata")
|
|
|
|
def github_wikidata() -> str:
|
2023-09-24 21:41:30 +01:00
|
|
|
"""Look for speakers on Wikidata based on the GitHub property."""
|
2023-09-22 21:00:56 +01:00
|
|
|
items = []
|
|
|
|
for line in open("found_wikidata_github"):
|
2023-09-25 14:55:08 +01:00
|
|
|
person_id, person_name, qid, wd_name, github, desc = eval(line)
|
2023-09-22 21:00:56 +01:00
|
|
|
person = model.Person.query.get(person_id)
|
|
|
|
if person.wikidata_qid:
|
|
|
|
continue
|
2023-09-25 14:55:08 +01:00
|
|
|
items.append((person, qid, wd_name, desc))
|
2023-09-22 21:00:56 +01:00
|
|
|
|
2023-09-25 12:58:28 +01:00
|
|
|
items.sort(key=lambda i: len(i[0].name))
|
|
|
|
|
2023-09-22 21:00:56 +01:00
|
|
|
return flask.render_template("github.html", items=items)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/reports")
|
|
|
|
def reports_page() -> str:
|
2023-09-24 21:41:30 +01:00
|
|
|
"""Page showing statistics."""
|
2023-09-22 21:00:56 +01:00
|
|
|
event_count = model.Event.query.count()
|
|
|
|
|
|
|
|
missing_event_date_count = model.Event.query.filter(
|
|
|
|
model.Event.event_date.is_(None)
|
|
|
|
).count()
|
|
|
|
|
|
|
|
speaker_count = model.Person.query.count()
|
|
|
|
no_bio_count = (
|
|
|
|
model.Person.query.join(model.ConferencePerson)
|
|
|
|
.filter(model.ConferencePerson.bio.is_(None))
|
|
|
|
.group_by(model.Person)
|
|
|
|
.count()
|
|
|
|
)
|
|
|
|
one_bio_count = (
|
|
|
|
model.Person.query.join(model.ConferencePerson)
|
|
|
|
.group_by(model.Person)
|
|
|
|
.filter(model.ConferencePerson.bio.isnot(None))
|
|
|
|
.having(func.count() == 1)
|
|
|
|
.count()
|
|
|
|
)
|
|
|
|
|
|
|
|
multiple_bio = (
|
|
|
|
model.Person.query.join(model.ConferencePerson)
|
|
|
|
.group_by(model.Person)
|
|
|
|
.filter(model.ConferencePerson.bio.isnot(None))
|
|
|
|
.having(func.count() > 1)
|
|
|
|
)
|
|
|
|
|
|
|
|
shorter_recent_bio = []
|
|
|
|
for person in multiple_bio:
|
|
|
|
bio_with_date = sorted(
|
|
|
|
[
|
|
|
|
(cp.conference.start, cp.bio)
|
|
|
|
for cp in person.conferences_association
|
|
|
|
if cp.bio
|
|
|
|
],
|
|
|
|
reverse=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(bio_with_date) < 2:
|
|
|
|
continue
|
|
|
|
|
|
|
|
most_recent_bio = bio_with_date[0][1]
|
|
|
|
len_recent_bio = len(most_recent_bio)
|
|
|
|
longest = max(len(bio) for start, bio in bio_with_date[1:])
|
|
|
|
|
|
|
|
if longest > len_recent_bio * 2:
|
|
|
|
shorter_recent_bio.append((person, len_recent_bio, longest))
|
|
|
|
|
|
|
|
return flask.render_template(
|
|
|
|
"reports.html",
|
|
|
|
event_count=event_count,
|
|
|
|
speaker_count=speaker_count,
|
|
|
|
no_bio_count=no_bio_count,
|
|
|
|
one_bio_count=one_bio_count,
|
|
|
|
multiple_bio_count=multiple_bio.count(),
|
|
|
|
shorter_recent_bio=shorter_recent_bio,
|
|
|
|
missing_event_date_count=missing_event_date_count,
|
|
|
|
missing_event_date=model.Event.query.filter(
|
|
|
|
model.Event.event_date.is_(None)
|
|
|
|
).order_by(model.Event.title),
|
2023-09-24 18:47:22 +01:00
|
|
|
no_venue_count=model.Conference.query.filter(
|
|
|
|
model.Conference.venue_id.is_(None), model.Conference.online.isnot(True)
|
|
|
|
).count(),
|
2023-09-22 21:00:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-13 11:49:08 +01:00
|
|
|
if __name__ == "__main__":
|
2023-09-15 19:04:41 +01:00
|
|
|
app.run(host="0.0.0.0", port=5002)
|