forked from sch/Slixfeed
Fix statistics
This commit is contained in:
parent
219c23a648
commit
c04a1b6534
5 changed files with 52 additions and 57 deletions
|
@ -69,6 +69,10 @@ TODO
|
||||||
|
|
||||||
17) Make the program portable (directly use the directory assets) -- Thorsten
|
17) Make the program portable (directly use the directory assets) -- Thorsten
|
||||||
|
|
||||||
|
18) The operator account will be given reports from the bot about its
|
||||||
|
activities every X minutes.
|
||||||
|
When a suspicious activity is detected, it will be reported immediately.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# vars and their meanings:
|
# vars and their meanings:
|
||||||
|
|
|
@ -16,6 +16,12 @@ TODO
|
||||||
2) Call sqlite function from function statistics.
|
2) Call sqlite function from function statistics.
|
||||||
Returning a list of values doesn't' seem to be a good practice.
|
Returning a list of values doesn't' seem to be a good practice.
|
||||||
|
|
||||||
|
3) Special statistics for operator:
|
||||||
|
* Size of database(s);
|
||||||
|
* Amount of JIDs subscribed;
|
||||||
|
* Amount of feeds of all JIDs;
|
||||||
|
* Amount of entries of all JIDs.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from asyncio.exceptions import IncompleteReadError
|
from asyncio.exceptions import IncompleteReadError
|
||||||
|
@ -225,7 +231,15 @@ def list_feeds_by_query(query, results):
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
def list_statistics(values):
|
async def get_setting_value(db_file, key):
|
||||||
|
value = (
|
||||||
|
await sqlite.get_settings_value(db_file, key) or
|
||||||
|
config.get_value_default("settings", "Settings", key)
|
||||||
|
)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
async def list_statistics(db_file):
|
||||||
"""
|
"""
|
||||||
Return table statistics.
|
Return table statistics.
|
||||||
|
|
||||||
|
@ -239,6 +253,27 @@ def list_statistics(values):
|
||||||
msg : str
|
msg : str
|
||||||
Statistics as message.
|
Statistics as message.
|
||||||
"""
|
"""
|
||||||
|
entries_unread = await sqlite.get_number_of_entries_unread(db_file)
|
||||||
|
entries = await sqlite.get_number_of_items(db_file, 'entries')
|
||||||
|
archive = await sqlite.get_number_of_items(db_file, 'archive')
|
||||||
|
entries_all = entries + archive
|
||||||
|
feeds_active = await sqlite.get_number_of_feeds_active(db_file)
|
||||||
|
feeds_all = await sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
|
key_archive = await get_setting_value(db_file, "archive")
|
||||||
|
key_interval = await get_setting_value(db_file, "interval")
|
||||||
|
key_quantum = await get_setting_value(db_file, "quantum")
|
||||||
|
key_enabled = await get_setting_value(db_file, "enabled")
|
||||||
|
|
||||||
|
# msg = """You have {} unread news items out of {} from {} news sources.
|
||||||
|
# """.format(unread_entries, entries, feeds)
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# value = cur.execute(sql, par).fetchone()[0]
|
||||||
|
# except:
|
||||||
|
# print("Error for key:", key)
|
||||||
|
# value = "Default"
|
||||||
|
# values.extend([value])
|
||||||
|
|
||||||
message = (
|
message = (
|
||||||
"```"
|
"```"
|
||||||
"\nSTATISTICS\n"
|
"\nSTATISTICS\n"
|
||||||
|
@ -250,8 +285,16 @@ def list_statistics(values):
|
||||||
"Items per update : {}\n"
|
"Items per update : {}\n"
|
||||||
"Operation status : {}\n"
|
"Operation status : {}\n"
|
||||||
"```"
|
"```"
|
||||||
).format(values[0], values[1], values[2], values[3],
|
).format(
|
||||||
values[4], values[5], values[6], values[7])
|
entries_unread,
|
||||||
|
entries_all,
|
||||||
|
feeds_active,
|
||||||
|
feeds_all,
|
||||||
|
key_archive,
|
||||||
|
key_interval,
|
||||||
|
key_quantum,
|
||||||
|
key_enabled
|
||||||
|
)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@ TODO
|
||||||
|
|
||||||
3) Add "if utility.is_feed(url, feed)" to view_entry and view_feed
|
3) Add "if utility.is_feed(url, feed)" to view_entry and view_feed
|
||||||
|
|
||||||
4) Refactor view_entry and view_feed - Why "if" twice?
|
4) Replace sqlite.remove_nonexistent_entries by sqlite.check_entry_exist
|
||||||
|
|
||||||
5) Replace sqlite.remove_nonexistent_entries by sqlite.check_entry_exist
|
|
||||||
Same check, just reverse.
|
Same check, just reverse.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -961,48 +961,6 @@ async def delete_archived_entry(cur, ix):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def statistics(db_file):
|
|
||||||
"""
|
|
||||||
Return table statistics.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
db_file : str
|
|
||||||
Path to database file.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
values : list
|
|
||||||
List of values.
|
|
||||||
"""
|
|
||||||
values = []
|
|
||||||
values.extend([await get_number_of_entries_unread(db_file)])
|
|
||||||
entries = await get_number_of_items(db_file, 'entries')
|
|
||||||
archive = await get_number_of_items(db_file, 'archive')
|
|
||||||
values.extend([entries + archive])
|
|
||||||
values.extend([await get_number_of_feeds_active(db_file)])
|
|
||||||
values.extend([await get_number_of_items(db_file, 'feeds')])
|
|
||||||
# msg = """You have {} unread news items out of {} from {} news sources.
|
|
||||||
# """.format(unread_entries, entries, feeds)
|
|
||||||
with create_connection(db_file) as conn:
|
|
||||||
cur = conn.cursor()
|
|
||||||
for key in ["archive", "interval",
|
|
||||||
"quantum", "enabled"]:
|
|
||||||
sql = (
|
|
||||||
"SELECT value "
|
|
||||||
"FROM settings "
|
|
||||||
"WHERE key = ?"
|
|
||||||
)
|
|
||||||
par = (key,)
|
|
||||||
try:
|
|
||||||
value = cur.execute(sql, par).fetchone()[0]
|
|
||||||
except:
|
|
||||||
print("Error for key:", key)
|
|
||||||
value = "Default"
|
|
||||||
values.extend([value])
|
|
||||||
return values
|
|
||||||
|
|
||||||
|
|
||||||
async def update_statistics(cur):
|
async def update_statistics(cur):
|
||||||
"""
|
"""
|
||||||
Update table statistics.
|
Update table statistics.
|
||||||
|
|
|
@ -756,13 +756,6 @@ async def message(self, message):
|
||||||
# "Every update will contain {} news items."
|
# "Every update will contain {} news items."
|
||||||
# ).format(response)
|
# ).format(response)
|
||||||
db_file = get_pathname_to_database(jid)
|
db_file = get_pathname_to_database(jid)
|
||||||
a = await sqlite.get_settings_value(db_file, key)
|
|
||||||
print(a)
|
|
||||||
print(key)
|
|
||||||
print(val)
|
|
||||||
print(a)
|
|
||||||
print(a)
|
|
||||||
print(a)
|
|
||||||
if await sqlite.get_settings_value(
|
if await sqlite.get_settings_value(
|
||||||
db_file, key):
|
db_file, key):
|
||||||
await sqlite.update_settings_value(
|
await sqlite.update_settings_value(
|
||||||
|
@ -927,8 +920,7 @@ async def message(self, message):
|
||||||
send_reply_message(self, message, response)
|
send_reply_message(self, message, response)
|
||||||
case "stats":
|
case "stats":
|
||||||
db_file = get_pathname_to_database(jid)
|
db_file = get_pathname_to_database(jid)
|
||||||
result = await sqlite.statistics(db_file)
|
response = await action.list_statistics(db_file)
|
||||||
response = action.list_statistics(result)
|
|
||||||
send_reply_message(self, message, response)
|
send_reply_message(self, message, response)
|
||||||
case _ if message_lowercase.startswith("disable "):
|
case _ if message_lowercase.startswith("disable "):
|
||||||
ix = message_text[8:]
|
ix = message_text[8:]
|
||||||
|
|
Loading…
Reference in a new issue