Skip to content

Commit

Permalink
Added an f2 variant metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
zond committed May 27, 2024
1 parent 3e6ad14 commit da5f245
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions install_external_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,88 @@ func main() {
fmt.Printf("SCORE=%f\n", odgSum / float64(count))
}
}
EOF

( cd "${DST}" && go build "${WRAPPER}.go" ) > "${INSTALL_LOG}" 2>&1
if test "${?}" != "0"; then
cat "${INSTALL_LOG}"
exit 3
fi

local WRAPPER="${DST}/serve_f2"
echo "Dropping f2 wrapper ${WRAPPER}..."
cat > "${WRAPPER}.go" <<EOF
package main
import (
"bufio"
"fmt"
"io"
"log"
"math"
"os"
"os/exec"
"strconv"
"strings"
)
func extract(line string, label string) (float64, bool, error) {
if match, found := strings.CutPrefix(line, fmt.Sprintf("%s: ", label)); found {
f, err := strconv.ParseFloat(match, 64)
if err != nil {
return 0, false, err
}
return f, true, nil
}
return 0, false, nil
}
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("READY:f2")
for {
fmt.Println("REF")
ref, err := reader.ReadString('\n')
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
fmt.Println("DIST")
dist, err := reader.ReadString('\n')
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
command := exec.Command("${PEAQ_BIN}", "-r", strings.TrimSpace(ref), "-t", strings.TrimSpace(dist))
output, err := command.CombinedOutput()
if err != nil {
log.Fatal(fmt.Errorf("when calling %v: %v\n%s", command, err, output))
}
adbSum := 0.0
avgModDiff1Sum := 0.0
count := 0
for _, line := range strings.Split(string(output), "\n") {
if f, found, err := extract(line, "ADBb"); err != nil {
log.Fatal(err)
} else if found {
count++
adbSum += f
}
if f, found, err := extract(line, "AvgModDiff1b"); err != nil {
log.Fatal(err)
} else if found {
avgModDiff1Sum += f
}
}
meanADB := adbSum / float64(count)
meanAvgModDiff1 := avgModDiff1Sum / float64(count)
fmt.Printf("SCORE=%f\n", 49.73 /
(1 + math.Pow(-0.0315 * meanAvgModDiff1 - 0.73,
2)) -46.95 * meanADB + 147.12)
}
}
EOF

( cd "${DST}" && go build "${WRAPPER}.go" ) > "${INSTALL_LOG}" 2>&1
Expand Down

0 comments on commit da5f245

Please sign in to comment.