dashboard-reddit.html 11.1 KB
Newer Older
militarpancho's avatar
militarpancho committed
1
2
3
<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">
4
<link rel="import" href="/elements/google-chart-elasticsearch/google-chart.html">
militarpancho's avatar
militarpancho committed
5
6
<link rel="import" href="/bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="/bower_components/paper-tabs/paper-tab.html">
7
<link rel="import" href="/elements/number-chart/number-chart.html">
militarpancho's avatar
militarpancho committed
8
<link rel="import" href="/bower_components/comment-chart/comment-chart.html">
militarpancho's avatar
militarpancho committed
9
10
<link rel="import" href="/bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="/bower_components/yasgui-polymer/yasgui.html">
11
12
13
<link rel="import" href="/bower_components/iron-pages/iron-pages.html">
<link rel="import" href="/bower_components/paper-item/paper-item.html">
<link rel="import" href="/bower_components/paper-menu/paper-menu.html">
14
<link rel="import" href="/elements/entities-chart/entities-chart.html">
15
<link rel="import" href="/elements/news-chart/news-chart.html">
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
16

17

militarpancho's avatar
militarpancho committed
18
<dom-module id="dashboard-reddit">
19

militarpancho's avatar
militarpancho committed
20
21
22

  <link rel="import" type="css" href="dashboard-tourpedia.css" type="css">
  <link rel="import" href="/styles/app-theme.html" type="css">
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

  <template>
    <iron-ajax auto
        url="queries.json"
        handle-as="json"
        last-response="{{queries}}"></iron-ajax>

    <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">
militarpancho's avatar
militarpancho committed
40
          <div style="width: 32%; margin-right: 2%; float: left">
41
            <number-chart 
42
              icon="/images/news.ico"
43
              stylebg="bg-red"
44
              title="Items selected"
45
46
47
              data="{{data}}">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
48
          <div style="width: 32%; margin-right: 2%; float: left">
49
50
            <number-chart 
              data="{{data}}"
51
              object="cnn"
52
              aggKey="author"
53
              title="CNN"
54
              icon="/images/cnn.png"
55
56
57
              stylebg="bg-yellow">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
58
           <div style="width: 32%; float: left"> 
militarpancho's avatar
militarpancho committed
59
60
             <number-chart  
               data="{{data}}" 
61
               object="The New York Times"
62
               aggKey="author"
63
               title="The New York Times" 
64
               icon="/images/times.png"
militarpancho's avatar
militarpancho committed
65
66
67
68
69
70
               aggkey="location"
               stylebg="bg-green"> 
             </number-chart>
           </div>
         </div>

71
72
        <div style="width: 100%; display: inline-block">
          <div class="chart_container" style="right: 0; float: right">
73
74
75
76
77
78
79
80
81
82
            <entities-chart
                field="about"
                data="{{data}}"
                title="Entities founded"
                icon="icons:list"
                param="{{param}}"
                id="entitieschart"
                filters="{{filters}}">
            </entities-chart>
      </div>
83
84
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
85
              field="author"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
86
87
88
89
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
90
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
91
              icon='icons:reorder'
92
              options='{"title": "Newspapers"}'
93
              cols='[{"label": "type", "type": "string"},{"label": "Count", "type": "number"}]'
94
95
96
            </google-chart>
          </div>
        </div>
97
     <div style="width: 100%"> 
militarpancho's avatar
militarpancho committed
98
          <div class="chart_container" style="left: 0; float: left">
militarpancho's avatar
militarpancho committed
99
100
101
102
103
104
            <google-chart
              field="sentiment"
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
militarpancho's avatar
militarpancho committed
105
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
106
107
108
              icon='social:mood'
              options='{"title": "Sentiments"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
109
            </google-chart>
110
       </div> 
militarpancho's avatar
militarpancho committed
111
112
          <div class="chart_container" style="left: 0; float: right">
            <google-chart
113
              field="emotion"
militarpancho's avatar
militarpancho committed
114
115
116
117
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
militarpancho's avatar
militarpancho committed
118
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
119
120
121
              icon='social:sentiment-very-dissatisfied'
              options='{"title": "Emotions"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
122
            </google-chart>
123
          </div>
124
      </div>
125
      
126
      <div class="chart_container" style="left: 0; float: left; width: 100%">
127
128
129
130
131
132
133
134
135
136
137
        <google-chart
          field="dataPublished"
          data="{{data}}"             
          id='line-chart'
          extra-id='line-chart'
          type='area'
          filters="{{filters}}"
          icon='icons:trending-up'
          options='{"title": "News rate"}'
          cols='[{"label": "Date", "type": "string"},{"label": "Count", "type": "number"}]'
        </google-chart>
138
139
      </div>
      <div class="chart_container" style="left: 0; float: left; width: 100%">
140
141
142
143
144
145
        <news-chart 
          datos = "{{data}}"
          title="List of news"
          filters="{{filters}}"
          icon='icons:receipt'>
        </news-chart>
146
147
       </div>

148
      </div>
149
150
151
    </div>
    <div>
        <yasgui-ui
152
153
       endpoint="http:///gsicrawler/query"
       queries="{{queries}}">
154
155
        </yasgui-ui>
    </div>
156
157
    </iron-pages>
  </template>
158
   
159
160

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
161
  var ready = false;
162
    Polymer({
militarpancho's avatar
militarpancho committed
163
      is: 'dashboard-reddit',
164
165
166
167
168
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 
169
170
171
        query: {
          type: String,
        },
172
        ids:{
173
174
          type: Array
           
175
176
177
178
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
179
180
181
182
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
        },
        fields: {
          type: Array,
          value: function() { return []; }
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],
199
200
201
202
203
204
      behaviors: [
        Polymer.IronA11yKeysBehavior
      ],
      keyBindings: {
        'enter': '_search'
      },
205
206

      ready: function(){
207
        //console.log("ready");
208
209
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
210
      _clientChanged: function() {
211
        //console.log("ClientChanged");
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
212
213
        ready = true;
        this._query();
214
      },
215
      _search: function(){
216
217
        //console.log("search fired")
        //console.log(this.query.length)
218
        if (this.query.length == 0){
219
          //console.log("default search fired")
220
221
222
223
          this._query()
        }
        else this._ESsearch()
      },
224
      _filtersChange: function() {
Alberto Pascual's avatar
Alberto Pascual committed
225
        var myfilters = []
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
226
        this._query();
227
228
       },
      _ESsearch: function() {
229
        //console.log("_filtersChangedash")
230
        var that = this;
231
        //console.log("Ready?: ", ready);
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
280
281
282
283
        if(ready){
          this.client.search({
          // undocumented params are appended to the query string
          index: "gsicrawler",
          body: {
            size: 20,
            query: {
              multi_match:{
                query: this.query,
                fields: ['author', 'headline', 'sentiments', 'about']
              }
            },
            aggs: {
             type: {
               terms: {
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
             author: {
               terms: {
                 field: "author.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
             about: {
               terms: {
                 field: "about.keyword",
                 order: {
                   _count: "desc"
                 } 
               }
             },
           sentiment: {
             terms: {
             field: "sentiments.marl:hasPolarity.keyword",
             order: {
               _count: "desc"
               }
             }
             },
          emotion: {
              terms: {
              field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
             order: {
               _count: "desc"
                     }      
                   }
284
285
286
287
288
289
290
      },
      dataPublished: {
              date_histogram : {
                field : "dataPublished",
                format: "MM-yyyy",
                interval : "month"
            }
291
       }
292
        }
293
294
295
296
297
298
299
      } 
          }).then(function (resp) {
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
            that.data = resp;
300
            //console.log(that.data);
301
302
303
            
            });
        }
Alberto Pascual's avatar
Alberto Pascual committed
304
      },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
305
       _query: function() {
306
        //console.log("_query")
307
        var that = this;
308
        //console.log("Ready?: ", ready);
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
309
310
        if(ready){
          this.client.search({
311
          // undocumented params are appended to the query string
312
          index: "gsicrawler",
313
          body: {
314
            size: 20,
315
316
317
318
319
320
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
321
             type: {
militarpancho's avatar
militarpancho committed
322
               terms: {
323
324
325
326
327
328
329
330
331
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
             author: {
               terms: {
                 field: "author.keyword",
militarpancho's avatar
militarpancho committed
332
333
                 order: {
                   _count: "desc"
334
                 }
militarpancho's avatar
militarpancho committed
335
               }
militarpancho's avatar
militarpancho committed
336
             },
337
338
339
340
341
342
             about: {
               terms: {
                 field: "about.keyword",
                 order: {
                   _count: "desc"
                 } 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
343
               }
344
             },
345
346
347
348
349
350
351
352
353
354
355
356
357
           sentiment: {
             terms: {
             field: "sentiments.marl:hasPolarity.keyword",
             order: {
               _count: "desc"
               }
             }
             },
          emotion: {
              terms: {
              field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
             order: {
               _count: "desc"
358
359
                     }      
                   }
360
361
362
363
364
365
366
367
      },
      dataPublished: {
              date_histogram : {
                field : "dataPublished",
                format: "MM-yyyy",
                interval : "month"
            }
       }
368
369
       }
      } 
370
          }).then(function (resp) {
371
372
373
374
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
375
            that.data = resp;
376
            //console.log(that.data);
377
            
378
379
380
381
382
383
384
            });
        }
      }
    });
  </script>

</dom-module>