-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring `dssdata.reductions.get_taps_changes` to avoid Pandas Warnings. The usage of `dssdata.reductions.get_taps_changes` was displaying Warning. Thus, this commit refactor this functions to be more conscise and avoid unecessary allocations in the memory. Also, this commit provides a better documentation for this function. * Fixing code highlight in docs * Updating dependencies and bump version * Removing poetry.lock from the repository
- Loading branch information
1 parent
86c4b91
commit 14992d7
Showing
5 changed files
with
40 additions
and
2,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,4 +112,5 @@ dmypy.json | |
Sistema*/ | ||
.vscode | ||
Meuteste*.py | ||
.venv/ | ||
.venv/ | ||
poetry.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
import pandas | ||
from typing import List | ||
from operator import add | ||
|
||
|
||
def get_taps_changes(tapDataFrame: pandas.DataFrame) -> pandas.DataFrame: | ||
""" | ||
Count the taps changes. That function is a reduction function. | ||
E.g.: | ||
If a trafo starts in tap number 4 and goes to tap number -3. | ||
The result is 7. | ||
`(4 -> 3 -> 2 -> 1 -> 0 -> -1 -> -2 -> -3)` | ||
Args: | ||
tapDataFrame: The return of [get_all_taps_number][dssdata.tools.regs.get_all_taps_number] or [get_tap_number][dssdata.tools.regs.get_tap_number]. | ||
Returns: | ||
The number of taps changes after time series power flow. | ||
""" # noqa | ||
|
||
def calc_one_step_chgs(first: list, second: list): | ||
return map(lambda data1, data2: abs(data1 - data2), first, second) | ||
|
||
def sum_changes_taps(list_df: List[list]): | ||
first = list_df[0] | ||
second = list_df[1] | ||
if len(list_df) == 2: | ||
return calc_one_step_chgs(first, second) | ||
else: | ||
return map( | ||
add, | ||
calc_one_step_chgs(first, second), | ||
sum_changes_taps(list_df[1:]), | ||
) | ||
|
||
iter_by_step = tapDataFrame.groupby(["step"]) | ||
|
||
list_df = tuple(map(lambda data: data[1]["tap"].to_list(), iter_by_step)) | ||
reg_names = tuple( | ||
map(lambda data: data[1]["reg_name"].to_list(), iter_by_step) | ||
)[0] | ||
|
||
return pandas.DataFrame( | ||
data=tuple(zip(reg_names, sum_changes_taps(list_df))), | ||
columns=["reg_name", "number_changes_tap"], | ||
) | ||
mapper = {"tap": "number_changes_tap"} | ||
|
||
def prepair_df(df, step): | ||
return df.loc[step].reset_index(drop=True).rename(columns=mapper) | ||
|
||
df = tapDataFrame.set_index(["step"]) | ||
steps = df.index.unique() | ||
|
||
df_new = prepair_df(df, steps[0]) | ||
df_new["number_changes_tap"] = 0 | ||
|
||
df_prev = prepair_df(df, steps[0]) | ||
|
||
for step in steps: | ||
df_step = prepair_df(df, step) | ||
diff = abs(df_prev["number_changes_tap"] - df_step["number_changes_tap"]) | ||
df_new["number_changes_tap"] += diff | ||
df_prev = df_step | ||
|
||
return df_new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.