-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asking the user for feedback using custom heuristic (#3139)
* ask user for feedback * change toolbar for 20 seconds * feedback in toolbar * remove dead code * flake8 * flake8 * small changes * wording * change to cli config * feedback as command * utc * remove from shell config * flake8
- Loading branch information
Courtney (CJ) Oka
authored
May 5, 2017
1 parent
e065618
commit 274a9fc
Showing
4 changed files
with
102 additions
and
7 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
53 changes: 53 additions & 0 deletions
53
src/command_modules/azure-cli-shell/azclishell/frequency_heuristic.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,53 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import os | ||
import datetime | ||
import json | ||
|
||
from azure.cli.core._config import set_global_config_value | ||
|
||
from azclishell.configuration import CONFIGURATION, get_config_dir as shell_config | ||
|
||
SHELL_CONFIG = CONFIGURATION | ||
DAYS_AGO = 28 | ||
ACTIVE_STATUS = 5 | ||
DISPLAY_TIME = 20 | ||
|
||
|
||
def update_frequency(): | ||
""" updates the frequency from files """ | ||
with open(os.path.join(shell_config(), SHELL_CONFIG.get_frequency()), 'r') as freq: | ||
try: | ||
frequency = json.load(freq) | ||
except ValueError: | ||
frequency = {} | ||
|
||
with open(os.path.join(shell_config(), SHELL_CONFIG.get_frequency()), 'w') as freq: | ||
now = datetime.datetime.utcnow() | ||
val = frequency.get(now) | ||
frequency[now] = val + 1 if val else 1 | ||
json.dump(frequency, freq) | ||
|
||
return frequency | ||
|
||
|
||
def frequency_measurement(): | ||
""" measures how many times a user has used this program in the last calendar week """ | ||
freq = update_frequency() | ||
count = 0 | ||
base = datetime.datetime.utcnow() | ||
date_list = [base - datetime.timedelta(days=x) for x in range(1, DAYS_AGO)] | ||
for day in date_list: | ||
count += 1 if freq.get(day, 0) > 0 else 0 | ||
return count | ||
|
||
|
||
def frequency_heuristic(): | ||
""" decides whether user meets requirements for frequency """ | ||
return frequency_measurement() >= ACTIVE_STATUS | ||
|
||
|
||
frequent_user = frequency_heuristic() |