Created
April 18, 2018 03:34
-
-
Save mikefaille/edf626790a0c35d50482035c2b04fd29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -A SEASON_COUNTER | |
for fn in `cat comptagevelo2009-20162.csv`; do | |
RAW_BIKE_COUNTER=$(echo $fn | awk -F '/' '{print $3}' | cut -b 12-) | |
MY_DATE_STR=$(cut --output-delimiter=" " -f 3,2,1 -d '/' <(echo $fn | head -c 10) ) | |
MY_DATE=($MY_DATE_STR) | |
YEAR=${MY_DATE[2]} | |
MONTH=${MY_DATE[1]} | |
DAY=${MY_DATE[0]} | |
_DAY_OF_YEAR=$(date --date="$YEAR-$MONTH-$DAY 00:00:00" "+%j") | |
# Force base 10. | |
#Date command return leading 0 | |
DAY_OF_YEAR=10#$_DAY_OF_YEAR | |
SEASON="" | |
if (( 80 <= $DAY_OF_YEAR && $DAY_OF_YEAR <= 171 )); then | |
SEASON="spring" | |
elif (( 172 <= $DAY_OF_YEAR && $DAY_OF_YEAR <= 265 )) ; then | |
SEASON="summer" | |
elif (( 266 <= $DAY_OF_YEAR && $DAY_OF_YEAR <= 354 )) ; then | |
SEASON="autumn" | |
else | |
SEASON="winter" | |
fi | |
LINE_BIKE_COUNT=$(echo $RAW_BIKE_COUNTER | awk -F',' '{s+=$1} END {print s}') | |
# echo $SEASON | |
SEASON_COUNTER[$SEASON]=$((${SEASON_COUNTER[$SEASON]} + ${LINE_BIKE_COUNT})) | |
done | |
echo spring : ${SEASON_COUNTER["spring"]} | |
echo summer : ${SEASON_COUNTER["summer"]} | |
echo autumn : ${SEASON_COUNTER["autumn"]} | |
echo winter : ${SEASON_COUNTER["winter"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment