@@ -338,20 +338,34 @@ def Get_Additional_Information(self, dictionary, is_statistic = False):
338
338
return return_dictionary
339
339
340
340
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" ]
343
348
344
349
# 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
352
355
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 ]
355
369
356
370
# Return the language input text
357
371
return input_text
@@ -844,21 +858,142 @@ def Manage_Statistic(self):
844
858
845
859
# If the "Questions" key is inside the statistic dictionary
846
860
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
+ }
851
893
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
+ }
854
937
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 ],
858
951
"Old number" : old_number ,
859
- "Number" : current_year_statistics [ key ]
952
+ "Number" : response
860
953
}
861
954
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
+
862
997
# Update the number of statistics
863
998
self .dictionary ["Text" ]["Statistics" ]["Number" ] = len (list (self .dictionary ["Text" ]["Statistics" ]["Dictionary" ].keys ()))
864
999
@@ -875,20 +1010,26 @@ def Manage_Statistic(self):
875
1010
add_to_number = False
876
1011
877
1012
# 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
+ ):
879
1020
# Add the defined number to the defined statistic key
880
1021
current_year_statistics [statistic_key ] += number
881
1022
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 ]
884
1025
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" ]
888
1029
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
892
1033
893
1034
# If the "Text decorator" is inside the statistic dictionary
894
1035
if "Text decorator" in self .dictionary ["Text" ]["Statistic" ]:
@@ -920,6 +1061,24 @@ def Manage_Statistic(self):
920
1061
# Update the statistics of the current year
921
1062
self .Update_Current_Year_Statistics (self .diary_slim ["Current year" ]["Statistics" ])
922
1063
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
+
923
1082
def Write (self ):
924
1083
# If the "Item" key is inside the text dictionary
925
1084
if "Item" in self .dictionary ["Text" ]:
@@ -968,6 +1127,9 @@ def Write(self):
968
1127
print ()
969
1128
print (show_text + ":" )
970
1129
1130
+ # Define a shortcut for the dictionary
1131
+ dictionary = self .dictionary ["Text" ]["Statistics" ]["Dictionary" ]
1132
+
971
1133
# Iterate through the dictionary of statistics
972
1134
for statistic in self .dictionary ["Text" ]["Statistics" ]["Dictionary" ].values ():
973
1135
# Define the text with the statistic text and colon
@@ -979,8 +1141,16 @@ def Write(self):
979
1141
# Add a colon
980
1142
text += ": "
981
1143
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
+
982
1152
# Add the current number of the statistic
983
- text += str ( statistic [ "Number" ])
1153
+ text += number
984
1154
985
1155
# Add the old number with the "before" text
986
1156
text += " (" + self .Language .language_texts ["before, title()" ].lower () + ": " + str (statistic ["Old number" ]) + ")"
0 commit comments