+bettercounter-cli
This commit is contained in:
parent
9b3ec9abc9
commit
6d016145d4
3 changed files with 134 additions and 0 deletions
3
bettercounter-cli/README.md
Normal file
3
bettercounter-cli/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Better Counter CLI
|
||||||
|
Cette application sert à afficher, en ligne de commande (CLI), les données exportées par l'application Android BetterCounter (fichier .csv).
|
||||||
|
Il suffit simplement d'indiquer le chemin dans le script (variable `original_file` en début de script).
|
127
bettercounter-cli/bettercounter-cli.sh
Executable file
127
bettercounter-cli/bettercounter-cli.sh
Executable file
|
@ -0,0 +1,127 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Chemin vers le fichier CSV original
|
||||||
|
original_file="exemple.csv"
|
||||||
|
# Nom du fichier temporaire pour traitement
|
||||||
|
temp_file="temp.csv"
|
||||||
|
|
||||||
|
# Créer une copie du fichier original
|
||||||
|
cp "$original_file" "$temp_file"
|
||||||
|
|
||||||
|
# Ajouter une virgule à la fin de chaque ligne du fichier copié, uniquement si elle n'existe pas déjà
|
||||||
|
awk '{if (substr($0,length,1) != ",") print $0","; else print $0;}' "$temp_file" > "${temp_file}.tmp"
|
||||||
|
mv "${temp_file}.tmp" "$temp_file"
|
||||||
|
|
||||||
|
# Fonction pour convertir un timestamp en date
|
||||||
|
convert_to_date() {
|
||||||
|
local timestamp_ms=$1
|
||||||
|
#date -d @"$((timestamp_ms / 1000))" +"%Y-%m-%d %H:%M:%S"
|
||||||
|
date -d @"$((timestamp_ms / 1000))" +"%d/%m/%Y %H:%M"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fonction pour afficher une boîte ASCII
|
||||||
|
ascii_box() {
|
||||||
|
local box_text="$1"
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
local color="\033[1;34m" # Bleu gras
|
||||||
|
local reset="\033[0m" # Réinitialisation de la couleur
|
||||||
|
|
||||||
|
# Définir la largeur de la boîte (en fonction de la taille du texte)
|
||||||
|
local box_width=$(( ${#box_text} + 4 )) # Ajouter 4 pour les marges
|
||||||
|
|
||||||
|
# Calculer le positionnement du texte (centré)
|
||||||
|
local padding=2 # On ajoute 2 espaces de chaque côté du texte
|
||||||
|
|
||||||
|
# Dessiner la boîte
|
||||||
|
printf '┌'
|
||||||
|
for (( j=0; j<box_width; j++ )); do
|
||||||
|
printf '─'
|
||||||
|
done
|
||||||
|
printf '┐\n'
|
||||||
|
|
||||||
|
# Afficher la ligne avec le texte
|
||||||
|
printf '│'
|
||||||
|
printf "%*s" $padding ""
|
||||||
|
printf "${color}%s${reset}" "$box_text"
|
||||||
|
printf "%*s" $padding ""
|
||||||
|
printf '│\n'
|
||||||
|
|
||||||
|
# Dessiner la ligne inférieure de la boîte
|
||||||
|
printf '└'
|
||||||
|
for (( j=0; j<box_width; j++ )); do
|
||||||
|
printf '─'
|
||||||
|
done
|
||||||
|
printf '┘\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Lire chaque ligne du fichier temporaire
|
||||||
|
while IFS=',' read -r type timestamps; do
|
||||||
|
# Traiter les timestamps en tenant compte de l'absence de virgule après le dernier timestamp
|
||||||
|
timestamps=$(echo "$timestamps" | awk '{gsub(/,$/, ""); print}')
|
||||||
|
|
||||||
|
# Convertir les timestamps séparés par des virgules en un tableau
|
||||||
|
IFS=',' read -ra timestamp_array <<< "$timestamps"
|
||||||
|
|
||||||
|
# Filtrer les timestamps valides (non vides et numériques)
|
||||||
|
valid_timestamps=()
|
||||||
|
for ts in "${timestamp_array[@]}"; do
|
||||||
|
if [[ -n "$ts" && "$ts" =~ ^[0-9]+$ ]]; then
|
||||||
|
valid_timestamps+=("$ts")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Calculer le nombre total d'itérations
|
||||||
|
total_iterations=${#valid_timestamps[@]}
|
||||||
|
|
||||||
|
# Débogage : afficher les timestamps valides
|
||||||
|
# echo "Timestamps valides: ${valid_timestamps[@]}"
|
||||||
|
|
||||||
|
if (( total_iterations > 0 )); then
|
||||||
|
# Trier les timestamps pour garantir l'ordre croissant
|
||||||
|
IFS=$'\n' sorted_timestamps=($(sort -n <<<"${valid_timestamps[*]}"))
|
||||||
|
unset IFS
|
||||||
|
|
||||||
|
# Débogage : afficher les timestamps triés
|
||||||
|
# echo "Timestamps triés: ${sorted_timestamps[@]}"
|
||||||
|
|
||||||
|
# Trouver la dernière itération (le plus grand timestamp)
|
||||||
|
last_timestamp=${sorted_timestamps[-1]}
|
||||||
|
|
||||||
|
# Convertir le dernier timestamp en date lisible
|
||||||
|
last_iteration_date=$(convert_to_date "$last_timestamp")
|
||||||
|
|
||||||
|
# Calculer la moyenne du temps entre les itérations
|
||||||
|
if (( total_iterations > 1 )); then
|
||||||
|
sum_intervals=0
|
||||||
|
for ((i = 1; i < total_iterations; i++)); do
|
||||||
|
interval=$((sorted_timestamps[i] - sorted_timestamps[i - 1]))
|
||||||
|
sum_intervals=$((sum_intervals + interval))
|
||||||
|
done
|
||||||
|
# Moyenne du temps entre les itérations en millisecondes
|
||||||
|
average_interval=$((sum_intervals / (total_iterations - 1)))
|
||||||
|
|
||||||
|
# Conversion en jours
|
||||||
|
average_days=$(echo "scale=2; $average_interval / 1000 / 60 / 60 / 24" | bc)
|
||||||
|
else
|
||||||
|
average_days="N/A"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Afficher les résultats pour ce type
|
||||||
|
#echo "Compteur: $type"
|
||||||
|
ascii_box "$type : $total_iterations"
|
||||||
|
#echo "Total: $total_iterations" # Nombre total de timestamps
|
||||||
|
echo "Dernier: $last_iteration_date"
|
||||||
|
echo "Interval moyen: $average_days jours"
|
||||||
|
#echo "--------------------------------------------"
|
||||||
|
else
|
||||||
|
#echo "Compteur: $type"
|
||||||
|
ascii_box "$type"
|
||||||
|
echo "Pas assez de données."
|
||||||
|
#echo "--------------------------------------------"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done < "$temp_file"
|
||||||
|
|
||||||
|
# Supprimer le fichier temporaire après traitement
|
||||||
|
rm "$temp_file"
|
4
bettercounter-cli/exemple.csv
Normal file
4
bettercounter-cli/exemple.csv
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Arroser les plantes,1715978356330,1716237319779,1716327000000,1716586200000,1716671700000,1716755400000,1717183800000,1717622100000,1717966884759,1718397755921,1718564400000,1718827525131,1719268873371,1719522000000,1719696600000,1720261200000,1720474200000,1720818000000,1720991518054,1721165699367,1721337000000,1721853629745,1722132013843,1722803926337,1723063148315,1723313700000,1723581000000,1723764790390,1723934617145,1724155200000,1724240708939
|
||||||
|
Assouplissements,1715893200000,1716102815829,1716585600000,1716614391470,1716704868180,1716746400000,1716901200000,1717091007533,1717612200000,1717818805638,1718138966498,1718524608253,1718558092277,1718659318712,1718730841837,1718745987586,1718827786600,1718948459419,1718987275565,1719007101530,1719053573292,1719073743180,1719268878594,1719291082676,1719339599767,1719370549341,1719437400000,1719463025688,1719488372915,1719548754003,1719599228218,1719661829039,1719783000000,1720069135321,1720307247679,1720342900438,1720384671588,1720473970284,1720541787906,1720845326315,1720881031154,1721126700000,1721165706256,1721232903629,1721337000000,1721362381053,1721455413991,1721518361938,1721595424940,1721673000000,1721799527005,1722147878345,1722157707014,1722196800000,1722313120768,1722372383251,1722488054389,1722548537903,1722634200000,1722664347131,1722751037036,1722802722381,1722836223470,1722892196644,1722978235515,1723029288539,1723063151521,1723238933173,1723265880508,1723293000000,1723411578252,1723437754623,1723498102740,1723581419207,1723605336828,1723636900947,1723670773113,1723832728162,1723845282032,1723874400000,1723897835492,1723911054800,1723919016284,1723932705126,1723985061038,1724015329593,1724066439891,1724229000000
|
||||||
|
Kung Fu - Cours,1715632200000,1715805000000,1716212700000,1716408000000,1716834600000,1717007400000,1717612200000,1718052580963,1718217000000,1719262341860,1719426794385,1720473959955,1721068200000,1721251767088,1721932200000,1722277800000,1723149622448,1723497917074
|
||||||
|
Kung Fu - Entrainement maison,1715772600000,1716102817442,1716377941270,1716705456947,1716705457168,1717500000000,1717500300000,1717612200000,1717818698697,1717864200000,1717995000000,1718044261611,1718396400000,1718433400475,1718659320663,1718659321246,1718731800000,1718732400000,1718787600000,1719034360283,1719034360660,1719314400000,1719314400000,1719637114533,1719894336331,1720040400000,1720307246191,1720384670604,1720873800000,1721068200000,1721165702482,1721165702791,1721363623616,1721363624190,1721413800000,1721595423247,1721710800000,1721710800000,1721799968672,1721799969150,1721880900000,1722024900000,1722083755570,1722083952180,1722122821836,1722157701992,1722157702951,1722397344952,1722548537303,1722836221871,1722836222352,1722892193732,1722920686939,1722978233533,1723063150595,1723200181907,1723266606728,1723329104308,1723353704945,1723353705610,1723437898088,1723437899258,1723553740693,1723553741523,1723670769836,1723670770413,1723764793025,1723764793208,1723832710511,1723911465405,1723911466079,1723996800000,1723996800000,1724181982816,1724181983417
|
|
Loading…
Reference in a new issue