-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Asking the user for feedback using custom heuristic #3139
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b08e133
ask user for feedback
e21a6d6
change toolbar for 20 seconds
b4812be
feedback in toolbar
e375839
Merge branch 'master' into feedback
5cc8bac
remove dead code
c5c8481
flake8
2145b54
Merge branch 'feedback' of https://github.com/oakeyc/azure-cli into f…
74d8e64
flake8
461f2ff
Merge branch 'master' of https://github.com/azure/azure-cli into feed…
517cb60
small changes
dc798f0
wording
d2464f0
change to cli config
d438c49
feedback as command
72a996d
utc
e3f7506
Merge branch 'master' into feedback
a38c823
remove from shell config
2a528f5
Merge branch 'feedback' of https://github.com/oakeyc/azure-cli into f…
bb78aba
flake8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 today_format(now): | ||
""" returns the date format """ | ||
return now.strftime("%Y-%m-%d") | ||
|
||
|
||
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.now() | ||
now = today_format(now) | ||
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.now() | ||
date_list = [base - datetime.timedelta(days=x) for x in range(1, DAYS_AGO)] | ||
for day in date_list: | ||
count += 1 if freq.get(today_format(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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTC?