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

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

133
      </div>
134
135
136
    </div>
    <div>
        <yasgui-ui
137
138
       endpoint="http:///gsicrawler/query"
       queries="{{queries}}">
139
140
        </yasgui-ui>
    </div>
141
142
    </iron-pages>
  </template>
143
   
144
145

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
146
  var ready = false;
147
    Polymer({
militarpancho's avatar
militarpancho committed
148
      is: 'dashboard-reddit',
149
150
151
152
153
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 
154
155
156
        query: {
          type: String,
        },
157
        ids:{
158
159
          type: Array
           
160
161
162
163
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
164
165
166
167
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
        },
        fields: {
          type: Array,
          value: function() { return []; }
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],
184
185
186
187
188
189
      behaviors: [
        Polymer.IronA11yKeysBehavior
      ],
      keyBindings: {
        'enter': '_search'
      },
190
191

      ready: function(){
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
192
        console.log("ready");
193
194
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
195
196
197
198
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
199
      },
200
201
202
203
204
205
206
207
208
      _search: function(){
        console.log("search fired")
        console.log(this.query.length)
        if (this.query.length == 0){
          console.log("default search fired")
          this._query()
        }
        else this._ESsearch()
      },
209
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
210
        this._query();
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
       },
      _ESsearch: function() {
        console.log("_filtersChangedash")
        var that = this;
        console.log("Ready?: ", ready);
        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"
                     }      
                   }
      }
       }
      } 
          }).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;
            console.log(that.data);
            
            });
        }
Alberto Pascual's avatar
Alberto Pascual committed
281
      },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
282
       _query: function() {
283
        console.log("_query")
284
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
285
286
287
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
288
          // undocumented params are appended to the query string
289
          index: "gsicrawler",
290
          body: {
291
            size: 20,
292
293
294
295
296
297
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
298
             type: {
militarpancho's avatar
militarpancho committed
299
               terms: {
300
301
302
303
304
305
306
307
308
                 field: "@type.keyword",
                 order: {
                   _count: "desc"
                 }
               }
             },
             author: {
               terms: {
                 field: "author.keyword",
militarpancho's avatar
militarpancho committed
309
310
                 order: {
                   _count: "desc"
311
                 }
militarpancho's avatar
militarpancho committed
312
               }
militarpancho's avatar
militarpancho committed
313
             },
314
315
316
317
318
319
             about: {
               terms: {
                 field: "about.keyword",
                 order: {
                   _count: "desc"
                 } 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
320
               }
321
             },
322
323
324
325
326
327
328
329
330
331
332
333
334
           sentiment: {
             terms: {
             field: "sentiments.marl:hasPolarity.keyword",
             order: {
               _count: "desc"
               }
             }
             },
          emotion: {
              terms: {
              field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
             order: {
               _count: "desc"
335
336
                     }      
                   }
337
338
339
      }
       }
      } 
340
          }).then(function (resp) {
341
342
343
344
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
345
            that.data = resp;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
346
            console.log(that.data);
347
            
348
349
350
351
352
353
354
            });
        }
      }
    });
  </script>

</dom-module>