Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 55 additions & 32 deletions docs_tofupilot/measurements/dimensional/client/main.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down
11 changes: 6 additions & 5 deletions docs_tofupilot/measurements/dimensional/openhtf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@


@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):
timestamp = t / 100
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

Expand All @@ -28,7 +30,6 @@ def main():
part_number="PCB01",
)

# Execute the test
with TofuPilot(test):
test.execute(lambda: "PCB1A003")

Expand Down
Loading