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">
18
<link rel="import" href="/elements/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
207
        </yasgui-ui>
    </div>
208
    </iron-pages>
209
210
         <div style="background-color:#ccc; padding: 1%;">
        <div style="width:32%; margin: 0 auto">
Alberto Pascual's avatar
new viz    
Alberto Pascual committed
211
       <img height="60px" src="/images/gsi.png">   © 2017 Grupo de Sistemas Inteligentes GSI-UPM 
212
213
        </div>
       </div>
214
  </template>
215
   
216
217

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

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

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

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

</dom-module>