Browse Source

Make /stream/list give some more extended info, like row count

Also changes the HTTP parameter from "extent" to "extended",
and the commandline parameter from "extent" to "ext".
tags/nilmdb-1.3.0
Jim Paris 10 years ago
parent
commit
9f914598c2
5 changed files with 53 additions and 37 deletions
  1. +3
    -3
      nilmdb/client/client.py
  2. +19
    -13
      nilmdb/cmdline/list.py
  3. +15
    -8
      nilmdb/server/nilmdb.py
  4. +6
    -6
      nilmdb/server/server.py
  5. +10
    -7
      tests/test_cmdline.py

+ 3
- 3
nilmdb/client/client.py View File

@@ -57,14 +57,14 @@ class Client(object):
as a dictionary."""
return self.http.get("dbinfo")

def stream_list(self, path = None, layout = None, extent = False):
def stream_list(self, path = None, layout = None, extended = False):
params = {}
if path is not None:
params["path"] = path
if layout is not None:
params["layout"] = layout
if extent:
params["extent"] = 1
if extended:
params["extended"] = 1
return self.http.get("stream/list", params)

def stream_get_metadata(self, path, keys = None):


+ 19
- 13
nilmdb/cmdline/list.py View File

@@ -24,23 +24,26 @@ def setup(self, sub):
group.add_argument("-l", "--layout", default="*",
help="Match only this stream layout")

group = cmd.add_argument_group("Interval extent")
group.add_argument("-E", "--extent", action="store_true",
help="Show min/max timestamps in this stream")
group = cmd.add_argument_group("Interval info")
group.add_argument("-E", "--ext", action="store_true",
help="Show extended stream info, like interval "
"extents and row count")

group = cmd.add_argument_group("Interval details")
group.add_argument("-d", "--detail", action="store_true",
help="Show available data time intervals")
group.add_argument("-s", "--start",
metavar="TIME", type=self.arg_time,
help="Starting timestamp (free-form, inclusive)")
help="Starting timestamp for intervals "
"(free-form, inclusive)")
group.add_argument("-e", "--end",
metavar="TIME", type=self.arg_time,
help="Ending timestamp (free-form, noninclusive)")
help="Ending timestamp for intervals "
"(free-form, noninclusive)")

group = cmd.add_argument_group("Misc options")
group.add_argument("-T", "--timestamp-raw", action="store_true",
help="Show raw timestamps in time intervals or extents")
help="Show raw timestamps when printing times")

return cmd

@@ -65,26 +68,29 @@ def cmd_list_verify(self):

def cmd_list(self):
"""List available streams"""
streams = self.client.stream_list(extent = True)
streams = self.client.stream_list(extended = True)

if self.args.timestamp_raw:
time_string = nilmdb.utils.time.float_time_to_string
else:
time_string = nilmdb.utils.time.format_time

for (path, layout, extent_min, extent_max) in streams:
for stream in streams:
(path, layout, int_min, int_max, rows, seconds) = stream[:6]
if not (fnmatch.fnmatch(path, self.args.path) and
fnmatch.fnmatch(layout, self.args.layout)):
continue

printf("%s %s\n", path, layout)

if self.args.extent:
if extent_min is None or extent_max is None:
printf(" extent: (no data)\n")
if self.args.ext:
if int_min is None or int_max is None:
printf(" interval extents: (no data)\n")
else:
printf(" extent: %s -> %s\n",
time_string(extent_min), time_string(extent_max))
printf(" interval extents: %s -> %s\n",
time_string(int_min), time_string(int_max))
printf(" total data: %d rows, %.6f seconds\n",
rows or 0, seconds or 0);

if self.args.detail:
printed = False


+ 15
- 8
nilmdb/server/nilmdb.py View File

@@ -269,7 +269,7 @@ class NilmDB(object):

return

def stream_list(self, path = None, layout = None, extent = False):
def stream_list(self, path = None, layout = None, extended = False):
"""Return list of lists of all streams in the database.

If path is specified, include only streams with a path that
@@ -278,19 +278,26 @@ class NilmDB(object):
If layout is specified, include only streams with a layout
that matches the given string.

If extent = False, returns a list of lists containing
If extended = False, returns a list of lists containing
the path and layout: [ path, layout ]

If extent = True, returns a list of lists containing the
path, layout, and min/max extent of the data:
[ path, layout, extent_min, extent_max ]
If extended = True, returns a list of lists containing
more information:
path
layout
interval_min (earliest interval start)
interval_max (latest interval end)
rows (total number of rows of data)
seconds (total time covered by this stream)
"""
params = ()
query = "SELECT streams.path, streams.layout"
if extent:
query += ", min(ranges.start_time), max(ranges.end_time)"
if extended:
query += ", min(ranges.start_time), max(ranges.end_time) "
query += ", sum(ranges.end_pos - ranges.start_pos) "
query += ", sum(ranges.end_time - ranges.start_time) "
query += " FROM streams"
if extent:
if extended:
query += " LEFT JOIN ranges ON streams.id = ranges.stream_id"
query += " WHERE 1=1"
if layout is not None:


+ 6
- 6
nilmdb/server/server.py View File

@@ -173,10 +173,10 @@ class Stream(NilmApp):

# /stream/list
# /stream/list?layout=float32_8
# /stream/list?path=/newton/prep&extent=1
# /stream/list?path=/newton/prep&extended=1
@cherrypy.expose
@cherrypy.tools.json_out()
def list(self, path = None, layout = None, extent = None):
def list(self, path = None, layout = None, extended = None):
"""List all streams in the database. With optional path or
layout parameter, just list streams that match the given path
or layout.
@@ -184,11 +184,11 @@ class Stream(NilmApp):
If extent is not given, returns a list of lists containing
the path and layout: [ path, layout ]

If extent is provided, returns a list of lists containing the
path, layout, and min/max extent of the data:
[ path, layout, extent_min, extent_max ]
If extended is provided, returns a list of lists containing
extended info: [ path, layout, extent_min, extent_max,
total_rows, total_seconds ]. More data may be added.
"""
return self.db.stream_list(path, layout, bool(extent))
return self.db.stream_list(path, layout, bool(extended))

# /stream/create?path=/newton/prep&layout=float32_8
@cherrypy.expose


+ 10
- 7
tests/test_cmdline.py View File

@@ -444,7 +444,7 @@ class TestCmdline(object):
# bad start time
self.fail("insert -t -r 120 --start 'whatever' /newton/prep /dev/null")

def test_07_detail_extent(self):
def test_07_detail_extended(self):
# Just count the number of lines, it's probably fine
self.ok("list --detail")
lines_(self.captured, 8)
@@ -491,16 +491,19 @@ class TestCmdline(object):
lines_(self.captured, 2)
self.contain("[ 1332497115.612000 -> 1332497160.000000 ]")

# Check --extent output
self.ok("list --extent")
lines_(self.captured, 6)
# Check --ext output
self.ok("list --ext")
lines_(self.captured, 9)

self.ok("list -E -T")
self.contain(" extent: 1332496800.000000 -> 1332497160.000000")
self.contain(" extent: (no data)")
c = self.contain
c("\n interval extents: 1332496800.000000 -> 1332497160.000000\n")
c("\n total data: 43200 rows, 359.983336 seconds\n")
c("\n interval extents: (no data)\n")
c("\n total data: 0 rows, 0.000000 seconds\n")

# Misc
self.fail("list --extent --start='23 Mar 2012 10:05:15.50'")
self.fail("list --ext --start='23 Mar 2012 10:05:15.50'")
self.contain("--start and --end only make sense with --detail")

def test_08_extract(self):


Loading…
Cancel
Save