-
Notifications
You must be signed in to change notification settings - Fork 841
Expand file tree
/
Copy pathreports.py
More file actions
executable file
·49 lines (37 loc) · 1.7 KB
/
Copy pathreports.py
File metadata and controls
executable file
·49 lines (37 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright The IETF Trust 2023-2026, All Rights Reserved
from typing import List, Set, Tuple
from django.db.models import QuerySet
from email.utils import parseaddr
from ietf.person.models import Person
from ietf.submit.models import Submission
def authors_by_year(year: int) -> Set[str]:
"""Email addresses provided by I-D authors for drafts that were submitted in the given year."""
addresses = set()
for submission in Submission.objects.filter(
submission_date__year=year, state="posted"
):
addresses.update([a["email"] for a in submission.authors])
return addresses
def submitters_by_year(year: int) -> Set[str]:
"""Email addresses provided by I-D submitters for drafts that were submitted in the given year."""
return set(
[
parseaddr(a)[1]
for a in Submission.objects.filter(
submitter__contains="@", submission_date__year=year, state="posted"
).values_list("submitter", flat=True)
]
)
def unique_people(addresses: List[str]) -> Tuple["QuerySet[Person]", Set]:
"""Identify Person records matching email addresses and email addresses with no Person record.
Given a list of email addresses, return
(
a list of unique Person records with a matching email address,
a list of unique email addresses with no matching Person record
)
The sum of the lengths of these lists is a best-approximation for how
many unique people the list of addresses belong to.
"""
persons = Person.objects.filter(email__address__in=addresses).distinct()
known_email = set(persons.values_list("email__address", flat=True))
return (persons, set(addresses) - set(known_email))