def pre_analyze(db): result = dict() mobile.DB = db readings = mobile.stream_readings() start = time.time() H = cluster.Hierarchy(next(readings)) for i, r in enumerate(readings): H.append(r) movements = cluster.segment(H, threshold=0.01) locs = cluster.locations(movements, threshold=0.5) return (H, movements, locs)
H = cluster.Hierarchy(next(readings)) for i, r in enumerate(readings): H.append(r) # if i % 1000 == 0: # print(i) print("Clustering duration = %.2f seconds" % (time.time() - start)) # Segmentation start = time.time() tops = cluster.segment(H, threshold=0.01) print("Segmentation duration = %.2f seconds" % (time.time() - start)) # Locations start = time.time() locs = cluster.locations(tops, threshold=0.1) print("Locations duration = %.2f seconds" % (time.time() - start)) def humanize(sec): if sec < 60: return "%2.2f s" % sec min = sec / 60.0 if min < 60: return "%2.2f m" % min hr = min / 60.0 return "%2.2f h" % hr def print_tops(tops): for i,C in enumerate(tops): t0, t1, dt = C.timespan() n_readings = len(C.readings())