Skip to content

Commit c4bd0ed

Browse files
authored
Merge pull request #34 from biojs/visualization_list
Visualization list
2 parents 7401794 + e6202bb commit c4bd0ed

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ install:
99
script:
1010
- python manage.py makemigrations
1111
- python manage.py migrate
12-
- python manage.py test

main/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
url(r'^top/$', views.top_components, name="top_components"),
1111
url(r'^details/(?P<url_name>[\w-]+)/$', views.component_details, name="component_details"),
1212
url(r'^visualization/(?P<url_name>[\w-]+)/(?P<visualization_name>[\w-]+)/$', views.render_visualization, name="render_visualization"),
13+
url(r'^random_snippets/$', views.generate_random_snippets, name='generate_random_snippets'),
1314
]

main/views.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import urllib, json
77
from django.core.management import call_command
88
from django.core.serializers.json import DjangoJSONEncoder
9+
import numpy as np
910

1011
def index(request):
1112
top_downloaded_components = Component.objects.all().only('name', 'id', 'downloads', 'url_name').order_by('-downloads')[:3]
@@ -79,4 +80,17 @@ def render_visualization(request, url_name, visualization_name):
7980
@staff_member_required
8081
def update_data(request):
8182
call_command('updatecomponents')
82-
return HttpResponse("Database Successfully Updated.")
83+
return HttpResponse("Database Successfully Updated.")
84+
85+
def generate_random_snippets(request):
86+
try:
87+
count = request.GET.get('q')
88+
if int(count) > Component.objects.filter(sniperdata__isnull=False).count():
89+
return HttpResponse('Input number "q" must not exceed %s.'%str(Component.objects.filter(sniperdata__isnull=False).count()))
90+
components = Component.objects.filter(sniperdata__isnull=False)
91+
required_components = np.random.choice(components, int(count), replace=False)
92+
req_str = '\n'.join([component.name for component in required_components])
93+
print req_str
94+
return HttpResponse(req_str, content_type="text/plain")
95+
except:
96+
return HttpResponse('Input number as query "q" in the URL.')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ django-redis==4.9.0
55
django-rest-framework==0.1.0
66
djangorestframework==3.8.2
77
idna==2.6
8+
numpy==1.14.5
89
Pillow==5.1.0
910
pytz==2018.4
1011
redis==2.10.6

0 commit comments

Comments
 (0)