diff --git a/docs_tofupilot/measurements/dimensional/client/main.py b/docs_tofupilot/measurements/dimensional/client/main.py index 775582e..2953753 100644 --- a/docs_tofupilot/measurements/dimensional/client/main.py +++ b/docs_tofupilot/measurements/dimensional/client/main.py @@ -1,52 +1,75 @@ import random from datetime import datetime +import numpy as np from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient client = TofuPilotClient() -def phase_voltage_measure(): - start_time_millis = datetime.now().timestamp() * 1000 +def standard(): + """Python lists approach - one point at a time""" + start = datetime.now().timestamp() * 1000 + measurements = [] - structured_measurements = [] for t in range(100): - timestamp = t / 100 - voltage = round(random.uniform(3.3, 3.5), 2) - current = round(random.uniform(0.3, 0.8), 3) - resistance = voltage / current - structured_measurements.append( - (timestamp, voltage, current, resistance)) - - phase = [ - { - "name": "power_phase", - "outcome": PhaseOutcome.PASS, - "start_time_millis": start_time_millis, - "end_time_millis": start_time_millis + 30 * 1000, - "measurements": [ - { - "name": "current_voltage_resistence_over_time", - "units": ["s", "V", "A", "Ohm"], - "measured_value": structured_measurements, - "outcome": MeasurementOutcome.PASS, - } - ], - } + timestamp = t / 100 # Time dimension + voltage = round(random.uniform(3.3, 3.5), 2) # Voltage dimension + current = round(random.uniform(0.3, 0.8), 3) # Current dimension + measurements.append((timestamp, voltage, current, voltage / current)) + + return { + "name": "loop_approach", + "outcome": PhaseOutcome.PASS, + "start_time_millis": start, + "end_time_millis": start + 30000, + "measurements": [ + { + "name": "current_voltage_resistance_over_time", + "units": ["s", "V", "A", "Ohm"], + "measured_value": measurements, + "outcome": MeasurementOutcome.PASS, + } + ], + } + + +def numpy_way(): + """NumPy approach - all points at once""" + start = datetime.now().timestamp() * 1000 + + # Generate all dimensions simultaneously + timestamps = np.linspace(0, 0.99, 100) + voltages = np.round(np.random.uniform(3.3, 3.5, 100), 2) + currents = np.round(np.random.uniform(0.3, 0.8, 100), 3) + + measurements = [ + tuple(x) + for x in np.column_stack((timestamps, voltages, currents, voltages / currents)) ] - return phase + return { + "name": "vector_approach", + "outcome": PhaseOutcome.PASS, + "start_time_millis": start, + "end_time_millis": start + 30000, + "measurements": [ + { + "name": "current_voltage_resistance_over_time", + "units": ["s", "V", "A", "Ohm"], + "measured_value": measurements, + "outcome": MeasurementOutcome.PASS, + } + ], + } def main(): - phases = phase_voltage_measure() - client.create_run( - procedure_id="FVT1", # Create the procedure first in the Application + procedure_id="FVT1", unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"}, - phases=phases, - run_passed=all( - phase["outcome"] == PhaseOutcome.PASS for phase in phases), + phases=[standard(), numpy_way()], + run_passed=True, ) diff --git a/docs_tofupilot/measurements/dimensional/openhtf/main.py b/docs_tofupilot/measurements/dimensional/openhtf/main.py index 9aba21c..9d52d7a 100644 --- a/docs_tofupilot/measurements/dimensional/openhtf/main.py +++ b/docs_tofupilot/measurements/dimensional/openhtf/main.py @@ -6,9 +6,11 @@ @htf.measures( - htf.Measurement("current_voltage_resistence_over_time") - .with_dimensions(units.SECOND, units.VOLT, units.AMPERE) - .with_units(units.OHM), + htf.Measurement("current_voltage_resistance_over_time") + .with_dimensions( + units.SECOND, units.VOLT, units.AMPERE + ) # Input axes: time, voltage, current + .with_units(units.OHM) # Output unit: resistance in ohms ) def power_phase(test): for t in range(100): @@ -16,7 +18,7 @@ def power_phase(test): voltage = round(random.uniform(3.3, 3.5), 2) current = round(random.uniform(0.3, 0.8), 3) resistance = voltage / current - test.measurements.current_voltage_resistence_over_time[ + test.measurements.current_voltage_resistance_over_time[ timestamp, voltage, current ] = resistance @@ -28,7 +30,6 @@ def main(): part_number="PCB01", ) - # Execute the test with TofuPilot(test): test.execute(lambda: "PCB1A003")