Skip to content

Commit

Permalink
Improved status messages and progress for the timeseries and CCA mode…
Browse files Browse the repository at this point in the history
…ls. Closes #54.
  • Loading branch information
tshead2 committed Aug 20, 2013
1 parent 2e89615 commit 6d4d059
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 0 additions & 7 deletions packages/slycat/web/server/worker/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def post_model_send_timeseries_rows(self, arguments):
name = arguments["name"]
rows = arguments["rows"]
self.send_timeseries_artifact_binary_rows(name, rows)
self.set_message("Timeseries %s stored %s rows." % (name, self.artifacts[name].row_count))
except KeyError as e:
raise cherrypy.HTTPError("400 Missing key: %s" % e.message)

Expand Down Expand Up @@ -365,7 +364,6 @@ def __init__(self, column_names, column_types):
self.named_pipe = None
self.stream = None
self.thread = None
self.row_count = 0

def get_stream(self):
def load_data(database, array, named_pipe, column_types):
Expand Down Expand Up @@ -393,7 +391,6 @@ def store_rows(self, rows):
stream.write("\0")
elif type == "double":
stream.write(struct.pack("<d", value))
self.row_count += 1

def store_columns(self, row_count, columns):
stream = self.get_stream()
Expand All @@ -407,7 +404,6 @@ def store_columns(self, row_count, columns):
stream.write("\0")
elif self.column_types[column] == "double":
stream.write(struct.pack("<d", value))
self.row_count += 1

def finish(self):
if self.stream is not None:
Expand Down Expand Up @@ -436,7 +432,6 @@ def __init__(self, column_names, column_types):
self.named_pipe = None
self.stream = None
self.thread = None
self.row_count = 0

def get_stream(self):
def load_data(database, array, named_pipe, column_types):
Expand Down Expand Up @@ -465,7 +460,6 @@ def store_rows(self, ids, times, rows):
stream.write("\0")
elif type == "double":
stream.write(struct.pack("<d", value))
self.row_count += 1

def finish(self):
if self.stream is not None:
Expand Down Expand Up @@ -501,7 +495,6 @@ def __init__(self, attributes, dimensions):
self.named_pipe = None
self.stream = None
self.thread = None
self.row_count = 0

def get_stream(self):
def load_data(database, array, named_pipe, attribute_types):
Expand Down
6 changes: 6 additions & 0 deletions packages/slycat/web/server/worker/model/cca3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, security, pid, mid, name, marking, description):
slycat.web.server.worker.model.prototype.__init__(self, security, "CCA model", pid, mid, "cca3", name, marking, description, incremental=True)

def compute_model(self):
self.set_progress(0.0)
self.set_message("Transforming data.")

# Get required inputs ...
data_table = self.load_table_artifact("data-table")
input_columns = self.load_json_artifact("input-columns")
Expand Down Expand Up @@ -45,6 +48,7 @@ def compute_model(self):
# cherrypy.log.error("%s" % X)
# cherrypy.log.error("%s" % Y)
# cherrypy.log.error("%s" % scale_inputs)
self.set_message("Computing CCA.")
x, y, x_loadings, y_loadings, r, wilks = cca(X, Y, scale_inputs=scale_inputs)
# cherrypy.log.error("%s" % x)
# cherrypy.log.error("%s" % y)
Expand All @@ -53,6 +57,7 @@ def compute_model(self):
# cherrypy.log.error("%s" % r)
# cherrypy.log.error("%s" % wilks)

self.set_message("Storing results.")
component_count = x.shape[1]
sample_count = x.shape[0]

Expand All @@ -79,3 +84,4 @@ def compute_model(self):
self.send_array_artifact_data("cca-statistics", [r[component], wilks[component]])
self.finish_array_artifact("cca-statistics", input=False)

self.set_progress(1.0)
9 changes: 7 additions & 2 deletions packages/slycat/web/server/worker/model/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ def compute_model(self):
self.store_json_file_artifact("clusters", sorted([name for name, artifact in cluster_artifacts]), input=False)

# For each cluster (timeseries set) ...
for name, artifact in cluster_artifacts:
# Rebin the timeseries within this cluster so they share common start / stop times and samples ...
for index, (name, artifact) in enumerate(cluster_artifacts):
progress_begin = float(index) / float(len(cluster_artifacts))
progress_end = float(index + 1) / float(len(cluster_artifacts))
self.set_progress(progress_begin)

self.set_message("Rebinning data for %s" % name)
# Rebin the timeseries within this cluster so they share common start / stop times and samples ...
time_min = self.scidb.query_value("aql", "select min(time) from %s" % artifact["columns"]).getDouble()
time_max = self.scidb.query_value("aql", "select max(time) from %s" % artifact["columns"]).getDouble()

Expand Down Expand Up @@ -73,6 +77,7 @@ def compute_model(self):
observation_count = len(cluster)
distance_matrix = numpy.zeros(shape=(observation_count, observation_count))
for i in range(0, observation_count):
self.set_progress(self.mix(progress_begin, progress_end, float(i) / float(observation_count)))
self.set_message("Computing distance matrix for %s, %s of %s" % (name, i+1, observation_count))
for j in range(i + 1, observation_count):
distance = math.sqrt(math.fsum([math.pow(b - a, 2.0) for a, b in zip(cluster[i]["values"], cluster[j]["values"])]))
Expand Down

0 comments on commit 6d4d059

Please sign in to comment.