-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add institutional dashboard summary.
- Loading branch information
John Tordoff
committed
Aug 23, 2024
1 parent
3920a29
commit 176253a
Showing
5 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import logging | ||
|
||
from django.db.models import Q | ||
|
||
from osf.metrics.reports import ( | ||
InstitutionDashboardSummaryReport, | ||
RunningTotal, | ||
NodeRunningTotals, | ||
RegistrationRunningTotals, | ||
FileRunningTotals, | ||
DataRunningTotals | ||
) | ||
from osf.models import Institution | ||
from ._base import DailyReporter | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
class InstitutionDashboardSummaryReporter(DailyReporter): | ||
def report(self, date): | ||
institutions = Institution.objects.all() | ||
reports = [] | ||
|
||
daily_query = Q(created__date=date) | ||
public_query = Q(is_public=True) | ||
private_query = Q(is_public=False) | ||
|
||
embargo_v2_query = Q(root__embargo__end_date__date__gt=date) | ||
|
||
for institution in institutions: | ||
node_qs = institution.nodes.filter( | ||
deleted__isnull=True, | ||
created__date__lte=date, | ||
).exclude(type='osf.registration') | ||
registration_qs = institution.nodes.filter( | ||
deleted__isnull=True, | ||
created__date__lte=date, | ||
type='osf.registration', | ||
) | ||
|
||
report = InstitutionDashboardSummaryReport( | ||
report_date=date, | ||
institution_id=institution._id, | ||
institution_name=institution.name, | ||
users=RunningTotal( | ||
total=institution.get_institution_users().filter(is_active=True).count(), | ||
total_daily=institution.get_institution_users().filter(date_confirmed__date=date).count(), | ||
), | ||
# Projects use get_roots to remove children | ||
projects=NodeRunningTotals( | ||
total=node_qs.get_roots().count(), | ||
public=node_qs.filter(public_query).get_roots().count(), | ||
private=node_qs.filter(private_query).get_roots().count(), | ||
|
||
total_daily=node_qs.filter(daily_query).get_roots().count(), | ||
public_daily=node_qs.filter(public_query & daily_query).get_roots().count(), | ||
private_daily=node_qs.filter(private_query & daily_query).get_roots().count(), | ||
), | ||
registerations=RegistrationRunningTotals( | ||
total=registration_qs.count(), | ||
public=registration_qs.filter(public_query).count(), | ||
embargoed=registration_qs.filter(private_query).count(), | ||
embargoed_v2=registration_qs.filter(private_query & embargo_v2_query).count(), | ||
|
||
total_daily=registration_qs.filter(daily_query).count(), | ||
public_daily=registration_qs.filter(public_query & daily_query).count(), | ||
embargoed_daily=registration_qs.filter(private_query & daily_query).count(), | ||
embargoed_v2_daily=registration_qs.filter(private_query & daily_query & embargo_v2_query).count(), | ||
), | ||
files=FileRunningTotals(), | ||
data=DataRunningTotals(), | ||
) | ||
|
||
reports.append(report) | ||
return reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters