Skip to content

Commit

Permalink
Running test server
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatsrivastava committed Feb 29, 2016
1 parent 7b7ae11 commit 7f96ca1
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 0 deletions.
Empty file.
103 changes: 103 additions & 0 deletions webserver/RangingServer/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""
Django settings for RangingServer project.
Generated by 'django-admin startproject' using Django 1.8.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '8zs6@v%htwv%=+1yoy%3vs)2mi7+0$%$yd@(&uo-3=-1lmdy4r'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testServer',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'RangingServer.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'RangingServer.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions webserver/RangingServer/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""RangingServer URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^testServer/', include('testServer.urls')),
url(r'^admin/', include(admin.site.urls)),
]
16 changes: 16 additions & 0 deletions webserver/RangingServer/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for RangingServer project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "RangingServer.settings")

application = get_wsgi_application()
Binary file added webserver/db.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions webserver/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "RangingServer.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Binary file added webserver/testServer/.DS_Store
Binary file not shown.
Empty file.
3 changes: 3 additions & 0 deletions webserver/testServer/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
22 changes: 22 additions & 0 deletions webserver/testServer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('targetID', models.IntegerField()),
('anchorID', models.IntegerField()),
('distance', models.IntegerField()),
],
),
]
29 changes: 29 additions & 0 deletions webserver/testServer/migrations/0002_auto_20160228_2345.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('testServer', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('tagID', models.IntegerField()),
('distance', models.FloatField()),
('theta', models.FloatField()),
('B', models.FloatField()),
('r1', models.FloatField()),
('r2', models.FloatField()),
],
),
migrations.DeleteModel(
name='Message',
),
]
33 changes: 33 additions & 0 deletions webserver/testServer/migrations/0003_auto_20160229_0031.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('testServer', '0002_auto_20160228_2345'),
]

operations = [
migrations.RemoveField(
model_name='tag',
name='id',
),
migrations.AlterField(
model_name='tag',
name='distance',
field=models.FloatField(null=True),
),
migrations.AlterField(
model_name='tag',
name='tagID',
field=models.IntegerField(serialize=False, primary_key=True),
),
migrations.AlterField(
model_name='tag',
name='theta',
field=models.FloatField(null=True),
),
]
Empty file.
9 changes: 9 additions & 0 deletions webserver/testServer/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models

class Tag(models.Model):
tagID = models.IntegerField(primary_key=True)
distance = models.FloatField(null=True)
theta = models.FloatField(null=True)
B = models.FloatField()
r1 = models.FloatField()
r2 = models.FloatField()
3 changes: 3 additions & 0 deletions webserver/testServer/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions webserver/testServer/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls import include, url
from django.contrib import admin

from . import views

urlpatterns = [
url(r'^set/(?P<tagID>[0-9]+)/(?P<B>[0-9]+\.?[0-9]*)/(?P<r1>[0-9]+\.?[0-9]*)/(?P<r2>[0-9]+\.?[0-9]*)', views.setData),
url(r'^get/(?P<tagID>[0-9]+)/', views.getDataFromTagID),
]
49 changes: 49 additions & 0 deletions webserver/testServer/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.shortcuts import render
import math
from django.http import JsonResponse, HttpResponse
from testServer.models import *

def calcDistanceAndTheta(B, r1, r2, old_distance, old_theta):
try:
distance = math.sqrt(0.5 * (r1**2) - 0.25 * (B**2) + 0.5 * (r2**2))
theta = (math.acos((distance ** 2 + (B/2)**2 - r1**2) / (distance * B)) - math.pi / 2.0) * (180 / math.pi)
return (distance, theta)
except ValueError:
return (old_distance, old_theta)


def setData(request, tagID, B, r1, r2):
tagID = int(tagID)
B = float(B)
r1 = float(r1)
r2 = float(r2)
currTag = Tag.objects.all().filter(tagID=tagID).first()
if(currTag != None):
currTag.B = B
currTag.r1 = r1
currTag.r2 = r2
else:
currTag = Tag(tagID=tagID, B=B, r1=r1, r2=r2, distance=None, theta=None )
(dist, theta) = calcDistanceAndTheta(B, r1, r2, currTag.distance, currTag.theta)

currTag.distance = dist
currTag.theta = theta
currTag.save()

if(dist != None and theta!= None):
html = "<html><body>It has been set to R=%f and theta=%f" % (dist , theta)
else:
html = "<html><body>Distance and theta are None as an error occured"
return HttpResponse(html)

def getDataFromTagID(request, tagID):
response = {}
currTag = Tag.objects.all().filter(tagID=tagID).first()
if (currTag != None):
response['R'] = currTag.distance
response['theta'] = currTag.theta

return JsonResponse(response)
else:
return JsonResponse({'error' : 'Couldnt find object with that ID'})

0 comments on commit 7f96ca1

Please sign in to comment.