dashboard-reddit.html 11.7 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

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

73
        <div class="row" style="width: 100%; display: inline-block">
74
          <div class="chart_container" style="right: 0; float: right">
75
            <entities-chart
Alberto Pascual's avatar
Alberto Pascual committed
76
                field="entities.dbps:anyURI"
77
78
79
80
81
82
83
                data="{{data}}"
                title="Entities founded"
                icon="icons:list"
                param="{{param}}"
                id="entitieschart"
                filters="{{filters}}">
            </entities-chart>
84
          </div>
85
86
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
87
              field="schema:author"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
88
89
90
91
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
92
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
93
              icon='icons:reorder'
94
              options='{"title": "Source"}'
95
              cols='[{"label": "type", "type": "string"},{"label": "Count", "type": "number"}]'
96
97
98
            </google-chart>
          </div>
        </div>
99
     <div class="row" style="width: 100%"> 
militarpancho's avatar
militarpancho committed
100
          <div class="chart_container" style="left: 0; float: left">
militarpancho's avatar
militarpancho committed
101
102
103
104
105
            <google-chart
              field="sentiment"
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
106
              type='column'
militarpancho's avatar
militarpancho committed
107
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
108
109
110
              icon='social:mood'
              options='{"title": "Sentiments"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
111
            </google-chart>
112
       </div> 
militarpancho's avatar
militarpancho committed
113
          <div class="chart_container" style="left: 0; float: right">
114
           <leaflet-maps></leaflet-maps>
115
          </div>
116
      </div>
117
      
118
      <div class="chart_container row" style="left: 0; float: left; width: 100%">
119
        <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
120
          field="schema:datePublished"
121
122
123
124
125
126
127
128
129
          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>
130
      </div>
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
      <div class="row">
      <div class="chart_container col-md-6" style="left: 0; float: left;">
        <paper-tabs selected="{{selectedpage}}">
          <paper-tab><iron-icon icon="icons:receipt"></iron-icon> List of news</paper-tab>
          <paper-tab>Social Media</paper-tab>
        </paper-tabs>
        <iron-pages class="lists" selected="{{selectedpage}}">
        <div>
          <news-chart 
            datos = "{{data}}"
            title="List of news"
            filters="{{filters}}"
            icon='icons:receipt'>
          </news-chart>
        </div>
        <div></div>
        </iron-pages>
       </div>
149
       </div>
150
      </div>
151
152
153
    </div>
    <div>
        <yasgui-ui
154
       endpoint="http:///krusti.gsi:13030/gsicrawler/query"
155
       queries="{{queries}}">
156
157
        </yasgui-ui>
    </div>
158
    </iron-pages>
159
160
161
162
163
         <div style="background-color:#ccc; padding: 1%;">
        <div style="width:32%; margin: 0 auto">
       <img height="60px" src="/images/gsi.png">   © 2017 Grupo de Sistemas Inteligentes GSI-UPM
        </div>
       </div>
164
  </template>
165
   
166
167

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

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],
210
211
212
213
214
215
      behaviors: [
        Polymer.IronA11yKeysBehavior
      ],
      keyBindings: {
        'enter': '_search'
      },
216
217

      ready: function(){
218
        //console.log("ready");
219
220
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
221
      _clientChanged: function() {
222
        //console.log("ClientChanged");
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
223
224
        ready = true;
        this._query();
225
      },
226
      _search: function(){
227
228
        //console.log("search fired")
        //console.log(this.query.length)
229
        if (this.query.length == 0){
230
          //console.log("default search fired")
231
232
233
234
          this._query()
        }
        else this._ESsearch()
      },
235
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
236
        this._query();
237
238
       },
      _ESsearch: function() {
239
        //console.log("_filtersChangedash")
240
        var that = this;
241
        //console.log("Ready?: ", ready);
242
243
244
245
246
247
248
249
250
        if(ready){
          this.client.search({
          // undocumented params are appended to the query string
          index: "gsicrawler",
          body: {
            size: 20,
            query: {
              multi_match:{
                query: this.query,
Alberto Pascual's avatar
Alberto Pascual committed
251
                fields: ['schema:author', 'schema:headline', 'sentiments', 'schema:about']
252
253
              }
            },
254
            sort:{'schema:datePublished':{order: "desc"}},
255
256
257
258
259
260
261
262
263
            aggs: {
             type: {
               terms: {
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
Alberto Pascual committed
264
             'schema:author': {
265
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
266
                 field: "schema:author.keyword",
267
268
269
270
271
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
Alberto Pascual committed
272
             'entities.dbps:anyURI': {
273
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
274
                 field: "entities.dbps:anyURI.keyword",
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
                 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"
                     }      
                   }
295
      },
Alberto Pascual's avatar
Alberto Pascual committed
296
      'schema:datePublished': {
297
              date_histogram : {
Alberto Pascual's avatar
Alberto Pascual committed
298
                field : "schema:datePublished",
299
300
301
                format: "MM-yyyy",
                interval : "month"
            }
302
       }
303
        }
304
305
306
307
308
309
310
      } 
          }).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;
311
            //console.log(that.data);
312
313
314
            
            });
        }
Alberto Pascual's avatar
Alberto Pascual committed
315
      },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
316
       _query: function() {
317
        //console.log("_query")
318
        var that = this;
319
        //console.log("Ready?: ", ready);
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
320
321
        if(ready){
          this.client.search({
322
          // undocumented params are appended to the query string
323
          index: "gsicrawler",
324
          body: {
325
            size: 20,
326
327
328
329
330
            query: {
              bool: {
                must: this.filters,
              }
            },
331
            sort:{'schema:datePublished':{order: "desc"}},
332
            aggs: {
333
             type: {
militarpancho's avatar
militarpancho committed
334
               terms: {
335
336
337
338
339
340
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
Alberto Pascual committed
341
             'schema:author': {
342
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
343
                 field: "schema:author.keyword",
militarpancho's avatar
militarpancho committed
344
345
                 order: {
                   _count: "desc"
346
                 }
militarpancho's avatar
militarpancho committed
347
               }
militarpancho's avatar
militarpancho committed
348
             },
Alberto Pascual's avatar
Alberto Pascual committed
349
             'entities.dbps:anyURI': {
350
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
351
                 field: "entities.dbps:anyURI.keyword",
352
353
354
                 order: {
                   _count: "desc"
                 } 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
355
               }
356
             },
357
358
359
360
361
362
363
364
365
366
367
368
369
           sentiment: {
             terms: {
             field: "sentiments.marl:hasPolarity.keyword",
             order: {
               _count: "desc"
               }
             }
             },
          emotion: {
              terms: {
              field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
             order: {
               _count: "desc"
370
371
                     }      
                   }
372
      },
Alberto Pascual's avatar
Alberto Pascual committed
373
      'schema:datePublished': {
374
              date_histogram : {
Alberto Pascual's avatar
Alberto Pascual committed
375
                field : "schema:datePublished",
376
377
378
379
                format: "MM-yyyy",
                interval : "month"
            }
       }
380
381
       }
      } 
382
          }).then(function (resp) {
383
384
385
386
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
387
            that.data = resp;
388
            //console.log(that.data);
389
            
390
391
392
393
394
395
396
            });
        }
      }
    });
  </script>

</dom-module>