dashboard-gsicrawler.html 15.2 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">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
15
<link rel="import" href="/elements/people-chart/people-chart.html">
16
<link rel="import" href="/elements/news-chart/news-chart.html">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
17
<link rel="import" href="/elements/tweet-chart/tweet-chart.html">
Alberto Pascual's avatar
Alberto Pascual committed
18
<link rel="import" href="/bower_components/leaflet-maps/leaflet-map.html">
19

20
<dom-module id="dashboard-gsicrawler">
21

militarpancho's avatar
militarpancho committed
22

23
  <link rel="import" type="css" href="dashboard-gsicrawler.css" type="css">
militarpancho's avatar
militarpancho committed
24
  <link rel="import" href="/styles/app-theme.html" type="css">
25
26
27
28
29
30
31

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

Alberto Pascual's avatar
new viz    
Alberto Pascual committed
32
33
34
35
36
37
38
    <div style="width:10%; padding: 1em; display:inline-block">
      <img style="width: 100%;"src="/images/trivalent.jpg">
    </div>
    <div style="width:80%;     padding-bottom: 12px; text-align:center; display:inline-block">
      <img style="width: 30%;  margin:0 auto;"src="/images/logo-gsi-crawler.png">
    </div>

39
40
41
42
43
44
45
    <paper-tabs selected="{{selected}}">
      <paper-tab>Dashboard</paper-tab>
      <paper-tab>Sparql Editor</paper-tab>
    </paper-tabs>

    <iron-pages selected="{{selected}}">
      <div>
46
        <div class="row">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
47
        <material-search active="true" search-value="{{query}}"></material-search>
48
49
        </div>
        <br>  
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
50
51
        <div class="row">
          <div class="col-md-3">
52
            <number-chart 
53
              icon="/images/news.ico"
54
              stylebg="bg-yellow"
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
55
              title="Selected elements"
56
57
58
              data="{{data}}">
            </number-chart>
          </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
59
          <div class="col-md-3">
60
61
            <number-chart 
              data="{{data}}"
62
              object="cnn"
Alberto Pascual's avatar
Alberto Pascual committed
63
              aggKey="schema:author"
64
              title="CNN"
65
66
              icon="/images/cnn1.png"
              stylebg="bg-red">
67
68
            </number-chart>
          </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
69
          <div class="col-md-3">
militarpancho's avatar
militarpancho committed
70
71
             <number-chart  
               data="{{data}}" 
72
               object="The New York Times"
Alberto Pascual's avatar
Alberto Pascual committed
73
               aggKey="schema:author"
74
               title="The New York Times" 
75
               icon="/images/times1.png"
militarpancho's avatar
militarpancho committed
76
77
78
79
               aggkey="location"
               stylebg="bg-green"> 
             </number-chart>
           </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
80
81
82
83
84
85
86
87
88
89
90
91
           <div class="col-md-3">
             <number-chart  
               data="{{data}}" 
               object="twitter"
               aggKey="schema:author"
               title="Twitter" 
               icon="/images/twitter.ico"
               subtitle="Total"
               aggkey="location"
               stylebg="bg-aqua"> 
             </number-chart>
           </div>
militarpancho's avatar
militarpancho committed
92
         </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
93
94
95
         <br> 
        <div class="row">
          <div class="col-md-6">
96
            <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
97
              field="schema:author"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
98
99
100
101
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
102
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
103
              icon='icons:reorder'
104
              options='{"title": "Source"}'
105
              cols='[{"label": "type", "type": "string"},{"label": "Count", "type": "number"}]'
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
106
107
108
109
110
111
112
113
114
115
116
117
            </google-chart>            
          </div>
          <div class="col-md-6">
            <entities-chart
                field="topics.rdfs:subClassOf"
                data="{{data}}"
                title="Topics"
                icon="icons:list"
                param="{{param}}"
                id="entitieschart"
                filters="{{filters}}">
            </entities-chart>
118
119
          </div>
        </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
120
121
122
        <br> 
     <div class="row"> 
        <div class="col-md-6">
militarpancho's avatar
militarpancho committed
123
124
125
            <google-chart
              field="sentiment"
              data="{{data}}"             
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
126
127
              id='barsentiment'
              extra-id='1'
128
              type='column'
militarpancho's avatar
militarpancho committed
129
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
130
131
132
              icon='social:mood'
              options='{"title": "Sentiments"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
133
            </google-chart>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
134
135
136
137
138
139
140
141
142
143
         </div> 
          <div class="col-md-6">
            <people-chart
                data="[[getPeople(data)]]"
                title="People"
                icon="maps:person-pin"
                param="{{param}}"
                id="entitieschart"
                filters="{{filters}}">
            </people-chart>
144
          </div>
145
      </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
146
147
148
      <br> 
      <div class="row">
        <div class="col-md-12">
149
        <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
150
          field="schema:datePublished"
151
152
153
154
155
156
          data="{{data}}"             
          id='line-chart'
          extra-id='line-chart'
          type='area'
          filters="{{filters}}"
          icon='icons:trending-up'
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
157
          options='{"title": "Temporal Trends"}'
158
159
          cols='[{"label": "Date", "type": "string"},{"label": "Count", "type": "number"}]'
        </google-chart>
160
      </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
161
162
      </div>
      <br> 
163
      <div class="row">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
164
      <div class="col-md-6">
165
166
        <paper-tabs selected="{{selectedpage}}">
          <paper-tab><iron-icon icon="icons:receipt"></iron-icon> List of news</paper-tab>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
167
          <paper-tab><iron-icon icon="icons:speaker-notes"></iron-icon> Social Media</paper-tab>
168
169
170
171
172
173
174
175
176
177
        </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>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
178
179
180
181
182
183
184
        <div>
          <tweet-chart 
            datos = "{{data}}"
            title="List of tweets"
            filters="{{filters}}"
            icon='communication:comment'>
          </tweet-chart></div>
185
186
        </iron-pages>
       </div>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
187
       <div class="col-md-6">
188
189
190
191
192
        <div class="top-bar">
        <iron-icon icon="maps:my-location"></iron-icon>
          <span>Geolocated News and Social Media</span>
        </div>
        <leaflet-map fit-to-markers>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
193
          <template is="dom-repeat" items="[[getPlaces(data)]]" as="place">
194
                <leaflet-marker latitude="{{place.lat}}" longitude="{{place.lng}}" title="{{place.name}}"> 
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
195
                    <b>Headline:</b>
196
197
                    <span>{{place.name}}</span>
                </leaflet-marker>
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
198
              </template>
199
        </leaflet-map>
200
       </div>
201
      </div>
202
203
204
    </div>
    <div>
        <yasgui-ui
205
       endpoint="http:///sefarad-fuseki.cluster.gsi.dit.upm.es/gsicrawler/query"
206
       queries="{{queries}}"
207
208
        </yasgui-ui>
    </div>
209
    </iron-pages>
210
211
         <div style="background-color:#ccc; padding: 1%;">
        <div style="width:32%; margin: 0 auto">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
212
       <img height="60px" src="/images/gsi.png">   © 2017 Grupo de Sistemas Inteligentes GSI-UPM 
213
214
        </div>
       </div>
215
  </template>
216
   
217
218

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
219
  var ready = false;
220
    Polymer({
221
      is: 'dashboard-gsicrawler',
222
223
224
225
226
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 
227
228
229
230
        selectedpage: {
          type: Number,
          value: 0
        }, 
231
232
233
        query: {
          type: String,
        },
234
        ids:{
235
236
          type: Array
           
237
238
239
240
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
241
242
243
244
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
        },
        fields: {
          type: Array,
          value: function() { return []; }
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],
261
262
263
264
265
266
      behaviors: [
        Polymer.IronA11yKeysBehavior
      ],
      keyBindings: {
        'enter': '_search'
      },
267
268

      ready: function(){
269
        //console.log("ready");
270
271
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
272
      _clientChanged: function() {
273
        //console.log("ClientChanged");
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
274
275
        ready = true;
        this._query();
276
      },
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
      getPeople: function(data){
        var people = []
        //console.log(data)
        data.hits.hits.forEach( function (entry){
          //console.log(entry)
          entry._source.entities.forEach(function(entity){
            //console.log(entity)
            if ('dbo:thumbnail' in entity) {
              people.push({'name': entity['nif:anchorOf'], 'image': entity['dbo:thumbnail']})
            }
          })
        })
        people = this.removeDuplicates(people, 'name')
        console.log(people)
        return people.slice(0,8)
      },
      removeDuplicates: function(originalArray, prop){
        var newArray = [];
        var lookupObject  = {};

         for(var i in originalArray) {
            lookupObject[originalArray[i][prop]] = originalArray[i];
         }

         for(i in lookupObject) {
             newArray.push(lookupObject[i]);
         }
          return newArray;
      },
      getPlaces: function(data){
        var places = []
        data.hits.hits.forEach( function (entry){
          entry._source.entities.forEach(function(entity){
            if ('latitude' in entity) {
              places.push({'lat': entity.latitude, 'lng': entity.longitude, 'name': entry._source['schema:headline']})
            }
          })
        })
        return places
      },
317
      _search: function(){
318
319
        //console.log("search fired")
        //console.log(this.query.length)
320
        if (this.query.length == 0){
321
          //console.log("default search fired")
322
323
324
325
          this._query()
        }
        else this._ESsearch()
      },
326
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
327
        this._query();
328
329
       },
      _ESsearch: function() {
330
        //console.log("_filtersChangedash")
331
        var that = this;
332
        //console.log("Ready?: ", ready);
333
334
335
336
337
        if(ready){
          this.client.search({
          // undocumented params are appended to the query string
          index: "gsicrawler",
          body: {
338
            size: 200,
339
340
341
            query: {
              multi_match:{
                query: this.query,
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
342
                fields: ['schema:author', 'schema:headline', 'sentiments', 'schema:about', 'entities.nif:anchorOf']
343
344
              }
            },
345
            sort:{'schema:datePublished':{order: "desc"}},
346
347
348
349
350
351
352
353
354
            aggs: {
             type: {
               terms: {
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
Alberto Pascual committed
355
             'schema:author': {
356
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
357
                 field: "schema:author.keyword",
358
359
360
361
362
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
363
364
365
366
367
368
369
370
371
             'entities.rdfs:subClassOf': {
               terms: {
                 field: "entities.rdfs:subClassOf.keyword",
                 order: {
                   _count: "desc"
                 } 
               }
             },
             'topics.rdfs:subClassOf': {
372
               terms: {
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
373
374
                 field: "topics.rdfs:subClassOf.keyword",
                 size: 20,
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
                 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"
                     }      
                   }
395
      },
Alberto Pascual's avatar
Alberto Pascual committed
396
      'schema:datePublished': {
397
              date_histogram : {
Alberto Pascual's avatar
Alberto Pascual committed
398
                field : "schema:datePublished",
399
400
401
                format: "MM-yyyy",
                interval : "month"
            }
402
       }
403
        }
404
405
406
407
408
409
410
      } 
          }).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;
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
411
            console.log(that.data);
412
413
414
            
            });
        }
Alberto Pascual's avatar
Alberto Pascual committed
415
      },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
416
       _query: function() {
417
        //console.log("_query")
418
        var that = this;
419
        //console.log("Ready?: ", ready);
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
420
421
        if(ready){
          this.client.search({
422
          // undocumented params are appended to the query string
423
          index: "gsicrawler",
424
          body: {
425
            size: 200,
426
427
428
429
430
            query: {
              bool: {
                must: this.filters,
              }
            },
431
            sort:{'schema:datePublished':{order: "desc"}},
432
            aggs: {
433
             type: {
militarpancho's avatar
militarpancho committed
434
               terms: {
435
436
437
438
439
440
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
Alberto Pascual's avatar
Alberto Pascual committed
441
             'schema:author': {
442
               terms: {
Alberto Pascual's avatar
Alberto Pascual committed
443
                 field: "schema:author.keyword",
militarpancho's avatar
militarpancho committed
444
445
                 order: {
                   _count: "desc"
446
                 }
militarpancho's avatar
militarpancho committed
447
               }
militarpancho's avatar
militarpancho committed
448
             },
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
449
450
451
452
453
454
455
456
457
             'entities.rdfs:subClassOf': {
               terms: {
                 field: "entities.rdfs:subClassOf.keyword",
                 order: {
                   _count: "desc"
                 } 
               }
             },
             'topics.rdfs:subClassOf': {
458
               terms: {
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
459
460
                 field: "topics.rdfs:subClassOf.keyword",
                 size: 20,
461
462
463
                 order: {
                   _count: "desc"
                 } 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
464
               }
465
             },
466
467
468
469
470
471
472
473
474
475
476
477
478
           sentiment: {
             terms: {
             field: "sentiments.marl:hasPolarity.keyword",
             order: {
               _count: "desc"
               }
             }
             },
          emotion: {
              terms: {
              field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
             order: {
               _count: "desc"
479
480
                     }      
                   }
481
      },
Alberto Pascual's avatar
Alberto Pascual committed
482
      'schema:datePublished': {
483
              date_histogram : {
Alberto Pascual's avatar
Alberto Pascual committed
484
                field : "schema:datePublished",
485
486
487
488
                format: "MM-yyyy",
                interval : "month"
            }
       }
489
490
       }
      } 
491
          }).then(function (resp) {
492
493
494
495
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
496
            that.data = resp;
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
497
            console.log(that.data);
498
            
499
500
501
502
503
504
505
            });
        }
      }
    });
  </script>

</dom-module>