add first capacitor selection according to a Pareto plane#1
Conversation
SevenOfNinePE
left a comment
There was a problem hiding this comment.
Structural criticism:
The toolbox uses data classes, but it is not object-oriented.
That is, there are functions, but no methods. This may be easier at the beginning,
but ultimately, the structuring options offered by classes are missing.
With classes, the code would be much more maintainable and extensions would be easier to write.
Example:
If there were a class for film capacitors and one for electrolytic capacitors, both classes would be
derived from the general capacitor class. This would have the (virtual) method calc_power_loss,
which calculates the power loss. Virtual means: The method only declared (parameters), but it has no function body.
This means that both the film capacitor and electrolytic capacitor classes must implement this method.
The user has the advantage of only load the capacitor data into the class (which load it to a dataframe, like now implemented)
and then they can calculate the power loss. It doesn't matter whether it's a film capacitor or an electrolytic capacitor.
It simply calls 'MyCap.calc_power_loss(...)' and the correct method is automatically selected.
The electrolytic capacitor or film instance then has its specific data frame.
There are certainly many methods that are the same for both (defined in the general capacitor class).
Different things are defined in the respective derived classes (film or electrolytic capacitor class), although they are declared virtually in the capacitor class.
| c_df = c_df.drop(columns=["multiplier_1", "multiplier_2", "MOQ", "p1_in_mm"]) | ||
|
|
||
| # transfer the datasheet given units to SI units | ||
| c_df['volume'] = c_df["width_in_mm"].astype(float) * 1e-3 * c_df["height_in_mm"].astype(float) * 1e-3 * c_df["length_in_mm"].astype(float) * 1e-3 |
There was a problem hiding this comment.
Usual magic numbers are forbidden. 1e-3 could be a constant, eg. milli_factor.
This is valid for all previous or succeeding numbers.
There was a problem hiding this comment.
fixed by adding a separate constant.py file
| # own libraries | ||
| from cst.cst_dataclasses import SelectCapacitor, CalculatedRequirementsValues | ||
|
|
||
| def calculate_from_requirements(capacitor_requirements: SelectCapacitor) -> CalculatedRequirementsValues: |
There was a problem hiding this comment.
Purpose of this function is not clear. In the example, the output is never used (eg. irms). Of course this value is maybe important, but it can be derivate from initial requirements.
|
|
||
| :param capacitor_type_list: list of capacitor types to load | ||
| :type capacitor_type_list: list[CapacitorType] | ||
| :return: |
There was a problem hiding this comment.
Missing return type (Should be indicated by tool?)
|
|
||
| :param capacitor_requirements: capacitor requirements and input values in a DTO | ||
| :type capacitor_requirements: CapacitorRequirements | ||
| """ |
There was a problem hiding this comment.
Missing return type (Should be indicated by tool?)
|
|
||
| :param ambient_temperature: ambient temperature in degree Celsius | ||
| :param df_derating: dataframe with temperature derating information | ||
| :return: derating factor |
There was a problem hiding this comment.
Missing Types of parameter inclusive return type (Should be indicated by tool?)
| :param width: capacitor width in meter | ||
| :param length: capacitor length in meter | ||
| :param height: capacitor height in meter | ||
| :return: thermal equivalent coefficient |
There was a problem hiding this comment.
Missing Types of parameter inclusive return type (Should be indicated by tool?)
| Filtering e.g. for the Pareto front must be done in a separate step by the user. | ||
|
|
||
| :param capacitor_requirements: capacitor requirements | ||
| :return: pandas data frame with all possible capacitors. |
There was a problem hiding this comment.
Missing Types of parameter inclusive return type (Should be indicated by tool?)
Several features are implemented as a first scetch:
This is the first draft as a base line. Next step is to introduce more features (like electrolytic capacitors).