Skip to content

Instantly share code, notes, and snippets.

@raffifu
Created July 4, 2023 03:42
Show Gist options
  • Save raffifu/58dc1d368e76957178dd7347bc731335 to your computer and use it in GitHub Desktop.
Save raffifu/58dc1d368e76957178dd7347bc731335 to your computer and use it in GitHub Desktop.
Calculated the detail of transkrip nilai from Simaster
#!/bin/bash
################################################################################
# recap_nilai.sh
# Description: Show detail of Transkrip Nilai download from Simaster
# Requirements: poppler-utils package
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
declare -A dict_nilai
dict_nilai["A"]=4
dict_nilai["B"]=3
dict_nilai["C"]=2
dict_nilai["D"]=1
dict_nilai["E"]=0
function translate_nilai() {
base=${1::1}
addi=${1:1:1}
if [ -z $addi ]; then
echo ${dict_nilai["$base"]}
return
fi
operator="$addi"
value="0.25"
if [ $addi = "/" ]; then
operator="-"
value="0.5"
fi
echo "${dict_nilai["$base"]} $operator $value" | bc
}
if [ $# -ne 1 ]; then
echo "Usage: $0 [Transkrip Nilai]"
exit 1
fi
filename="$1"
total_sks=0
total_nilai=0
declare -A obj_resume
if ! [ -f "$filename" ]; then
echo "File Not exist"
exit 1
fi
for line in $(pdftotext -layout "$filename" -); do
if [[ $line = "=" ]]; then
break
elif [[ $line =~ [1-9]\.00 ]]; then
current_sks=$line
elif [[ $line =~ ^[A-E](\/[B-E]|[+-])?$ ]]; then
[ -v obj_resume["$line"] ] || obj_resume["$line"]=0
obj_resume["$line"]=$(echo "${obj_resume["$line"]} + $current_sks" | bc)
total_sks=$(echo "$total_sks + $current_sks" | bc)
fi
done
echo "RINCIAN SKS"
echo "================="
for key in "${!obj_resume[@]}"; do
echo "Total Nilai $key: ${obj_resume["$key"]} SKS"
total_nilai=$(echo "$total_nilai + `translate_nilai "$key"` * ${obj_resume["$key"]}" | bc)
done
ip=$(echo "scale=2; $total_nilai / $total_sks" | bc)
echo "================="
echo "Total SKS: $total_sks"
echo "Calculated IP: $ip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment