Created
February 9, 2012 17:42
-
-
Save gadamc/1781501 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from couchdbkit import Server, Database | |
| s = Server('https://edwdbik.fzk.de:6984') | |
| db = s['automat'] | |
| vr = db.view('data/bypctime', reduce=False, descending=True, startkey=1318357552, endkey=1318357452, include_docs=True) | |
| values = {} | |
| ignorekeys = ['_id', '_rev', 'type', 'author', 'ipaddr', 'date', 'utctime'] | |
| #savekeys = ['T_Bolo', 'T_PT1'] | |
| for row in vr: | |
| #the view returns each document (because I said 'include_docs =True') | |
| doc = row['doc'] | |
| for key, value in doc.items(): #iterate through all key/value pairs in the document | |
| if key in ignorekeys: #skip these keys because they aren't interesting | |
| continue | |
| #if key not in savekeys: #only save these keys | |
| # continue | |
| if values.has_key(key) == False: #create a list for this key if its doesn't exist | |
| values[key] = [] | |
| values[key].append([doc['utctime'], value]) #add the values to the list | |
| #values is now a dictionary of x,y values for each key that it finds in the documents returned by the automat server | |
| #warning: this may be a slow routine if you query over a large range of time because you're grabbing a lot of data. | |
| #for example | |
| print values['T_Bolo'][1][0] | |
| print values['T_Bolo'][1][1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment