-
Notifications
You must be signed in to change notification settings - Fork 1
/
showZoningDistribution.sh
executable file
·116 lines (106 loc) · 2.24 KB
/
showZoningDistribution.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
if [[ $# -lt 1 ]]; then
echo >&2 "$0 <seed>-<size>"
exit 1
fi
BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
simplifyZone() {
in="$1"
case "$in" in
"commercial downtown industrial")
echo "Commercial/Industrial"
;;
"downtown residentialnew")
echo "Residential"
;;
"downtown residentialnew residentialold")
echo "Residential"
;;
"residentialnew residentialold")
echo "Residential"
;;
"downtown resdentialold residentialnew")
echo "Residential"
;;
"commercial downtown")
echo "Commercial"
;;
"residentialnew")
echo "Residential"
;;
"industrial residentialnew residentialold")
echo "Industrial/Residential"
;;
"industrial residential")
echo "Industrial/Residential"
;;
"nozone")
echo "Wilderness"
;;
"residentialold")
echo "Residential"
;;
"industrial residentialold")
echo "Industrial/Residential"
;;
"commercial residentialnew")
echo "Commercial/Residential"
;;
"")
echo "Wilderness"
;;
*)
echo "${in^}"
;;
esac
}
getZone() {
"${BIN}/zoning.sh" "$1" | \
cut -d $'\t' -f 1 | \
tr -d ' ' | \
tr '[:upper:]' '[:lower:]' | \
tr ',' $'\n' | \
sort | \
xargs
}
printStats() {
declare -A ZONE
declare -A COUNT
declare TOTAL XML prefab zone sortedZones
XML="$1"
TOTAL=0
mapfile -t < <(xmlstarlet sel -t -m "/prefabs/decoration" -v "@name" -n - <<< "$XML")
for prefab in "${MAPFILE[@]}"; do
if [[ -n ${ZONE["$prefab"]+abc} ]]; then
zone="${ZONE["$prefab"]}"
else
zone="$(getZone "$prefab")"
zone="$(simplifyZone "$zone")"
ZONE["$prefab"]="$zone"
fi
TOTAL=$((TOTAL + 1))
COUNT["$zone"]=$((${COUNT["$zone"]:-0} + 1))
done
mapfile -t sortedZones < <(printf "%s\n" "${!COUNT[@]}" | sort)
for zone in "${sortedZones[@]}"; do
printf "%s\t%2d%%\n" "$zone" $((${COUNT["$zone"]} * 100 / TOTAL))
done
}
for name; do
FILE="${name%.xml}.xml"
if [[ -f "$FILE" ]]; then
XML="$(< "$FILE" )"
elif [[ -n "${F7D2D:+yes}" && -f "${F7D2D}/previews/$name.zip" ]]; then
XML="$(unzip -qq -c "${F7D2D}/previews/$name.zip" "${FILE}")"
else
echo >&2 "$FILE not found"
continue
fi
if [[ -t 1 ]]; then
printStats "$XML" | column -t -s $'\t'
else
printStats "$XML"
fi
done