Binary file not shown.
										
									
								
							
							
								
								
									
										25
									
								
								dashboard.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								dashboard.py
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ from eca import * | ||||
| from eca.generators import start_offline_tweets | ||||
|  | ||||
| import random | ||||
| import re | ||||
|  | ||||
| ## You might have to update the root path to point to the correct path | ||||
| ## (by default, it points to <rules>_static) | ||||
| @@ -12,7 +13,7 @@ root_content_path = 'dashboard_static' | ||||
| # the action will be called with the context and the event | ||||
| @event('init') | ||||
| def setup(ctx, e): | ||||
|     start_offline_tweets('sports1.txt', event_name="tweet", time_factor=0.1) | ||||
|     start_offline_tweets('sports1.txt', event_name="tweet", time_factor=1) | ||||
|     ctx.count = 0 | ||||
|     # fire('sample', {'previous': 0.0}) | ||||
|  | ||||
| @@ -21,6 +22,22 @@ def setup(ctx, e): | ||||
| def clip(lower, value, upper): | ||||
|     return max(lower, min(value, upper)) | ||||
|  | ||||
|  | ||||
| # simple word splitter | ||||
| pattern = re.compile('\W+') | ||||
|  | ||||
| # sample stopword list, needs to be much more sophisticated | ||||
| stopwords = ["volleyball", "football", "basketball", "baseball", "tennis", "cricket", "soccer", "rugby"] | ||||
|  | ||||
|  | ||||
| def words(message): | ||||
|     result = pattern.split(message) | ||||
|     result = map(lambda w: w.lower(), result) | ||||
|     result = filter(lambda w: w in stopwords, result) | ||||
|     result = filter(lambda w: len(w) > 2, result) | ||||
|     return result | ||||
|  | ||||
|  | ||||
| @event('tweet') | ||||
| def generate_tweet(ctx, e): | ||||
|     tweet = e.data | ||||
| @@ -28,7 +45,11 @@ def generate_tweet(ctx, e): | ||||
|     # sample = clip(-100, e.data['previous'] + random.uniform(+5.0, -5.0), 100) | ||||
|     # emit to outside world | ||||
|     emit('tweet', tweet) | ||||
|  | ||||
|     for w in words(tweet['text']): | ||||
|         emit('balk', { | ||||
|             'action': 'add', | ||||
|             'value': (str(w), 1) | ||||
|         }) | ||||
|     # # chain event | ||||
|     # fire('tweet', {'previous': tweet}, delay=0.05) | ||||
|  | ||||
|   | ||||
| @@ -111,6 +111,7 @@ | ||||
|                     </div> | ||||
|                     <div class="popchart column"> | ||||
|                         <span class="colheader chartheader">Sports Popularity Filter</span> | ||||
|                         <div id="balk" style="height:300px; background-color: white;"></div> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </div> | ||||
| @@ -118,6 +119,7 @@ | ||||
|     </div> | ||||
|     <script src="/lib/jquery-2.1.1.min.js"></script> | ||||
|     <script src="/lib/jquery.flot.min.js"></script> | ||||
|     <script src="/lib/jquery.flot.categories.min.js"></script> | ||||
|     <script src="/lib/core.js"></script> | ||||
|     <script src="/lib/charts.js"></script> | ||||
|     <script src="/lib/log.js"></script> | ||||
| @@ -128,6 +130,8 @@ | ||||
|         block("#tweet").tweets({ | ||||
|             memory: 20 | ||||
|         }); | ||||
|         block('#balk').barchart(); | ||||
|         events.connect('balk', '#balk'); | ||||
|         events.connect("tweet", "#tweet"); | ||||
|  | ||||
|         // // create a rolling chart block | ||||
|   | ||||
| @@ -16,7 +16,7 @@ def add_request_handlers(httpd): | ||||
| @event('init') | ||||
| def setup(ctx, e): | ||||
|     # start the offline tweet stream | ||||
|     start_offline_tweets('data/bata_2014.txt', 'chirp', time_factor=100000) | ||||
|     start_offline_tweets('sports1.txt', 'chirp', time_factor=100000) | ||||
|     ctx.words = {} | ||||
|  | ||||
| # simple word splitter | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user
	 GitHub
						GitHub