dashboard-reddit.env.html 11.3 KB
Newer Older
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">
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">
8
9
10
11
12
13
<link rel="import" href="/bower_components/comment-chart/comment-chart.html">
<link rel="import" href="/bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="/bower_components/yasgui-polymer/yasgui.html">
<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
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
<link rel="import" href="/elements/news-chart/news-chart.html">


<dom-module id="dashboard-reddit">


  <link rel="import" type="css" href="dashboard-tourpedia.css" type="css">
  <link rel="import" href="/styles/app-theme.html" type="css">

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

        <div style="width: 100%; display: inline-block">
          <div class="chart_container" style="right: 0; float: right">
73
            <entities-chart
Alberto Pascual's avatar
Alberto Pascual committed
74
                field="entities.dbps:anyURI"
75
76
77
78
79
80
81
82
                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
Alberto Pascual's avatar
Alberto Pascual committed
85
              field="schema:author"
86
87
88
89
90
91
92
93
94
95
96
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
              filters="{{filters}}"
              icon='icons:reorder'
              options='{"title": "Newspapers"}'
              cols='[{"label": "type", "type": "string"},{"label": "Count", "type": "number"}]'
            </google-chart>
          </div>
        </div>
97
     <div style="width: 100%"> 
98
99
100
101
102
103
104
105
106
107
108
109
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
              field="sentiment"
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
              filters="{{filters}}"
              icon='social:mood'
              options='{"title": "Sentiments"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
            </google-chart>
110
       </div> 
111
112
113
114
115
116
117
118
119
120
121
122
          <div class="chart_container" style="left: 0; float: right">
            <google-chart
              field="emotion"
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
              filters="{{filters}}"
              icon='social:sentiment-very-dissatisfied'
              options='{"title": "Emotions"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
            </google-chart>
123
          </div>
124
      </div>
Alberto Pascual's avatar
Alberto Pascual committed
125
      
126
      <div class="chart_container" style="left: 0; float: left; width: 100%">
Alberto Pascual's avatar
Alberto Pascual committed
127
        <google-chart
Alberto Pascual's avatar
Alberto Pascual committed
128
          field="schema:datePublished"
Alberto Pascual's avatar
Alberto Pascual committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
          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>
      </div>
      <div class="chart_container" style="left: 0; float: left; width: 100%">
        <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
Alberto Pascual's avatar
Alberto Pascual committed
152
       endpoint="http:///krusti.gsi/gsicrawler/query"
153
       queries="{{queries}}">
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        </yasgui-ui>
    </div>
    </iron-pages>
  </template>
   

  <script>
  var ready = false;
    Polymer({
      is: 'dashboard-reddit',
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 
169
170
171
        query: {
          type: String,
        },
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
        ids:{
          type: Array
           
        },
        data:{
          type: Object
        },
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
        },
        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
210
      },

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

</dom-module>