datatracker/ietf/secr/proceedings/reports.py
Jennifer Richards 32054111df
fix: fix failing tests and eliminate naive datetime warnings (#4402)
* test: fix timestamp construction in several doc tests

* refactor: rename date2datetime to datetime_from_date and clarify code

* chore: helper to get tzinfo for PRODUCTION_TIMEZONE

* fix: fix timezone handling in make_last_call()

* test: fix datetime generation in doc.tests_charter

* refactor: remove PRODUCTION_TIMEZONE setting

Replaces the PRODUCTION_TIMEZONE setting with a constant,
DEADLINE_TZINFO, in ietf.utils.timezone.

* test: be more careful about timezone in tests_charter.py

* test: be more careful about timezone in doc/tests.py

* fix: fix timezone handling affecting doc.tests_draft

* fix: fix timezone handling affecting tests_irsg_ballot.py

* fix: fix timezone handling affecting tests_review.py

* fix: fix timezone handling affecting last ietf.doc tests

* fix: fix timezone handling affecting last ietf.group tests

* fix: fix timezone handling affecting ietf.iesg tests

* fix: handle timezones in get_8989_eligibility_querysets

* fix: handle timezones affecting ietfauth tests

* fix: return tz-aware datetime from utc_from_string

* fix: specify timezone for constants in ipr_rfc_number()

* fix: specify tz for ipr deadlines

* fix: handle timezones affecting liaisons tests

* fix: treat leap day in get_8989_eligibility_querysets()

Manual cherry-pick of 248d6474

* test: treat leap day properly in nomcom tests

* fix: fix timezone handling affecting nomcom tests

* test: fix timezone handling in review tests

* fix: fix timezone handling affecting secr.meetings tests

* fix: handle both pytz and zoneinfo timezones in ietf.utils.timezone

* fix: fix timezone handling affecting secr.proceedings tests

* refactor: use make_aware() helper in secr.meetings tests

* test: fix timezone handling in secr.telechat tests

* fix: fix timezone handling affecting stats tests

* fix: eliminate tz-naive helpers affecting sync email parsing

* fix: include timezone data when serializing DeletedEvent data

* fix: fix timezone handling affecting sync tests

* style: remove unused import
2022-09-01 13:07:28 -03:00

107 lines
4.6 KiB
Python

import datetime
from django.template.loader import render_to_string
from django.utils import timezone
from ietf.meeting.models import Meeting
from ietf.doc.models import DocEvent, Document
from ietf.secr.proceedings.proc_utils import get_progress_stats
from ietf.utils.timezone import datetime_from_date
def report_id_activity(start,end):
# get previous meeting
meeting = Meeting.objects.filter(date__lt=timezone.now(),type='ietf').order_by('-date')[0]
syear,smonth,sday = start.split('-')
eyear,emonth,eday = end.split('-')
sdate = datetime_from_date(datetime.date(int(syear),int(smonth),int(sday)), meeting.tz())
edate = datetime_from_date(datetime.date(int(eyear),int(emonth),int(eday)), meeting.tz())
#queryset = Document.objects.filter(type='draft').annotate(start_date=Min('docevent__time'))
new_docs = Document.objects.filter(type='draft').filter(docevent__type='new_revision',
docevent__newrevisiondocevent__rev='00',
docevent__time__gte=sdate,
docevent__time__lte=edate)
new = new_docs.count()
updated = 0
updated_more = 0
for d in new_docs:
updates = d.docevent_set.filter(type='new_revision',time__gte=sdate,time__lte=edate).count()
if updates > 1:
updated += 1
if updates > 2:
updated_more +=1
# calculate total documents updated, not counting new, rev=00
result = set()
events = DocEvent.objects.filter(doc__type='draft',time__gte=sdate,time__lte=edate)
for e in events.filter(type='new_revision').exclude(newrevisiondocevent__rev='00'):
result.add(e.doc)
total_updated = len(result)
# calculate sent last call
last_call = events.filter(type='sent_last_call').count()
# calculate approved
approved = events.filter(type='iesg_approved').count()
# get 4 weeks
monday = datetime_from_date(Meeting.get_current_meeting().get_ietf_monday(), meeting.tz())
cutoff = monday + datetime.timedelta(days=3)
ff1_date = cutoff - datetime.timedelta(days=28)
#ff2_date = cutoff - datetime.timedelta(days=21)
#ff3_date = cutoff - datetime.timedelta(days=14)
#ff4_date = cutoff - datetime.timedelta(days=7)
ff_docs = Document.objects.filter(type='draft').filter(docevent__type='new_revision',
docevent__newrevisiondocevent__rev='00',
docevent__time__gte=ff1_date,
docevent__time__lte=cutoff)
ff_new_count = ff_docs.count()
ff_new_percent = format(ff_new_count / float(new),'.0%')
# calculate total documents updated in final four weeks, not counting new, rev=00
result = set()
events = DocEvent.objects.filter(doc__type='draft',time__gte=ff1_date,time__lte=cutoff)
for e in events.filter(type='new_revision').exclude(newrevisiondocevent__rev='00'):
result.add(e.doc)
ff_update_count = len(result)
ff_update_percent = format(ff_update_count / float(total_updated),'.0%')
#aug_docs = augment_with_start_time(new_docs)
'''
ff1_new = aug_docs.filter(start_date__gte=ff1_date,start_date__lt=ff2_date)
ff2_new = aug_docs.filter(start_date__gte=ff2_date,start_date__lt=ff3_date)
ff3_new = aug_docs.filter(start_date__gte=ff3_date,start_date__lt=ff4_date)
ff4_new = aug_docs.filter(start_date__gte=ff4_date,start_date__lt=edate)
ff_new_iD = ff1_new + ff2_new + ff3_new + ff4_new
'''
context = {'meeting':meeting,
'new':new,
'updated':updated,
'updated_more':updated_more,
'total_updated':total_updated,
'last_call':last_call,
'approved':approved,
'ff_new_count':ff_new_count,
'ff_new_percent':ff_new_percent,
'ff_update_count':ff_update_count,
'ff_update_percent':ff_update_percent}
report = render_to_string('proceedings/report_id_activity.txt', context)
return report
def report_progress_report(start_date,end_date):
syear,smonth,sday = start_date.split('-')
eyear,emonth,eday = end_date.split('-')
sdate = datetime.datetime(int(syear),int(smonth),int(sday))
edate = datetime.datetime(int(eyear),int(emonth),int(eday))
context = get_progress_stats(sdate,edate)
report = render_to_string('proceedings/report_progress_report.txt', context)
return report