<commit_before>#! /bin/bash
# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of fiware-cosmos.
#
# fiware-cosmos is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# fiware-cosmos 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 Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with fiware-cosmos. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# francisco dot romerobueno at telefonica dot com

# Show the usage
if [ $# -ne 5 ]; then
        echo "Usage: ./get_user_stats.sh <db_host> <db_port> <db_name> <db_user> <db_password>"
        exit 1;
fi

# Arguments
dbHost=$1
dbPort=$2
dbName=$3
dbUser=$4
dbPassword=$5

// From string to number months converter
// $1 --> month to be converted
convert_month() {
	local month_str=$1

	case $month_str in 
                Jan )
                        return 1
			;;
                Feb )
                        return 2
			;;
		Mar )
			return 3
			;;
		Apr )
			return 4
			;;
		May )
			return 5
			;;
		Jun )
			return 6
			;;
		Jul )
			return 7
			;;
		Ago )
			return 8
			;;
		Sep )
			return 9
			;;
		Oct )
			return 10
			;;
		Nov )
			return 11
			;;
		Dec )
			return 12
			;;
	esac
}

// Per username iteration
while read -r username; do
	// Get the last access time
	last_result=$(last -R $username | head -n1)
	year=$(date | awk '{ print $6 }')
	convert_month $(echo $last_result | awk '{ print $4 }')
	month=$?
	day=$(echo $last_result | awk '{ print $5 }')
	hour_minute=$(echo $last_result | awk '{ print $6 }')
	last_access_time=$(echo $year-$month-$day $hour_minute:00)
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set last_access_time='$last_access_time' where username='$username'"

	// Get the local file system size
	fs_du_result=$(du -chb /home/$username | grep total | awk '{ print $1 }')
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set fs_used='$fs_du_result' where username='$username'"

	// Get the HDFS size
	hdfs_du_result=$(hadoop fs -dus /user/$username | awk '{ print $2 }')
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set hdfs_used='$hdfs_du_result' where username='$username'"
done < <(mysql $dbName -u $dbUser -p$dbPassword -se "select username from cosmos_user")
<commit_msg>FIX the comments on get_user_stats.sh<commit_after>#! /bin/bash
# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of fiware-cosmos.
#
# fiware-cosmos is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# fiware-cosmos 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 Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with fiware-cosmos. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# francisco dot romerobueno at telefonica dot com

# Show the usage
if [ $# -ne 5 ]; then
        echo "Usage: ./get_user_stats.sh <db_host> <db_port> <db_name> <db_user> <db_password>"
        exit 1;
fi

# Arguments
dbHost=$1
dbPort=$2
dbName=$3
dbUser=$4
dbPassword=$5

# From string to number months converter
# $1 --> month to be converted
convert_month() {
	local month_str=$1

	case $month_str in 
                Jan )
                        return 1
			;;
                Feb )
                        return 2
			;;
		Mar )
			return 3
			;;
		Apr )
			return 4
			;;
		May )
			return 5
			;;
		Jun )
			return 6
			;;
		Jul )
			return 7
			;;
		Ago )
			return 8
			;;
		Sep )
			return 9
			;;
		Oct )
			return 10
			;;
		Nov )
			return 11
			;;
		Dec )
			return 12
			;;
	esac
}

# Per username iteration
while read -r username; do
	# Get the last access time
	last_result=$(last -R $username | head -n1)
	year=$(date | awk '{ print $6 }')
	convert_month $(echo $last_result | awk '{ print $4 }')
	month=$?
	day=$(echo $last_result | awk '{ print $5 }')
	hour_minute=$(echo $last_result | awk '{ print $6 }')
	last_access_time=$(echo $year-$month-$day $hour_minute:00)
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set last_access_time='$last_access_time' where username='$username'"

	# Get the local file system size
	fs_du_result=$(du -chb /home/$username | grep total | awk '{ print $1 }')
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set fs_used='$fs_du_result' where username='$username'"

	# Get the HDFS size
	hdfs_du_result=$(hadoop fs -dus /user/$username | awk '{ print $2 }')
	mysql $dbName -u $dbUser -p$dbPassword -se "update cosmos_user set hdfs_used='$hdfs_du_result' where username='$username'"
done < <(mysql $dbName -u $dbUser -p$dbPassword -se "select username from cosmos_user")

{'fraction_non_alphanumeric': 0.11011687363038715, 'fraction_numerical': 0.013878743608473338, 'mean_word_length': 3.093423019431988, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4126688', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1770, 'n_words': 652}