#!/bin/bash

# Usage: source dataset_table.sh

TOTAL_IMAGES=$(cat $THERMAL_FACE_AUTOML | sort -u -t, -k1,2 | wc -l | bc)
TOTAL_ANNOTATIONS=$(cat $THERMAL_FACE_AUTOML | wc -l | bc)

TRAINING_COMBINED_IMAGES=$(cat $THERMAL_FACE_AUTOML | grep TRAIN | sort -u -t, -k1,2 | wc -l | bc)
TRAINING_COMBINED_ANNOTATIONS=$(cat $THERMAL_FACE_AUTOML | grep TRAIN | wc -l | bc)
VALIDATION_COMBINED_IMAGES=$(cat $THERMAL_FACE_AUTOML | grep VALIDATE | sort -u -t, -k1,2 | wc -l | bc)
VALIDATION_COMBINED_ANNOTATIONS=$(cat $THERMAL_FACE_AUTOML | grep VALIDATE | wc -l | bc)
TEST_COMBINED_IMAGES=$(cat $THERMAL_FACE_AUTOML | grep TEST | sort -u -t, -k1,2 | wc -l | bc)
TEST_COMBINED_ANNOTATIONS=$(cat $THERMAL_FACE_AUTOML | grep TEST | wc -l | bc)

TRAINING_FRACTION_COMBINED_IMAGES=$(echo "100 * $TRAINING_COMBINED_IMAGES / $TOTAL_IMAGES" | bc -l)
TRAINING_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * $TRAINING_COMBINED_ANNOTATIONS / $TOTAL_ANNOTATIONS" | bc -l)
VALIDATION_FRACTION_COMBINED_IMAGES=$(echo "100 * $VALIDATION_COMBINED_IMAGES / $TOTAL_IMAGES" | bc -l)
VALIDATION_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * $VALIDATION_COMBINED_ANNOTATIONS / $TOTAL_ANNOTATIONS" | bc -l)
TEST_FRACTION_COMBINED_IMAGES=$(echo "100 * $VALIDATION_COMBINED_IMAGES / $TOTAL_IMAGES" | bc -l)
TEST_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * $VALIDATION_COMBINED_ANNOTATIONS / $TOTAL_ANNOTATIONS" | bc -l)

TDFACE_TRAINING_IMAGES=$(cat $TDFACE_AUTOML | grep TRAIN | sort -u -t, -k1,2 | wc -l | bc)
TDFACE_TRAINING_ANNOTATIONS=$(cat $TDFACE_AUTOML | grep TRAIN | wc -l | bc)
TDFACE_VALIDATION_IMAGES=$(cat $TDFACE_AUTOML | grep VALIDATE | sort -u -t, -k1,2 | wc -l | bc)
TDFACE_VALIDATION_ANNOTATIONS=$(cat $TDFACE_AUTOML | grep VALIDATE | wc -l | bc)
TDFACE_TEST_IMAGES=$(cat $TDFACE_AUTOML | grep TEST | sort -u -t, -k1,2 | wc -l | bc)
TDFACE_TEST_ANNOTATIONS=$(cat $TDFACE_AUTOML | grep TEST | wc -l | bc)
TDFACE_TRAINING_FRACTION_SOURCE=$(echo "100 * $TDFACE_TRAINING_FRACTION" | bc -l)
TDFACE_VALIDATION_FRACTION_SOURCE=$(echo "100 * $TDFACE_VALIDATION_FRACTION" | bc -l)
TDFACE_TEST_FRACTION_SOURCE=$(echo "100 * $TDFACE_TEST_FRACTION" | bc -l)
TDFACE_TRAINING_FRACTION_COMBINED_IMAGES=$(echo "100 * ($TDFACE_TRAINING_IMAGES / $TRAINING_COMBINED_IMAGES)" | bc -l)
TDFACE_TRAINING_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($TDFACE_TRAINING_ANNOTATIONS / $TRAINING_COMBINED_ANNOTATIONS)" | bc -l)
TDFACE_VALIDATION_FRACTION_COMBINED_IMAGES=$(echo "100 * ($TDFACE_VALIDATION_IMAGES / $VALIDATION_COMBINED_IMAGES)" | bc -l)
TDFACE_VALIDATION_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($TDFACE_VALIDATION_ANNOTATIONS / $VALIDATION_COMBINED_ANNOTATIONS)" | bc -l)
TDFACE_TEST_FRACTION_COMBINED_IMAGES=$(echo "100 * ($TDFACE_TEST_IMAGES / $TEST_COMBINED_IMAGES)" | bc -l)
TDFACE_TEST_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($TDFACE_TEST_ANNOTATIONS / $TEST_COMBINED_ANNOTATIONS)" | bc -l)

FLIR_ADAS_TRAINING_IMAGES=$(cat $FLIR_ADAS_AUTOML | grep TRAIN | sort -u -t, -k1,2 | wc -l | bc)
FLIR_ADAS_TRAINING_ANNOTATIONS=$(cat $FLIR_ADAS_AUTOML | grep TRAIN | wc -l | bc)
FLIR_ADAS_VALIDATION_IMAGES=$(cat $FLIR_ADAS_AUTOML | grep VALIDATE | sort -u -t, -k1,2 | wc -l | bc)
FLIR_ADAS_VALIDATION_ANNOTATIONS=$(cat $FLIR_ADAS_AUTOML | grep VALIDATE | wc -l | bc)
FLIR_ADAS_TEST_IMAGES=$(cat $FLIR_ADAS_AUTOML | grep TEST | sort -u -t, -k1,2 | wc -l | bc)
FLIR_ADAS_TEST_ANNOTATIONS=$(cat $FLIR_ADAS_AUTOML | grep TEST | wc -l | bc)
FLIR_ADAS_TRAINING_FRACTION_SOURCE=$(echo "100 * $FLIR_ADAS_TRAINING_FRACTION" | bc -l)
FLIR_ADAS_VALIDATION_FRACTION_SOURCE=$(echo "100 * $FLIR_ADAS_VALIDATION_FRACTION" | bc -l)
FLIR_ADAS_TEST_FRACTION_SOURCE=$(echo "100 * $FLIR_ADAS_TEST_FRACTION" | bc -l)
FLIR_ADAS_TRAINING_FRACTION_COMBINED_IMAGES=$(echo "100 * ($FLIR_ADAS_TRAINING_IMAGES / $TRAINING_COMBINED_IMAGES)" | bc -l)
FLIR_ADAS_TRAINING_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($FLIR_ADAS_TRAINING_ANNOTATIONS / $TRAINING_COMBINED_ANNOTATIONS)" | bc -l)
FLIR_ADAS_VALIDATION_FRACTION_COMBINED_IMAGES=$(echo "100 * ($FLIR_ADAS_VALIDATION_IMAGES / $VALIDATION_COMBINED_IMAGES)" | bc -l)
FLIR_ADAS_VALIDATION_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($FLIR_ADAS_VALIDATION_ANNOTATIONS / $VALIDATION_COMBINED_ANNOTATIONS)" | bc -l)
FLIR_ADAS_TEST_FRACTION_COMBINED_IMAGES=$(echo "100 * ($FLIR_ADAS_TEST_IMAGES / $TEST_COMBINED_IMAGES)" | bc -l)
FLIR_ADAS_TEST_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($FLIR_ADAS_TEST_ANNOTATIONS / $TEST_COMBINED_ANNOTATIONS)" | bc -l)

WIDERFACE_VALIDATION_TRAINING_IMAGES=$(cat $WIDERFACE_VALIDATION_AUTOML | grep TRAIN | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_VALIDATION_TRAINING_ANNOTATIONS=$(cat $WIDERFACE_VALIDATION_AUTOML | grep TRAIN | wc -l | bc)
WIDERFACE_VALIDATION_VALIDATION_IMAGES=$(cat $WIDERFACE_VALIDATION_AUTOML | grep VALIDATE | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_VALIDATION_VALIDATION_ANNOTATIONS=$(cat $WIDERFACE_VALIDATION_AUTOML | grep VALIDATE | wc -l | bc)
WIDERFACE_VALIDATION_TEST_IMAGES=$(cat $WIDERFACE_VALIDATION_AUTOML | grep TEST | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_VALIDATION_TEST_ANNOTATIONS=$(cat $WIDERFACE_VALIDATION_AUTOML | grep TEST | wc -l | bc)
WIDERFACE_VALIDATION_TRAINING_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_VALIDATION_TRAINING_FRACTION" | bc -l)
WIDERFACE_VALIDATION_VALIDATION_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_VALIDATION_VALIDATION_FRACTION" | bc -l)
WIDERFACE_VALIDATION_TEST_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_VALIDATION_TEST_FRACTION" | bc -l)
WIDERFACE_VALIDATION_TRAINING_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_VALIDATION_TRAINING_IMAGES / $TRAINING_COMBINED_IMAGES)" | bc -l)
WIDERFACE_VALIDATION_TRAINING_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_VALIDATION_TRAINING_ANNOTATIONS / $TRAINING_COMBINED_ANNOTATIONS)" | bc -l)
WIDERFACE_VALIDATION_VALIDATION_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_VALIDATION_VALIDATION_IMAGES / $VALIDATION_COMBINED_IMAGES)" | bc -l)
WIDERFACE_VALIDATION_VALIDATION_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_VALIDATION_VALIDATION_ANNOTATIONS / $VALIDATION_COMBINED_ANNOTATIONS)" | bc -l)
WIDERFACE_VALIDATION_TEST_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_VALIDATION_TEST_IMAGES / $TEST_COMBINED_IMAGES)" | bc -l)
WIDERFACE_VALIDATION_TEST_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_VALIDATION_TEST_ANNOTATIONS / $TEST_COMBINED_ANNOTATIONS)" | bc -l)

WIDERFACE_TRAINING_TRAINING_IMAGES=$(cat $WIDERFACE_TRAINING_AUTOML | grep TRAIN | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_TRAINING_TRAINING_ANNOTATIONS=$(cat $WIDERFACE_TRAINING_AUTOML | grep TRAIN | wc -l | bc)
WIDERFACE_TRAINING_VALIDATION_IMAGES=$(cat $WIDERFACE_TRAINING_AUTOML | grep VALIDATE | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_TRAINING_VALIDATION_ANNOTATIONS=$(cat $WIDERFACE_TRAINING_AUTOML | grep VALIDATE | wc -l | bc)
WIDERFACE_TRAINING_TEST_IMAGES=$(cat $WIDERFACE_TRAINING_AUTOML | grep TEST | sort -u -t, -k1,2 | wc -l | bc)
WIDERFACE_TRAINING_TEST_ANNOTATIONS=$(cat $WIDERFACE_TRAINING_AUTOML | grep TEST | wc -l | bc)
WIDERFACE_TRAINING_TRAINING_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_TRAINING_TRAINING_FRACTION" | bc -l)
WIDERFACE_TRAINING_VALIDATION_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_TRAINING_VALIDATION_FRACTION" | bc -l)
WIDERFACE_TRAINING_TEST_FRACTION_SOURCE=$(echo "100 * $WIDERFACE_TRAINING_TEST_FRACTION" | bc -l)
WIDERFACE_TRAINING_TRAINING_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_TRAINING_TRAINING_IMAGES / $TRAINING_COMBINED_IMAGES)" | bc -l)
WIDERFACE_TRAINING_TRAINING_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_TRAINING_TRAINING_ANNOTATIONS / $TRAINING_COMBINED_ANNOTATIONS)" | bc -l)
WIDERFACE_TRAINING_VALIDATION_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_TRAINING_VALIDATION_IMAGES / $VALIDATION_COMBINED_IMAGES)" | bc -l)
WIDERFACE_TRAINING_VALIDATION_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_TRAINING_VALIDATION_ANNOTATIONS / $VALIDATION_COMBINED_ANNOTATIONS)" | bc -l)
WIDERFACE_TRAINING_TEST_FRACTION_COMBINED_IMAGES=$(echo "100 * ($WIDERFACE_TRAINING_TEST_IMAGES / $TEST_COMBINED_IMAGES)" | bc -l)
WIDERFACE_TRAINING_TEST_FRACTION_COMBINED_ANNOTATIONS=$(echo "100 * ($WIDERFACE_TRAINING_TEST_ANNOTATIONS / $TEST_COMBINED_ANNOTATIONS)" | bc -l)

cat << EOF

Total images (annotations): $(printf "%'.f" $TOTAL_IMAGES) ($(printf "%'.f" $TOTAL_ANNOTATIONS))

| | Training set | Validation set | Test set |
| -: | -: | -: | -: |
| **Tufts Face Database (IR)** | $(printf "%'.f" $TDFACE_TRAINING_IMAGES) ($(printf "%'.f" $TDFACE_TRAINING_ANNOTATIONS)) | $(printf "%'.f" $TDFACE_VALIDATION_IMAGES) ($(printf "%'.f" $TDFACE_VALIDATION_ANNOTATIONS)) | $(printf "%'.f" $TDFACE_TEST_IMAGES) ($(printf "%'.f" $TDFACE_TEST_ANNOTATIONS)) |
| _Fraction of source images_ | $(printf "%.f%%" $TDFACE_TRAINING_FRACTION_SOURCE) | $(printf "%.f%%" $TDFACE_VALIDATION_FRACTION_SOURCE) | $(printf "%.f%%" $TDFACE_TEST_FRACTION_SOURCE) |
| _Fraction of combined_ | $(printf "%.f%%" $TDFACE_TRAINING_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $TDFACE_TRAINING_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $TDFACE_VALIDATION_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $TDFACE_VALIDATION_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $TDFACE_TEST_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $TDFACE_TEST_FRACTION_COMBINED_ANNOTATIONS)) |
| **FLIR ADAS (Faces)** | $(printf "%'.f" $FLIR_ADAS_TRAINING_IMAGES) ($(printf "%'.f" $FLIR_ADAS_TRAINING_ANNOTATIONS)) | $(printf "%'.f" $FLIR_ADAS_VALIDATION_IMAGES) ($(printf "%'.f" $FLIR_ADAS_VALIDATION_ANNOTATIONS)) | $(printf "%'.f" $FLIR_ADAS_TEST_IMAGES) ($(printf "%'.f" $FLIR_ADAS_TEST_ANNOTATIONS)) |
| _Fraction of source images_ | $(printf "%.f%%" $FLIR_ADAS_TRAINING_FRACTION_SOURCE) | $(printf "%.f%%" $FLIR_ADAS_VALIDATION_FRACTION_SOURCE) | $(printf "%.f%%" $FLIR_ADAS_TEST_FRACTION_SOURCE) |
| _Fraction of combined_ | $(printf "%.f%%" $FLIR_ADAS_TRAINING_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $FLIR_ADAS_TRAINING_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $FLIR_ADAS_VALIDATION_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $FLIR_ADAS_VALIDATION_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $FLIR_ADAS_TEST_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $FLIR_ADAS_TEST_FRACTION_COMBINED_ANNOTATIONS)) |
| **WIDER FACE (Validation)** | $(printf "%'.f" $WIDERFACE_VALIDATION_TRAINING_IMAGES) ($(printf "%'.f" $WIDERFACE_VALIDATION_TRAINING_ANNOTATIONS)) | $(printf "%'.f" $WIDERFACE_VALIDATION_VALIDATION_IMAGES) ($(printf "%'.f" $WIDERFACE_VALIDATION_VALIDATION_ANNOTATIONS)) | $(printf "%'.f" $WIDERFACE_VALIDATION_TEST_IMAGES) ($(printf "%'.f" $WIDERFACE_VALIDATION_TEST_ANNOTATIONS)) |
| _Fraction of source images_ | $(printf "%.f%%" $WIDERFACE_VALIDATION_TRAINING_FRACTION_SOURCE) | $(printf "%.f%%" $WIDERFACE_VALIDATION_VALIDATION_FRACTION_SOURCE) | $(printf "%.f%%" $WIDERFACE_VALIDATION_TEST_FRACTION_SOURCE) |
| _Fraction of combined_ | $(printf "%.f%%" $WIDERFACE_VALIDATION_TRAINING_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_VALIDATION_TRAINING_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $WIDERFACE_VALIDATION_VALIDATION_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_VALIDATION_VALIDATION_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $WIDERFACE_VALIDATION_TEST_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_VALIDATION_TEST_FRACTION_COMBINED_ANNOTATIONS)) |
| **WIDER FACE (Training)** | $(printf "%'.f" $WIDERFACE_TRAINING_TRAINING_IMAGES) ($(printf "%'.f" $WIDERFACE_TRAINING_TRAINING_ANNOTATIONS)) | $(printf "%'.f" $WIDERFACE_TRAINING_VALIDATION_IMAGES) ($(printf "%'.f" $WIDERFACE_TRAINING_VALIDATION_ANNOTATIONS)) | $(printf "%'.f" $WIDERFACE_TRAINING_TEST_IMAGES) ($(printf "%'.f" $WIDERFACE_TRAINING_TEST_ANNOTATIONS)) |
| _Fraction of source images_ | $(printf "%.f%%" $WIDERFACE_TRAINING_TRAINING_FRACTION_SOURCE) | $(printf "%.f%%" $WIDERFACE_TRAINING_VALIDATION_FRACTION_SOURCE) | $(printf "%.f%%" $WIDERFACE_TRAINING_TEST_FRACTION_SOURCE) |
| _Fraction of combined_ | $(printf "%.f%%" $WIDERFACE_TRAINING_TRAINING_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_TRAINING_TRAINING_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $WIDERFACE_TRAINING_VALIDATION_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_TRAINING_VALIDATION_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $WIDERFACE_TRAINING_TEST_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $WIDERFACE_TRAINING_TEST_FRACTION_COMBINED_ANNOTATIONS)) |
| **_Combined_** | $(printf "%'.f" $TRAINING_COMBINED_IMAGES) ($(printf "%'.f" $TRAINING_COMBINED_ANNOTATIONS)) | $(printf "%'.f" $VALIDATION_COMBINED_IMAGES) ($(printf "%'.f" $VALIDATION_COMBINED_ANNOTATIONS)) | $(printf "%'.f" $TEST_COMBINED_IMAGES) ($(printf "%'.f" $TEST_COMBINED_ANNOTATIONS)) |
| _Fraction of combined sources_ | $(printf "%.f%%" $TRAINING_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $TRAINING_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $VALIDATION_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $VALIDATION_FRACTION_COMBINED_ANNOTATIONS)) | $(printf "%.f%%" $TEST_FRACTION_COMBINED_IMAGES) ($(printf "%.f%%" $TEST_FRACTION_COMBINED_ANNOTATIONS)) |

EOF
