Skip to content

Commit a07fd1a

Browse files
committed
In the "Diary_Slim" module, I made the following changes:
In the "Write_On_Diary_Slim" class, I improved how the information for statistics with various questions is defined. Now the "Manage_Statistic" method checks if the current question has the "Create sub-dictionary" key. If it does, it creates a sub-dictionary using the user's response as the key. It also checks if the current question has the "Add to sub-dictionary" key. The method uses the value of that key to find the sub-dictionary and adds the user's response value to it. Then, it updates the numbers with the values of the responses inside the statistics dictionary. And it changes the text that will be written using a formatting text. For example, I can work at the "Potatoes" company and earn money there. Then, it would create a statistic sub-dictionary called "Potatoes", with the sub-keys "Days that I worked" and "Money that I earned". I also created a new method called "Define_Money_Text". It is used to define a text that will accompany a number that represents money. For example: "$" in "$100" (normal version), and "dollars" in "100 dollars" (extended version). The question dictionary needs to have the "Money" key for that method to be executed. And it can have the "Use extended money text" key to use the extended version of the money text.
1 parent 0c6f418 commit a07fd1a

File tree

6 files changed

+250
-46
lines changed

6 files changed

+250
-46
lines changed

Module files/Diary_Slim/Texts.json

+4
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,9 @@
150150
"type_how_many_times_you_drove_the_car": {
151151
"en": "Type how many times you drove the car",
152152
"pt": "Digite quantas vezes você dirigiu o carro"
153+
},
154+
"type_how_many_times_you_rode_your_bike": {
155+
"en": "Type how many times you rode your bike",
156+
"pt": "Digite quantas vezes você andou de bicicleta"
153157
}
154158
}

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-01-08 21:32:11-03:00",
13+
"Object": "2025-01-14 20:56:19-03:00",
1414
"Time": 0,
15-
"Time text": "21:32",
15+
"Time text": "20:56",
1616
"Unit": {
1717
"en": "hours",
1818
"pt": "horas"
@@ -23,9 +23,9 @@
2323
}
2424
},
2525
"Can drink water": {
26-
"Object": "2025-01-08 22:12:11-03:00",
26+
"Object": "2025-01-14 21:36:19-03:00",
2727
"Time": 40,
28-
"Time text": "22:12",
28+
"Time text": "21:36",
2929
"Unit": {
3030
"en": "minutes",
3131
"pt": "minutos"
@@ -36,9 +36,9 @@
3636
}
3737
},
3838
"Will be hungry": {
39-
"Object": "2025-01-09 00:32:11-03:00",
39+
"Object": "2025-01-14 23:56:19-03:00",
4040
"Time": 3,
41-
"Time text": "00:32",
41+
"Time text": "23:56",
4242
"Unit": {
4343
"en": "hours",
4444
"pt": "horas"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Testing": false,
3-
"Verbose": false,
3+
"Verbose": true,
44
"User information": false,
55
"Has active switches": false
66
}

Module files/Utility/Language/Texts.json

+21-5
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,27 @@
22112211
},
22122212
"days_that_i_worked": {
22132213
"en": "Days that I worked",
2214-
"pt": "Dias que eu trabalheiDias que trabalhei"
2214+
"pt": "Dias que eu trabalhei"
2215+
},
2216+
"times_i_worked_on": {
2217+
"en": "Times I worked on",
2218+
"pt": "Vezes que trabalhei no"
2219+
},
2220+
"i_worked_on_{}_and_earned_{}": {
2221+
"en": "I worked on {} and earned {}",
2222+
"pt": "Trabalhei no {} e ganhei {}"
2223+
},
2224+
"money_that_i_earned": {
2225+
"en": "Money that I earned",
2226+
"pt": "Dinheiro que eu ganhei"
2227+
},
2228+
"money_text, type: format": {
2229+
"en": "${}",
2230+
"pt": "R$ {}"
2231+
},
2232+
"money_text_extended, type: format": {
2233+
"en": "{} dollars",
2234+
"pt": "{} reais"
22152235
},
22162236
"before, title()": {
22172237
"en": "Before",
@@ -2221,10 +2241,6 @@
22212241
"en": "Visits of",
22222242
"pt": "Visitas de"
22232243
},
2224-
"times_i_worked_on": {
2225-
"en": "Times I worked on",
2226-
"pt": "Vezes que trabalhei no"
2227-
},
22282244
"genders, type: dict": {
22292245
"en": {
22302246
"masculine": {

Modules/Diary_Slim/Write_On_Diary_Slim/__init__.py

+201-31
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,34 @@ def Get_Additional_Information(self, dictionary, is_statistic = False):
338338
return return_dictionary
339339

340340
def Define_Input_Text(self, question):
341-
# Define the input text
342-
input_text = question["Input text"]
341+
# Define the default value of the input text as the question
342+
input_text = question
343+
344+
# If the "Input text" key is inside the question dictionary
345+
if "Input text" in question:
346+
# Define the input text
347+
input_text = question["Input text"]
343348

344349
# If the input text is a string
345-
# And the input text is a key to a text dictionary inside the root texts dictionary of this module
346-
if (
347-
isinstance(input_text, str) == True and
348-
input_text in self.texts
349-
):
350-
# Get the correct text dictionary from the text key
351-
input_text = self.texts[input_text]
350+
if isinstance(input_text, str) == True:
351+
# If the input text is a key inside the root texts dictionary of this module
352+
if input_text in self.texts:
353+
# Define the dictionary of texts as that one
354+
texts_dictionary = self.texts
352355

353-
# Get the user language version of the input text
354-
input_text = input_text[self.user_language]
356+
# Else, define it as the dictionary of the "Language" module
357+
else:
358+
texts_dictionary = self.Language.texts
359+
360+
# If the input text is inside the local texts dictionary
361+
if input_text in texts_dictionary:
362+
# Get the correct text dictionary from the text key
363+
input_text = texts_dictionary[input_text]
364+
365+
# If the user language key is inside the input text dictionary
366+
if self.user_language in input_text:
367+
# Get the user language version of the input text
368+
input_text = input_text[self.user_language]
355369

356370
# Return the language input text
357371
return input_text
@@ -844,21 +858,142 @@ def Manage_Statistic(self):
844858

845859
# If the "Questions" key is inside the statistic dictionary
846860
if "Questions" in statistic:
847-
# Iterate through the responses
848-
for answer_key, answer in response.items():
849-
# Save the old number
850-
old_number = current_year_statistics[key]
861+
# If the "Create sub-dictionary" key is inside the question dictionary
862+
if "Create sub-dictionary" in question:
863+
# Define the sub-dictionary key
864+
sub_key = question["Response"]
865+
866+
# Define the dictionary to add
867+
to_add = {
868+
"Text": statistic_text
869+
}
870+
871+
# If the sub-key is not inside the dictionary
872+
if sub_key not in to_add:
873+
# Add the sub-key with the dictionary
874+
to_add[sub_key] = {
875+
statistic["Key"]: 0
876+
}
877+
878+
# Update the old number
879+
old_number = to_add[sub_key][statistic["Key"]]
880+
881+
# Add one to the number
882+
to_add[sub_key][statistic["Key"]] += 1
883+
884+
# Define the sub-dictionaries dictionary, with the question key (question number)
885+
sub_dictionaries = {
886+
key: to_add[sub_key]
887+
}
888+
889+
# Update the to add dictionary to add the keys of the root statistics dictionary
890+
to_add = {
891+
**to_add
892+
}
851893

852-
# Add the answer to the statistic using the response/question key
853-
current_year_statistics[key] += answer
894+
# Update the numbers
895+
to_add["Old number"] = old_number
896+
to_add["Number"] = to_add[sub_key][statistic["Key"]]
897+
898+
# Add the sub-dictionary to the root statistics dictionary
899+
self.dictionary["Text"]["Statistics"]["Dictionary"][statistic_key] = to_add
900+
901+
# Update the current year statistics in the current statistic key
902+
self.diary_slim["Current year"]["Statistics"][text_key] = {
903+
sub_key: to_add
904+
}
905+
906+
# Define the current year statistics dictionary (with the current statistic key) as the "to add" one
907+
current_year_statistics = self.diary_slim["Current year"]["Statistics"][text_key]
908+
909+
# If the "Add to sub-dictionary" key is inside the question dictionary
910+
if "Add to sub-dictionary" in question:
911+
# Get the sub-key
912+
sub_key = question["Add to sub-dictionary"]
913+
914+
# If the question key is not inside the sub-dictionary
915+
if question["Key"] not in sub_dictionaries[sub_key]:
916+
sub_dictionaries[sub_key][question["Key"]] = 0
917+
918+
# Get the old number
919+
old_number = sub_dictionaries[sub_key][question["Key"]]
920+
921+
# Add the question key with the response as value, to the selected sub-dictionary
922+
sub_dictionaries[sub_key][question["Key"]] = response
923+
924+
# Define the sub-dictionary
925+
sub_dictionary = sub_dictionaries[sub_key]
926+
927+
# Get the correct sub-key
928+
sub_key = questions[sub_key]["Response"]
929+
930+
# Update the sub-dictionary on the root statistics dictionary
931+
self.dictionary["Text"]["Statistics"]["Dictionary"][statistic_key].update(sub_dictionary)
932+
933+
# Update the current year statistics in the current statistic key
934+
self.diary_slim["Current year"]["Statistics"][text_key] = {
935+
sub_key: sub_dictionary
936+
}
854937

855-
# Add the key to the statistic dictionary inside the Diary Slim dictionary
856-
self.dictionary["Text"]["Statistics"]["Dictionary"][key] = {
857-
"Text": self.language_texts[key.replace(" ", "_").lower()],
938+
# Define the current year statistics dictionary (with the current statistic key) as the "to add" one
939+
current_year_statistics = {
940+
sub_key: self.diary_slim["Current year"]["Statistics"][text_key]
941+
}
942+
943+
# ---------- #
944+
945+
# Define the local text key
946+
local_text_key = question["Key"].replace(" ", "_").lower()
947+
948+
# Add the additional question key to the root statistics dictionary
949+
self.dictionary["Text"]["Statistics"]["Dictionary"][question["Key"]] = {
950+
"Text": self.Language.language_texts[local_text_key],
858951
"Old number": old_number,
859-
"Number": current_year_statistics[key]
952+
"Number": response
860953
}
861954

955+
# If the "Money" key is inside the question dictionary
956+
if "Money" in question:
957+
# Add the money key to the root statistics dictionary
958+
self.dictionary["Text"]["Statistics"]["Dictionary"][question["Key"]]["Money"] = question["Money"]
959+
960+
# ---------- #
961+
962+
# Change the "Changed statistic" to True
963+
self.dictionary["Text"]["Statistics"]["Changed statistic"] = True
964+
965+
# ---------- #
966+
967+
# Define the number as zero
968+
number = 0
969+
970+
# ---------- #
971+
972+
# Define the list of items to use
973+
items = [
974+
sub_key,
975+
response
976+
]
977+
978+
# If the "Money" key is inside the question dictionary
979+
if "Money" in question:
980+
# Define the "Use extended" variable
981+
use_extended = True
982+
983+
# If the "Use extended money text" is inside the question dictionary
984+
if "Use extended money text" in question:
985+
# Define the "Use extended" variable as the one inside that key
986+
use_extended = question["Use extended money text"]
987+
988+
# Add the money text to the response and update the item inside the list above
989+
items[1] = self.Define_Money_Text(response, use_extended = use_extended)
990+
991+
# Get the format text
992+
format_text = question["Format text"]
993+
994+
# Format the text with the list of items, updating the text to write
995+
self.dictionary["Text to write"] = self.Language.language_texts[format_text].format(*items)
996+
862997
# Update the number of statistics
863998
self.dictionary["Text"]["Statistics"]["Number"] = len(list(self.dictionary["Text"]["Statistics"]["Dictionary"].keys()))
864999

@@ -875,20 +1010,26 @@ def Manage_Statistic(self):
8751010
add_to_number = False
8761011

8771012
# If the "add to number" state variable is True
878-
if add_to_number == True:
1013+
# And the statistic key exists inside the current year statistics dictionary
1014+
# And the number is not equal to zero
1015+
if (
1016+
add_to_number == True and
1017+
statistic_key in current_year_statistics and
1018+
number != 0
1019+
):
8791020
# Add the defined number to the defined statistic key
8801021
current_year_statistics[statistic_key] += number
8811022

882-
# Update the number inside the statistics dictionary inside the Diary Slim text dictionary
883-
self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Number"] = current_year_statistics[statistic_key]
1023+
# Update the number inside the statistics dictionary inside the Diary Slim text dictionary
1024+
self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Number"] = current_year_statistics[statistic_key]
8841025

885-
# If the old number is not the same as the new number
886-
old_number = self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Old number"]
887-
new_number = self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Number"]
1026+
# If the old number is not the same as the new number
1027+
old_number = self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Old number"]
1028+
new_number = self.dictionary["Text"]["Statistics"]["Dictionary"][statistic["Key"]]["Number"]
8881029

889-
if old_number != new_number:
890-
# Change the "Changed statistic" to True
891-
self.dictionary["Text"]["Statistics"]["Changed statistic"] = True
1030+
if old_number != new_number:
1031+
# Change the "Changed statistic" to True
1032+
self.dictionary["Text"]["Statistics"]["Changed statistic"] = True
8921033

8931034
# If the "Text decorator" is inside the statistic dictionary
8941035
if "Text decorator" in self.dictionary["Text"]["Statistic"]:
@@ -920,6 +1061,24 @@ def Manage_Statistic(self):
9201061
# Update the statistics of the current year
9211062
self.Update_Current_Year_Statistics(self.diary_slim["Current year"]["Statistics"])
9221063

1064+
def Define_Money_Text(self, number, use_extended = True):
1065+
# Define the default text key
1066+
text_key = "money_text"
1067+
1068+
# If the "Use extended" state is True
1069+
if use_extended == True:
1070+
# Add the "_extended" text to the text key
1071+
text_key += "_extended"
1072+
1073+
# Add the ", type: format" text to the text key
1074+
text_key += ", type: format"
1075+
1076+
# Format the money number with the correct money text defined before
1077+
number = self.Language.language_texts[text_key].format(number)
1078+
1079+
# Return the number with the money text
1080+
return number
1081+
9231082
def Write(self):
9241083
# If the "Item" key is inside the text dictionary
9251084
if "Item" in self.dictionary["Text"]:
@@ -968,6 +1127,9 @@ def Write(self):
9681127
print()
9691128
print(show_text + ":")
9701129

1130+
# Define a shortcut for the dictionary
1131+
dictionary = self.dictionary["Text"]["Statistics"]["Dictionary"]
1132+
9711133
# Iterate through the dictionary of statistics
9721134
for statistic in self.dictionary["Text"]["Statistics"]["Dictionary"].values():
9731135
# Define the text with the statistic text and colon
@@ -979,8 +1141,16 @@ def Write(self):
9791141
# Add a colon
9801142
text += ": "
9811143

1144+
# Define the number
1145+
number = str(statistic["Number"])
1146+
1147+
# If the "Money" key is inside the statistic dictionary
1148+
if "Money" in statistic:
1149+
# Define the money text
1150+
number = self.Define_Money_Text(number)
1151+
9821152
# Add the current number of the statistic
983-
text += str(statistic["Number"])
1153+
text += number
9841154

9851155
# Add the old number with the "before" text
9861156
text += " (" + self.Language.language_texts["before, title()"].lower() + ": " + str(statistic["Old number"]) + ")"

0 commit comments

Comments
 (0)