Skip to content

Commit 3c3b553

Browse files
committed
In the "GamePlayer" module, on its root class, I created the new method "Update_Statistics" following the same pattern as the method of the same name inside the "Stories" class.
In the "Watch_History" module, on its root class, I created the new method "Update_Statistics" following the same pattern as the method of the same name inside the "Stories" class.
1 parent 57ec86d commit 3c3b553

File tree

15 files changed

+1073
-125
lines changed

15 files changed

+1073
-125
lines changed

Module files/Food_Time/Times.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"Will be hungry": 3
1111
},
1212
"Ate": {
13-
"Object": "2025-02-10 02:18:09-03:00",
13+
"Object": "2025-02-19 17:03:49-03:00",
1414
"Time": 0,
15-
"Time text": "02:18",
15+
"Time text": "17:03",
1616
"Unit": {
1717
"en": "hours",
1818
"pt": "horas"
@@ -23,9 +23,9 @@
2323
}
2424
},
2525
"Can drink water": {
26-
"Object": "2025-02-10 02:58:09-03:00",
26+
"Object": "2025-02-19 17:43:49-03:00",
2727
"Time": 40,
28-
"Time text": "02:58",
28+
"Time text": "17:43",
2929
"Unit": {
3030
"en": "minutes",
3131
"pt": "minutos"
@@ -36,9 +36,9 @@
3636
}
3737
},
3838
"Will be hungry": {
39-
"Object": "2025-02-10 05:18:09-03:00",
39+
"Object": "2025-02-19 20:03:49-03:00",
4040
"Time": 3,
41-
"Time text": "05:18",
41+
"Time text": "20:03",
4242
"Unit": {
4343
"en": "hours",
4444
"pt": "horas"

Module files/GamePlayer/Texts.json

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
"en": "Game sessions played in",
156156
"pt": "Sessões de jogo jogadas em"
157157
},
158+
"times_that_i_played_the_{}_game_called_{}": {
159+
"en": "Times that I played the {} game called \"{}\"",
160+
"pt": "Vezes que eu joguei o jogo de {} chamado \"{}\""
161+
},
158162
"game_types_played_in_all_years": {
159163
"en": "Game types played in all years",
160164
"pt": "Tipos de jogo jogados em todos os anos"

Module files/Stories/Texts.json

+4
Original file line numberDiff line numberDiff line change
@@ -490,5 +490,9 @@
490490
"id_of_the_story_in": {
491491
"en": "ID of the story in",
492492
"pt": "ID da história em"
493+
},
494+
"chapters_of_my_story_{}_{}": {
495+
"en": "Chapters of my story \"{}\" {}",
496+
"pt": "Capítulos da minha história \"{}\" {}"
493497
}
494498
}

Module files/Watch_History/Texts.json

+4
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@
303303
"pt": "Digite o número de vezes que você assistiu",
304304
"en": "Type the number of times that you watched"
305305
},
306+
"times_that_i_watched_{}_{}": {
307+
"en": "Times that I watched {} \"{}\"",
308+
"pt": "Vezes que eu assisti {} \"{}\""
309+
},
306310
"re_watched, capitalize()": {
307311
"pt": "Re-assistido",
308312
"en": "Re-watched"

Modules/Diary_Slim/Diary_Slim/__init__.py

+185-9
Original file line numberDiff line numberDiff line change
@@ -1318,18 +1318,27 @@ def Create_External_Statistics(self):
13181318
if module_title not in external_statistics["List"]:
13191319
external_statistics["List"].append(module_title)
13201320

1321+
# Add the module title to the dictionary of external statistics if it is not already present
1322+
if module_title not in external_statistics["Dictionary"]:
1323+
external_statistics["Dictionary"][module_title] = {}
1324+
13211325
# Get the statistic key from the module dictionary
13221326
statistic_key = module["Statistic key"]
13231327

13241328
# Add the statistic key to the list of keys if it is not already present
13251329
if statistic_key not in external_statistics["Keys"]:
13261330
external_statistics["Keys"].append(statistic_key)
13271331

1328-
# If the module title is inside the external statistics dictionary
1332+
# Define the "check empty dictionary" switch
1333+
check_empty_dictionary = True
1334+
1335+
# If the "check empty dictionary" switch is True
13291336
# And the "Years" dictionary of the external statistic is empty
1337+
# or the "check empty dictionary" switch is False
13301338
if (
1331-
module["Title"] in external_statistics["Dictionary"] and
1332-
external_statistics["Dictionary"][module["Title"]]["Years"] == {}
1339+
check_empty_dictionary == True and
1340+
external_statistics["Dictionary"][module["Title"]]["Years"] == {} or
1341+
check_empty_dictionary == False
13331342
):
13341343
# Import the module
13351344
module["Module"] = importlib.import_module("." + module["Title"], module["Title"])
@@ -1372,7 +1381,8 @@ def Create_External_Statistics(self):
13721381
# Add the local statistic dictionary to the root statistics dictionary template
13731382
self.statistics_template[statistic_key] = {
13741383
"Module": module["Title"],
1375-
"Total": 0
1384+
"Total": 0,
1385+
"Dictionary": {}
13761386
}
13771387

13781388
# Update the module dictionary inside the modules dictionary
@@ -1563,6 +1573,13 @@ def Update_Statistics(self):
15631573
# Get the list of keys
15641574
keys = list(years.keys())
15651575

1576+
# Iterate through the list of keys
1577+
for key in keys.copy():
1578+
# If the year key is not inside the dictionary of years
1579+
if key not in self.years["Dictionary"]:
1580+
# Remove the key
1581+
keys.pop(key)
1582+
15661583
# Iterate through the list of keys
15671584
for key in keys:
15681585
# Get the year dictionary of that key
@@ -1576,9 +1593,11 @@ def Update_Statistics(self):
15761593

15771594
# Add the "Total" key and the number dictionaries inside the "Numbers" to the root year statistics dictionary
15781595
root_year["Statistics"][statistic_key] = {
1579-
**root_statistics,
1596+
"Module": root_statistics["Module"],
15801597
"Total": year["Total"],
1581-
**year["Numbers"]
1598+
"Dictionary": {
1599+
**year["Numbers"]
1600+
}
15821601
}
15831602

15841603
# Iterate through the months inside the year dictionary
@@ -1594,9 +1613,11 @@ def Update_Statistics(self):
15941613

15951614
# Add the "Total" key and the number dictionaries inside the "Numbers" to the root month statistics dictionary
15961615
root_year["Months"][month_key]["Statistics"][statistic_key] = {
1597-
**root_statistics,
1616+
"Module": root_statistics["Module"],
15981617
"Total": month["Total"],
1599-
**month["Numbers"]
1618+
"Dictionary": {
1619+
**month["Numbers"]
1620+
}
16001621
}
16011622

16021623
# Add the year dictionary to the local dictionary of years
@@ -1660,13 +1681,168 @@ def Update_Statistics(self):
16601681
# Update the "External statistics" JSON file with the "External statistics" dictionary
16611682
self.JSON.Edit(self.diary_slim["Folders"]["Data"]["External statistics"]["Statistics"], self.statistics["External statistics"])
16621683

1663-
def Update_Current_Year_Statistics(self, year_statistics, month_statistics):
1684+
def Update_Current_Year_Statistics(self, year_statistics = None, month_statistics = None):
16641685
# Write the year statistics dictionary into the year statistics file
16651686
self.JSON.Edit(self.diary_slim["Current year"]["Folders"]["Statistics"], year_statistics)
16661687

16671688
# Write the month statistics dictionary into the month statistics file
16681689
self.JSON.Edit(self.diary_slim["Current year"]["Month"]["Folders"]["Statistics"], month_statistics)
16691690

1691+
def Update_External_Statistics(self, statistic_key, statistics):
1692+
# Define the list of parameters (statistic dictionaries to update)
1693+
parameters = [
1694+
self.diary_slim["Current year"]["Statistics"],
1695+
self.diary_slim["Current year"]["Month"]["Statistics"]
1696+
]
1697+
1698+
# Define the root statistics text
1699+
text = ""
1700+
1701+
# ---------- #
1702+
1703+
# Get the current year statistics
1704+
year_statistics = statistics["Year"]
1705+
1706+
# Update the statistic key inside the root year statistics dictionary
1707+
parameters[0][statistic_key] = year_statistics
1708+
1709+
# Get the year statistics text
1710+
text += self.Show_Statistics("Year", year_statistics, statistics["Dictionary"], return_text = True) + "\n"
1711+
1712+
# ---------- #
1713+
1714+
# Get the current month statistics
1715+
month_statistics = statistics["Month"]
1716+
1717+
# Update the statistic key inside the root month statistics dictionary
1718+
parameters[1][statistic_key] = month_statistics
1719+
1720+
# Get the year statistics text
1721+
text += self.Show_Statistics("Month", month_statistics, statistics["Dictionary"], return_text = True)
1722+
1723+
# ---------- #
1724+
1725+
# Update the statistics of the current year, with the two parameters
1726+
self.Update_Current_Year_Statistics(*parameters)
1727+
1728+
# Return the statistics text
1729+
return text
1730+
1731+
def Show_Statistics(self, date_type, statistics, dictionary = None, return_text = False):
1732+
# Define the text key
1733+
text_key = date_type.lower()
1734+
1735+
# If the "Number" key is inside the statistics dictionary
1736+
if "Number" in statistics:
1737+
# Get the number of updated statistics for the month/year
1738+
new_number = statistics["Number"]
1739+
1740+
# If the "dictionary" parameter is not None
1741+
if dictionary != None:
1742+
# Get the old and new numbers from the numbers dictionary (inside the date type dictionary)
1743+
old_number = dictionary["Numbers"][date_type]["Old"]
1744+
new_number = 1
1745+
1746+
# Define the statistic text to show as singular or plural depending on the number
1747+
singular = self.Language.language_texts["updated_" + text_key + "_statistic"]
1748+
plural = self.Language.language_texts["updated_" + text_key + "_statistics"]
1749+
1750+
show_text = self.Text.By_Number(new_number, singular, plural)
1751+
1752+
# If the "dictionary" parameter is not None
1753+
if dictionary != None:
1754+
# Get the new number from the numbers dictionary (inside the date type dictionary)
1755+
new_number = dictionary["Numbers"][date_type]["New"]
1756+
1757+
# Define the root statistics text
1758+
statistics_text = "\n" + \
1759+
show_text + ":" + "\n"
1760+
1761+
# If the "return text" parameter is False
1762+
if return_text == False:
1763+
# Show the statistics text
1764+
print(statistics_text)
1765+
1766+
# Define the default "in text" as "in [year]"
1767+
in_text = self.Language.language_texts["in"] + " " + str(self.diary_slim["Current year"]["Number"])
1768+
1769+
# If the date type is "Month"
1770+
if date_type == "Month":
1771+
# Re-define the in text to be "in [month name]"
1772+
in_text = self.Language.language_texts["in"] + " " + str(self.diary_slim["Current year"]["Month"]["Name text"])
1773+
1774+
# If the "dictionary" parameter is not None
1775+
if dictionary != None:
1776+
# Get the first key of the statistics dictionary
1777+
first_key = list(statistics["Dictionary"].keys())[0]
1778+
1779+
# Make a copy of the statistics dictionary
1780+
statistics = deepcopy(statistics)
1781+
1782+
# Make the dictionary only have the first key
1783+
statistics["Dictionary"] = {
1784+
first_key: statistics["Dictionary"][first_key]
1785+
}
1786+
1787+
# Iterate through the dictionary of statistics
1788+
for statistic in statistics["Dictionary"].values():
1789+
# If the statistic is a dictionary
1790+
if isinstance(statistic, dict):
1791+
# If the "Old number" key is inside the statistic dictionary
1792+
if "Old number" in statistic:
1793+
# Get the old number from it
1794+
old_number = statistic["Old number"]
1795+
1796+
# If the "Number" key is inside the statistic dictionary
1797+
if "Number" in statistic:
1798+
# Get the new number from it
1799+
new_number = statistic["Number"]
1800+
1801+
# If the "Text" key is inside the statistic dictionary
1802+
if "Text" in statistic:
1803+
text = statistic["Text"]
1804+
1805+
# If the "dictionary" parameter is not None
1806+
# And there is a "Text" key inside it
1807+
if (
1808+
dictionary != None and
1809+
"Text" in dictionary
1810+
):
1811+
# Get the text from it
1812+
text = dictionary["Text"]
1813+
1814+
# Add the in text text and a colon
1815+
text = "\t" + text + " " + in_text + ": "
1816+
1817+
# Define the number
1818+
number = str(new_number)
1819+
1820+
# If the statistic is a dictionary
1821+
# And the "Money" key is inside the statistic dictionary
1822+
if (
1823+
isinstance(statistic, dict) and
1824+
"Money" in statistic
1825+
):
1826+
# Define the money text
1827+
number = self.Define_Money_Text(number)
1828+
1829+
# Add the current number of the statistic
1830+
text += number
1831+
1832+
# Add the old number with the "before" text
1833+
text += " (" + self.Language.language_texts["before, title()"].lower() + ": " + str(old_number) + ")"
1834+
1835+
# Add the text to the root statistics text
1836+
statistics_text += text
1837+
1838+
# If the "return text" parameter is False
1839+
if return_text == False:
1840+
# Show the text and number with a tab
1841+
print(text)
1842+
1843+
# Return the statistics text
1844+
return statistics_text
1845+
16701846
def Next_State(self, dictionary):
16711847
# Define the states variable for easier typing
16721848
states = dictionary["States"]

0 commit comments

Comments
 (0)