Skip to content

Commit 40388e1

Browse files
author
xtutran
committed
finish the gsmgarena hierachy display
1 parent d29fdb8 commit 40388e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2573
-155
lines changed

hierarchy-data/data.ipynb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
"import urllib"
1616
]
1717
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"metadata": {
22+
"collapsed": true
23+
},
24+
"outputs": [],
25+
"source": [
26+
"from starbase import Connection\n"
27+
]
28+
},
1829
{
1930
"cell_type": "code",
2031
"execution_count": 146,
@@ -167,10 +178,8 @@
167178
},
168179
{
169180
"cell_type": "code",
170-
"execution_count": 156,
171-
"metadata": {
172-
"collapsed": true
173-
},
181+
"execution_count": 12,
182+
"metadata": {},
174183
"outputs": [],
175184
"source": [
176185
"import happybase\n",
@@ -180,7 +189,7 @@
180189
},
181190
{
182191
"cell_type": "code",
183-
"execution_count": 157,
192+
"execution_count": 13,
184193
"metadata": {
185194
"collapsed": true
186195
},
@@ -191,7 +200,7 @@
191200
},
192201
{
193202
"cell_type": "code",
194-
"execution_count": 158,
203+
"execution_count": 14,
195204
"metadata": {},
196205
"outputs": [
197206
{
@@ -200,7 +209,7 @@
200209
"['phone_specs']"
201210
]
202211
},
203-
"execution_count": 158,
212+
"execution_count": 14,
204213
"metadata": {},
205214
"output_type": "execute_result"
206215
}
@@ -222,10 +231,8 @@
222231
},
223232
{
224233
"cell_type": "code",
225-
"execution_count": 168,
226-
"metadata": {
227-
"collapsed": true
228-
},
234+
"execution_count": 8,
235+
"metadata": {},
229236
"outputs": [],
230237
"source": [
231238
"connection.close()"

hierarchy-data/mysite/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hierarchy-data/mysite/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hierarchy-data/mysite/.idea/mysite.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hierarchy-data/mysite/.idea/workspace.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
204 Bytes
Binary file not shown.
261 Bytes
Binary file not shown.
Binary file not shown.
322 Bytes
Binary file not shown.

hierarchy-data/webapp/integration/templates/detail.html renamed to hierarchy-data/mysite/integration/templates/detail.html

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
1919
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
2020
crossorigin="anonymous"></script>
21-
2221
{% load static %}
2322
<link rel="stylesheet" href="{% static 'css/specs.css' %}" type="text/css"/>
24-
{% load static %}
23+
<!--{% load static %}-->
2524
<script src="{% static 'js/colResizable-1.5.min.js' %}"></script>
26-
{% load static %}
25+
<!--{% load static %}-->
2726
<script src="{% static 'js/fuzzyset.js' %}"></script>
28-
{% load static %}
27+
<!--{% load static %}-->
2928
<script src="{% static 'js/fuzzy.js' %}"></script>
30-
{% load static %}
29+
<!--{% load static %}-->
3130
<script src="{% static 'js/quantities.js' %}"></script>
32-
{% load static %}
33-
<script src="{% static 'js/jquery-highlight-min1.js' %}"></script>
31+
<!--{% load static %}-->
32+
<script src="{% static 'js/jquery.highlight-5.js' %}"></script>
3433
<script type="text/javascript">
3534
var d3Regex = /\b([0-9]+(\.[0-9]+)?)[\s]*x[\s]*\b([0-9]+(\.[0-9]+)?)[\s]*x[\s]*\b([0-9]+(\.[0-9]+)?)[\s]*([\w]+)/g
3635
var d2Regex = /\b([0-9]+(\.[0-9]+)?)[\s]* x[\s]*\b([0-9]+(\.[0-9]+)?)[\s]*([\w]+)/g;
@@ -403,6 +402,8 @@
403402
</center>
404403
</div>
405404
<br/>
405+
406+
{% load custom_tag %}
406407
{% if phone_data %}
407408
<table class="table table-hover" id="specs" border="1" width="100%">
408409
<tr class="danger">
@@ -423,34 +424,50 @@ <h2 class="htitle">{{ spec.0 }}</h2>
423424
{% if sub != '' %}
424425
<li class="s_lv_1">
425426
<strong>{{ sub }}: </strong>
426-
<ul>
427-
{% for subsub, v in value.items %}
428-
{% if subsub != '' %}
429-
<li class="s_lv_2">
430-
<strong>{{ subsub }}: </strong>
427+
{% if value.items != '' %}
428+
<ul>
429+
{% split value as values %}
430+
{% for v in values%}
431+
<!--<div class="hiddenRow">-->
432+
<!--<div class="accordion-body collapse packageDetails1" id="accordion3">-->
433+
<li class="s_lv_3">
434+
<input type="checkbox" class="phone" value="{{ v }}"> {{ v }}
435+
</li>
436+
<!--</div>-->
437+
<!--</div>-->
438+
{% endfor %}
439+
</ul>
440+
{% else %}
441+
<ul>
442+
{% for subsub, v in value.items %}
443+
{% if subsub != '' %}
444+
<li class="s_lv_2">
445+
<strong>{{ subsub }}: </strong>
446+
<div class="hiddenRow">
447+
<ul >
448+
<div class="accordion-body collapse packageDetails1" id="accordion1">
449+
<li class="s_lv_3">
450+
<input type="checkbox" class="phone" value="{{ v.0 }}"> {{ v.0 }}
451+
</li>
452+
</div >
453+
</ul>
454+
</div>
455+
</li>
456+
{% else %}
457+
{% for d in v %}
431458
<div class="hiddenRow">
432-
<ul >
433-
<div class="accordion-body collapse packageDetails1" id="accordion1">
434-
<li class="s_lv_3">
435-
<input type="checkbox" class="phone" value="{{ v.0 }}"> {{ v.0 }}
436-
</li>
437-
</div >
438-
</ul>
439-
</div>
440-
</li>
441-
{% else %}
442-
{% for d in v %}
443-
<div class="hiddenRow">
444-
<div class="accordion-body collapse packageDetails1" id="accordion2">
445-
<li class="s_lv_3">
446-
<input type="checkbox" class="phone" value="{{ d }}"> {{ d }}
447-
</li>
459+
<div class="accordion-body collapse packageDetails1" id="accordion2">
460+
<li class="s_lv_3">
461+
<input type="checkbox" class="phone" value="{{ d }}"> {{ d }}
462+
</li>
463+
</div>
448464
</div>
449-
</div>
450-
{% endfor %}
451-
{% endif %}
452-
{% endfor %}
453-
</ul>
465+
{% endfor %}
466+
{% endif %}
467+
{% endfor %}
468+
</ul>
469+
{% endif %}
470+
454471
</li>
455472
{% else %}
456473
{% for subsub, v in value.items %}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.conf import settings
2+
3+
for a in settings.INSTALLED_APPS:
4+
try:
5+
__path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
6+
except ImportError:
7+
pass
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django import template
2+
3+
register = template.Library()
4+
5+
6+
@register.simple_tag
7+
def split(value):
8+
return value.split('^^^')
9+
10+
11+
# register.tag('split', split)
Binary file not shown.

hierarchy-data/webapp/integration/urls.py renamed to hierarchy-data/mysite/integration/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
urlpatterns = [
66
url(r'^phone?$', views.index, name='index'),
77
url(r'^phone/list/$', views.listing, name='list'),
8-
# url(r'^phone/detail/$', views.detail, name='detail'),
8+
url(r'^phone/detail/$', views.detail, name='detail'),
99
# url(r'^freebase/matching/$', views.freebase, name='freebase')
1010
]
511 Bytes
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from django.shortcuts import render
2+
from django.http import HttpResponse, HttpResponseBadRequest
3+
from django.template import loader
4+
import happybase
5+
import pandas as pd
6+
import sys,os
7+
# import extract
8+
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
9+
10+
# pool = happybase.ConnectionPool(size=3, host='192.168.1.240')
11+
global_schema = {}# extract.read_global_schema("integration/rules/global_schema.txt")
12+
13+
14+
# Create your views here.
15+
def index(request):
16+
return HttpResponse("Welcome to Data Integration site!")
17+
18+
19+
def paginate(phones, page):
20+
paginator = Paginator(phones, 25) # Show 25 contacts per page
21+
try:
22+
phones = paginator.page(page)
23+
except PageNotAnInteger:
24+
# If page is not an integer, deliver first page.
25+
phones = paginator.page(1)
26+
except EmptyPage:
27+
# If page is out of range (e.g. 9999), deliver last page of results.
28+
phones = paginator.page(paginator.num_pages)
29+
return phones
30+
31+
32+
def _get_specs(table, column, row_prefix, limit):
33+
# with pool.connection() as connection:
34+
phones = []
35+
exit_code = 0
36+
if column not in table.families():
37+
return phones, exit_code
38+
39+
try:
40+
for key, data in table.scan(filter=b'FirstKeyOnlyFilter()',
41+
row_prefix=bytes(row_prefix), limit=limit, columns=[column]):
42+
phones.append((key.decode('utf-8'), key.decode('utf-8')))
43+
except IOError and AssertionError:
44+
exit_code = 1
45+
return phones, exit_code
46+
47+
48+
def _get_spec(table, column, row_key):
49+
try:
50+
row = table.row(bytes(row_key), columns=[column])
51+
except IOError and AssertionError:
52+
return {}, 1
53+
54+
spec = pd.DataFrame(row, index=[0]).T.reset_index()
55+
# spec.columns = ['feature', 'value']
56+
features = spec['index'].apply(lambda x: pd.Series(x.replace('{}:'.format(column.lower()), '').split(':')))
57+
feature_cols = map(lambda x: 'level_{}'.format(x), features.columns)
58+
features.columns = feature_cols
59+
features['value'] = spec[0]
60+
61+
while len(feature_cols) != 1:
62+
features = features.groupby(feature_cols[:-1]).\
63+
apply(lambda x: dict(zip(x[feature_cols[-1]], x.value))).\
64+
reset_index().\
65+
rename(columns={0: 'value'})
66+
feature_cols = features.columns[:-1]
67+
68+
return map(lambda x: tuple(x), features.values), 0
69+
70+
71+
def listing(request):
72+
parameters = request.GET
73+
tables = parameters.getlist('table') if 'table' in parameters else ['phonearena', 'gsmgarena']
74+
row_prefix = parameters['prefix'] if 'prefix' in parameters else ''
75+
try:
76+
limit = int(parameters.get('limit'))
77+
limit = limit if (limit <= 300) and (limit > 0) else 300
78+
except ValueError:
79+
limit = 100
80+
except TypeError:
81+
limit = 100
82+
page = request.GET.get('page')
83+
84+
pool = happybase.ConnectionPool(size=3, host='192.168.56.101')
85+
with pool.connection() as connection:
86+
table = connection.table('phone_specs')
87+
phone_data = {}
88+
for column in tables:
89+
phones, exit_code = _get_specs(table, column.lower(), row_prefix=row_prefix.upper(), limit=limit)
90+
if exit_code == 0:
91+
phone_data[column] = paginate(phones, page)
92+
phone_data[column] = phones
93+
94+
return render(request, 'list.html', {'phones': phone_data,
95+
'prefix': row_prefix, 'limit': limit})
96+
97+
98+
def detail(request):
99+
print request.POST
100+
if 'phone' in request.POST:
101+
params = request.POST.getlist('phone')
102+
pool = happybase.ConnectionPool(size=3, host='192.168.56.101')
103+
with pool.connection() as connection:
104+
table = connection.table('phone_specs')
105+
phone_data = {}
106+
for param in params:
107+
tokens = param.split('###')
108+
column = tokens[0]
109+
row_key = tokens[1]
110+
data, exit_code = _get_spec(table, column, row_key)
111+
phone_data[param] = sorted(data, key=sortfn)
112+
113+
return render(request, 'detail.html', {'phone_data': phone_data})
114+
else:
115+
return HttpResponseBadRequest('Bad request')
116+
117+
118+
def sortfn(item):
119+
if len(global_schema) == 0:
120+
return item[0]
121+
else:
122+
return global_schema[item[0].lower()]
5.71 KB
Binary file not shown.
File renamed without changes.

hierarchy-data/mysite/mysite/__init__.py

Whitespace-only changes.
199 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)