| #!/usr/bin/env bash |
|
|
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")" |
|
|
| die() { |
| echo "(E) ${@}" 1>&2 |
| exit 1 |
| } |
|
|
| warn() { |
| echo "(W) ${@}" 1>&2 |
| } |
|
|
| info() { |
| |
| [ -n ${QUIET:-""} ] || echo "(I) ${@}" 1>&2 |
| } |
|
|
| |
| DATA_DIR="/Volume1/AI4CODE/CodeNet_AIZU" |
| MODE=all |
| QUIET= |
|
|
| for i in "$@" |
| do |
| case $i in |
| -h|--help) |
| echo "Usage: ${SCRIPT_NAME} [-hq] [-d=dir] [-m=mode]" |
| echo -e " -d|--data:\tpath to the dataset directory" |
| echo -e " -h|--help:\tshow this brief usage summary" |
| echo -e " -m|--mode:\trun in certain checking mode" |
| echo -e " -q|--quiet:\tsuppress informational messages" |
| echo |
| echo "Option defaults are (empty means not in effect):" |
| echo -e " -d:\t${DATA_DIR}" |
| echo -e " -m:\t${MODE}" |
| echo -e " -q:\t${QUIET}" |
| echo |
| echo "Verifies the integrity of the dataset:" |
| echo "makes sure that metadata and data correspond." |
| echo "The available mode options are: metada, data, or all (default)." |
| exit 2 |
| ;; |
| -d=*|--data=*) |
| DATA_DIR="${i#*=}" |
| shift |
| ;; |
| -m=*|--mode=*) |
| MODE="${i#*=}" |
| shift |
| ;; |
| -q|--quiet) |
| QUIET=1 |
| shift |
| ;; |
| *) |
| break; |
| ;; |
| esac |
| done |
| if [[ -n ${1:-""} ]]; then |
| warn "trailing non-option arguments are ignored" |
| fi |
|
|
| |
| [ -d "${DATA_DIR}" ] || die "Expect dataset directory ${DATA_DIR}" |
| |
| for dir in "data" "metadata" "problem_descriptions"; do |
| [ -d "${DATA_DIR}/${dir}" ] || die "Expect directory ${DATA_DIR}/${dir}" |
| done |
|
|
| info "Script '${SCRIPT_NAME}' parameters:" |
| info "Check mode : ${MODE}" |
| info "Dataset dir.: ${DATA_DIR}" |
|
|
| |
| DATA="${DATA_DIR}/data" |
| METADATA="${DATA_DIR}/metadata" |
| DESCRIPTIONS="${DATA_DIR}/problem_descriptions" |
|
|
| check_metadata() |
| { |
| |
| HEADER="id,name,dataset,time_limit,memory_limit,rating,tags,complexity,original_id,original_contest_id" |
| |
| |
|
|
| info "Checking problem metadata" |
|
|
| PROBLEM_CSV="${METADATA}/problem_list.csv" |
| |
| [ -f "${PROBLEM_CSV}" ] || \ |
| die "missing metadata CSV file ${PROBLEM_CSV}" |
|
|
| info "Processing ${PROBLEM_CSV}" |
|
|
| |
| |
| { |
| read -r header |
| |
| header="${header%$'\r'}" |
| |
| [ "${header}" == "${HEADER}" ] || \ |
| warn "incorrect CSV header: ${header}" |
|
|
| while IFS=, read -a line; do |
| |
| id=${line[0]} |
|
|
| |
| [ -f "${METADATA}/${id}.csv" ] || \ |
| warn "missing metadata CSV file for problem ${id}" |
|
|
| |
| [ -d "${DATA}/${id}" ] || \ |
| warn "missing data directory for problem ${id}" |
| done |
| } < "${PROBLEM_CSV}" |
|
|
| |
| |
| HEADER="submission_id,problem_id,user_id,date,language,original_language,filename_ext,status,cpu_time,memory,code_size,accuracy,original_submission_id,original_problem_id,original_contest_id" |
| |
| |
|
|
| info "Checking whether all source files mentioned in metadata exist" |
|
|
| |
| for SUBMISSIONS_CSV in ${METADATA}/p?????.csv; do |
|
|
| info "Processing ${SUBMISSIONS_CSV}" |
|
|
| |
| problem="${SUBMISSIONS_CSV: -10}" |
| problem="${problem:0:6}" |
|
|
| |
| [ -f "${DESCRIPTIONS}/${problem}.html" ] || \ |
| warn "missing HTML description for ${problem}" |
|
|
| |
| [ -d "${DATA}/${problem}" ] || \ |
| warn "missing directory for ${problem}" |
|
|
| |
| |
| { |
| read -r header |
| |
| header="${header%$'\r'}" |
| |
| [ "${header}" == "${HEADER}" ] || \ |
| die "incorrect CSV header: ${header}" |
|
|
| while IFS=, read -a line; do |
| |
| submission_id=${line[0]} |
| problem_id=${line[1]} |
| language=${line[4]} |
| filename_ext=${line[6]} |
| status=${line[7]} |
|
|
| |
| [ "${status}" != "" ] || \ |
| warn "unexpected empty status" |
| |
| [ "${problem_id}" == "${problem}" ] || \ |
| warn "problem filename ${problem} and id ${problem_id} mismatch" |
| |
| subdir="${DATA}/${problem_id}/${language}" |
| [ -d "${subdir}" ] || \ |
| warn "missing directory ${language} for ${problem_id}" |
| |
| file="${subdir}/${submission_id}.${filename_ext}" |
| [ -f "${file}" ] || \ |
| warn "missing submission ${subdir}/${file}" |
| done |
| } < "${SUBMISSIONS_CSV}" |
| done |
| } |
|
|
| |
|
|
| check_data() |
| { |
| info "Checking whether all source files are mentioned in the metadata" |
|
|
| |
|
|
| |
| shopt -s nullglob |
|
|
| num_incorrect_code_size=0 |
| |
| |
| pushd "${DATA}" >/dev/null |
| for problem_id in *; do |
| info "Processing submissions for problem ${problem_id}" |
| |
| csv="${METADATA}/${problem_id}.csv" |
| pushd "${problem_id}" >/dev/null |
| for language in *; do |
| info "Processing submissions for language ${language}" |
| pushd "${language}" >/dev/null |
| for submission in *; do |
| |
| |
| submission_id="${submission%.*}" |
| filename_ext="${submission##*\.}" |
|
|
| |
| record=$(fgrep "${submission_id}," ${csv}) |
| if [ $? != 0 ]; then |
| warn "missing submission ${submission} in ${problem_id}.csv metadata" |
| continue |
| fi |
|
|
| |
| |
| |
|
|
| |
| IFS=, read -a line < <(echo "${record}") |
|
|
| |
| [ "${line[1]}" == "${problem_id}" ] || \ |
| warn "${problem_id}.csv,${submission_id}: problem id mismatch; expect ${problem_id}, got ${line[1]}" |
| |
| [ "${line[4]}" == "${language}" ] || \ |
| warn "${problem_id}.csv,${submission_id}: language mismatch; expect ${language}, got ${line[4]}" |
| |
| |
| |
| |
| |
| size=$(stat -c %s "${submission}") |
| [ "${line[10]}" == "${size}" ] || \ |
| warn "${problem_id}.csv,${submission}: code size mismatch; expect ${size}, got ${line[10]}" |
| [ "${line[10]}" == "${size}" ] || ((num_incorrect_code_size++)) |
| |
| if [ $(head -n1 "${submission}"|cat -e|grep -c -m1 -P '(?<!M-)\^M\$$') == 1 ]; then |
| warn "${problem_id}.csv,${submission}: has DOS line endings" |
| fi |
| done |
| popd >/dev/null |
| done |
| popd >/dev/null |
| done |
| popd >/dev/null |
|
|
| [ "${num_incorrect_code_size}" -gt 0 ] && \ |
| warn "cases with incorrect code size: ${num_incorrect_code_size}" |
| } |
|
|
| if [ "${MODE}" == "metadata" ] || [ "${MODE}" == "all" ]; then |
| check_metadata |
| fi |
| if [ "${MODE}" == "data" ] || [ "${MODE}" == "all" ]; then |
| check_data |
| fi |
|
|