Jupyter Service Development Guide

Source: Internet
Author: User
Tags jupyter

1. Take Kylin data
Import Requestsimport Pandas as Pddef getdtu (dtuid,addr):    sqldata = ' {' SQL ': ' select * from DTU where dtuid=\ '%s\ ' and Addr=\ '%s\ ' ORDER by dtutime Desc, ' project ': ' Yongli ', ' offset ': 0, ' limit ': '% ' (dtuid, addr)    response = Requests . Post (URL     = ' http://kylin1.wdp:7070/kylin/api/query ',                             data    = SqlData,                             auth    = (' admin ', ' admin ') ),                              headers = {"Content-type": "Application/json"})    Dfcols = PD. DataFrame (Response.json () ["Columnmetas"])    df = PD. DataFrame (Response.json () ["Results"], columns=dfcols["label"].values)    values = PD. DataFrame ({' Dtutime ': df["Dtutime"].map (PD. Timestamp),                            addr:df["Dtuvalue"]})        return valuesgetdtu (' 8627427973 ', ' 1800 ')

?


2. Merging rows
From pandas import Series, Dataframeimport pandas as Pddef getdtustd (Dtuid, Addrs):    addrlist = Addrs.strip (). Split (', ')    result = PD. DataFrame ({' addr ': [],                           ' std ': []}) for        i in addrlist:        std = getstd (dtuid, i)        result = Result.append (STD, Ignore_index=true)        return result    getdtustd (' 8627427973 ', ' 1820,1810,0004 ')

?

3. Merging columns
Import pandas as Pddef Getstdjson (dtuid,addr= ' 0002,0004,1019,101a,101b,101c,101d, 1023,1024,1025,1800,1802,1804,1806,1808,180A,180C,180E,1810,1812,1814,1816,1818,181A,181C,181E, 1820,1822,1824,1826,1828,182a,182c,182e,1830,2000,2002,2004,2006,2008,200a,200c,200e, 2100,2102,2104,2106,2108,210a,210c,210e '): data = GETDTUSTD (dtuid,addr) comments = PD. DataFrame ({' addr ': [' 0002 ', ' 0004 ', ' 1019 ', ' 101A ', ' 101B ', ' 101C ', ' 101D ', ' 1023 ', ' 1024 ', ' 1025 ', ' 1800 ', ' 1802 ', ' 1804 ', ' 1806 ', ' 1808 ', ' 180A ', ' 180C ', ' 180E ', ' 1810 ', ' 1812 ', ' 1814 ', ' 1816 ', ' 1818 ', ' 181A ', ' 181C ', ' 181E ', ' 1820 ', ' 1822 ', ' 1824 ', ' 1826 ', ' 1828 ', ' 182A ', ' 182C ', ' 182E ', ' 1830 ', ' + ', ' 2002 ', ' 2004 ', ' 2006 ', ' The ', ' 200A ', ' 200C ', ' 200E ', ' 2100 ', ' 2102 ', ' 2104 ', ' 2106 ', ' 2108 ', ' 210A ', ' 210C ', ' 210E ', ' comment ': [' voltage-to-ratio ', ' current-to-ratio ', ' A-phase power factor ', ' B-phase power factor ', ' C ' Phase factor ', ' total power factor ', ' frequency ', ' a phase phase angle ', ' b phase phase angle ', ' c phase angle ', ' a phase voltage ', ' B phase voltage ', ' C phase voltage ', ' average phase voltage ', ' ab line voltage ', ' BC line voltage ', ' CA line voltage ', ' average line voltage ', ' a phase current ', ' B-Phase current ', ' C-phase current ', ' Average current ', ' 0-wire current ', ' A-phase active power ', ' B-phase active power ', ' C-phase active power ', ' total active power ', ' A-phase reactive energy ', ' B-phase reactive energy ', ' C-phase reactive energy '', ' total reactive power ', ' A at the same rate ', ' b see in power ', ' C in power ', ' total apparent power ', ' a phase positive active energy ', ' B phase positive active energy ', ' c phase positive active energy ', ' total positive active energy ', ' a phase positive reactive energy ', ' B phase positive to reactive energy ',        ' C-phase positive reactive energy ', ' total forward reactive energy ', ' a opposite to active energy ', ' b opposite to active energy ', ' c opposite to active energy ', ' total reverse active energy ', ' a contrary to reactive energy ', ' b opposite to reactive energy ', ' C to reactive energy ', ' total reverse reactive energy '}) result = Pd.merge (data, comments, on= ' addr ') #print result return "{\" code\ ": 200,\" message\ ": \" Success\ ", \" data\ ":" + Result.to_json (orient= ' Records ', force_ascii=false) + "}" #getStdJson (' 8627427973 ', ' 1820,1810,0004 ')?

?


4. Drawing
%matplotlib Inlineimport Matplotlib.pyplot as PLT, mpld3from matplotlib.ticker import Multiplelocator,         Funcformatterimport matplotlib.dates as Mdatedef drawdtu (dtuid,addr): #print "-------ENTER drawdtu (%s)-------"%dtuid data = GETDTU (DTUID,ADDR) FIG, ax = plt.subplots (figsize= (5,3)) Ax.plot (Data[0], data[1], '-', label= '%s '%ad DR, color = ' Blue ') Majorlocator = Multiplelocator (5) Majorformatter = Mdate. Dateformatter ('%H ') Minorlocator = Multiplelocator (1) ax.xaxis.set_major_locator (majorlocator) ax.xaxis.set_major _formatter (Majorformatter) # for the minor ticks, use no labels; Default Nullformatter ax.xaxis.set_minor_locator (minorlocator) #plt. Xlabel ("Date") #plt. Ylabel ("Value") #p    Lt.title ("DTU Monitor") plt.legend (loc= ' Upper Center ', bbox_to_anchor= (0.5,0.98), ncol=3,fancybox=true,shadow=true)    Ax.grid (color= "Lightgray", alpha=0.7) #fig. Set_size_inches (4, 4) #plt. Show () HTML = mpld3.fig_to_html (Fig) return HTML#DRAWDTU (' 8627427973 ', ' 0004 ') 
?
5. Publishing services
From flask import flask, make_response, Requestapp = Flask (__name__) @app. Route ("/dtustd/", methods=["GET", "OPTIONS"]) def dtustd (dtuid):    #o = DRAWDTUSTD (dtuid)    o = Getstdjson (dtuid)    resp = Make_response (o)    resp.headers[ "Access-control-allow-origin"] = "*"    resp.headers["access-control-request-method"] = "post,get,put,delete, OPTIONS "    resp.headers[" access-control-allow-methods "] =" post,get,put,delete,options "    resp.headers[" Access-control-allow-headers "] =" X-requested-with,content-type "        if Request.method = = ' OPTIONS ':        print" It ' s OPTIONS "    return Respapp.run (host=" 0.0.0.0 ", port=5007)

Jupyter Service Development Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.