NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

def on_message(ws, message):
print(message)
msg = json.loads(message)
cmd = msg['cmd']

if cmd == 'MBY':
country = msg['country']
tally = get_medals_last_10_years(country)
tallyarray=[]
for i, row in tally.iterrows():
medaltally = {"Year":int(row["Year"]),
"Gold":int(row["Gold"]),
"Silver":int(row["Silver"]),
"Bronze":int(row["Bronze"])}
tallyarray.append(medaltally)
wsresponse = {}
wsresponse["forcmd"] = "MBY"
wsresponse["response"] = tallyarray
ws.send(json.dumps(wsresponse))
elif cmd == 'MBSC':
country = msg['country']
year = 2008
response = get_medals_category(country, year)

ct = response.count()
if ct > 5:
response = response.nlargest(5)

medals = []
categories = []
for i, row in response.iteritems():
categories.append(i)
medals.append(row)

wsresponse = {}
wsresponse["forcmd"] = "MBSC"
wsresponse["response"] = { "categories":categories, "medals":medals}
ws.send(json.dumps(wsresponse))
elif cmd == 'MBSA':
country = msg['country']
response = get_medals_category_all(country)

ct = response.count()
if ct > 5:
response = response.nlargest(5)

medals = []
categories = []
for i, row in response.iteritems():
categories.append(i)
medals.append(row)

wsresponse = {}
wsresponse["forcmd"] = "MBSA"
wsresponse["response"] = { "categories":categories, "medals":medals}
ws.send(json.dumps(wsresponse))
elif cmd == 'T10G':
edition = msg["edition"]
response = get_top_ten_gold_tally(edition)
ct = response.count()
if ct > 10:
response = response.nlargest(10)
medals = []
for i, row in response.iteritems():
data = {"country":i,"tally":row}
medals.append(data)
wsresponse = {}
wsresponse["forcmd"] = "T10G"
wsresponse["response"] = medals
print(wsresponse)
ws.send(json.dumps(wsresponse))
elif cmd == 'T10M':
year = msg["edition"]
response = get_top_ten_total_tally(year)
ct = response.count()
if ct > 10:
response = response.nlargest(10)
medals = []
for i, row in response.iteritems():
data = {"country":i,"tally":row}
medals.append(data)
wsresponse = {}
wsresponse["forcmd"] = "T10M"
wsresponse["response"] = medals
print(wsresponse)
ws.send(json.dumps(wsresponse))
elif cmd == 'CORR':
corr = get_correlation_medalstally()
wsresponse = {}
wsresponse["forcmd"] = "CORR"
wsresponse["response"] = corr
ws.send(json.dumps(wsresponse))
elif cmd == 'YV':
yearvenue = get_year_venue()
yearvenuearray = []
for i in range(yearvenue.size):
value = {"Year":yearvenue.index[i],"Venue":yearvenue.values[i].tolist()[0]}
yearvenuearray.append(value)
responsejson = {}
responsejson["forcmd"]="YV"
responsejson["response"]=yearvenuearray
ws.send(json.dumps(responsejson))
elif cmd == 'DATA':
country = msg['country']
edition = msg['edition']
olympicsslice = get_country_edition_data(country,edition)
data = []
numofcolumns = olympicsslice.columns.size
cols = []
values = []
for column in olympicsslice.columns:
cols.append(column)
for value in olympicsslice.values:
values.append(value.tolist())
data = {"cols":cols,"vals":values}
responsejson = {}
responsejson['forcmd']='DATA'
responsejson['response']= data
ws.send(json.dumps(responsejson))
elif cmd == 'EDITIONS':
years = get_all_olympic_years()
yearsarray = []
for i,row in years.iteritems():
for value in row:
yearsarray.append(value)
length = len(yearsarray)
wsresponse = []
for i in range(length):
year = {"text":yearsarray[i],"value":yearsarray[i]}
wsresponse.append(year)
responsejson = {}
responsejson['forcmd']='EDITIONS'
responsejson['response']= wsresponse
ws.send(json.dumps(responsejson))
elif cmd == 'COUNTRIES':
countries = get_all_countries()
countriesarray = []
codearray = []
for i,row in countries.iteritems():
if i=='Code':
for value in row:
codearray.append(value)
elif i=='Country':
for value in row:
countriesarray.append(value)
length = len(codearray)
wsresponse = []
for i in range(length):
country = {"text":countriesarray[i],"value":codearray[i]}
wsresponse.append(country)
responsejson = {}
responsejson['forcmd']='COUNTRIES'
responsejson['response']= wsresponse
ws.send(json.dumps(responsejson))

def on_error(ws, error):
print(error)

def on_close(ws):
ws.send("DSX Listen End")

def on_open(ws):
def run(*args):
for i in range(10000):
hbeat = '{"cmd":"Olympics DSX HeartBeat"}'
ws.send(hbeat)
time.sleep(100)

_thread.start_new_thread(run, ())


def start_websocket_listener():
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://dsx-nodered-pelin.mybluemix.net/ws/orchestrate",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.