EnergyInnovation / eps-us

Energy Policy Simulator - United States
GNU General Public License v3.0
22 stars 7 forks source link

Add error check step to FoPITY Python script #233

Closed jrissman closed 2 years ago

jrissman commented 2 years ago

In FractionOfPolicyImplementedThisYear.py, prior to writing any policy schedule files, add an error checking step. The script should check whether any years are repeated on the same line and should report where duplicate years are found. It should write the error text out to a new text file so that the error can be observed even if running the Python script by double-clicking it (where console output won't be shown). The script should only alter the policy schedule .csv files if the error check passes without finding any errors.

The error checking step could optionally check for other issues, such as whether all implementation percentages are between 0% and 100% inclusive.

jrissman commented 2 years ago

Consider splitting the script into two files - one for data and one for the code. That will make it easier in the future to update the code for regions that have customized their implementation schedules.

jrissman commented 2 years ago

Completed in ee5b516.

If you have already customized another region's FractionOfPolicyImplementedThisYear.py file and you want to add the new error checking capabilities to that region, you can simply replace everything below the Functions header in that region's FractionOfPolicyImplementedThisYear.py file with the content below the Functions header in the updated U.S. version of the file.

The line number of the Functions header might vary by region, but you can easily find it by searching for the word "Functions", which only occurs once in the whole script.

The new error check capability checks for two things:

If it finds an error, it will produce a text file called FoPITY-Error-Log.txt that identifies all the errors and where they occur. It will not update any of the .csv files if an error is found.

If it does not find an error, it will delete FoPITY-Error-Log.txt and then will update all the .csv files.

You shouldn't need Todd's separate script to check FoPITY files anymore. Just update the main FractionOfPolicyImplementedThisYear.py script as described above and it will find all the errors in a given region's schedule data. Then you can correct them easily.

jrissman commented 2 years ago

Note that when I say "everything below the Functions header," I mean from that header through the very end of the file, including the content under the Main Program header.

jrissman commented 2 years ago

Okay, I added checks for two more error conditions: