Quickstart#
New releases of efficalc are distributed on PyPI.
Installation#
Install to your project via pip:
pip install efficalc
First Calculation Function#
Efficalc works best when calculations are defined as a function. The most common classes you’ll use are Input
and Calculation
.
For example, if you want a calculation for pythagorean’s theorem and the perimeter of a right triangle, your calculation may be:
1from efficalc import Calculation, Input, Title, sqrt
2
3
4def calculation():
5 Title("Pythagorean's Theorem and Perimeter")
6
7 a = Input("a", 3, description="Length of side a")
8 b = Input("b", 4, description="Length of side b")
9
10 c = Calculation("c", sqrt(a**2 + b**2), description="Length of the hypotenuse")
11
12 Calculation("P", a + b + c, description="Perimeter of the triangle")
View Reports#
There are a few ways to produce a report for your calculations. To view and print the report from your browser, you can do something as simple as:
1from efficalc.report_builder import ReportBuilder
2from pythagorean_perimeter import calculation
3
4builder = ReportBuilder(calculation)
5builder.view_report()
Running this code gives us this nice report:
Change Input Values#
Now that’s great and easy, but it will always return the same calculation with the same default inputs that we gave in the Calculation
function (3 and 4).
But we want to make our calculations flexible so we can use the same function for many different design inputs. Luckily, the ReportBuilder
makes this super easy by supplying any input overrides to the second argument.
Here’s an example:
1from efficalc.report_builder import ReportBuilder
2from pythagorean_perimeter import calculation
3
4# define the new inputs to override the defaults
5new_inputs = {"a": 5, "b": 6}
6
7# run the report with the input override values
8builder = ReportBuilder(calculation, new_inputs)
9builder.view_report()
Now, our report shows the updated inputs. Not the default inputs we defined in the calculation function:
And that’s all there is to it!
Well actually there’s a lot more that you can do with efficalc.
But the overall pattern is the same no matter how advanced you want to make your calculations. Take a deeper dive into our examples and API documentation to see all of the options we have to build the perfect calculations.
Happy efficalcing!