Belle II Software light-2406-ragdoll
StatisticsVisitor Class Reference

Public Member Functions

def __init__ (self)
 
def read_rst_file (self, Path path)
 
def walk_directory (self, Path path)
 

Public Attributes

 statistics
 statistics object
 

Static Public Attributes

dict regexes
 Dictionary keys must match attributes of Statistics class.
 

Detailed Description

Statistics visitor class

Definition at line 42 of file online_book_statistics.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)
Initialize class

Definition at line 57 of file online_book_statistics.py.

57 def __init__(self):
58 """Initialize class"""
59
60 self.statistics = Statistics()
61

Member Function Documentation

◆ read_rst_file()

def read_rst_file (   self,
Path  path 
)
Read rst file

Definition at line 62 of file online_book_statistics.py.

62 def read_rst_file(self, path: Path):
63 """Read rst file"""
64 text = path.read_text()
65 self.statistics.characters += len(text)
66 for line in text.split("\n"):
67 for key, regex in self.regexes.items():
68 if regex.findall(line):
69 setattr(
70 self.statistics, key, getattr(self.statistics, key) + 1
71 )
72

◆ walk_directory()

def walk_directory (   self,
Path  path 
)
Loop over all directories in the path

Definition at line 73 of file online_book_statistics.py.

73 def walk_directory(self, path: Path):
74 """Loop over all directories in the path"""
75 print(f"Walking {path}")
76 for root, _, files in os.walk(path):
77 for file in files:
78 path = Path(root) / file
79 if path.suffix == ".rst":
80 self.read_rst_file(path)
81
82

Member Data Documentation

◆ regexes

dict regexes
static
Initial value:
= dict(
code_inclusions=re.compile("(code-block\\s*::)|(literalinclude\\s*::)"),
hints=re.compile(":class:.*hint"),
solutions=re.compile(":class:.*solution"),
exercises=re.compile(":class:.*exercise"),
overview_boxes=re.compile(":class:.*overview"),
key_points=re.compile(":class:.*key-points"),
figures=re.compile("figure\\s*::")
)

Dictionary keys must match attributes of Statistics class.

Definition at line 47 of file online_book_statistics.py.

◆ statistics

statistics

statistics object

Definition at line 60 of file online_book_statistics.py.


The documentation for this class was generated from the following file: