-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transporter 2.4.7 Release
- Loading branch information
Showing
61 changed files
with
1,899 additions
and
1,078 deletions.
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
74 changes: 74 additions & 0 deletions
74
indicators/management/commands/pc_indicators_add_periodic_targets.py
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,74 @@ | ||
from datetime import datetime, date | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
from django.db.models import Count | ||
from indicators.models import Indicator | ||
from workflow.models import Program | ||
from indicators.utils import add_additional_periodic_targets | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Add all relevant periodic targets to participant count indicators. It will create additional periodic targets | ||
for participant count indicators with program dates that extent the current FY.that doesn't already have one. | ||
""" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--execute', action='store_true', help='Without this flag, the command will only be a dry run') | ||
parser.add_argument( | ||
'--change_customsort_to_fy', action='store_true', help='Changes customsort value of periodic targets to match the fiscal year') | ||
parser.add_argument( | ||
'--suppress_output', action='store_true', | ||
help="Suppresses the output so tests don't get too messy") | ||
|
||
@transaction.atomic | ||
def handle(self, *args, **options): | ||
if options['change_customsort_to_fy']: | ||
pc_indicators = Indicator.objects.filter(admin_type=Indicator.ADMIN_PARTICIPANT_COUNT).prefetch_related('periodictargets') | ||
for indicator in pc_indicators: | ||
self.add_fy_customsort(indicator) | ||
|
||
counts = {'eligible_programs': 0, 'ineligible_programs': 0, 'programs_pts_created': 0,} | ||
|
||
today = datetime.utcnow().date() | ||
reporting_end_date = date(today.year, 6, 30) | ||
|
||
eligible_programs = Program.objects.filter(indicator__admin_type=Indicator.ADMIN_PARTICIPANT_COUNT, reporting_period_end__gt=reporting_end_date) | ||
pc_indicators_multiple_pts = Indicator.objects.filter(admin_type=Indicator.ADMIN_PARTICIPANT_COUNT)\ | ||
.prefetch_related('periodictargets').annotate(num_pts=Count('periodictargets')).filter(num_pts__gte=2) | ||
ineligible_programs = eligible_programs.filter(indicator__id__in=[ind.pk for ind in pc_indicators_multiple_pts]) | ||
counts['ineligible_programs'] = ineligible_programs.count() | ||
eligible_programs = eligible_programs.exclude(indicator__id__in=[ind.pk for ind in pc_indicators_multiple_pts]) | ||
counts['eligible_programs'] = eligible_programs.count() | ||
|
||
if options['execute']: | ||
for program in eligible_programs: | ||
add_additional_periodic_targets(program) | ||
counts['programs_pts_created'] += 1 | ||
|
||
if not options['suppress_output']: | ||
print('') | ||
if options['verbosity'] > 1: | ||
template = '{p.name}|{p.countries}|{p.reporting_period_start}|{p.reporting_period_end}|{p.funding_status}' | ||
print('Programs with PC Indicators that have multiple pts already.') | ||
for p in ineligible_programs: | ||
print(template.format(p=p)) | ||
print('Created indicators for these programs') | ||
for p in eligible_programs: | ||
print(template.format(p=p)) | ||
print('\nStats') | ||
for key in counts: | ||
print(f'{key} count: {counts[key]}') | ||
if not options['execute']: | ||
print('\nINDICATOR CREATION WAS A DRY RUN\n') | ||
|
||
|
||
@staticmethod | ||
def add_fy_customsort(indicator): | ||
for pt in indicator.periodictargets.all(): | ||
year = int(''.join(filter(str.isdigit, pt.period))) | ||
pt.customsort = year | ||
pt.save() | ||
|
||
|
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,32 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db.utils import IntegrityError | ||
from indicators.models import LevelTier | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Command to resolve errors related to a RF program missing level tiers | ||
""" | ||
help = "Creates level tiers for Nawiri" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--execute', action='store_true', help='Without this flag, the command will only be a dry run') | ||
|
||
def handle(self, *args, **options): | ||
program_id = 819 | ||
level_tiers = [ | ||
{'name': 'Goal', 'tier_depth': 1, 'program_id': program_id}, | ||
{'name': 'Outcome', 'tier_depth': 2, 'program_id': program_id}, | ||
{'name': 'Output', 'tier_depth': 3, 'program_id': program_id}, | ||
{'name': 'Activity', 'tier_depth': 4, 'program_id': program_id}, | ||
] | ||
|
||
for level_tier in level_tiers: | ||
if options['execute']: | ||
try: | ||
new_level_tier = LevelTier(**level_tier) | ||
new_level_tier.save() | ||
print(f'Created level {level_tier["name"]}') | ||
except IntegrityError: | ||
# IntegrityError is raised if the unique constraint fails | ||
continue |
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
Oops, something went wrong.