Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix management commands to make the day argument optional #3705

Merged
merged 1 commit into from Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,7 +21,7 @@ class Command(BaseCommand):
help = "Update the number of active contributors for each locale/product."

def add_arguments(self, parser):
parser.add_argument('day', type=valid_date)
parser.add_argument('day', nargs='?', type=valid_date)

def handle(self, day=None, **options):
"""
Expand Down
2 changes: 1 addition & 1 deletion kitsune/kpi/management/commands/calculate_csat_metrics.py
Expand Up @@ -99,7 +99,7 @@ def handle(self, **options):
page += 1

for code in csat:
metric_kind, _ = MetricKind.objects.get_or_create(code=code)
metric_kind = MetricKind.objects.get_or_create(code=code)[0]
value = (
csat[code] / counts[code] if counts[code] else 50
) # If no responses assume neutral
Expand Down
12 changes: 6 additions & 6 deletions kitsune/kpi/management/commands/update_contributor_metrics.py
Expand Up @@ -30,7 +30,7 @@ class Command(BaseCommand):
help = "Calculate and save contributor metrics."

def add_arguments(self, parser):
parser.add_argument('day', type=valid_date)
parser.add_argument('day', nargs='?', type=valid_date)

def handle(self, day=None, **options):
update_support_forum_contributors_metric(day)
Expand Down Expand Up @@ -72,9 +72,9 @@ def update_support_forum_contributors_metric(day=None):
count = contributors.count()

# Save the value to Metric table.
metric_kind = MetricKind.objects.get(
metric_kind = MetricKind.objects.get_or_create(
code=SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE
)
)[0]
Metric.objects.create(
kind=metric_kind, start=thirty_days_back, end=day, value=count
)
Expand Down Expand Up @@ -131,12 +131,12 @@ def update_kb_contributors_metric(day=None):
)

# Save the values to Metric table.
metric_kind = MetricKind.objects.get(code=KB_ENUS_CONTRIBUTORS_METRIC_CODE)
metric_kind = MetricKind.objects.get_or_create(code=KB_ENUS_CONTRIBUTORS_METRIC_CODE)[0]
Metric.objects.create(
kind=metric_kind, start=thirty_days_back, end=day, value=en_us_count
)

metric_kind = MetricKind.objects.get(code=KB_L10N_CONTRIBUTORS_METRIC_CODE)
metric_kind = MetricKind.objects.get_or_create(code=KB_L10N_CONTRIBUTORS_METRIC_CODE)[0]
Metric.objects.create(
kind=metric_kind, start=thirty_days_back, end=day, value=l10n_count
)
Expand Down Expand Up @@ -181,7 +181,7 @@ def update_aoa_contributors_metric(day=None):
count = contributors.count()

# Save the value to Metric table.
metric_kind = MetricKind.objects.get(code=AOA_CONTRIBUTORS_METRIC_CODE)
metric_kind = MetricKind.objects.get_or_create(code=AOA_CONTRIBUTORS_METRIC_CODE)[0]
Metric.objects.create(
kind=metric_kind, start=thirty_days_back, end=day, value=count
)
Expand Down
2 changes: 1 addition & 1 deletion kitsune/kpi/management/commands/update_l10n_metric.py
Expand Up @@ -59,7 +59,7 @@ def handle(self, **options):
)

# Save the value to Metric table.
metric_kind = MetricKind.objects.get(code=L10N_METRIC_CODE)
metric_kind = MetricKind.objects.get_or_create(code=L10N_METRIC_CODE)[0]
day = date.today()
Metric.objects.create(
kind=metric_kind,
Expand Down
4 changes: 2 additions & 2 deletions kitsune/kpi/management/commands/update_search_ctr_metric.py
Expand Up @@ -36,8 +36,8 @@ def handle(self, **options):
ctr_data = googleanalytics.search_ctr(start, end)

# Create the metrics.
clicks_kind = MetricKind.objects.get(code=SEARCH_CLICKS_METRIC_CODE)
searches_kind = MetricKind.objects.get(code=SEARCH_SEARCHES_METRIC_CODE)
clicks_kind = MetricKind.objects.get_or_create(code=SEARCH_CLICKS_METRIC_CODE)[0]
searches_kind = MetricKind.objects.get_or_create(code=SEARCH_SEARCHES_METRIC_CODE)[0]
for date_str, ctr in ctr_data.items():
day = datetime.strptime(date_str, "%Y-%m-%d").date()

Expand Down
2 changes: 1 addition & 1 deletion kitsune/kpi/management/commands/update_visitors_metric.py
Expand Up @@ -31,7 +31,7 @@ def handle(self, **options):
visitors = googleanalytics.visitors(start, end)

# Create the metrics.
metric_kind = MetricKind.objects.get(code=VISITORS_METRIC_CODE)
metric_kind = MetricKind.objects.get_or_create(code=VISITORS_METRIC_CODE)[0]
for date_str, visits in visitors.items():
day = datetime.strptime(date_str, "%Y-%m-%d").date()
Metric.objects.create(
Expand Down
7 changes: 3 additions & 4 deletions kitsune/kpi/management/utils.py
Expand Up @@ -84,10 +84,9 @@ def _get_up_to_date_count(top_60_docs, locale):
def _process_exit_survey_results():
"""Collect and save new exit survey results."""
# Gather and process up until yesterday's exit survey results.
yes_kind, _ = MetricKind.objects.get_or_create(code=EXIT_SURVEY_YES_CODE)
no_kind, _ = MetricKind.objects.get_or_create(code=EXIT_SURVEY_NO_CODE)
dunno_kind, _ = MetricKind.objects.get_or_create(
code=EXIT_SURVEY_DONT_KNOW_CODE)
yes_kind = MetricKind.objects.get_or_create(code=EXIT_SURVEY_YES_CODE)[0]
no_kind = MetricKind.objects.get_or_create(code=EXIT_SURVEY_NO_CODE)[0]
dunno_kind = MetricKind.objects.get_or_create(code=EXIT_SURVEY_DONT_KNOW_CODE)[0]

latest_metric = _get_latest_metric(EXIT_SURVEY_YES_CODE)
if latest_metric is not None:
Expand Down