|
27 | 27 | along with this program. If not, see <https://www.gnu.org/licenses/>. |
28 | 28 | """ |
29 | 29 |
|
| 30 | +import sys |
| 31 | + |
30 | 32 | import matplotlib.pyplot as plt |
31 | 33 | from typing import Dict, Union |
32 | 34 |
|
@@ -78,31 +80,23 @@ def save(self, oFile: str) -> None: |
78 | 80 | plt.savefig(oFile) |
79 | 81 | plt.close() |
80 | 82 |
|
81 | | - def getStatistics(self) -> Dict[str, Union[int, float]]: |
| 83 | + def getStatistics(self) -> None: |
82 | 84 | if not self.patternCounts: |
83 | | - return {} |
| 85 | + return None |
| 86 | + |
| 87 | + minLen = min(self.patternCounts.keys()) |
| 88 | + maxLen = max(self.patternCounts.keys()) |
84 | 89 |
|
85 | | - return { |
86 | | - 'totalPatterns': sum(self.patternCounts.values()), |
87 | | - 'minPatternSize': min(self.patternCounts.keys()), |
88 | | - 'maxPatternSize': max(self.patternCounts.keys()), |
89 | | - 'patternSizeDistribution': self.patternCounts |
90 | | - } |
| 90 | + print("Statistics:") |
| 91 | + print(f" Length range: {minLen}-{maxLen}") |
| 92 | + print(" Pattern Size Distribution <size: #count>:") |
| 93 | + for size, count in sorted(self.patternCounts.items()): |
| 94 | + print(f" {size}:{count}") |
| 95 | + return None |
91 | 96 |
|
92 | 97 |
|
93 | 98 | if __name__ == "__main__": |
94 | | - samplePatterns = { |
95 | | - ('A',): 100, |
96 | | - ('B',): 150, |
97 | | - ('C',): 120, |
98 | | - ('A', 'B'): 80, |
99 | | - ('A', 'C'): 70, |
100 | | - ('B', 'C'): 90, |
101 | | - ('A', 'B', 'C'): 50, |
102 | | - ('D',): 110, |
103 | | - ('A', 'D'): 60, |
104 | | - ('B', 'D'): 65, |
105 | | - } |
106 | | - |
107 | | - obj = plotFrequentPatternSetsGraph(samplePatterns) |
| 99 | + # Usage: python plotFrequentPatternSetsGraph.py patterns.txt |
| 100 | + obj = plotFrequentPatternSetsGraph(sys.argv[1]) |
108 | 101 | obj.plot() |
| 102 | + obj.getStatistics() |
0 commit comments