dashboard-reddit.html 7.87 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
5
6
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../material-search/material-search.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../google-chart-elasticsearch/google-chart.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../number-chart/number-chart.html">
7
8
<link rel="import" href="../comment-chart/comment-chart.html">

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
9

10

militarpancho's avatar
militarpancho committed
11
<dom-module id="dashboard-reddit">
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

  <style is="custom-style">
    @import url("../../styles/app-theme.html");
  </style>
  <link rel="import" type="css" href="dashboard-tourpedia.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">
militarpancho's avatar
militarpancho committed
34
          <div style="width: 23%; margin-right: 2%; float: left">
35
36
37
38
39
40
            <number-chart 
              icon="info"
              stylebg="bg-red"
              data="{{data}}">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
41
          <div style="width: 23%; margin-right: 2%; float: left">
42
43
            <number-chart 
              data="{{data}}"
militarpancho's avatar
militarpancho committed
44
45
46
47
              object="article"
              aggKey="type"
              title="Articles"
              icon="icons:receipt"
48
49
50
              stylebg="bg-yellow">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
51
52
53
54
55
56
57
58
59
60
61
62
63
           <div style="width: 23%; margin-right: 2%; float: left"> 
             <number-chart  
               data="{{data}}" 
               object="comment"
			   aggKey="type"
               title="Comments" 
               icon="maps:rate-review"
               aggkey="location"
               stylebg="bg-green"> 
             </number-chart>
           </div>
         </div>

64
65
66
        <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
67
              data="{{data}}"
militarpancho's avatar
militarpancho committed
68
              field="subreddit"
69
70
71
72
              id='pie-chart4'
              extra-id='pie-chart4'
              type='pie'
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
73
              icon='icons:list'
74
              param='{{param}}'
militarpancho's avatar
militarpancho committed
75
              options='{"title": "Comments Subreddits"}'
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
76
              cols='[{"label": "subreddit", "type": "string"},{"label": "Count", "type": "number"}]'
77
            </google-chart>
militarpancho's avatar
militarpancho committed
78
		  </div>
79
80
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
81
              field="subreddit"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
82
83
84
85
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
86
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
87
              icon='icons:reorder'
militarpancho's avatar
militarpancho committed
88
              options='{"title": "Articles Subreddits"}'
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
89
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
90
91
92
            </google-chart>
          </div>
        </div>
militarpancho's avatar
militarpancho committed
93
		 <div style="width: 100%"> 
militarpancho's avatar
militarpancho committed
94
          <div class="chart_container" style="left: 0; float: left">
militarpancho's avatar
militarpancho committed
95
96
97
98
99
100
            <google-chart
              field="sentiment"
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
militarpancho's avatar
militarpancho committed
101
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
102
103
104
              icon='social:mood'
              options='{"title": "Sentiments"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
105
            </google-chart>
militarpancho's avatar
militarpancho committed
106
107
108
		   </div> 
          <div class="chart_container" style="left: 0; float: right">
            <google-chart
109
              field="emotion"
militarpancho's avatar
militarpancho committed
110
111
112
113
              data="{{data}}"             
              id='pie-chart5'
              extra-id='pie-chart5'
              type='pie'
militarpancho's avatar
militarpancho committed
114
              filters="{{filters}}"
militarpancho's avatar
militarpancho committed
115
116
117
              icon='social:sentiment-very-dissatisfied'
              options='{"title": "Emotions"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
militarpancho's avatar
militarpancho committed
118
            </google-chart>
militarpancho's avatar
militarpancho committed
119
		   </div>
120
  
militarpancho's avatar
militarpancho committed
121
		   <div style="clear: both"></div>
militarpancho's avatar
militarpancho committed
122
123
        </div>
        <div style="width: 100%">
124
125
126
127
          <div class="chart_container" style="left: 0; float: left; width: 100%">
            <comment-chart 
				datos = {{data}}
			    filters="{{filters}}"
militarpancho's avatar
militarpancho committed
128
                icon='social:people'>
129
            </comment-chart>
militarpancho's avatar
militarpancho committed
130
          </div>
militarpancho's avatar
militarpancho committed
131
132
          <!--<div class="chart_container" style="left: 0; float: right">
           <google-chart
133
134
			  data = {{data}}
			  field="subreddit"
militarpancho's avatar
militarpancho committed
135
136
137
138
139
140
141
142
              id='column-chart1'
              extra-id='column-chart1'
              type='column'
              filters="{{filters}}"
              icon='maps:local-play'
              param='{{param}}'
              optionsbi='{"legend": "none"}'
              options='{"title": "Subreddits sentiment count"}'
143
			  cols='[{"label": "Subreddits", "type": "string"},{"label": "Count", "type": "number"}]'>
militarpancho's avatar
militarpancho committed
144
            </google-chart>
145
		  </div>-->
militarpancho's avatar
militarpancho committed
146
		</div>
147
148
149
150
151
      </div>
    </iron-pages>
  </template>

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

        ids:{
162
163
          type: Array
           
164
165
166
167
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
168
169
170
171
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        },
        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
190
        console.log("ready");
191
192
193
194
      },
      
      addPlace: function(event) {
        this.set('places', this.places.concat(event.detail.response))
195
        console.log(this.places)
196
197
198
199
200
201
202
203
204
205
      },
      
      getName: function(id) {
        return "http://tour-pedia.org/api/getPlaceDetails?id=" + id
      },
      
      getPoints: function(f) {
        return f.base;
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
206
207
208
209
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
210
211
      },
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
212
213
214
        this._query();
       },
       _query: function() {
215
        console.log("_filtersChangedash")
216
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
217
218
219
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
220
          // undocumented params are appended to the query string
221
          index: "reddit",
222
223
224
225
226
227
228
229
          body: {
            size: 10,
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
militarpancho's avatar
militarpancho committed
230
231
232
233
234
235
236
237
238
239
             type: {
               terms: {
                 field: "_type",
                 order: {
                   _count: "desc"
                 }
               }
             },
             subreddit: {
               terms: {
militarpancho's avatar
militarpancho committed
240
                 field: "subreddit.keyword",
militarpancho's avatar
militarpancho committed
241
242
243
244
                 order: {
                   _count: "desc"
                 } 
               }
militarpancho's avatar
militarpancho committed
245
246
247
             },
			 sentiment: {
			   terms: {
militarpancho's avatar
militarpancho committed
248
				 field: "sentiment.keyword",
militarpancho's avatar
militarpancho committed
249
250
251
252
				 order: {
				   _count: "desc"
			     }
			   }
253
		     },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
254
255
 			emotion: {
 		      terms: {
militarpancho's avatar
militarpancho committed
256
 			    field: "emotion.keyword",
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
257
258
259
260
261
262
 				 order: {
 				   _count: "desc"
                 }      
               }
 			}
 		   }
263
		  }	
264
          }).then(function (resp) {
265
266
267
268
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
269
            that.data = resp;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
270
            console.log(that.data);
271
            
272
273
274
275
276
277
278
            });
        }
      }
    });
  </script>

</dom-module>