Rename to Pydashie
This commit is contained in:
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>PyDashie</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
10
.pydevproject
Normal file
10
.pydevproject
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?eclipse-pydev version="1.0"?>
|
||||||
|
|
||||||
|
<pydev_project>
|
||||||
|
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||||
|
<path>/PyDashie</path>
|
||||||
|
</pydev_pathproperty>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
|
</pydev_project>
|
||||||
124
pydashie/main.py
Normal file
124
pydashie/main.py
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
import Queue
|
||||||
|
import datetime
|
||||||
|
import collections
|
||||||
|
import coffeescript
|
||||||
|
|
||||||
|
from repeated_timer import RepeatedTimer
|
||||||
|
|
||||||
|
from flask import Flask, render_template, Response
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
events_queue = Queue.Queue()
|
||||||
|
items = collections.deque()
|
||||||
|
seedX = 0
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def hello():
|
||||||
|
return render_template('main.html', title='pyDashie Dashboard')
|
||||||
|
|
||||||
|
@app.route("/assets/application.js")
|
||||||
|
def javascripts():
|
||||||
|
# scripts = [
|
||||||
|
# 'assets/javascripts/jquery.js',
|
||||||
|
# 'assets/javascripts/es5-shim.js',
|
||||||
|
# 'assets/javascripts/d3.v2.min.js',
|
||||||
|
# 'assets/javascripts/batman.js',
|
||||||
|
# 'assets/javascripts/batman.jquery.js',
|
||||||
|
# 'assets/javascripts/jquery.gridster.js',
|
||||||
|
# 'assets/javascripts/jquery.leanModal.min.js',
|
||||||
|
# 'assets/javascripts/dashing.coffee',
|
||||||
|
# 'assets/javascripts/jquery.knob.js',
|
||||||
|
# 'assets/javascripts/rickshaw.min.js',
|
||||||
|
# 'assets/javascripts/application.coffee',
|
||||||
|
# 'assets/javascripts/dashing.gridster.coffee'
|
||||||
|
# ]
|
||||||
|
scripts = ['assets/javascripts/application.js']
|
||||||
|
|
||||||
|
base_directory = os.getcwd()
|
||||||
|
full_paths = [os.path.join(base_directory, script_name) for script_name in scripts]
|
||||||
|
output = ''
|
||||||
|
for path in full_paths:
|
||||||
|
if '.coffee' in path:
|
||||||
|
print('Compiling Coffee on %s ' % path)
|
||||||
|
output = output + coffeescript.compile(open(path).read())
|
||||||
|
else:
|
||||||
|
output = output + open(path).read()
|
||||||
|
return Response(output, mimetype='application/javascript')
|
||||||
|
|
||||||
|
@app.route('/assets/application.css')
|
||||||
|
def application_css():
|
||||||
|
scripts = [
|
||||||
|
'assets/stylesheets/application.css',
|
||||||
|
]
|
||||||
|
base_directory = os.getcwd()
|
||||||
|
full_paths = [os.path.join(base_directory, script_name) for script_name in scripts]
|
||||||
|
output = ''
|
||||||
|
for path in full_paths:
|
||||||
|
output = output + open(path).read()
|
||||||
|
return Response(output, mimetype='text/css')
|
||||||
|
|
||||||
|
@app.route('/views/<widget_name>.html')
|
||||||
|
def widget_html(widget_name):
|
||||||
|
base_directory = os.getcwd()
|
||||||
|
path = os.path.join(base_directory, 'widgets', widget_name, '%s.html' % widget_name)
|
||||||
|
return open(path).read()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/events')
|
||||||
|
def events():
|
||||||
|
return Response(pop_queue(), mimetype='text/event-stream')
|
||||||
|
|
||||||
|
def pop_queue():
|
||||||
|
while True:
|
||||||
|
yield events_queue.get()
|
||||||
|
|
||||||
|
def sample_synergy():
|
||||||
|
synergy_data = {'value': random.randint(0, 100),
|
||||||
|
'id': 'synergy',
|
||||||
|
'updateAt': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')}
|
||||||
|
formatted_json = 'data: %s\n\n' % (json.dumps(synergy_data))
|
||||||
|
events_queue.put(formatted_json)
|
||||||
|
|
||||||
|
def sample_buzzwords():
|
||||||
|
items = [
|
||||||
|
{'label': 'Test',
|
||||||
|
'value': random.randint(0, 20)},
|
||||||
|
{'label': 'Test2',
|
||||||
|
'value': random.randint(0, 20)},
|
||||||
|
]
|
||||||
|
item_data = {'items': items,
|
||||||
|
'id': 'buzzwords',
|
||||||
|
'updateAt': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')}
|
||||||
|
formatted_json = 'data: %s\n\n' % (json.dumps(item_data))
|
||||||
|
events_queue.put(formatted_json)
|
||||||
|
|
||||||
|
def sample_convergence():
|
||||||
|
print 'Added convergence'
|
||||||
|
global seedX
|
||||||
|
if not seedX:
|
||||||
|
seedX = 0
|
||||||
|
items.append({'x':seedX,
|
||||||
|
'y':random.randint(0,20)})
|
||||||
|
seedX += 1
|
||||||
|
if len(items) > 10:
|
||||||
|
items.popleft()
|
||||||
|
item_data = {'points': list(items),
|
||||||
|
'id': 'convergence',
|
||||||
|
'updateAt': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')}
|
||||||
|
formatted_json = 'data: %s\n\n' % (json.dumps(item_data))
|
||||||
|
events_queue.put(formatted_json)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
rt = RepeatedTimer(1, sample_synergy)
|
||||||
|
rt2 = RepeatedTimer(1, sample_buzzwords)
|
||||||
|
rt3 = RepeatedTimer(1, sample_convergence)
|
||||||
|
try:
|
||||||
|
print 'Before app run'
|
||||||
|
app.run(debug=True, port=5000, threaded=True)
|
||||||
|
finally:
|
||||||
|
rt.stop()
|
||||||
|
rt2.stop()
|
||||||
|
rt3.stop()
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
import Queue
|
||||||
import datetime
|
import datetime
|
||||||
import coffeescript
|
import coffeescript
|
||||||
|
|
||||||
|
#from repeated_timer import RepeatedTimer
|
||||||
|
|
||||||
from flask import Flask, render_template, Response
|
from flask import Flask, render_template, Response
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
#events_queue = Queue.Queue()
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello():
|
def hello():
|
||||||
return render_template('main.html')
|
return render_template('main.html')
|
||||||
@@ -58,6 +64,10 @@ def widget_html(widget_name):
|
|||||||
path = os.path.join(base_directory, 'widgets', widget_name, '%s.html' % widget_name)
|
path = os.path.join(base_directory, 'widgets', widget_name, '%s.html' % widget_name)
|
||||||
return open(path).read()
|
return open(path).read()
|
||||||
|
|
||||||
|
#@app.route('/events')
|
||||||
|
#def events():
|
||||||
|
# print 'In Events'
|
||||||
|
# return Response(pop_queue(), mimetype='text/event-stream')
|
||||||
@app.route('/events')
|
@app.route('/events')
|
||||||
def events():
|
def events():
|
||||||
def generate():
|
def generate():
|
||||||
@@ -67,5 +77,25 @@ def events():
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
return Response(generate(), mimetype='text/event-stream')
|
return Response(generate(), mimetype='text/event-stream')
|
||||||
|
|
||||||
|
#def pop_queue():
|
||||||
|
# print 'In Pop Queue'
|
||||||
|
# while True:
|
||||||
|
# yield sample_widgets()#events_queue.get()
|
||||||
|
# time.sleep(2)
|
||||||
|
# print 'Read from Queue'
|
||||||
|
#
|
||||||
|
#def sample_widgets():
|
||||||
|
# synergy_data = {'value': random.randint(0, 100),
|
||||||
|
# 'id': 'synergy',
|
||||||
|
# 'updateAt': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')}
|
||||||
|
# events_queue.put('data: {%s}\n\n' % (json.dumps(synergy_data)))
|
||||||
|
# print 'Put some data in Queue'
|
||||||
|
#
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
#rt = RepeatedTimer(1, sample_widgets)
|
||||||
app.run(debug=True, port=5000, threaded=True)
|
app.run(debug=True, port=5000, threaded=True)
|
||||||
|
# try:
|
||||||
|
# print 'Before app run'
|
||||||
|
#
|
||||||
|
# finally:
|
||||||
|
# pass#rt.stop()
|
||||||
26
pydashie/repeated_timer.py
Normal file
26
pydashie/repeated_timer.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from threading import Timer
|
||||||
|
|
||||||
|
class RepeatedTimer(object):
|
||||||
|
def __init__(self, interval, function, *args, **kwargs):
|
||||||
|
self._timer = None
|
||||||
|
self.interval = interval
|
||||||
|
self.function = function
|
||||||
|
self.args = args
|
||||||
|
self.kwargs = kwargs
|
||||||
|
self.is_running = False
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
|
self.is_running = False
|
||||||
|
self.start()
|
||||||
|
self.function(*self.args, **self.kwargs)
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if not self.is_running:
|
||||||
|
self._timer = Timer(self.interval, self._run)
|
||||||
|
self._timer.start()
|
||||||
|
self.is_running = True
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._timer.cancel()
|
||||||
|
self.is_running = False
|
||||||
BIN
pydashie/repeated_timer.pyc
Normal file
BIN
pydashie/repeated_timer.pyc
Normal file
Binary file not shown.
@@ -9,7 +9,7 @@
|
|||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
|
|
||||||
<!-- The javascript and css are managed by sprockets. The files can be found in the /assets folder-->
|
<!-- The javascript and css are managed by sprockets. The files can be found in the /assets folder-->
|
||||||
<script type="text/javascript" src="/assets/application.js"></script>
|
<script type="text/javascript" ssrc="/assets/application.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/application.css">
|
<link rel="stylesheet" href="/assets/application.css">
|
||||||
|
|
||||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
|
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<div class="gridster">
|
<div class="gridster">
|
||||||
<ul>
|
<ul>
|
||||||
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
|
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
|
||||||
<div data-id="welcome" data-view="Text" data-title="Hello" data-text="This is your shiny new dashboard." data-moreinfo="Protip: You can drag the widgets around!"></div>
|
<div data-id="welcome" data-view="Text" data-title="Hello" data-text="This is your shiny new (python powered) dashboard." data-moreinfo="Protip: You can drag the widgets around!"></div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
|
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
|
||||||
4
setup.py
4
setup.py
@@ -1,9 +1,9 @@
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='PyDashy',
|
name='PyDashie',
|
||||||
version='0.1dev',
|
version='0.1dev',
|
||||||
packages=['pydashy',],
|
packages=['pydashie',],
|
||||||
license='MIT',
|
license='MIT',
|
||||||
long_description=open('README.txt').read(),
|
long_description=open('README.txt').read(),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user