TimberVis Flexiboard: Visualization and Exploration Flexiboard for Timber Buildings IoT data sensors. The pulse of the wood Monitoring of Wooden houses: Time series of sensors data measuring humidity, temperatures, vibrations and weather conditions. https://lnu.se/forskning/forskningsprojekt/projekt-flexiboard-for-visualisering-och-utforskning-av-trabyggnader/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
infravis-trahust/web-html/codereport.py

101 lines
3.4 KiB

import sys
import re
def analyze_file(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
num_lines = len(lines)
variables = []
functions = 0
ifs = 0
switches = 0
foreachs = 0
for line in lines:
line = line.strip()
# Check for variable declarations and add them to the list
var_declaration_match_js = re.match(r"^(var|let|const)\s+([\w$]+)", line)
var_declaration_match_py = re.match(r"^(?:.*)?(\w+)\s*=", line)
if var_declaration_match_js:
variable = var_declaration_match_js.group(2)
variables.append(variable)
elif var_declaration_match_py:
variable = var_declaration_match_py.group(1)
variables.append(variable)
# Count the number of function declarations
function_declaration_match_js = re.match(r"^(function)\s+[\w$]+\(", line)
function_declaration_match_py = re.match(r"^(?:def)\s+(?:(?:\w+\s*\(.*\))|(?:\w+))", line)
if function_declaration_match_js or function_declaration_match_py:
functions += 1
# Count the number of if statements
if re.match(r"^(if)\s*\(", line):
ifs += 1
# Count the number of switch statements
if re.match(r"^(switch)\s*\(", line):
switches += 1
# Count the number of forEach statements
if re.match(r"^(.+)\.forEach\s*\(", line):
foreachs += 1
return {
'file': file_path,
'num_lines': num_lines,
'num_variables': variables,
'num_functions': functions,
'num_ifs': ifs,
'num_switches': switches,
'num_foreachs': foreachs
}
if __name__ == '__main__':
if len(sys.argv) < 2:
print('Please provide at least one JavaScript or Python file to analyze.')
sys.exit(1)
total_lines = 0
total_variables = []
total_functions = 0
total_ifs = 0
total_switches = 0
total_foreachs = 0
reports = []
for file_path in sys.argv[1:]:
analysis = analyze_file(file_path)
total_lines += analysis["num_lines"]
total_variables.extend(analysis["num_variables"])
total_functions += analysis["num_functions"]
total_ifs += analysis["num_ifs"]
total_switches += analysis["num_switches"]
total_foreachs += analysis["num_foreachs"]
report = f'File: {analysis["file"]}\n'
report += f'Number of Lines: {analysis["num_lines"]}\n'
report += f'Number of Variables: {len(set(analysis["num_variables"]))}\n'
report += f'Number of Functions: {analysis["num_functions"]}\n'
report += f'Number of If Statements: {analysis["num_ifs"]}\n'
report += f'Number of Switch Statements: {analysis["num_switches"]}\n'
report += f'Number of ForEach Statements: {analysis["num_foreachs"]}\n'
report += '---\n'
reports.append(report)
print('Total Report:')
print('---')
print(f'All Files: {", ".join(sys.argv[1:])}')
print(f'Number of Lines: {total_lines}')
print(f'Number of Variables: {len(set(total_variables))}')
print(f'Number of Functions: {total_functions}')
print(f'Number of If Statements: {total_ifs}')
print(f'Number of Switch Statements: {total_switches}')
print(f'Number of ForEach Statements: {total_foreachs}')
print('---\n')
for report in reports:
print(report)