HichamJohra / energy_flexibility_kpis

Energy flexibility KPIs
MIT License
5 stars 6 forks source link

kpi.py bug and flexibility_factor bug #12

Closed ZhelunChen closed 1 year ago

ZhelunChen commented 1 year ago

@kingsleynweye

line 9 of kpi.py causing error - ModuleNotFoundError: No module named 'energy_flexibility_kpis'

flexibility_factor always return -1, probably because an error on line 75. should probably use "|" instead of "&"

kingsleynweye commented 1 year ago

thanks @ZhelunChen. I have provided a fix for the error on line 75: https://github.com/HichamJohra/energy_flexibility_kpis/commit/2e68f5083d8736bf5fb70a2c52a2c0ef395e432f

Please, can you point me to the module you are running that is failing on line 9?

ZhelunChen commented 1 year ago

@kingsleynweye The test module I developed is the test_kpi.py file in the /test subfolder. I think hicham just merged it to the develop branch. I was not able to call the function successfully with line 9 enable.

kingsleynweye commented 1 year ago

@kingsleynweye The test module I developed is the test_kpi.py file in the /test subfolder. I think hicham just merged it to the develop branch. I was not able to call the function successfully with line 9 enable.

Okay, I see it now. I think it might be a thing of how you are calling the tests. Are you calling it like: python -m unittest

ZhelunChen commented 1 year ago

@kingsleynweye ah, you are right. Thanks!

ZhelunChen commented 1 year ago

@kingsleynweye Sorry, I thought that was the issue, but it wasn't after testing it. I try in both cmd and my anonconda environment, get the same error.

D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test>python -m unittest test_kpi E

ERROR: test_kpi (unittest.loader._FailedTest.test_kpi)

ImportError: Failed to import test module: test_kpi Traceback (most recent call last): File "C:\Users\zhelu\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py", line 154, in loadTestsFromName module = import(module_name) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test\test_kpi.py", line 11, in import kpi File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\kpi.py", line 9, in from energy_flexibility_kpis.utilities import Parser ModuleNotFoundError: No module named 'energy_flexibility_kpis'


Ran 1 test in 0.000s

FAILED (errors=1)

kingsleynweye commented 1 year ago

@kingsleynweye Sorry, I thought that was the issue, but it wasn't after testing it. I try in both cmd and my anonconda environment, get the same error.

D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test>python -m unittest test_kpi

E

ERROR: test_kpi (unittest.loader._FailedTest.test_kpi)

ImportError: Failed to import test module: test_kpi Traceback (most recent call last): File "C:\Users\zhelu\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py", line 154, in loadTestsFromName module = import(module_name) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test\test_kpi.py", line 11, in import kpi File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\kpi.py", line 9, in from energy_flexibility_kpis.utilities import Parser ModuleNotFoundError: No module named 'energy_flexibility_kpis'

Ran 1 test in 0.000s

FAILED (errors=1)

What is the cmd you are executing? It runs fine on my end after I fix the filepath error for data1_simple by supplying the absolute filepath to data1_simple.csv in pd.read_csv. This is what I get:

(env) kingsleyenweye@MacBook-Pro-5 contribute-energy_flexibility_kpis % python -m unittest                                         
.
----------------------------------------------------------------------
Ran 1 test in 0.006s

OK

I am running the command from the root of the repository.

ZhelunChen commented 1 year ago

@kingsleynweye Thanks! I've updated the filepath to data1_simple.csv to match the location of the 'test_kpi.py' file, so it can be run from any directory. This change is available in the most recent commit 7995b08755e0db39ec580c6b625d8af341f8a6af. While I have no further issue calling kpi.py, I recommend updating the import method to ensure that 'kpi.py' can be called from any working directory in the future for others sake.

kingsleynweye commented 1 year ago

@kingsleynweye Thanks! I've updated the filepath to data1_simple.csv to match the location of the 'test_kpi.py' file, so it can be run from any directory. This change is available in the most recent commit 7995b08. While I have no further issue calling kpi.py, I recommend updating the import method to ensure that 'kpi.py' can be called from any working directory in the future for others sake.

Thanks @ZhelunChen and I see what you mean. The way python describes importing package modules is in the form:

import package_name.module_name

Another example is in the pandas source code, which is the format I adopted in line 9.

I think the thing to be aware of is that when a package is pip installed, it will be executed from the root path which is why file and module paths have to be defined in absolute form from that location.