76 lines
1.6 KiB
Python
76 lines
1.6 KiB
Python
|
|
"""
|
||
|
|
Comparison Hook
|
||
|
|
Auto-generated by Atomizer Phase 2.9
|
||
|
|
|
||
|
|
Compare min force to average
|
||
|
|
|
||
|
|
Operation: ratio
|
||
|
|
Formula: min_to_avg_ratio = min_force / avg_force
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
def compare_ratio(min_force, avg_force):
|
||
|
|
"""
|
||
|
|
Compare values using ratio.
|
||
|
|
|
||
|
|
Args:
|
||
|
|
min_force: float
|
||
|
|
avg_force: float
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
float: Comparison result
|
||
|
|
"""
|
||
|
|
result = min_force / avg_force
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main entry point for hook execution."""
|
||
|
|
if len(sys.argv) < 2:
|
||
|
|
print("Usage: python {} <input_file.json>".format(sys.argv[0]))
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
input_file = Path(sys.argv[1])
|
||
|
|
|
||
|
|
# Read inputs
|
||
|
|
with open(input_file, 'r') as f:
|
||
|
|
inputs = json.load(f)
|
||
|
|
|
||
|
|
# Extract required inputs
|
||
|
|
min_force = inputs.get("min_force")
|
||
|
|
if min_force is None:
|
||
|
|
print(f"Error: Required input 'min_force' not found")
|
||
|
|
sys.exit(1)
|
||
|
|
avg_force = inputs.get("avg_force")
|
||
|
|
if avg_force is None:
|
||
|
|
print(f"Error: Required input 'avg_force' not found")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
# Calculate comparison
|
||
|
|
result = compare_ratio(min_force, avg_force)
|
||
|
|
|
||
|
|
# Write output
|
||
|
|
output_file = input_file.parent / "min_to_avg_ratio.json"
|
||
|
|
output = {
|
||
|
|
"min_to_avg_ratio": result,
|
||
|
|
"operation": "ratio",
|
||
|
|
"formula": "min_force / avg_force",
|
||
|
|
"inputs_used": {"min_force": min_force, "avg_force": avg_force}
|
||
|
|
}
|
||
|
|
|
||
|
|
with open(output_file, 'w') as f:
|
||
|
|
json.dump(output, f, indent=2)
|
||
|
|
|
||
|
|
print(f"min_to_avg_ratio = {result:.6f}")
|
||
|
|
print(f"Result saved to: {output_file}")
|
||
|
|
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
main()
|