dashboard-tourpedia.html 12.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/material-search/material-search.html">
<link rel="import" href="../../bower_components/paper-material/paper-material.html">
<link rel="import" href="../../bower_components/google-chart-elk/google-chart.html">
<link rel="import" href="../../bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="../../bower_components/yasgui/yasgui.html">
<link rel="import" href="../../bower_components/reviews-table/reviews-table.html">
<link rel="import" href="../../bower_components/number-chart/number-chart.html">
<link rel="import" href="../../bower_components/leaflet-map/leaflet-map.html">

<dom-module id="dashboard-tourpedia">

  <style is="custom-style">
    @import url("../../styles/app-theme.html");
  </style>
  <link rel="import" type="css" href="dashboard-tourpedia.css">

  <template>
    <iron-ajax auto
        url="queries.json"
        handle-as="json"
        last-response="{{queries}}"></iron-ajax>
    <iron-ajax auto
        url="/endpoint.json"
        handle-as="json"
        last-response="{{endpoint}}"></iron-ajax>
    <template is="dom-repeat" items="{{ids}}" as="id"> 
      <iron-ajax auto 
        url="{{getName(id)}}"
        handle-as="json"
        on-response="addPlace"></iron-ajax>
    </template>

    <paper-tabs selected="{{selected}}">
      <paper-tab>Dashboard</paper-tab>
      <paper-tab>Sparql Editor</paper-tab>
    </paper-tabs>

    <iron-pages selected="{{selected}}">
      <div>
        <material-search search-value="{{query}}"></material-search>
        <br>
        <div style="width: 100%; display: inline-block">
          <div style="width: 23%; margin-right: 2.6%; float: left">
            <number-chart 
              icon="info"
              stylebg="bg-red"
              data="{{data}}">
            </number-chart>
          </div>
          <div style="width: 23%; margin-right: 2.6%; float: left">
            <number-chart 
              data="{{data}}"
              object="restaurant"
              title="Restaurants"
              icon="maps:local-dining"
              stylebg="bg-yellow">
            </number-chart>
          </div>
          <div style="width: 23%; margin-right: 2.6%; float: left">
            <number-chart 
              data="{{data}}"
              object="poi"
              title="POIs"
              icon="social:whatshot"
              stylebg="bg-green">
            </number-chart>
          </div>
          <div style="width: 23%; float: left">
            <number-chart 
              icon="maps:hotel"
              data="{{data}}"
              title="Accommodations"
              object="accommodation"
              stylebg="bg-aqua">
            </number-chart>
          </div>
        </div>
        <div style="width: 100%; display: inline-block">
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
              field="category"
              datos="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
              filters="{{filters}}"
              icon='room'
              param="{{param}}"
              options='{"title": "Different types of places"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
              rows='[ ["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30] ]'>
            </google-chart>
          </div>
          <div class="chart_container" style="right: 0; float: right">
            <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
97
              datos="{{data}}"
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
              field="location"
              id='pie-chart4'
              extra-id='pie-chart4'
              type='pie'
              filters="{{filters}}"
              icon='maps:my-location'
              param='{{param}}'
              options='{"title": "Places at different cities"}'
              cols='[{"label": "Place", "type": "string"},{"label": "Count", "type": "number"}]'
              rows='[ ["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30] ]'>
            </google-chart>
          </div>
        </div>
        <div style="width: 100%">
          <div class="chart_container" style="left: 0; float: left">
           <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
114
              datos="{{data}}"
115
              field="numReviews"
116
117
118
119
120
121
122
123
124
125
126
127
128
129
              id='column-chart1'
              extra-id='column-chart1'
              type='column'
              filters="{{filters}}"
              icon='maps:rate-review'
              param='{{param}}'
              optionsbi='{"legend": "none"}'
              options='{"title": "Count of number of reviews"}'
              cols='[{"label": "Reviews", "type": "number"},{"label": "Count", "type": "number"}]'
              rows='[ [0, 31],[1, 28],[2, 31],[3, 30],[4, 30],[5, 31],[6, 30] ]'>
            </google-chart>
          </div>
          <div class="chart_container" style="right: 0; float: right">
            <google-chart
130
              datos="{{data}}"
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
              field="polarity"
              fields='["category", "location"]'
              id='bar-chart3'
              extra-id='bar-chart3'
              type='bar'
              filters="{{filters}}"
              icon='maps:local-play'
              param='{{param}}'
              optionsbi='{"legend": "none"}'
              options='{"title": "Count of different polarities"}'
              cols='[{"label": "Polarity", "type": "number"},{"label": "Count", "type": "number"}]'
              rows='[ ["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30] ]'>
            </google-chart>
          </div>
            <div style="clear: both"></div>
        </div>
        <div style="width: 100%">
          <div class="chart_container" style="left: 0; float: left">
            <reviews-table 
150
                data="{{ids}}"
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
                icon='social:people'>
            </reviews-table>
          </div>
          <div class="chart_container" style="right: 0; float: right"> 
            <leaflet-map fit-to-markers>      
              <template is="dom-repeat" items="[[getPoints(places.*)]]" as="place">      
                <leaflet-marker latitude="{{place.lat}}" longitude="{{place.lng}}" title="{{place.name}}"> 
                    <b>Name:</b>
                    <span>{{place.name}}</span>
                </leaflet-marker>
              </template>
            </leaflet-map>
          </div>
          <div style="clear: both"></div>
        </div>
      </div>
      <div>
        <yasgui-ui
            endpoint="http://fuseki-tourpedia.cluster.gsi.dit.upm.es/tourpedia/query"
            queries="{{queries}}">
        </yasgui-ui>
      </div>
    </iron-pages>
  </template>

  <script>
  var filtered = false;
    Polymer({
      is: 'dashboard-tourpedia',
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 

        ids:{
187
188
189
          type: Array
          /*value: ["481","482","32512","32420","91963","96677","160677","131425","322429","322612"]*/
           
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        },

        data:{
          type: Object
        },

        query: {
          type: String,
          observer: '_queryChanged'
        },

        fields: {
          type: Array,
          value: function() { return []; }
        },

        places: {
          type: Array,
          notify: true,
          value: []
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],

      ready: function(){
        this.queryDefault();
      },
      
      addPlace: function(event) {
        this.set('places', this.places.concat(event.detail.response))
229
        console.log(this.places)
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
      },
      
      getName: function(id) {
        return "http://tour-pedia.org/api/getPlaceDetails?id=" + id
      },
      
      getPoints: function(f) {
        return f.base;
      },

      _queryChanged: function() {
        console.log("_queryChanged")
        this.query ? this.queryChange(this.query) : this.queryDefault();
      },

      queryChange: function(value) {
        console.log("_filtersChange")
        var that = this;
        var client = new $.es.Client({
            hosts: this.host
          });
          client.search({
          // undocumented params are appended to the query string
          index: "tourpedia",
          type: "places",
          body: {
            size: 10,
            query: {
              multi_match: {
                fields: ["category","location"],
                query: this.query

              }
            },
            aggs: {
              category: {
                terms: {
                  field: "category",
                  order: {
                    _count: "desc"
                  }
                }
              },
              location: {
                terms: {
                  field: "location",
                  order: {
                    _count: "desc"
                  }
                }
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
              },
              numReviews: {
                terms: {
                  field: "numReviews",
                  order: {
                    _count: "desc"
                  }
                }
              },
              polarity: {
                terms: {
                  field: "polarity",
                  order: {
                    _count: "desc"
                  }
                }
296
297
298
299
              }
            }      
          }
          }).then(function (resp) {
300
301
302
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
303
            that.data = resp;
304
            
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
        });
        
      },
     
      queryDefault: function() {
        var that = this;
        var client = new $.es.Client({
          hosts: this.host
        });
        client.search({
          // undocumented params are appended to the query string
          index: "tourpedia",
          type: "places",
          body: {
            size: 10,
            query: {
              match_all: {}
            },
323
            sort: {numReviews: "desc"},
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
            aggs: {
              category: {
                terms: {
                  field: "category",
                  order: {
                    _count: "desc"
                  }
                }
              },
              location: {
                terms: {
                  field: "location",
                  order: {
                    _count: "desc"
                  }
                }
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
              },
              numReviews: {
                terms: {
                  field: "numReviews",
                  order: {
                    _count: "desc"
                  }
                }
              },
              polarity: {
                terms: {
                  field: "polarity",
                  order: {
                    _count: "desc"
                  }
                }
356
357
358
359
              }
            }      
          }
        }).then(function (resp) {
360
361
362
363
          var myids = []
          resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
          that.ids = myids;
          //console.log(that.ids)
364
          that.data = resp;
365
          //console.log(that.data)
366
367
368
369
        });
      },

      _filtersChange: function() {
370
        console.log("_filtersChangedash")
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
        var that = this;
        if(filtered){
          var client = new $.es.Client({
            hosts: this.host
          });
          client.search({
          // undocumented params are appended to the query string
          index: "tourpedia",
          type: "places",
          body: {
            size: 10,
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
              category: {
                terms: {
                  field: "category",
                  order: {
                    _count: "desc"
                  }
                }
              },
              location: {
                terms: {
                  field: "location",
                  order: {
                    _count: "desc"
                  }
                }
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
              },
              numReviews: {
                terms: {
                  field: "numReviews",
                  order: {
                    _count: "desc"
                  }
                }
              },
              polarity: {
                terms: {
                  field: "polarity",
                  order: {
                    _count: "desc"
                  }
                }
419
420
421
422
              }
            }      
          }
          }).then(function (resp) {
423
424
425
426
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
427
            that.data = resp;
428
429
            //console.log(that.data)
            
430
431
432
433
434
435
436
            });
        }
      }
    });
  </script>

</dom-module>