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

add simple success rate calculation #5104

Merged
merged 2 commits into from
Sep 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 50 additions & 72 deletions app/assets/v2/js/user_popover.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,58 @@
let popoverData = [];

const renderPopOverData = json => {
return `
<div class="popover-bounty__content">
<div class="d-flex justify-content-between mb-2">
<h2 class="title font-subheader font-weight-bold username">${
json.profile.handle
}</h2>
<span class="text-muted specialty pt-2">Specialty: ${json.profile.keywords
.slice(0, 3)
.toString()}</span>
${Object.keys(json.profile.organizations).map(
(org, index) => {
if (index < 3) {
`<img src="/dynamic/avatar/${org}" alt="${org}" class="rounded-circle" width="24" height="24">`;
} else {
`<img class="rounded-circle m-1" width="24" height="24" title=${Object.keys(json.profile.organizations.length)} times" src=""/>`;
}
let orgs = Object.keys(json.profile.organizations).map((org, index) => {
if (index < 3) {
return `<img src="/dynamic/avatar/${org}" alt="${org}" class="rounded-circle" width="24" height="24">`;
}
)}
</div>
<span class="earned">~ ${
Number(json.profile.total_earned).toFixed(4)
} ETH earned</span>
<div class="statistics d-flex justify-content-between mt-2">
<div class="popover_card text-center mr-4 pt-2">
<span class="contributor-position font-weight-semibold">#${
json.profile.position
}</span>
<p class="mt-2">Gitcoin Contributor</p>
</div>
<div class="contributions d-flex justify-content-between">
<div class="popover_card text-center mr-2 pt-2">
<span class="completed-bounties font-weight-semibold">${
json.statistics.work_completed
}</span>
<p class="mt-2">Bounties Completed</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="in-progress text-center font-weight-semibold">${
json.statistics.work_in_progress
}</span>
<p class="mt-2">Bounties In Progress</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="abandoned-bounties font-weight-semibold">${
json.statistics.work_abandoned
}</span>
<p class="mt-2">Bounties Abandoned</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="removed-bounties font-weight-semibold">${
json.statistics.work_removed
}</span>
<p class="mt-2">Bounties Removed</p>
</div>
</div>
</div>
</div>
return `<span class="m-1">+${Object.keys(json.profile.organizations).length - 3}</span>`;
}).join(' ');

return `
<div class="popover-bounty__content">
<div class="d-flex justify-content-between mb-2">
<img src="${json.profile.avatar_url}" width="30" class="rounded-circle">
<h2 class="title font-subheader font-weight-bold username">${json.profile.handle}</h2>
<span class="text-muted specialty pt-2">Specialty: ${json.profile.keywords.slice(0, 3).toString()}</span>
${orgs.length ? '<span>Contributes to: </span>' + orgs : ''}
</div>
<span class="earned">~ ${Number(json.profile.total_earned).toFixed(4)} ETH earned</span>
<div class="statistics d-flex justify-content-between mt-2">
<div class="popover_card text-center mr-4 pt-2">
<span class="contributor-position font-weight-semibold">#${json.profile.position}</span>
<p class="mt-2">Gitcoin Contributor</p>
</div>
<div class="contributions d-flex justify-content-between">
<div class="popover_card text-center mr-2 pt-2">
<span class="completed-bounties font-weight-semibold">${json.statistics.work_completed}</span>
<p class="mt-2">Bounties Completed</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="in-progress text-center font-weight-semibold">${json.statistics.work_in_progress}</span>
<p class="mt-2">Bounties In Progress</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="abandoned-bounties font-weight-semibold">${json.statistics.work_abandoned}</span>
<p class="mt-2">Bounties Abandoned</p>
</div>
<div class="popover_card text-center mr-2 pt-2">
<span class="removed-bounties font-weight-semibold">${json.statistics.work_removed}</span>
<p class="mt-2">Bounties Removed</p>
</div>
</div>
</div>
</div>

<div class="popover-bounty__footer">
<div class="d-flex justify-content-between">
<span class="title text-muted">Latest Activity
<span class="current_status font-weight-semibold">${currentStatus(
json.recent_activity.activity_type
)}</span>
</span>
<span class="text-muted time-ago">${moment(
json.recent_activity.created,
'YYYYMMDD'
).fromNow()}</span>
</div>
<p class="text-muted pt-2 activity-title">${
json.recent_activity.activity_metadata.title
}</p>
</div>`;
<div class="popover-bounty__footer">
<div class="d-flex justify-content-between">
<span class="title text-muted">Latest Activity
<span class="current_status font-weight-semibold">${currentStatus(json.recent_activity.activity_type)}</span>
</span>
<span class="text-muted time-ago">${moment(json.recent_activity.created, 'YYYYMMDD').fromNow()}</span>
</div>
<p class="text-muted pt-2 activity-title">${json.recent_activity.activity_metadata.title}</p>
</div>
`;
};

const openContributorPopOver = (contributor, element) => {
Expand Down
11 changes: 11 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,17 @@ def is_staff(self):
"""
return self.user.is_staff if self.user else False

@property
def success_rate(self):
network = self.get_network()
num_completed_bounties = self.bounties.filter(
idx_status__in=['done'], network=network).count()
terminal_state_bounties = self.bounties.filter(
idx_status__in=Bounty.TERMINAL_STATUSES, network=network).count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know how to solve the cooperative bounty case, since I can be paid out but the bounty still open.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is kind of the same situation on the dashboard, should we fetch fulfillments also?

if terminal_state_bounties == 0:
return 1.0
return num_completed_bounties * 1.0 / (terminal_state_bounties + num_completed_bounties)

@property
def get_quarterly_stats(self):
"""Generate last 90 days stats for this user.
Expand Down
6 changes: 3 additions & 3 deletions app/dashboard/templates/bounty/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ <h5 class="bounty-heading">{% trans "Funder" %}</h5>
</div>
<div class="col-12 col-md-2">
<div class="activity-name">
<a href="/profile/[[:name]]" target="_blank">
<a href="/profile/[[:name]]" target="_blank" data-username="[[:name]]" data-html="true" data-toggle="popover" data-container="body">
[[:name]]
</a>
</div>
Expand Down Expand Up @@ -485,8 +485,8 @@ <h3>{{ noscript.keywords }}</h3>
<script src="{% static "v2/js/clipboard.js" %}"></script>
<script>
$('[data-toggle="popover"]').popover()
$("body").on("mouseover", "[data-username] img", function(e) {
openContributorPopOver($(this).parent().data("username"), $(this));
$("body").on("mouseover", "[data-username]", function(e) {
openContributorPopOver($(this).data("username"), $(this));
});
</script>
<script src="{% static "v2/js/lib/daterangepicker.min.js" %}"></script>
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,10 +1803,11 @@ def profile_details(request, handle):

response = {
'profile': ProfileSerializer(profile).data,
'success_rate': profile.success_rate,
'recent_activity': {
'activity_metadata': activity.metadata,
'activity_type': activity.activity_type,
'created': activity.created,
'created': activity.created
},
'statistics': {
'work_completed': count_work_completed,
Expand Down