def add_header_section( report: reporting.Report, settings: dict, activity_phases: limb.Property ): """ :param report: :param settings: :param activity_phases: :return: """ activity_phases = activity_phases.values() support_phases = settings['support_phases'] activity_phases = ['{}%'.format(round(100 * x)) for x in activity_phases] support_phases = ['{}%'.format(round(100 * x)) for x in support_phases] report.add_template( paths.resource('trial', 'header.html'), title=settings.get('name'), summary=settings.get('summary'), duty_cycle=round(100.0 * settings['duty_cycle']), activity_phases=activity_phases, support_phases=support_phases, date=datetime.utcnow().strftime("%m-%d-%Y %H:%M") )
def invalid_positions( settings: dict, time_steps: list, foot_positions: limb.Property ): """ Iterates through the time_steps and foot_positions lists and removes values at the beginning and end where any invalid data is found. Such invalid data exists when some amount of time at the beginning or end of the simulation is valid for 1 or more of the limbs in the trackway, but not all 4. :param settings: Configuration for the simulation trial :param time_steps: A list of times at which the simulation calculated foot positions :param foot_positions: The calculated positions of each foot for each time step in the time_steps list """ was_culled = False start_time = settings.get('start_time', 0) end_time = settings.get('end_time', 1e8) values = list(foot_positions.values()) values.append(time_steps) index = 0 while index < len(values[0]): entries = [] for v in values: entries.append(v[index]) cull = ( None in entries or entries[-1] < start_time or entries[-1] > end_time ) if cull: was_culled = True for v in values: v[index:index + 1] = [] else: index += 1 return was_culled
def trackway_positions( limb_positions: limb.Property, drawer, positions=None ): """ :param limb_positions: :param drawer: :param positions: :return: """ limb_positions = create_positions(limb_positions, positions) bounds = [1e12, 1e12, -1e12, -1e12] for positions in limb_positions.values(): for pos in positions: bounds[0] = min(bounds[0], pos.x.raw, pos.x.value) bounds[1] = min(bounds[1], pos.y.raw, pos.y.value) bounds[2] = max(bounds[2], pos.x.raw, pos.x.value) bounds[3] = max(bounds[3], pos.y.raw, pos.y.value) scale = 2048.0 / max( abs(bounds[2] - bounds[0]), abs(bounds[3] - bounds[1]) ) drawer.add_style_definition('.left_pes', { 'fill': svg.SvgWriter.LIMB_COLORS.left_pes, 'opacity': '0.5' }) drawer.add_style_definition('.right_pes', { 'fill': svg.SvgWriter.LIMB_COLORS.right_pes, 'opacity': '0.5' }) drawer.add_style_definition('.left_manus', { 'fill': svg.SvgWriter.LIMB_COLORS.left_manus, 'opacity': '0.5' }) drawer.add_style_definition('.right_manus', { 'fill': svg.SvgWriter.LIMB_COLORS.right_manus, 'opacity': '0.5' }) for key, positions in limb_positions.items(): is_pes = key in [limb.LEFT_PES, limb.RIGHT_PES] for pos in positions: classes = [key, 'track-pos'] html_data = { 'x': '{}'.format(pos.x.value), 'x-unc': '{}'.format(pos.x.uncertainty), 'y': '{}'.format(pos.y.value), 'y-unc': '{}'.format(pos.y.uncertainty), 'color': svg.SvgWriter.LIMB_COLORS.get(key) } if pos.annotation: html_data['annotation'] = pos.annotation if pos.uid: html_data['uid'] = pos.uid if pos.name: html_data['name'] = pos.name if pos.assumed: html_data['assumed'] = '1' classes.append('assumed') drawer.draw_circle( x=scale*pos.x.raw, y=-scale*pos.y.raw, radius=PES_RADIUS if is_pes else RADIUS, classes=classes, data=html_data ) color = svg.SvgWriter.LIMB_COLORS.get(key) print_style_name = '.{}'.format(key) print_style = { 'fill': color, 'opacity': '0.5', 'stroke-width': '{}px'.format(STROKE), 'stroke': color } assumed_style_name = '.{}.assumed'.format(key) assumed_style = { 'fill': 'white', 'opacity': '0.33' } marker_style_name = '.{}-marker'.format(key) marker_style = { 'fill': 'transparent', 'stroke-width': '{}px'.format(STROKE), 'stroke': color } if not is_pes: dash_array = '{},{}'.format(4, 4) marker_style['stroke-dasharray'] = '{},{}'.format(8,4) print_style['stroke-dasharray'] = dash_array assumed_style['stroke-dasharray'] = dash_array drawer.add_style_definition(print_style_name, print_style) drawer.add_style_definition(assumed_style_name, assumed_style) drawer.add_style_definition(marker_style_name, marker_style) p0 = positions[0] drawer.draw_circle( x=scale*p0.x.raw, y=-scale*p0.y.raw, radius=(PES_RADIUS if is_pes else RADIUS) + 0.5 * STROKE, classes=marker_style_name[1:], name=key ) return { 'scale': scale, 'offset': (0, 0) }