Render a scatterplot visualization. Args: key (str): The key type to visualize. Returns: TemplateResponse: The populated scatterplot data visualization template.
(request, key='hourly_rate', template='dataviz/scatterplot.html', hide_usernames=False)
| 679 | |
| 680 | |
| 681 | def viz_scatterplot_helper(request, key='hourly_rate', template='dataviz/scatterplot.html', hide_usernames=False): |
| 682 | """Render a scatterplot visualization. |
| 683 | |
| 684 | Args: |
| 685 | key (str): The key type to visualize. |
| 686 | |
| 687 | Returns: |
| 688 | TemplateResponse: The populated scatterplot data visualization template. |
| 689 | |
| 690 | """ |
| 691 | stats = [] |
| 692 | keyword = request.GET.get('keyword', None) |
| 693 | type_options = ['hourly_rate'] |
| 694 | if request.GET.get('data'): |
| 695 | rows = [['hourlyRate', 'daysBack', 'username', 'weight']] |
| 696 | fulfillments = BountyFulfillment.objects.filter(accepted=True).exclude(fulfiller_hours_worked=None) |
| 697 | if keyword: |
| 698 | filter_bounties = Bounty.objects.filter(raw_data__icontains=keyword) |
| 699 | fulfillments = fulfillments.filter(bounty__in=filter_bounties) |
| 700 | for bf in fulfillments: |
| 701 | #print(bf.pk, bf.created_on) |
| 702 | try: |
| 703 | weight = math.log(bf.bounty.value_in_usdt, 10) / 4 |
| 704 | username = bf.bounty.org_name |
| 705 | if hide_usernames: |
| 706 | username = "repo: " + helper_hide_pii(username.lower(), 1) |
| 707 | row = [str(bf.bounty.hourly_rate), str((timezone.now() - bf.accepted_on).days), username, str(weight), ] |
| 708 | if bf.bounty.hourly_rate: |
| 709 | rows.append(row) |
| 710 | except Exception: |
| 711 | pass |
| 712 | |
| 713 | output_rows = [] |
| 714 | for row in rows: |
| 715 | output_rows.append(",".join(row)) |
| 716 | |
| 717 | output = "\n".join(output_rows) |
| 718 | return HttpResponse(output) |
| 719 | |
| 720 | params = { |
| 721 | 'stats': stats, |
| 722 | 'key': key, |
| 723 | 'page_route': 'scatterplot', |
| 724 | 'type_options': type_options, |
| 725 | 'viz_type': key, |
| 726 | 'keyword': keyword, |
| 727 | } |
| 728 | response = TemplateResponse(request, template, params) |
| 729 | response['X-Frame-Options'] = 'SAMEORIGIN' |
| 730 | return response |
no test coverage detected