def format(entry): formatted_entry = ad.AttrDict() formatted_entry["_id"] = entry["_id"] formatted_entry.user_id = entry.user_id metadata = entry.metadata if "time_zone" not in metadata: metadata.time_zone = "America/Los_Angeles" fc.expand_metadata_times(metadata) formatted_entry.metadata = metadata data = ad.AttrDict() if 'agb' in entry.data: data.type = ecwa.MotionTypes(entry.data.agb).value elif 'zzaEg' in entry.data: data.type = ecwa.MotionTypes(entry.data.zzaEg).value else: data.type = ecwa.MotionTypes(entry.data.zzaKM).value if 'agc' in entry.data: data.confidence = entry.data.agc elif 'zzaEh' in entry.data: data.confidence = entry.data.zzaEh else: data.confidence = entry.data.zzaKN data.ts = formatted_entry.metadata.write_ts data.local_dt = formatted_entry.metadata.write_local_dt data.fmt_time = formatted_entry.metadata.write_fmt_time formatted_entry.data = data return formatted_entry
def grouped_to_summary(time_grouped_df, key_to_fill_fn, summary_fn): ret_list = [] # When we group by a time range, the key is the end of the range for key, section_group_df in time_grouped_df: curr_msts = ecwms.ModeStatTimeSummary() key_to_fill_fn(key, section_group_df, curr_msts) curr_msts.nUsers = len(section_group_df.user_id.unique()) mode_grouped_df = section_group_df.groupby('sensed_mode') mode_results = summary_fn(mode_grouped_df) for mode, result in mode_results.items(): curr_msts[ecwm.MotionTypes(mode).name] = result ret_list.append(curr_msts) return ret_list
def format(entry): formatted_entry = ad.AttrDict() formatted_entry["_id"] = entry["_id"] formatted_entry.user_id = entry.user_id metadata = entry.metadata if "time_zone" not in metadata: metadata.time_zone = "America/Los_Angeles" fc.expand_metadata_times(metadata) formatted_entry.metadata = metadata #logging.info('*** Motion Data write_ts: %d' % metadata.write_ts) if 'ts' not in entry.data: # old style entries data = ad.AttrDict() else: data = entry.data if 'agb' in entry.data: data.type = ecwa.MotionTypes(entry.data.agb).value elif 'zzaEg' in entry.data: data.type = ecwa.MotionTypes(entry.data.zzaEg).value elif 'zzbjA' in entry.data: data.type = ecwa.MotionTypes(entry.data.zzbjA).value elif 'ajO' in entry.data: data.type = ecwa.MotionTypes(entry.data.ajO).value elif 'zzaKM' in entry.data: data.type = ecwa.MotionTypes(entry.data.zzaKM).value elif 'zzbhB' in entry.data: data.type = ecwa.MotionTypes(entry.data.zzbhB).value if 'agc' in entry.data: data.confidence = entry.data.agc elif 'zzaEh' in entry.data: data.confidence = entry.data.zzaEh elif 'zzbjB' in entry.data: data.confidence = entry.data.zzbjB elif 'ajP' in entry.data: data.confidence = entry.data.ajP elif 'zzaKN' in entry.data: data.confidence = entry.data.zzaKN elif 'zzbhC' in entry.data: data.confidence = entry.data.zzbhC if 'ts' not in entry.data: data.ts = formatted_entry.metadata.write_ts data.local_dt = formatted_entry.metadata.write_local_dt data.fmt_time = formatted_entry.metadata.write_fmt_time formatted_entry.data = data return formatted_entry
def is_huge_invalid_ts_offset(filterMethod, lastPoint, currPoint, timeseries, motionInRange): intermediate_transitions = filterMethod.transition_df[ (filterMethod.transition_df.ts >= lastPoint.ts) & (filterMethod.transition_df.ts <= currPoint.ts)] ignore_modes_list = [ ecwm.MotionTypes.TILTING.value, ecwm.MotionTypes.UNKNOWN.value, ecwm.MotionTypes.STILL.value, ecwm.MotionTypes.NONE.value, ecwm.MotionTypes.STOPPED_WHILE_IN_VEHICLE.value ] non_still_motions = [ ma for ma in motionInRange if ma["data"]["type"] not in ignore_modes_list and ma["data"]["confidence"] == 100 ] logging.debug("non_still_motions = %s" % [(ecwm.MotionTypes( ma["data"]["type"]), ma["data"]["confidence"], ma["data"]["fmt_time"]) for ma in non_still_motions]) non_still_motions_rate = len(non_still_motions) / (currPoint.ts - lastPoint.ts) logging.debug( "in is_huge_invalid_ts_offset: len(intermediate_transitions) = %d, non_still_motions = %d, time_diff = %s mins, non_still_motions_rate = %s" % (len(intermediate_transitions), len(non_still_motions), (currPoint.ts - lastPoint.ts) / 60, non_still_motions_rate)) # If we have no transitions and at least one high confidence motion # activity every 5 minutes, we claim that we were actually moving during the # interim and the currPoint is invalid if len(intermediate_transitions ) == 0 and non_still_motions_rate > 1 / (5 * 60): logging.debug("in is_huge_invalid_ts_offset: returning True") return True else: logging.debug("in is_huge_invalid_ts_offset: returning False") return False
def grouped_to_summary(time_grouped_df, key_to_fill_fn, summary_fn): ret_list = [] # When we group by a time range, the key is the end of the range for key, section_group_df in time_grouped_df: curr_msts = ecwms.ModeStatTimeSummary() key = fix_int64_key_if_needed(key) key_to_fill_fn(key, section_group_df, curr_msts) curr_msts.nUsers = len(section_group_df.user_id.unique()) mode_grouped_df = section_group_df.groupby('sensed_mode') mode_results = summary_fn(mode_grouped_df) for mode, result in mode_results.items(): if eac.get_section_key_for_analysis_results() == "analysis/inferred_section": curr_msts[ecwmp.PredictedModeTypes(mode).name] = result else: curr_msts[ecwm.MotionTypes(mode).name] = result ret_list.append(curr_msts) # import bson.json_util as bju # logging.debug("After appending %s, ret_list = %s" % (curr_msts, ret_list)) # for k in curr_msts.keys(): # print("Serializing key = %s" % k) # logging.debug("Serializing key %s = %s" % # (k, bju.dumps(curr_msts[k]))) return ret_list