added project 2
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Directory structure
|
||||
CHALLENGE_DIR=~/challenge
|
||||
TRACKING_DIR="$CHALLENGE_DIR/.tracking"
|
||||
DATA_DIR="$TRACKING_DIR/data"
|
||||
REPORT_DIR="$TRACKING_DIR/reports"
|
||||
|
||||
# Data files
|
||||
PROGRESS_FILE="$DATA_DIR/progress.csv"
|
||||
SCORE_FILE="$DATA_DIR/score.csv"
|
||||
LOG_FILE="$DATA_DIR/challenge.log"
|
||||
COMMAND_LOG="$DATA_DIR/commands.log"
|
||||
TIME_LOG="$DATA_DIR/time.log"
|
||||
HINT_FILE="$DATA_DIR/hints_used.csv"
|
||||
ACHIEVEMENT_FILE="$DATA_DIR/achievements.csv"
|
||||
ATTEMPT_FILE="$DATA_DIR/attempts.csv"
|
||||
SKILL_FILE="$DATA_DIR/skills.csv"
|
||||
|
||||
# Formatting
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Achievement definitions with categories
|
||||
declare -A ACHIEVEMENTS=(
|
||||
# Speed achievements
|
||||
["speed_demon"]="Complete any challenge in under 1 minute|speed"
|
||||
["speed_runner"]="Complete 3 challenges in under 5 minutes|speed"
|
||||
|
||||
# Efficiency achievements
|
||||
["efficiency_expert"]="Complete a challenge using minimal commands|efficiency"
|
||||
["command_master"]="Use advanced command options|efficiency"
|
||||
|
||||
# Learning achievements
|
||||
["self_learner"]="Complete without hints|learning"
|
||||
["persistent"]="Try until success|learning"
|
||||
["explorer"]="Try multiple solution approaches|learning"
|
||||
|
||||
# Skill achievements
|
||||
["file_master"]="Master file operations|skill"
|
||||
["permission_guru"]="Master permission management|skill"
|
||||
["search_expert"]="Master file searching|skill"
|
||||
)
|
||||
|
||||
# Skill tracking definitions
|
||||
declare -A SKILLS=(
|
||||
["file_ops"]="File Operations"
|
||||
["permissions"]="Permission Management"
|
||||
["search"]="File Search and Analysis"
|
||||
["text_proc"]="Text Processing"
|
||||
["monitoring"]="System Monitoring"
|
||||
)
|
||||
|
||||
# Logging function with severity levels
|
||||
log_message() {
|
||||
local severity=$1
|
||||
local message=$2
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
local color
|
||||
|
||||
case $severity in
|
||||
"INFO") color=$BLUE ;;
|
||||
"SUCCESS") color=$GREEN ;;
|
||||
"WARNING") color=$YELLOW ;;
|
||||
"ERROR") color=$RED ;;
|
||||
*) color=$NC ;;
|
||||
esac
|
||||
|
||||
echo -e "${color}[$severity]${NC} $message"
|
||||
echo "[$timestamp] [$severity] $message" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Initialize environment with comprehensive setup
|
||||
init_environment() {
|
||||
log_message "INFO" "Initializing enhanced challenge environment..."
|
||||
|
||||
# Create directory structure
|
||||
for dir in "$DATA_DIR" "$REPORT_DIR" "$CHALLENGE_DIR"/{files,backup,temp}; do
|
||||
if ! mkdir -p "$dir"; then
|
||||
log_message "ERROR" "Failed to create directory: $dir"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Initialize data files with headers
|
||||
cat > "$PROGRESS_FILE" << EOF
|
||||
challenge_id,timestamp,status,difficulty,skills_used
|
||||
EOF
|
||||
|
||||
cat > "$SCORE_FILE" << EOF
|
||||
challenge_id,points,timestamp,efficiency_bonus,speed_bonus
|
||||
EOF
|
||||
|
||||
cat > "$ATTEMPT_FILE" << EOF
|
||||
challenge_id,attempt_number,timestamp,commands_used,duration,success
|
||||
EOF
|
||||
|
||||
cat > "$SKILL_FILE" << EOF
|
||||
skill_id,level,experience,last_used
|
||||
EOF
|
||||
|
||||
# Initialize skills
|
||||
for skill in "${!SKILLS[@]}"; do
|
||||
echo "$skill,1,0,0" >> "$SKILL_FILE"
|
||||
done
|
||||
|
||||
setup_command_tracking
|
||||
log_message "SUCCESS" "Environment initialized successfully"
|
||||
}
|
||||
|
||||
# Enhanced command tracking
|
||||
setup_command_tracking() {
|
||||
local track_cmd='
|
||||
command_status=$?
|
||||
cmd=$(history 1 | cut -c 8-)
|
||||
timestamp=$(date +%s)
|
||||
echo "$timestamp|$command_status|$cmd" >> '"$COMMAND_LOG"'
|
||||
analyze_command "$cmd"
|
||||
'
|
||||
|
||||
if ! grep -q "PROMPT_COMMAND" ~/.bashrc; then
|
||||
echo "PROMPT_COMMAND='$track_cmd'" >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
fi
|
||||
}
|
||||
|
||||
# Command analysis for skill progression
|
||||
analyze_command() {
|
||||
local cmd=$1
|
||||
case "$cmd" in
|
||||
*find*) update_skill "search" 2 ;;
|
||||
*chmod*|*chown*) update_skill "permissions" 2 ;;
|
||||
*grep*|*sed*|*awk*) update_skill "text_proc" 2 ;;
|
||||
*ps*|*top*|*netstat*) update_skill "monitoring" 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Update skill progression
|
||||
update_skill() {
|
||||
local skill=$1
|
||||
local exp_gain=$2
|
||||
local current_level current_exp
|
||||
|
||||
IFS=, read -r _ current_level current_exp _ < <(grep "^$skill," "$SKILL_FILE")
|
||||
|
||||
current_exp=$((current_exp + exp_gain))
|
||||
if [ $current_exp -ge $((current_level * 100)) ]; then
|
||||
current_level=$((current_level + 1))
|
||||
current_exp=0
|
||||
log_message "SUCCESS" "🎓 Skill Level Up: ${SKILLS[$skill]} is now level $current_level!"
|
||||
fi
|
||||
|
||||
sed -i "/^$skill,/c\\$skill,$current_level,$current_exp,$(date +%s)" "$SKILL_FILE"
|
||||
}
|
||||
|
||||
# Enhanced progress tracking with recommendations
|
||||
show_progress() {
|
||||
clear
|
||||
echo -e "\n${BOLD}🎮 Challenge Progress Report${NC}"
|
||||
echo "=============================="
|
||||
|
||||
# Show statistics
|
||||
show_statistics
|
||||
|
||||
# Show achievements by category
|
||||
show_achievements
|
||||
|
||||
# Show skill progression
|
||||
show_skills
|
||||
|
||||
# Show recommendations
|
||||
show_recommendations
|
||||
}
|
||||
|
||||
# Detailed statistics display
|
||||
show_statistics() {
|
||||
local total_score=0
|
||||
local challenges_completed=0
|
||||
|
||||
while IFS=, read -r challenge points _ efficiency_bonus speed_bonus; do
|
||||
[ -z "$challenge" ] && continue
|
||||
total_score=$((total_score + points + ${efficiency_bonus:-0} + ${speed_bonus:-0}))
|
||||
((challenges_completed++))
|
||||
done < "$SCORE_FILE"
|
||||
|
||||
echo -e "\n${BOLD}📊 Statistics${NC}"
|
||||
echo "----------------"
|
||||
printf "Challenges Completed: %d/10\n" "$challenges_completed"
|
||||
printf "Total Score: %d/1500\n" "$total_score"
|
||||
printf "Average Score: %d\n" "$((total_score / (challenges_completed || 1)))"
|
||||
}
|
||||
|
||||
# Achievement display by category
|
||||
show_achievements() {
|
||||
echo -e "\n${BOLD}🏆 Achievements${NC}"
|
||||
echo "----------------"
|
||||
|
||||
local categories=("speed" "efficiency" "learning" "skill")
|
||||
|
||||
for category in "${categories[@]}"; do
|
||||
echo -e "\n${YELLOW}${category^} Achievements:${NC}"
|
||||
while IFS=, read -r achievement timestamp description; do
|
||||
[ -z "$achievement" ] && continue
|
||||
IFS='|' read -r achievement_desc achievement_cat <<< "${ACHIEVEMENTS[$achievement]}"
|
||||
[[ "$achievement_cat" == "$category" ]] && echo " ✓ $achievement_desc"
|
||||
done < "$ACHIEVEMENT_FILE"
|
||||
done
|
||||
}
|
||||
|
||||
# Skill progression display
|
||||
show_skills() {
|
||||
echo -e "\n${BOLD}🎓 Skills${NC}"
|
||||
echo "----------------"
|
||||
|
||||
while IFS=, read -r skill level exp last_used; do
|
||||
[ -z "$skill" ] && continue
|
||||
local skill_name="${SKILLS[$skill]}"
|
||||
local progress=$((exp * 100 / (level * 100)))
|
||||
printf "%s (Level %d): [%-20s] %d%%\n" \
|
||||
"$skill_name" "$level" \
|
||||
"$(printf '#%.0s' $(seq 1 $((progress / 5))))" \
|
||||
"$progress"
|
||||
done < "$SKILL_FILE"
|
||||
}
|
||||
|
||||
# Learning recommendations
|
||||
show_recommendations() {
|
||||
echo -e "\n${BOLD}📚 Recommendations${NC}"
|
||||
echo "----------------"
|
||||
|
||||
# Analyze weak skills
|
||||
local weakest_skill=""
|
||||
local lowest_level=999
|
||||
|
||||
while IFS=, read -r skill level _; do
|
||||
[ -z "$skill" ] && continue
|
||||
if [ "$level" -lt "$lowest_level" ]; then
|
||||
lowest_level=$level
|
||||
weakest_skill=$skill
|
||||
fi
|
||||
done < "$SKILL_FILE"
|
||||
|
||||
[ -n "$weakest_skill" ] && echo "Focus on improving: ${SKILLS[$weakest_skill]}"
|
||||
|
||||
# Suggest next challenges based on skill levels
|
||||
echo "Recommended next challenges:"
|
||||
suggest_challenges
|
||||
}
|
||||
|
||||
# Check if challenge is completed
|
||||
is_challenge_completed() {
|
||||
local challenge=$1
|
||||
grep -q "^$challenge," "$SCORE_FILE" && return 0
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user