dashboard-reddit.html 8.5 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
5
6
7
<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="../reviews-table/reviews-table.html">
<link rel="import" href="../number-chart/number-chart.html">
8
9
<link rel="import" href="../comment-chart/comment-chart.html">

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

11

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

  <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>
    <iron-ajax auto
        url="/endpoint.json"
        handle-as="json"
        last-response="{{endpoint}}"></iron-ajax>
28
	<!--    <template is="dom-repeat" items="{{ids}}" as="id"> 
29
30
31
32
      <iron-ajax auto 
        url="{{getName(id)}}"
        handle-as="json"
        on-response="addPlace"></iron-ajax>
33
	</template> -->
34
35
36
37
38
39
40
41
42
43
44

    <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
45
          <div style="width: 23%; margin-right: 2%; float: left">
46
47
48
49
50
51
            <number-chart 
              icon="info"
              stylebg="bg-red"
              data="{{data}}">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
52
          <div style="width: 23%; margin-right: 2%; float: left">
53
54
            <number-chart 
              data="{{data}}"
militarpancho's avatar
militarpancho committed
55
56
57
58
              object="article"
              aggKey="type"
              title="Articles"
              icon="icons:receipt"
59
60
61
              stylebg="bg-yellow">
            </number-chart>
          </div>
militarpancho's avatar
militarpancho committed
62
63
64
65
66
67
68
69
70
71
72
73
74
           <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>

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

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
163
  var ready = false;
164
    Polymer({
militarpancho's avatar
militarpancho committed
165
      is: 'dashboard-reddit',
166
167
168
169
170
171
172
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 

        ids:{
173
174
          type: Array
           
175
176
177
178
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
179
180
181
182
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
        },
        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
201
        console.log("ready");
202
203
204
205
      },
      
      addPlace: function(event) {
        this.set('places', this.places.concat(event.detail.response))
206
        console.log(this.places)
207
208
209
210
211
212
213
214
215
216
      },
      
      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
217
218
219
220
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
221
222
      },
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
223
224
225
        this._query();
       },
       _query: function() {
226
        console.log("_filtersChangedash")
227
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
228
229
230
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
231
          // undocumented params are appended to the query string
232
          index: "reddit",
militarpancho's avatar
militarpancho committed
233
          type: ["article","comment"],
234
235
236
237
238
239
240
241
          body: {
            size: 10,
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
242
              subredditName: {
243
                terms: {
244
                  field: "subredditName",
245
246
247
248
                  order: {
                    _count: "desc"
                  }
                }
militarpancho's avatar
militarpancho committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
              },
             type: {
               terms: {
                 field: "_type",
                 order: {
                   _count: "desc"
                 }
               }
             },
             subreddit: {
               terms: {
                 field: "subreddit",
                 order: {
                   _count: "desc"
                 } 
               }
militarpancho's avatar
militarpancho committed
265
266
267
268
269
270
271
272
             },
			 sentiment: {
			   terms: {
				 field: "sentiment",
				 order: {
				   _count: "desc"
			     }
			   }
273
274
275
276
277
278
279
280
281
282
283
284
		     },
			 // ,
			 //emotion: {
		     //  terms: {
			 //    field: "emotion",
			 //	 order: {
			 //	   _count: "desc"
             //    }      
             //  }
			// }
		   }
		  }	
285
          }).then(function (resp) {
286
287
288
289
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
290
            that.data = resp;
militarpancho's avatar
militarpancho committed
291
            //console.log(that.data);
292
            
293
294
295
296
297
298
299
            });
        }
      }
    });
  </script>

</dom-module>