-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
43 lines (32 loc) · 1010 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from functools import reduce
from stl_analyzer.parser import parse_stl_file
from stl_analyzer.validator import validate_stl_data
from stl_analyzer.analyzer import analyze_stl_data
from stl_analyzer.model import STLAnalysis
from stl_analyzer.exceptions import STLAnalysisException
def compose(*functions):
funcs_reversed = functions[::-1]
def _compose_2(f, g):
return lambda x: f(g(x))
return reduce(_compose_2, funcs_reversed, lambda x: x)
def analyze_stl_file(full_path: str) -> STLAnalysis:
"""Analyze stl file
Arguments:
full_path {str}
Returns:
STLAnalysis
"""
try:
return compose(
parse_stl_file,
validate_stl_data,
analyze_stl_data)(full_path)
except STLAnalysisException as e:
print(str(e))
def view_analysis(analysis: STLAnalysis):
"""Run analysis and display print
Arguments:
full_path {str} -- path to stl file
"""
if analysis:
analysis.print()