@@ -425,6 +425,7 @@ def Define_History(self):
425
425
# ---------- #
426
426
427
427
# Iterate through the years list
428
+ # Years list: "2020" to the current year
428
429
for year in self .years_list :
429
430
# Create the year folder
430
431
folders = {
@@ -1299,10 +1300,12 @@ def Create_External_Statistics(self):
1299
1300
# If the external statistics file is not empty
1300
1301
if self .File .Contents (file )["lines" ] != []:
1301
1302
# Get the JSON dictionary
1302
- json_dictionary = self .JSON .To_Python (file )
1303
+ # json_dictionary = self.JSON.To_Python(file)
1303
1304
1304
1305
# Update the root year dictionary with the local JSON one, using the "Define_Options" method
1305
- external_statistics = self .Define_Options (external_statistics , json_dictionary )
1306
+ #external_statistics = self.Define_Options(external_statistics, json_dictionary)
1307
+
1308
+ test = ""
1306
1309
1307
1310
# ---------- #
1308
1311
@@ -1314,16 +1317,23 @@ def Create_External_Statistics(self):
1314
1317
** module
1315
1318
}
1316
1319
1320
+ # Get the statistic key from the module dictionary
1321
+ statistic_key = module ["Statistic key" ]
1322
+
1317
1323
# Add the module title to the list of external statistics if it is not already present
1318
1324
if module_title not in external_statistics ["List" ]:
1319
1325
external_statistics ["List" ].append (module_title )
1320
1326
1321
1327
# Add the module title to the dictionary of external statistics if it is not already present
1322
1328
if module_title not in external_statistics ["Dictionary" ]:
1323
- external_statistics ["Dictionary" ][module_title ] = {}
1324
-
1325
- # Get the statistic key from the module dictionary
1326
- statistic_key = module ["Statistic key" ]
1329
+ external_statistics ["Dictionary" ][module_title ] = {
1330
+ "Module" : module_title ,
1331
+ "Statistic key" : statistic_key ,
1332
+ "Text key" : "" ,
1333
+ "Text" : {},
1334
+ "List" : [],
1335
+ "Years" : {}
1336
+ }
1327
1337
1328
1338
# Add the statistic key to the list of keys if it is not already present
1329
1339
if statistic_key not in external_statistics ["Keys" ]:
@@ -1356,6 +1366,7 @@ def Create_External_Statistics(self):
1356
1366
if "Create_Statistics" in module ["Methods" ]:
1357
1367
# Get the dictionary of statistics from the "Create_Statistics" method
1358
1368
# Passing the list of years as a parameter
1369
+ # Years list: "2020" to the current year
1359
1370
statistics = module ["Class" ].Create_Statistics (self .years_list )
1360
1371
1361
1372
# Define the dictionary of parameters
@@ -1562,6 +1573,8 @@ def Update_Statistics(self):
1562
1573
1563
1574
# Update the external statistics dictionaries of the years and months
1564
1575
1576
+ update = False
1577
+
1565
1578
# Iterate through the "External statistics" dictionary
1566
1579
for statistics in self .statistics ["External statistics" ]["Dictionary" ].values ():
1567
1580
# Define the statistic key
@@ -1591,16 +1604,16 @@ def Update_Statistics(self):
1591
1604
# Get the root statistics dictionary
1592
1605
root_statistics = root_year ["Statistics" ][statistic_key ]
1593
1606
1594
- # Add the "Total" key and the number dictionaries inside the "Numbers" to the root year statistics dictionary
1595
- root_year ["Statistics" ][statistic_key ] = {
1596
- "Module" : root_statistics ["Module" ],
1597
- "Total" : year ["Total" ],
1598
- "Dictionary" : {
1599
- ** year ["Numbers" ]
1607
+ if update == True :
1608
+ # Add the "Total" key and the number dictionaries inside the "Numbers" to the root year statistics dictionary
1609
+ root_year ["Statistics" ][statistic_key ] = {
1610
+ "Module" : root_statistics ["Module" ],
1611
+ "Total" : year ["Total" ],
1612
+ "Dictionary" : {
1613
+ ** year ["Numbers" ]
1614
+ }
1600
1615
}
1601
- }
1602
1616
1603
- # Iterate through the months inside the year dictionary
1604
1617
for month in year ["Months" ].values ():
1605
1618
# Get the month key using the list of month names in the user language with the month number with leading zeroes
1606
1619
month_key = month ["Key" ] + " - " + self .Date .language_texts ["month_names, type: list" ][int (month ["Key" ])]
@@ -1611,17 +1624,19 @@ def Update_Statistics(self):
1611
1624
# Get the root statistics dictionary
1612
1625
root_statistics = root_year ["Months" ][month_key ]["Statistics" ][statistic_key ]
1613
1626
1614
- # Add the "Total" key and the number dictionaries inside the "Numbers" to the root month statistics dictionary
1615
- root_year ["Months" ][month_key ]["Statistics" ][statistic_key ] = {
1616
- "Module" : root_statistics ["Module" ],
1617
- "Total" : month ["Total" ],
1618
- "Dictionary" : {
1619
- ** month ["Numbers" ]
1627
+ if update == True :
1628
+ # Add the "Total" key and the number dictionaries inside the "Numbers" to the root month statistics dictionary
1629
+ root_year ["Months" ][month_key ]["Statistics" ][statistic_key ] = {
1630
+ "Module" : root_statistics ["Module" ],
1631
+ "Total" : month ["Total" ],
1632
+ "Dictionary" : {
1633
+ ** month ["Numbers" ]
1634
+ }
1620
1635
}
1621
- }
1622
1636
1623
- # Add the year dictionary to the local dictionary of years
1624
- years_dictionary [key ] = root_year
1637
+ if update == True :
1638
+ # Add the year dictionary to the local dictionary of years
1639
+ years_dictionary [key ] = root_year
1625
1640
1626
1641
# Iterate through the dictionary of years
1627
1642
for key , year in self .years ["Dictionary" ].items ():
@@ -1659,6 +1674,15 @@ def Update_Statistics(self):
1659
1674
# Remove the statistic from the "Statistics" dictionary
1660
1675
year ["Months" ][month_key ]["Statistics" ].pop (statistic_key )
1661
1676
1677
+ # If the statistic key is not inside the month dictionary
1678
+ if statistic_key not in month ["Statistics" ]:
1679
+ # Add the "Total" key and the number dictionaries inside the "Numbers" to the root month statistics dictionary
1680
+ year ["Months" ][month_key ]["Statistics" ][statistic_key ] = {
1681
+ "Module" : statistic ["Module" ],
1682
+ "Total" : 0 ,
1683
+ "Dictionary" : {}
1684
+ }
1685
+
1662
1686
# Add the year dictionary to the local dictionary of years
1663
1687
years_dictionary [key ] = year
1664
1688
@@ -1707,7 +1731,7 @@ def Update_External_Statistics(self, statistic_key, statistics):
1707
1731
parameters [0 ][statistic_key ] = year_statistics
1708
1732
1709
1733
# Get the year statistics text
1710
- text += self .Show_Statistics ("Year" , year_statistics , statistics [ "Dictionary" ] , return_text = True ) + "\n "
1734
+ text += self .Show_Statistics ("Year" , statistics , return_text = True ) + "\n "
1711
1735
1712
1736
# ---------- #
1713
1737
@@ -1718,7 +1742,7 @@ def Update_External_Statistics(self, statistic_key, statistics):
1718
1742
parameters [1 ][statistic_key ] = month_statistics
1719
1743
1720
1744
# Get the year statistics text
1721
- text += self .Show_Statistics ("Month" , month_statistics , statistics [ "Dictionary" ] , return_text = True )
1745
+ text += self .Show_Statistics ("Month" , statistics , return_text = True )
1722
1746
1723
1747
# ---------- #
1724
1748
@@ -1728,41 +1752,36 @@ def Update_External_Statistics(self, statistic_key, statistics):
1728
1752
# Return the statistics text
1729
1753
return text
1730
1754
1731
- def Show_Statistics (self , date_type , statistics , dictionary = None , return_text = False ):
1755
+ def Show_Statistics (self , date_type , statistics , return_text = False ):
1732
1756
# Define the text key
1733
1757
text_key = date_type .lower ()
1734
1758
1759
+ # Define the new number as one
1760
+ new_number = 1
1761
+
1735
1762
# If the "Number" key is inside the statistics dictionary
1736
1763
if "Number" in statistics :
1737
1764
# Get the number of updated statistics for the month/year
1738
1765
new_number = statistics ["Number" ]
1739
1766
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
1767
# Define the statistic text to show as singular or plural depending on the number
1747
1768
singular = self .Language .language_texts ["updated_" + text_key + "_statistic" ]
1748
1769
plural = self .Language .language_texts ["updated_" + text_key + "_statistics" ]
1749
1770
1750
1771
show_text = self .Text .By_Number (new_number , singular , plural )
1751
1772
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
1773
# Define the root statistics text
1758
1774
statistics_text = "\n " + \
1759
- show_text + ":" + " \n "
1775
+ show_text + ":"
1760
1776
1761
1777
# If the "return text" parameter is False
1762
1778
if return_text == False :
1763
1779
# Show the statistics text
1764
1780
print (statistics_text )
1765
1781
1782
+ # Add a line break to the root statistics text
1783
+ statistics_text += "\n "
1784
+
1766
1785
# Define the default "in text" as "in [year]"
1767
1786
in_text = self .Language .language_texts ["in" ] + " " + str (self .diary_slim ["Current year" ]["Number" ])
1768
1787
@@ -1771,58 +1790,48 @@ def Show_Statistics(self, date_type, statistics, dictionary = None, return_text
1771
1790
# Re-define the in text to be "in [month name]"
1772
1791
in_text = self .Language .language_texts ["in" ] + " " + str (self .diary_slim ["Current year" ]["Month" ]["Name text" ])
1773
1792
1774
- # If the "dictionary" parameter is not None
1775
- if dictionary != None :
1793
+ # If the "External statistic" key is inside the statistics dictionary
1794
+ if "External statistic" in statistics :
1776
1795
# Get the first key of the statistics dictionary
1777
1796
first_key = list (statistics ["Dictionary" ].keys ())[0 ]
1778
1797
1779
- # Make a copy of the statistics dictionary
1798
+ # Make a copy of the statistics dictionary to not modify the root one
1780
1799
statistics = deepcopy (statistics )
1781
1800
1782
1801
# Make the dictionary only have the first key
1783
1802
statistics ["Dictionary" ] = {
1784
- first_key : statistics ["Dictionary" ][first_key ]
1803
+ first_key : {
1804
+ "Old number" : statistics ["Dictionary" ]["Numbers" ][date_type ]["Old" ],
1805
+ "Number" : statistics ["Dictionary" ]["Numbers" ][date_type ]["New" ],
1806
+ "Text" : statistics ["Text" ]
1807
+ }
1785
1808
}
1786
1809
1787
1810
# Iterate through the dictionary of statistics
1788
1811
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" ]
1812
+ # Get the old number
1813
+ old_number = statistic ["Old number" ]
1814
+
1815
+ # Get the new number
1816
+ new_number = statistic ["Number" ]
1813
1817
1814
- # Add the in text text and a colon
1818
+ # If the "Text" key is inside the statistic dictionary
1819
+ if "Text" in statistic :
1820
+ # Define the text as it
1821
+ text = statistic ["Text" ]
1822
+
1823
+ # Else, try to find it inside the root statistics dictionary
1824
+ else :
1825
+ text = statistics ["Text" ]
1826
+
1827
+ # Add the in text text and a colon and space
1815
1828
text = "\t " + text + " " + in_text + ": "
1816
1829
1817
1830
# Define the number
1818
1831
number = str (new_number )
1819
1832
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
- ):
1833
+ # If the "Money" key is inside the statistic dictionary
1834
+ if "Money" in statistic :
1826
1835
# Define the money text
1827
1836
number = self .Define_Money_Text (number )
1828
1837
0 commit comments