Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ekocbiyik/skyz
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrugulec committed Dec 1, 2019
2 parents 156fd4e + dfc0ea9 commit eb0dc1a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
19 changes: 19 additions & 0 deletions backend/skyz/management/commands/test_ai_bayes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand
from skyz.models.model import TestDataTablosu
from skyz.rest.bayes_search import BayesSearch

class Command(BaseCommand):

def handle(self, *args, **kwargs):
objects = TestDataTablosu.objects.all()
total_object_count = len(objects)
succes_rate = 0
for test in objects:
tmp = test.__dict__
response = BayesSearch().post_to_bayes(tmp['content'])
if response == tmp['category']:
succes_rate += 1
print(str(total_object_count)+"/"+str(succes_rate))



File renamed without changes.
26 changes: 26 additions & 0 deletions backend/skyz/rest/bayes_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework.views import APIView
from rest_framework.response import Response
import requests
import json


class BayesSearch(APIView):
bayes_backend_ip = 'http://127.0.0.1:6161/'
bayes_api_path = 'api/classify'

body = {
"body": None
}


def post(self, request):
category = self.post_to_bayes(self.request.data['context'])
return Response(category)

def post_to_bayes(self, content):
self.body['body'] = content
headers = {'content-type': 'application/json'}
f = requests.post(url=self.bayes_backend_ip + self.bayes_api_path, data=json.dumps(self.body), headers=headers)
content = json.loads(f.content)
category = content['content']
return category
2 changes: 2 additions & 0 deletions backend/skyz/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
from skyz.rest.login import Login
from skyz.rest.elastic_query import ElasticSearch, ElasticInsert
from skyz.rest.test_date_insert import TestData
from skyz.rest.bayes_search import BayesSearch
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/', Login.as_view()),
url(r'^api/elasticsearch', ElasticSearch.as_view()),
url(r'^api/elasticinsert', ElasticInsert.as_view()),
url(r'^api/testdateinsert', TestData.as_view()),
url(r'^api/bayessearch', BayesSearch.as_view()),
]


Expand Down
2 changes: 1 addition & 1 deletion middleware/AcikHack.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_12">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_13">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand Down

0 comments on commit eb0dc1a

Please sign in to comment.