Skip to content

Commit

Permalink
adding ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajiv Roopan authored and Rajiv Roopan committed Jun 17, 2015
1 parent 575a1ef commit dc197e5
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 0 deletions.
Empty file added ui/__init__.py
Empty file.
Binary file added ui/__init__.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions ui/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.
Binary file added ui/admin.pyc
Binary file not shown.
Empty file added ui/migrations/__init__.py
Empty file.
Binary file added ui/migrations/__init__.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions ui/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Binary file added ui/models.pyc
Binary file not shown.
70 changes: 70 additions & 0 deletions ui/templates/mapbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }

div#search-container {
position:absolute;
top:10px;
right:10px;
padding:5px 10px;
background:rgba(0,0,0,0.5);
color:#fff;
font-size:11px;
line-height:18px;
border-radius:3px;
}

.css-icon {
width: 2px;
height: 2px;
background-color: dodgerblue;
{# border-top: 30px solid transparent;#}
{# border-bottom: 30px solid transparent;#}
{# border-left: 30px solid #ff8888;#}
}
</style>
</head>
<body>
<div id='map' class="dark"></div>

<pre id='coordinates' class='ui-coordinates'></pre>
<div id="search-container">
<input name="location" type="text" placeholder="Enter a Location" />
<button>Change Location</button>

<input name="query" type="text" placeholder="Enter a search term" />
<button>Filter</button>
</div>

</body>
</html>

<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiOHFsYWJzIiwiYSI6IjJYcnhObFEifQ.cqWyVvIXQf0BJp6hatERmw';
var map = L.mapbox.map('map', 'mapbox.light')
.setView([40.7611095,-73.9913995], 13);

// Define an icon called cssIcon
var cssIcon = L.divIcon({
// Specify a class name we can refer to in CSS.
className: 'css-icon',
// Set marker width and height
iconSize: [2, 2]
});

{% for hit in hits %}
var marker = L.marker([{{ hit.lat }},{{ hit.lon }}], {icon: cssIcon}).addTo(map);

//http://mw1.google.com/crisisresponse/icons/teal_dot.png
{% endfor %}
</script>
3 changes: 3 additions & 0 deletions ui/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.
78 changes: 78 additions & 0 deletions ui/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from django.shortcuts import render
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.conf import settings

from elasticsearch import Elasticsearch

# create instance of elasticsearch
es = Elasticsearch([settings.ELASTIC_SEARCH_HOST])

# Create your views here.
def index(request):
return render_to_response('ui/index.html', {
},context_instance=RequestContext(request))

# Create your views here.
def map(request):
out = get_taxi_data()

return render_to_response('mapbox.html', {
'hits': out
},context_instance=RequestContext(request))

def get_tweets():
result = es.search(index="tweets", doc_type="tweet", body={
# "query": {"match_all" : { }},
"query": {
"filtered": {
"filter": {
"geo_distance": {
"distance": "10km",
"location": {
"lat": 40.7611095,
"lon": -73.9913995
}
}
}
}
},
"size": 5000
})

hits = result['hits']['hits']

out = []

for hit in hits:
out.append(hit['_source']['location'])

return out

def get_taxi_data():
result = es.search(index="nyc_taxi_data", doc_type="taxi", body={
# "query": {"match_all" : { }},
"query": {
"filtered": {
"filter": {
"geo_distance": {
"distance": "4km",
"dropoff_location": {
"lat": 40.7611095,
"lon": -73.9913995
}
}
}
}
},
"size": 3000
})

hits = result['hits']['hits']

out = []

for hit in hits:
out.append(hit['_source']['dropoff_location'])

return out
Binary file added ui/views.pyc
Binary file not shown.

0 comments on commit dc197e5

Please sign in to comment.