Added : stats file genereated with sync command

This commit is contained in:
Cyrille L 2022-07-21 18:40:21 +02:00
parent 0b5d8f0dec
commit 4628b78749
8 changed files with 175 additions and 13 deletions

View File

@ -34,7 +34,11 @@
add : Create sidebar, add/replace (ARTICLE) at (POSITION)
create : (alone argument), (re)Create whole sidebar
sync : Create RSS feed and sync folders from wip to www
stats : Manually generate stats (for statoolinfos)
! useless with sync argument.
! Works only for "server" install for now
sync : Create RSS feed, Stats and sync folders from wip to www
rss : Create RSS feed in wip folder
log : (Multi-arguments)

View File

@ -103,6 +103,7 @@ case "$1" in
edit) edit__OPTIONS "$@" ;; # manage__articles
log) log__OPTIONS "$@" ;; # manage__articles
db) db__OPTIONS "$@" ;; # manage__db
stats) stats__OPTIONS ;; # manage__stats
*) noarg "$1" ;;
esac

View File

@ -34,7 +34,11 @@
add : Create sidebar, add/replace (ARTICLE) at (POSITION)
create : (alone argument), (re)Create whole sidebar
sync : Create RSS feed and sync folders from wip to www
stats : Manually generate stats (for statoolinfos)
! useless with sync argument.
! Works only for "server" install for now
sync : Create RSS feed, Stats and sync folders from wip to www
rss : Create RSS feed in wip folder
log : (Multi-arguments)

View File

@ -80,6 +80,9 @@ check__dels "$article_tmp_post"
! [[ $stl_error ]] \
&& log__add -i -C -A "Content Ok"
# Statistics ; manage__stats
stats__words "$article_tmp_post"
# If no error, write to db
db__print
@ -163,6 +166,7 @@ get__content_metas "^abbr: " "$1" check
! [[ $stl_error ]] \
&& log__add -i -C -M "Optional Metas Ok"
}
@ -192,6 +196,8 @@ if ! [[ `grep "_$header_f1" "$article_tmp_post"` ]];then
"Line $ln. No content: '_$header_f1'"
return
fi
((stat_links++))
}

View File

@ -256,11 +256,20 @@ domain__get
&& return
create__RSS_feed
rsync -a --exclude ".*" "$domain_dir_wip/" "$domain_dir_www/"
# Create www hash status in DB
db__get_wip_articles "set_www_hash" # manage__db
# Statistics
if [[ $domain_stats == "yes" ]];then
stats__init
db__get_wip_articles "stats"
stats__statoolinfos
fi
# Sync wip to www
rsync -a --exclude ".*" "$domain_dir_wip/" "$domain_dir_www/"
# Log
this_article="$domain_dir_www"
log__add -i -M WWW "Synced WIP server to WWW server"

View File

@ -117,8 +117,10 @@ $(
)
# Statistics
article_words=$article_words
article_titles=$stat_titles
article_paragraphs=$stat_paragraphs
article_links=$stat_links
article_quotes=$stat_quotes
article_lists=$stat_lists
article_bolds=$article_bolds
@ -189,6 +191,7 @@ rm -f "$db_rmp_list"
exit
}
#======================================================================
# Get articles from database, with wip status
# Generic function to :
@ -199,23 +202,53 @@ exit
db__get_wip_articles() {
while IFS=: read -r 'file' 'article_wip'
do
echo "> $article_wip"
[[ `awk -F= '{print $2}' <<<"$article_wip"` -gt 0 ]] \
|| continue
[[ `awk -F= '{print $2}' <<<"$article_wip"` -gt 0 ]] || continue
source "$file"
# From sync_wip_to_www() ; manage__HTML
case "$1" in
# From sync_wip_to_www() ; manage__HTML
set_www_hash)
if ! [[ $article_www_hash == $article_wip_hash ]];then
sed -i "s^article_www_hash=.*^article_www_hash=$article_wip_hash^" "$file"
sed -i "s^article_www_hash=.*^article_www_hash=$article_wip_hash^" \
"$file"
# Log
this_article="$domain_dir_www$article_uri_srv"
log__add -i -W -A "Added online: $article_title"
fi
;;
# Generate statistics
stats)
case "$stl_install" in
server)
[[ $article_www_hash -gt 0 ]] || continue
((stat_articles_www++))
article_words_www=$((article_words + article_words_www))
article_titles_www=$((article_titles + article_titles_www))
article_paragraphs_www=$((article_paragraphs + article_paragraphs_www))
article_links_www=$(( article_links + article_links_www))
article_quotes_www=$((article_quotes + article_quotes_www))
article_lists_www=$((article_lists + article_lists_www))
article_bolds_www=$((article_bolds + article_bolds_www))
article_strongs_www=$((article_strongs + article_strongs_www))
article_emphasis_www=$((article_emphasis + article_emphasis_www))
article_icodes_www=$((article_icodes+ article_icodes_www))
article_cross_www=$((article_cross + article_cross_www))
article_dels_www=$((article_dels + article_dels_www))
files_images_www=$((files_images + files_images_www))
files_links_www=$((files_links + files_links_www))
files_codes_www=$((files_codes + files_codes_www))
files_bruts_www=$((files_bruts + files_bruts_www))
;;
local)
((stat_articles_wip++))
;;
esac
;;
esac
done < <(grep -H "article_wip_hash" "$domain_db_articles/"*.db)

View File

@ -85,6 +85,7 @@ case "$3" in
-Mlt) log_f3="link:" ;;
-M) log_f3="Metas" ;;
-A) log_f3="Article" ;;
-S) log_f3="Stats" ;;
*) log_f3="$3"
esac

View File

@ -11,5 +11,109 @@
# Argument: stats
#======================================================================
stats__OPTIONS() {
echo "! Working in progress"
domain__get
# Init stats
stats__init
db__get_wip_articles "stats"
stats__statoolinfos
}
#======================================================================
# Stats initialization
#======================================================================
stats__init() {
article_words_www=0
article_titles_www=0
article_paragraphs_www=0
article_links_www=0
article_quotes_www=0
article_lists_www=0
article_bolds_www=0
article_strongs_www=0
article_emphasis_www=0
article_icodes_www=0
article_cross_www=0
article_dels_www=0
files_images_www=0
files_links_www=0
files_codes_www=
files_bruts_www=0
}
#======================================================================
# Create stl.properties for statoolinfos
#======================================================================
stats__statoolinfos() {
case "$stl_install" in
server)
cat <<EOSTATS > "$domain_dir_www/stl.properties"
stl.articles = $stat_articles_www
stl.articles.titles = $article_titles_www
stl.articles.words = $article_words_www
stl.articles.paragraphs = $article_paragraphs_www
stl.articles.links = $article_links_www
stl.articles.bolds = $article_bolds_www
stl.articles.strongs = $article_strongs_www
stl.articles.emphasis = $article_emphasis_www
stl.articles.inlinecodes = $article_icodes_www
stl.articles.cross = $article_cross_www
stl.articles.dels = $article_dels_www
stl.articles.quotes = $article_quotes_www
stl.articles.lists = $article_lists_www
# Files
stl.articles.filelinks = $files_links_www
stl.articles.images = $files_images_www
stl.articles.filecodes = $files_codes_www
stl.articles.filebruts = $files_bruts_www
EOSTATS
;;
esac
this_article="$domain_dir_www/stl.properties"
log__add -i -W -S "Statoolinfos file generated"
}
#======================================================================
# Count words in article
# Called from checkers() ; check_article
# $1: $article_tmp_post
#======================================================================
stats__words() {
article_words=`cat "$1" | wc -w`
content_stats_images=`grep "_image:" "$1" | wc -l`
content_stats_fcodes=`grep "_code:" "$1" | wc -l`
content_stats_fbruts=`grep "_brut:" "$1" | wc -l`
content_stats_slists=`grep "<<" "$1" | wc -w`
content_stats_clists=`grep ">>" "$1" | wc -l`
content_stats_olists=`grep "^+" "$1" | wc -l`
content_stats_ulists=`grep "^=" "$1" | wc -l`
content_stats_commts=`grep "^# " "$1" | wc -w`
content_stats_titles=`grep "^#[1-6] " "$1" | wc -l`
content_stats_mquots=`grep "^---" "$1" | wc -l`
content_stats_oparas=`grep "^(" "$1" | wc -w`
content_stats_cparas=`grep "^)" "$1" | wc -l`
article_words=\
$(( article_words \
- content_stats_images \
- content_stats_fcodes \
- content_stats_fbruts \
- content_stats_slists \
- content_stats_clists \
- content_stats_olists \
- content_stats_ulists \
- content_stats_commts \
- content_stats_titles \
- content_stats_mquots \
- content_stats_oparas \
- content_stats_cparas
))
}