Working live tweets
This commit is contained in:
		
							
								
								
									
										12
									
								
								dashboard.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								dashboard.py
									
									
									
									
									
								
							| @@ -12,7 +12,7 @@ root_content_path = 'dashboard_static' | |||||||
| # the action will be called with the context and the event | # the action will be called with the context and the event | ||||||
| @event('init') | @event('init') | ||||||
| def setup(ctx, e): | def setup(ctx, e): | ||||||
|     start_offline_tweets('sports1.txt', event_name="tweet") |     start_offline_tweets('sports1.txt', event_name="tweet", time_factor=0.01) | ||||||
|     ctx.count = 0 |     ctx.count = 0 | ||||||
|     # fire('sample', {'previous': 0.0}) |     # fire('sample', {'previous': 0.0}) | ||||||
|  |  | ||||||
| @@ -23,19 +23,11 @@ def clip(lower, value, upper): | |||||||
|  |  | ||||||
| @event('tweet') | @event('tweet') | ||||||
| def generate_tweet(ctx, e): | def generate_tweet(ctx, e): | ||||||
|     ctx.count += 1 |  | ||||||
|     if ctx.count % 50 == 0: |  | ||||||
|         emit('debug', {'text': 'Log message #'+str(ctx.count)+'!'}) |  | ||||||
|         print('Log message #'+str(ctx.count)+'!') |  | ||||||
|     tweet = e.data |     tweet = e.data | ||||||
|     print(tweet) |  | ||||||
|     # base sample on previous one |     # base sample on previous one | ||||||
|     # sample = clip(-100, e.data['previous'] + random.uniform(+5.0, -5.0), 100) |     # sample = clip(-100, e.data['previous'] + random.uniform(+5.0, -5.0), 100) | ||||||
|     # emit to outside world |     # emit to outside world | ||||||
|     emit('tweet', { |     emit('tweet', tweet) | ||||||
|         'action': 'add', |  | ||||||
|         'value': tweet |  | ||||||
|     }) |  | ||||||
|  |  | ||||||
|     # # chain event |     # # chain event | ||||||
|     # fire('tweet', {'previous': tweet}, delay=0.05) |     # fire('tweet', {'previous': tweet}, delay=0.05) | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ | |||||||
|      |      | ||||||
| </head> | </head> | ||||||
| <body> | <body> | ||||||
|  |     <div id="tweet" style="height: 200px;"></div> | ||||||
|     <div class="container"> |     <div class="container"> | ||||||
|         <div class="header"> |         <div class="header"> | ||||||
|             <div class="logo"> |             <div class="logo"> | ||||||
| @@ -88,9 +89,6 @@ | |||||||
|             --> |             --> | ||||||
|             <div class = "maintable"> |             <div class = "maintable"> | ||||||
|                 <div class = "leftcol"> |                 <div class = "leftcol"> | ||||||
|                     <div id="tweet"> |  | ||||||
|  |  | ||||||
|                     </div> |  | ||||||
|                 </div> |                 </div> | ||||||
|                 <div class="centercol"></div> |                 <div class="centercol"></div> | ||||||
|                 <div class = "searchbar"></div> |                 <div class = "searchbar"></div> | ||||||
| @@ -106,23 +104,28 @@ | |||||||
|     <script src="./lib/tweets.js"></script> |     <script src="./lib/tweets.js"></script> | ||||||
|     <script src="./js/code.js"></script> |     <script src="./js/code.js"></script> | ||||||
|     <script src="./js/connection.js"></script> |     <script src="./js/connection.js"></script> | ||||||
| </body> |     <script> | ||||||
| <!-- <script> |         block("#tweet").tweets({ | ||||||
| // create a rolling chart block |             memory: 20 | ||||||
| block('#graph').rolling_chart({ |  | ||||||
|     memory: 150, |  | ||||||
|     chart: { |  | ||||||
|         yaxis: { |  | ||||||
|             min: -100, |  | ||||||
|             max: 100 |  | ||||||
|         }, |  | ||||||
|         xaxis: { |  | ||||||
|             show: false |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|         }); |         }); | ||||||
|  |         events.connect("tweet", "#tweet"); | ||||||
|          |          | ||||||
| // connect sample event to graph |         // // create a rolling chart block | ||||||
| events.connect('sample', '#graph'); |         // block('#graph').rolling_chart({ | ||||||
| </script> --> |         //     memory: 150, | ||||||
|  |         //     chart: { | ||||||
|  |         //         yaxis: { | ||||||
|  |         //             min: -100, | ||||||
|  |         //             max: 100 | ||||||
|  |         //         }, | ||||||
|  |         //         xaxis: { | ||||||
|  |         //             show: false | ||||||
|  |         //         } | ||||||
|  |         //     } | ||||||
|  |         // }); | ||||||
|  |          | ||||||
|  |         // // connect sample event to graph | ||||||
|  |         // events.connect('tweet', '#graph'); | ||||||
|  |         </script> | ||||||
|  | </body> | ||||||
| </html> | </html> | ||||||
| @@ -27,8 +27,4 @@ function tweetCell(tweet, parent) { | |||||||
|     cell.innerHTML = |     cell.innerHTML = | ||||||
|         "<div>" |         "<div>" | ||||||
| } | } | ||||||
| (function($, block) { |  | ||||||
|     block("#tweet").tweets({ |  | ||||||
|         memory: 20 |  | ||||||
|     }); |  | ||||||
| })(jQuery, block); |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user