dashboard-reddit.html 7.79 KB
Newer Older
militarpancho's avatar
militarpancho committed
1
2
3
4
5
6
7
<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">
<link rel="import" href="/bower_components/google-chart-elasticsearch/google-chart.html">
<link rel="import" href="/bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="/bower_components/paper-tabs/paper-tab.html">
<link rel="import" href="/bower_components/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/news-chart/news-chart.html">
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
15

16

militarpancho's avatar
militarpancho committed
17
<dom-module id="dashboard-reddit">
18

militarpancho's avatar
militarpancho committed
19
20
21

  <link rel="import" type="css" href="dashboard-tourpedia.css" type="css">
  <link rel="import" href="/styles/app-theme.html" type="css">
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

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

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

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

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
148
  var ready = false;
149
    Polymer({
militarpancho's avatar
militarpancho committed
150
      is: 'dashboard-reddit',
151
152
153
154
155
156
157
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 

        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
184
185
        },
        fields: {
          type: Array,
          value: function() { return []; }
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],

      ready: function(){
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
186
        console.log("ready");
187
188
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
189
190
191
192
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
193
194
      },
      _filtersChange: function() {
Alberto Pascual's avatar
Alberto Pascual committed
195
        var myfilters = []
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
196
        this._query();
Alberto Pascual's avatar
Alberto Pascual committed
197
      },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
198
       _query: function() {
199
        console.log("_filtersChangedash")
200
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
201
202
203
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
204
          // undocumented params are appended to the query string
205
          index: "gsicrawler",
206
          body: {
Alberto Pascual's avatar
Alberto Pascual committed
207
            size: 100,
208
209
210
211
212
213
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
214
             creator: {
militarpancho's avatar
militarpancho committed
215
               terms: {
216
                 field: "creator.keyword",
militarpancho's avatar
militarpancho committed
217
218
                 order: {
                   _count: "desc"
219
                 }
militarpancho's avatar
militarpancho committed
220
               }
militarpancho's avatar
militarpancho committed
221
             },
222
223
224
225
226
227
             about: {
               terms: {
                 field: "about.keyword",
                 order: {
                   _count: "desc"
                 } 
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
228
               }
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
             },
    			 sentiment: {
    			   terms: {
    				 field: "sentiments.marl:hasPolarity.keyword",
    				 order: {
    				   _count: "desc"
    			     }
    			   }
    		     },
     			emotion: {
     		      terms: {
     			    field: "emotions.onyx:hasEmotion.onyx:hasEmotionCategory.keyword",
     				 order: {
     				   _count: "desc"
                     }      
                   }
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
245
246
 			}
 		   }
247
		  }	
248
          }).then(function (resp) {
249
250
251
252
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
253
            that.data = resp;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
254
            console.log(that.data);
255
            
256
257
258
259
260
261
262
            });
        }
      }
    });
  </script>

</dom-module>