Created
August 29, 2017 18:48
-
-
Save vrootic/c8cb6eff32bc779500cc430b90ab1b25 to your computer and use it in GitHub Desktop.
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
def plot_tool_release_industry_usage(version_name, industry): | |
if version_name == "all": | |
session = Session.objects.all().select_related() | |
if industry != "all": | |
session = session.filter(user__industry=industry) | |
else: | |
session = Session.objects.filter(version_name=version_name).select_related() | |
if industry != "all": | |
session = session.filter(user__industry=industry) | |
total_num_operation = Operation.objects.all().count() | |
tool_name = [op["tool_name"] for op in Operation.objects.values("tool_name").distinct()] | |
usage = [] | |
for tn in tool_name: | |
count = 0 | |
operation = Operation.objects.filter(tool_name=tn).select_related("session") | |
for op in operation: | |
if op.session in session: | |
count += 1 | |
usage.append(round(count/total_num_operation*100, 2)) | |
usage = sorted(usage, reverse=True) | |
percentage = [str(i) + "%" for i in usage] | |
tool_release_industry_data = { | |
"tool_name": tool_name, | |
"usage": usage, | |
"percentage": percentage | |
} | |
plot = Bar(tool_release_industry_data, values='usage', | |
color='tool_name', | |
tooltips=[ | |
("Tool Name", "@tool_name"), | |
("Percentage", "@percentage") | |
], | |
label=CatAttr(columns=['tool_name', 'percentage'], sort=False), | |
ylabel='Tool Usage(%)', legend = False, | |
plot_height=350, plot_width=500, responsive=True) | |
return plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment