|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +if [[ $# -lt 2 || $# -gt 3 ]]; then |
| 5 | + echo "Usage: $0 <code> <result_uuid|estimate_result_uuid> [kind]" |
| 6 | + echo " <code>: program name (directory under programs/)" |
| 7 | + echo " <result_uuid|estimate_result_uuid>: UUID to use as the re-estimation entry point" |
| 8 | + echo " [kind]: result | estimate (default: estimate)" |
| 9 | + echo "" |
| 10 | + echo "Examples:" |
| 11 | + echo " $0 qws 11111111-2222-3333-4444-555555555555" |
| 12 | + echo " $0 qws 11111111-2222-3333-4444-555555555555 estimate" |
| 13 | + echo " $0 qws 11111111-2222-3333-4444-555555555555 result" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +code="$1" |
| 18 | +input_uuid="$2" |
| 19 | +kind="${3:-estimate}" |
| 20 | + |
| 21 | +if [[ ! "$input_uuid" =~ ^[0-9a-fA-F-]{36}$ ]]; then |
| 22 | + echo "ERROR: UUID format looks invalid: $input_uuid" >&2 |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +if [[ ! -d "programs/$code" ]]; then |
| 27 | + echo "ERROR: programs/$code does not exist" >&2 |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +if [[ -z "${RESULT_SERVER:-}" || -z "${RESULT_SERVER_KEY:-}" ]]; then |
| 32 | + echo "ERROR: RESULT_SERVER and RESULT_SERVER_KEY must be set" >&2 |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +rm -f results/result*.json results/estimate*.json results/source_estimate.json |
| 37 | +mkdir -p results |
| 38 | + |
| 39 | +case "$kind" in |
| 40 | + estimate) |
| 41 | + export estimate_result_uuid="$input_uuid" |
| 42 | + unset result_uuid 2>/dev/null || true |
| 43 | + unset estimate_uuid 2>/dev/null || true |
| 44 | + ;; |
| 45 | + result) |
| 46 | + export result_uuid="$input_uuid" |
| 47 | + unset estimate_result_uuid 2>/dev/null || true |
| 48 | + unset estimate_uuid 2>/dev/null || true |
| 49 | + ;; |
| 50 | + *) |
| 51 | + echo "ERROR: kind must be one of: estimate, result" >&2 |
| 52 | + exit 1 |
| 53 | + ;; |
| 54 | +esac |
| 55 | + |
| 56 | +export code |
| 57 | + |
| 58 | +echo "Re-estimation test" |
| 59 | +echo " code: $code" |
| 60 | +echo " kind: $kind" |
| 61 | +echo " uuid: $input_uuid" |
| 62 | +echo "" |
| 63 | + |
| 64 | +echo "[1/2] Fetching source result" |
| 65 | +bash scripts/fetch_result_by_uuid.sh |
| 66 | + |
| 67 | +echo "" |
| 68 | +echo "[2/2] Running estimation" |
| 69 | +bash scripts/run_estimate.sh "$code" |
| 70 | + |
| 71 | +echo "" |
| 72 | +echo "Generated files:" |
| 73 | +ls results/result*.json results/estimate*.json 2>/dev/null || true |
| 74 | + |
| 75 | +if [[ -f results/result0.json ]]; then |
| 76 | + echo "" |
| 77 | + echo "Fetched result metadata:" |
| 78 | + jq '{code, system, Exp, _server_uuid, _server_timestamp}' results/result0.json || true |
| 79 | +fi |
| 80 | + |
| 81 | +if compgen -G "results/estimate*.json" > /dev/null; then |
| 82 | + for estimate_file in results/estimate*.json; do |
| 83 | + echo "" |
| 84 | + echo "Estimate metadata for $estimate_file:" |
| 85 | + jq '{ |
| 86 | + code, |
| 87 | + exp, |
| 88 | + performance_ratio, |
| 89 | + applicability, |
| 90 | + estimate_metadata: { |
| 91 | + source_result_uuid, |
| 92 | + estimation_result_uuid, |
| 93 | + requested_estimation_package, |
| 94 | + estimation_package |
| 95 | + } |
| 96 | + }' "$estimate_file" || true |
| 97 | + done |
| 98 | +else |
| 99 | + echo "WARNING: No estimate*.json files generated" |
| 100 | +fi |
0 commit comments