Browse Source

Use simplejson instead of json for performance

Misc cleanups

More work on tests to get more coverage


git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10869 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/bxinterval-last
Jim Paris 12 years ago
parent
commit
3f436e6dfd
8 changed files with 15 additions and 17 deletions
  1. +7
    -6
      nilmdb/client.py
  2. +0
    -2
      nilmdb/cmdline/extract.py
  3. +1
    -1
      nilmdb/server.py
  4. +0
    -1
      runserver.py
  5. +0
    -1
      tests/test_client.py
  6. +5
    -3
      tests/test_cmdline.py
  7. +0
    -1
      tests/test_layout.py
  8. +2
    -2
      tests/test_nilmdb.py

+ 7
- 6
nilmdb/client.py View File

@@ -7,7 +7,7 @@ import time
import sys
import re
import os
import json
import simplejson as json
import urlparse
import urllib
import pycurl
@@ -233,7 +233,7 @@ class Client(object):
"path": path
}
if start is not None:
params["start"] = repr(start) # keep full precision
params["start"] = repr(start) # use repr to keep precision
if end is not None:
params["end"] = repr(end)

@@ -249,15 +249,16 @@ class Client(object):

def stream_extract(self, path, start = None, end = None, bare = False):
"""
Return a generator that yields chunks of ascii-formatted data
from the stream. Multiple requests are made to the server if
the results get truncated.
Extract data from a stream. Returns a generator that yields
chunks of ASCII-formatted data that matches the database
layout for the given path. Multiple requests are made to the
server if shorter requests get truncated.
"""
params = {
"path": path
}
if start is not None:
params["start"] = repr(start) # keep full precision
params["start"] = repr(start) # use repr to keep precision
if end is not None:
params["end"] = repr(end)
params["bare"] = bare


+ 0
- 2
nilmdb/cmdline/extract.py View File

@@ -39,8 +39,6 @@ def cmd_extract(self):
printf("# start: %s\n", self.time_string(self.args.start))
printf("# end: %s\n", self.time_string(self.args.end))

return 0

printed = False
for data in self.client.stream_extract(self.args.path,
self.args.start,


+ 1
- 1
nilmdb/server.py View File

@@ -11,7 +11,7 @@ import cherrypy
import sys
import time
import os
import json
import simplejson as json

try:
import cherrypy


+ 0
- 1
runserver.py View File

@@ -1,7 +1,6 @@
#!/usr/bin/python

import nilmdb
import json
import argparse

parser = argparse.ArgumentParser(description='Run the NILM server')


+ 0
- 1
tests/test_client.py View File

@@ -6,7 +6,6 @@ import datetime_tz

from nose.tools import *
from nose.tools import assert_raises
import json
import itertools
import distutils.version
import os


+ 5
- 3
tests/test_cmdline.py View File

@@ -4,7 +4,6 @@ import nilmdb.cmdline

from nose.tools import *
from nose.tools import assert_raises
import json
import itertools
import datetime_tz
import os
@@ -352,10 +351,13 @@ class TestCmdline(object):
eq_(self.captured.count('\n'), 11)

def test_cmdline_8_extract(self):
# nonexistent stream
self.fail("extract /no/such/foo --start 2000-01-01 --end 2020-01-01")
self.contain("Error getting stream info")

self.ok("extract -a /newton/prep --start 2000-01-01 --end 2020-01-01")
self.dump()
# full dump
# self.ok("extract -a /newton/prep --start 2000-01-01 --end 2020-01-01")
# self.dump()

def test_cmdline_9_truncated(self):
# Test truncated responses by overriding the nilmdb response_size


+ 0
- 1
tests/test_layout.py View File

@@ -3,7 +3,6 @@ import nilmdb
from nose.tools import *
from nose.tools import assert_raises
import distutils.version
import json
import itertools
import os
import shutil


+ 2
- 2
tests/test_nilmdb.py View File

@@ -3,8 +3,8 @@ import nilmdb
from nose.tools import *
from nose.tools import assert_raises
import distutils.version
import json
import itertools
import simplejson as json
import itertools
import os
import shutil
import sys


Loading…
Cancel
Save