Skip to content

Instantly share code, notes, and snippets.

@stefan789
Created September 11, 2015 08:58
Show Gist options
  • Save stefan789/8dc1bfcc7ad1ecb10e2f to your computer and use it in GitHub Desktop.
Save stefan789/8dc1bfcc7ad1ecb10e2f to your computer and use it in GitHub Desktop.
import numpy as np
import json
import cloudant
import datetime as dt
import pytz
berlin = pytz.timezone("Europe/Berlin")
# set up db and define functions
#acct = cloudant.Account(uri="http://10.155.59.88:5984")
acct = cloudant.Account(uri="http://raid.nedm1:5984")
res = acct.login(USER, PW)
assert res.status_code == 200
db = acct["nedm%2Ffluxgate"]
des = db.design("slow_control_time_label")
the_view = des.view("slow_control_time_label")
# get view data from db
results = the_view.get(params=dict(descending=False,
endkey = end,
startkey = start
)).json()
# extract date and components from view results and convert to numpy array
dateresults = np.asarray([(dt.datetime(*i["key"][:-1], tzinfo=pytz.utc)) for i in results["rows"] if i["key"][6]=="Bx1"])
Bx1 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="Bx1"])
By1 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="By1"])
Bz1 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="Bz1"])
Bx2 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="Bx2"])
By2 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="By2"])
Bz2 = np.asarray([(i["value"]) for i in results["rows"] if i["key"][6]=="Bz2"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment