dashboard-tourpedia.html 8.12 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
5
6
7
8
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../material-search/material-search.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../google-chart-elasticsearch/google-chart.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../reviews-table/reviews-table.html">
<link rel="import" href="../number-chart/number-chart.html">

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

<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>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        <!-- <div style="width: 100%; display: inline-block"> -->
        <!--   <div style="width: 23%; margin-right: 2.6%; float: left"> -->
        <!--     <number-chart  -->
        <!--       data="{{data}}" -->
        <!--       object="londres" -->
        <!--       title="Londres" -->
        <!--       icon="maps:local-dining" -->
        <!--       aggkey="location" -->
        <!--       stylebg="bg-yellow"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!--   <div style="width: 23%; margin-right: 2.6%; float: left"> -->
        <!--     <number-chart  -->
        <!--       data="{{data}}" -->
        <!--       object="madrid" -->
        <!--       aggkey="location" -->
        <!--       title="Madrid" -->
        <!--       icon="social:whatshot" -->
        <!--       stylebg="bg-green"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!--   <div style="width: 23%; float: left"> -->
        <!--     <number-chart  -->
        <!--       icon="maps:hotel" -->
        <!--       data="{{data}}" -->
        <!--       title="Paris" -->
        <!--       object="paris" -->
        <!--       aggkey="location" -->
        <!--       stylebg="bg-aqua"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!-- </div> -->
110
111
112
        <div style="width: 100%; display: inline-block">
          <div class="chart_container" style="right: 0; float: right">
            <google-chart
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
113
              data="{{data}}"
114
115
116
117
118
119
120
121
122
123
124
125
126
              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"}]'
            </google-chart>
          </div>
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
127
128
129
130
131
              field="category"
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
132
              filters="{{filters}}"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
133
134
135
136
              icon='room'
              param="{{param}}"
              options='{"title": "Different types of places"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
137
138
139
140
141
142
143
144
            </google-chart>
          </div>
        </div>
      </div>
    </iron-pages>
  </template>

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
145
  var ready = false;
146
147
148
149
150
151
152
153
154
    Polymer({
      is: 'dashboard-tourpedia',
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 

        ids:{
155
156
157
          type: Array
          /*value: ["481","482","32512","32420","91963","96677","160677","131425","322429","322612"]*/
           
158
159
160
161
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
162
163
164
165
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        },
        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(){
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
190
        console.log("ready");
191
192
193
194
      },
      
      addPlace: function(event) {
        this.set('places', this.places.concat(event.detail.response))
195
        console.log(this.places)
196
197
198
199
200
201
202
203
204
205
      },
      
      getName: function(id) {
        return "http://tour-pedia.org/api/getPlaceDetails?id=" + id
      },
      
      getPoints: function(f) {
        return f.base;
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
206
207
208
209
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
210
211
      },
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
212
213
214
        this._query();
       },
       _query: function() {
215
        console.log("_filtersChangedash")
216
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
217
218
219
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
          // 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"
                  }
                }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
              },
              numReviews: {
                terms: {
                  field: "numReviews",
                  order: {
                    _count: "desc"
                  }
                }
              },
              polarity: {
                terms: {
                  field: "polarity",
                  order: {
                    _count: "desc"
                  }
                }
262
263
264
265
              }
            }      
          }
          }).then(function (resp) {
266
267
268
269
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
270
            that.data = resp;
271
272
            //console.log(that.data)
            
273
274
275
276
277
278
279
            });
        }
      }
    });
  </script>

</dom-module>