From 7533b83d8ae989157b102612fc1bc6a5820f2089 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Tue, 4 Apr 2023 17:22:26 +0200 Subject: [PATCH] Updated code for stats in function count_stats(). Thx neox for help --- src/var/lib/tyto/program/show.py | 86 +++++++------- src/var/lib/tyto/program/stats.py | 182 +++++++++++------------------- 2 files changed, 108 insertions(+), 160 deletions(-) diff --git a/src/var/lib/tyto/program/show.py b/src/var/lib/tyto/program/show.py index 468d210..80b17e9 100644 --- a/src/var/lib/tyto/program/show.py +++ b/src/var/lib/tyto/program/show.py @@ -103,17 +103,17 @@ def manage(target): # as edit* &nd show* [action] have same target file actions = \ { - 'show' : 'src', - 'edit' : 'src', - 'post' : 'src', - 'show-db' : 'db', - 'edit-db' : 'db', - 'show-about' : 'about', - 'edit-about' : 'about', - 'show-wip' : 'wip', - 'edit-wip' : 'wip', - 'show-www' : 'www', - 'edit-www' : 'www' + "show" : 'src', + "edit" : 'src', + "post" : 'src', + "show-db" : 'db', + "edit-db" : 'db', + "show-about" : 'about', + "edit-about" : 'about', + "show-wip" : 'wip', + "edit-wip" : 'wip', + "show-www" : 'www', + "edit-www" : 'www' } action = actions[args.action] @@ -121,46 +121,46 @@ def manage(target): do = \ { 'src' : { - 'domain' : dom.config, - 'footer' : dom.footer_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_src + "domain" : dom.config, + "footer" : dom.footer_f, + "metas" : dom.metas_f, + "navbar" : dom.navbar_f, + "sidebar" : dom.sidebar_f, + "post" : post_src }, 'db' : { - 'domain' : dom.config, - 'footer' : dom.footer_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_db + "domain" : dom.config, + "footer" : dom.footer_f, + "metas" : dom.metas_f, + "navbar" : dom.navbar_f, + "sidebar" : dom.sidebar_f, + "post" : post_db }, 'about' : { - 'domain' : dom.config, - 'footer' : dom.footer_about_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_db + "domain" : dom.config, + "footer" : dom.footer_about_f, + "metas" : dom.metas_f, + "navbar" : dom.navbar_f, + "sidebar" : dom.sidebar_f, + "post" : post_db }, 'wip' : { - 'domain' : dom.config, - 'footer' : dom.wip_footer_f, - 'metas' : dom.wip_metas_f, - 'navbar' : dom.wip_navbar_f, - 'sidebar' : dom.wip_sidebar_f, - 'post' : post_wip, - 'stats' : dom.wip_stats_f, + "domain" : dom.config, + "footer" : dom.wip_footer_f, + "metas" : dom.wip_metas_f, + "navbar" : dom.wip_navbar_f, + "sidebar" : dom.wip_sidebar_f, + "post" : post_wip, + "stats" : dom.wip_stats_f, }, 'www' : { - 'domain' : dom.config, - 'footer' : dom.www_footer_f, - 'metas' : dom.www_metas_f, - 'navbar' : dom.www_navbar_f, - 'sidebar' : dom.www_sidebar_f, - 'post' : post_www, - 'stats' : dom.www_stats_f, + "domain" : dom.config, + "footer" : dom.www_footer_f, + "metas" : dom.www_metas_f, + "navbar" : dom.www_navbar_f, + "sidebar" : dom.www_sidebar_f, + "post" : post_www, + "stats" : dom.www_stats_f, }, } diff --git a/src/var/lib/tyto/program/stats.py b/src/var/lib/tyto/program/stats.py index ebf9392..e5652a8 100644 --- a/src/var/lib/tyto/program/stats.py +++ b/src/var/lib/tyto/program/stats.py @@ -87,7 +87,7 @@ def loop_articles(process): sti_articles += 1 if sti_articles == 1: count_stats(False) else: count_stats(True) - + # Create file if article if sti_articles > 0: create_stats_file(file_uri) else: logs.out("28", '%s stats'%process, True) @@ -96,98 +96,46 @@ def loop_articles(process): # False: Set First statistics # # True: Count total statistics # #-------------------------------# -def count_stats(add): - global sti_uniq_anchors - global sti_uniq_abbrs - global sti_uniq_links - global sti_uniq_images - global sti_uniq_files - global sti_uniq_codes - global sti_uniq_raws - - global sti_posts_coms - global sti_posts_tags - global sti_posts_lines - global sti_posts_words - global sti_posts_titles - global sti_posts_paragraphs - global sti_posts_anchors - global sti_posts_abbrs - global sti_posts_strongs - global sti_posts_bolds - global sti_posts_emphasis - global sti_posts_italics - global sti_posts_dels - global sti_posts_underlines - global sti_posts_cites - global sti_posts_customs - global sti_posts_icodes - global sti_posts_bcodes - global sti_posts_quotes - global sti_posts_lists - - +def count_stats(add): # Set if not add: - sti_uniq_anchors = uniq_anchors - sti_uniq_abbrs = uniq_abbrs - sti_uniq_links = uniq_links - sti_uniq_images = uniq_images - sti_uniq_files = uniq_files - sti_uniq_codes = uniq_codes - sti_uniq_raws = uniq_raws + global stats - sti_posts_coms = post_coms - sti_posts_tags = post_tags - sti_posts_lines = post_lines - sti_posts_words = post_words - sti_posts_titles = post_titles - sti_posts_paragraphs = post_paragraphs - sti_posts_anchors = post_anchors - sti_posts_abbrs = post_abbrs - sti_posts_strongs = post_strongs - sti_posts_bolds = post_bolds - sti_posts_emphasis = post_emphasis - sti_posts_italics = post_italics - sti_posts_dels = post_dels - sti_posts_underlines = post_underlines - sti_posts_cites = post_cites - sti_posts_customs = post_customs - sti_posts_icodes = post_icodes - sti_posts_bcodes = post_bcodes - sti_posts_quotes = post_quotes - sti_posts_lists = post_lists + stats = { \ + "sti_uniq_anchors" : uniq_anchors, + "sti_uniq_abbrs" : uniq_abbrs, + "sti_uniq_links" : uniq_links, + "sti_uniq_images" : uniq_images, + "sti_uniq_files" : uniq_files, + "sti_uniq_codes" : uniq_codes, + "sti_uniq_raws" : uniq_raws, + "sti_post_coms" : post_coms, + "sti_post_tags" : post_tags, + "sti_post_lines" : post_lines, + "sti_post_words" : post_words, + "sti_post_titles" : post_titles, + "sti_post_paragraphs" : post_paragraphs, + "sti_post_anchors" : post_anchors, + "sti_post_abbrs" : post_abbrs, + "sti_post_strongs" : post_strongs, + "sti_post_bolds" : post_bolds, + "sti_post_emphasis" : post_emphasis, + "sti_post_italics" : post_italics, + "sti_post_dels" : post_dels, + "sti_post_underlines" : post_underlines, + "sti_post_cites" : post_cites, + "sti_post_customs" : post_customs, + "sti_post_icodes" : post_icodes, + "sti_post_bcodes" : post_bcodes, + "sti_post_quotes" : post_quotes, + "sti_post_lists" : post_lists, + } # Count - else: - sti_uniq_anchors = sti_uniq_anchors + uniq_anchors - sti_uniq_abbrs = sti_uniq_abbrs + uniq_abbrs - sti_uniq_links = sti_uniq_links + uniq_links - sti_uniq_images = sti_uniq_images + uniq_images - sti_uniq_files = sti_uniq_files + uniq_files - sti_uniq_codes = sti_uniq_codes + uniq_codes - sti_uniq_raws = sti_uniq_raws + uniq_raws - - sti_posts_coms = sti_posts_coms + post_coms - sti_posts_tags = sti_posts_tags + post_tags - sti_posts_lines = sti_posts_lines + post_lines - sti_posts_words = sti_posts_words + post_words - sti_posts_titles = sti_posts_titles + post_titles - sti_posts_paragraphs = sti_posts_paragraphs + post_paragraphs - sti_posts_anchors = sti_posts_anchors + post_anchors - sti_posts_abbrs = sti_posts_abbrs + post_abbrs - sti_posts_strongs = sti_posts_strongs + post_strongs - sti_posts_bolds = sti_posts_bolds + post_bolds - sti_posts_emphasis = sti_posts_emphasis + post_emphasis - sti_posts_italics = sti_posts_italics + post_italics - sti_posts_dels = sti_posts_dels + post_dels - sti_posts_underlines = sti_posts_underlines + post_underlines - sti_posts_cites = sti_posts_cites + post_cites - sti_posts_customs = sti_posts_customs + post_customs - sti_posts_icodes = sti_posts_icodes + post_icodes - sti_posts_bcodes = sti_posts_bcodes + post_bcodes - sti_posts_quotes = sti_posts_quotes + post_quotes - sti_posts_lists = sti_posts_lists + post_lists + else: + for i in stats: + stat_db = i.rsplit("sti_")[1] + stats[i] = stats[i] + eval(stat_db) #============================# @@ -202,45 +150,45 @@ def create_stats_file(file_uri): '\n' + \ '# Uniq statistics from articles\' headers\n' + \ 'stats_articles = %d\n'%int(sti_articles) + \ - 'stats_uniq_anchors = %d\n'%int(sti_uniq_anchors) + \ - 'stats_uniq_abbrs = %d\n'%int(sti_uniq_abbrs) + \ - 'stats_uniq_links = %d\n'%int(sti_uniq_links) + \ - 'stats_uniq_images = %d\n'%int(sti_uniq_images) + \ - 'stats_uniq_files = %d\n'%int(sti_uniq_files) + \ - 'stats_uniq_codes = %d\n'%int(sti_uniq_codes) + \ - 'stats_uniq_raws = %d\n'%int(sti_uniq_raws) + \ + 'stats_uniq_anchors = %d\n'%stats["sti_uniq_anchors"] + \ + 'stats_uniq_abbrs = %d\n'%stats["sti_uniq_abbrs"] + \ + 'stats_uniq_links = %d\n'%stats["sti_uniq_links"] + \ + 'stats_uniq_images = %d\n'%stats["sti_uniq_images"] + \ + 'stats_uniq_files = %d\n'%stats["sti_uniq_files"] + \ + 'stats_uniq_codes = %d\n'%stats["sti_uniq_codes"] + \ + 'stats_uniq_raws = %d\n'%stats["sti_uniq_raws"] + \ '\n' + \ '# Statistics from articles\' contents\n' + \ - 'stats_posts_coms = %d\n'%int(sti_posts_coms) + \ - 'stats_posts_tags = %d\n'%int(sti_posts_tags) + \ - 'stats_posts_lines = %d\n'%int(sti_posts_lines) + \ - 'stats_posts_words = %d\n'%int(sti_posts_words) + \ - 'stats_posts_titles = %d\n'%int(sti_posts_titles) + \ - 'stats_posts_paragraphs = %d\n'%int(sti_posts_paragraphs) + \ - 'stats_posts_anchors = %d\n'%int(sti_posts_anchors) + \ - 'stats_posts_abbrs = %d\n'%int(sti_posts_abbrs) + \ - 'stats_posts_strongs = %d\n'%int(sti_posts_strongs) + \ - 'stats_posts_bolds = %d\n'%int(sti_posts_bolds) + \ - 'stats_posts_emphasis = %d\n'%int(sti_posts_emphasis) + \ - 'stats_posts_italics = %d\n'%int(sti_posts_italics) + \ - 'stats_posts_dels = %d\n'%int(sti_posts_dels) + \ - 'stats_posts_underlines = %d\n'%int(sti_posts_underlines) + \ - 'stats_posts_cites = %d\n'%int(sti_posts_cites) + \ - 'stats_posts_customs = %d\n'%int(sti_posts_customs) + \ - 'stats_posts_icodes = %d\n'%int(sti_posts_icodes) + \ - 'stats_posts_bcodes = %d\n'%int(sti_posts_bcodes) + \ - 'stats_posts_quotes = %d\n'%int(sti_posts_quotes) + \ - 'stats_posts_lists = %d\n'%int(sti_posts_lists) + 'stats_posts_coms = %d\n'%stats["sti_post_coms"] + \ + 'stats_posts_tags = %d\n'%stats["sti_post_tags"] + \ + 'stats_posts_lines = %d\n'%stats["sti_post_lines"] + \ + 'stats_posts_words = %d\n'%stats["sti_post_words"] + \ + 'stats_posts_titles = %d\n'%stats["sti_post_titles"] + \ + 'stats_posts_paragraphs = %d\n'%stats["sti_post_paragraphs"] + \ + 'stats_posts_anchors = %d\n'%stats["sti_post_anchors"] + \ + 'stats_posts_abbrs = %d\n'%stats["sti_post_abbrs"] + \ + 'stats_posts_strongs = %d\n'%stats["sti_post_strongs"] + \ + 'stats_posts_bolds = %d\n'%stats["sti_post_bolds"] + \ + 'stats_posts_emphasis = %d\n'%stats["sti_post_emphasis"] + \ + 'stats_posts_italics = %d\n'%stats["sti_post_italics"] + \ + 'stats_posts_dels = %d\n'%stats["sti_post_dels"] + \ + 'stats_posts_underlines = %d\n'%stats["sti_post_underlines"] + \ + 'stats_posts_cites = %d\n'%stats["sti_post_cites"] + \ + 'stats_posts_customs = %d\n'%stats["sti_post_customs"] + \ + 'stats_posts_icodes = %d\n'%stats["sti_post_icodes"] + \ + 'stats_posts_bcodes = %d\n'%stats["sti_post_bcodes"] + \ + 'stats_posts_quotes = %d\n'%stats["sti_post_quotes"] + \ + 'stats_posts_lists = %d\n'%stats["sti_post_lists"] tyto.set_file(file_uri, 'New', sti) try: print(' └', langs.site.stats_f%( - sti_articles, sti_posts_words + sti_articles, stats["sti_post_words"] ) ) except: print(' └ Articles = %s ; Words = %s'%( - sti_articles, sti_posts_words + sti_articles, stats["sti_post_words"] ) )