From c99c32927e8ab3e5a4301a5fdf65ec17a12bba14 Mon Sep 17 00:00:00 2001 From: fliu2 Date: Wed, 9 Aug 2017 11:23:17 +0100 Subject: [PATCH] WebConsole and GraphQL interface experiment. --- DataVisulization/DashTest.py | 87 +++++++++++++++++++++++++++++ graphQLengine/graphQLtest.py | 29 ++++++++++ rqTest/client.py | 25 +++++++++ rqTest/rqtest.py | 7 +++ tensorlab/gc_impl/gcp_fs_imp.py | 2 +- tensorlab/gc_impl/google_index.py | 2 +- tensorlab/mongo_impl/mongo_db_fs.py | 2 +- 7 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 graphQLengine/graphQLtest.py create mode 100644 rqTest/client.py create mode 100644 rqTest/rqtest.py diff --git a/DataVisulization/DashTest.py b/DataVisulization/DashTest.py index e69de29..88cdb1e 100644 --- a/DataVisulization/DashTest.py +++ b/DataVisulization/DashTest.py @@ -0,0 +1,87 @@ +import dash +from dash.dependencies import Input,Output +import dash_core_components as dcc +import dash_html_components as html +import plotly.graph_objs as go +import pandas as pd + + +import pymongo + + +app=dash.Dash() + + +df = pd.read_csv( + 'https://gist.githubusercontent.com/chriddyp/' + + '5d1ea79569ed194d432e56108a04d188/raw/' + + 'a9f9e8076b837d541398e999dcbac2b2826a81f8/'+ + 'gdp-life-exp-2007.csv') + + + +app.layout=html.Div(children=[ + html.H1(children="hello dash"), + + html.Div(children=''' + Dash: a Weba pplication framework for python + '''), + + dcc.Input(id='my-id', value='initial value', type="text"), + html.P(), + + html.Div(id='my-div'), + + +##for date visuzlaiton, server side rendering# + html.Img(id='my-img',src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"), + + + + dcc.Dropdown( + options=[ + {'label': 'New York City', 'value': 'NYC'}, + {'label': u'Montreal', 'value': 'MTL'}, + {'label': 'San Francisco', 'value': 'SF'} + ], + value='MTL' + ), + + dcc.Graph(id='example-graph', + figure={ + 'data':[ + go.Scatter( + x=df[df['continent'] == i]['gdp per capita'], + y=df[df['continent'] == i]['life expectancy'], + text=df[df['continent'] == i]['country'], + mode='markers', + opacity=0.7, + marker={ + 'size': 15, + 'line': {'width': 0.5, 'color': 'white'} + }, + name=i + ) for i in df.continent.unique() + ], + 'layout':{ + 'title':'Dash visulization' + } + + + } + + ) + +]) + + +@app.callback( + Output(component_id='my-div', component_property='children'), + [Input(component_id='my-id', component_property='value')] +) +def update_output_div(input_value): + print "server call back" + return "{}".format(input_value) + +if __name__ =='__main__': + app.run_server(debug=True) diff --git a/graphQLengine/graphQLtest.py b/graphQLengine/graphQLtest.py new file mode 100644 index 0000000..bedfe06 --- /dev/null +++ b/graphQLengine/graphQLtest.py @@ -0,0 +1,29 @@ +import graphene + +class Query(graphene.ObjectType): + hello=graphene.String(name=graphene.Argument(graphene.String, default_value="stranger")) + greeting = graphene.String(name=graphene.Argument(graphene.String, default_value="stranger")) + + def resolve_hello(self,args,context,info): + print "resolve hello" + print context + print info + return 'hello'+args['name'] + + def resolve_greeting(self,args,context,info): + print "reslove greeting" + return 'greeting'+args['name'] + + + +scheme=graphene.Schema(query=Query) + +results=scheme.execute('{hello,greeting}') + +print results.data['hello'] +print results.data + + + + + diff --git a/rqTest/client.py b/rqTest/client.py new file mode 100644 index 0000000..37c7c80 --- /dev/null +++ b/rqTest/client.py @@ -0,0 +1,25 @@ +from redis import Redis +from rq import Queue +from rqtest import count_words_at_url +import time + +c=Redis() + +import requests +from rq.decorators import job + + + + + + +q=Queue(connection=c) + +print q + +j=q.enqueue(count_words_at_url,'http://nvie.com') + +time.sleep(3) +j.result + +print j.result \ No newline at end of file diff --git a/rqTest/rqtest.py b/rqTest/rqtest.py new file mode 100644 index 0000000..cc7a26b --- /dev/null +++ b/rqTest/rqtest.py @@ -0,0 +1,7 @@ +import requests + + + +def count_words_at_url(url): + resp=requests.get(url) + return len(resp.text.split()) diff --git a/tensorlab/gc_impl/gcp_fs_imp.py b/tensorlab/gc_impl/gcp_fs_imp.py index fda8123..2f5d675 100644 --- a/tensorlab/gc_impl/gcp_fs_imp.py +++ b/tensorlab/gc_impl/gcp_fs_imp.py @@ -1,5 +1,5 @@ import gc_file_io -from tensor_lab.tensor_db import fsImpl +from tensorlab.tensor_db import fsImpl class gcpfldImpl(fsImpl): diff --git a/tensorlab/gc_impl/google_index.py b/tensorlab/gc_impl/google_index.py index a8a460c..02559c9 100644 --- a/tensorlab/gc_impl/google_index.py +++ b/tensorlab/gc_impl/google_index.py @@ -1,4 +1,4 @@ -from tensor_lab.tensor_db import indxImpl +from tensorlab.tensor_db import indxImpl from gc_index_db import GoogleDocDB from google.cloud import logging diff --git a/tensorlab/mongo_impl/mongo_db_fs.py b/tensorlab/mongo_impl/mongo_db_fs.py index c16c8c5..78e0591 100644 --- a/tensorlab/mongo_impl/mongo_db_fs.py +++ b/tensorlab/mongo_impl/mongo_db_fs.py @@ -1,6 +1,6 @@ import gridfs from pymongo import MongoClient -from tensor_lab.tensor_db import indxImpl,fsImpl +from tensorlab.tensor_db import indxImpl,fsImpl from gridfs import GridFS