Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated node stats and system stats functions #36

Merged
merged 12 commits into from
Jul 12, 2017

Conversation

bemcdonnell
Copy link
Member

Addresses #35 #31

@bemcdonnell bemcdonnell added this to the v5.1.13 milestone May 25, 2017
@bemcdonnell bemcdonnell self-assigned this May 25, 2017
src/massbal.c Outdated
case 9: value = massbal_getFlowError(); break;
case 9: *value = massbal_getFlowError(); break;
// default
default: errorcode = ERR_API_OUTBOUNDS; break;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a more descriptive error code. Something "Invalid parameter code" The more descriptive the error message the easier it is for the user receiving it to diagnose and solve the problem on their own. That's why it's important.

src/massbal.c Outdated
// Cumulative Dry Weather Inflow Volume
case 0: value = FlowTotals.dwInflow * UCF(VOLUME); break;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer enum variable used for case switch.

src/stats.c Outdated
// Check if object index is within bounds
if (index < 0 || index >= Nobjects[NODE])
{
errorcode = ERR_API_OUTBOUNDS;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More descriptive error code. Consider "node index out of bounds".

src/stats.c Outdated

switch (element)
// Check if Open
if (swmm_IsOpenFlag() == FALSE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow of control here is not what it should be. As soon as an error condition is encountered you want execution to stop and have the error returned. But this logic continues to check for errors. What it multiple error conditions are present? You are handing back information on the last error condition encountered not the first encountered.

Handle the most severe error condition first with an if statement, then the next most severe with an else if, and so on until all error conditions have been checked, then use an else to enclose the block of main functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! That's a better flow

src/stats.c Outdated
case 16: value = StorageStats[subindex].exfilLosses * UCF(VOLUME); break;
case 16: *value = StorageStats[k].exfilLosses * UCF(VOLUME); break;
// Default
default: errorcode = ERR_API_OUTBOUNDS; break;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make error more descriptive.

src/toolkitAPI.c Outdated
// Check if in bounds
if (type >= 0 && type < 10)
if (paramtype >= 0 && paramtype < 10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be using enums here.

src/toolkitAPI.c Outdated
return(0);
}
else return(ERR_API_OUTBOUNDS);
int errorcode = massbal_getRunoffTotal(paramtype, value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing to simply return massbal_getRunoffTotal(); This is better because we get the same functionality without the definition of a local variable.

src/toolkitAPI.c Outdated
return(0);
}
else return(ERR_API_OUTBOUNDS);
int errorcode = massbal_getRoutingFlowTotal(paramtype, value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing to simply return massbal_getRoutingFlowTotal(); This is better because we get the same functionality without the definition of a local variable.

src/toolkitAPI.c Outdated
return(0);
}
else return(ERR_API_OUTBOUNDS);
int errorcode = stats_getSubcatchStat(index, paramtype, value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing to simply return stats_getSubcatchStat(); This is better because we get the same functionality without the definition of a local variable.

@bemcdonnell
Copy link
Member Author

@michaeltryby, these are good suggestions. It's a good idea for me to add the enums for these. I'll post changes soon

@bemcdonnell
Copy link
Member Author

@michaeltryby, i addressed the bulk of your suggestions here. Let me know what you think about my enums.... I suspect there might be some name changes there.

@bemcdonnell
Copy link
Member Author

@michaeltryby, Please review the updates

Copy link

@michaeltryby michaeltryby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! The only thing I see missing are helper functions for constructing and freeing the structs.

@bemcdonnell
Copy link
Member Author

@michaeltryby Thanks! merging it now. :-)

@bemcdonnell bemcdonnell merged commit 8c531de into pyswmm:toolkitapi Jul 12, 2017
@bemcdonnell bemcdonnell deleted the stats branch July 12, 2017 20:50
@bemcdonnell bemcdonnell modified the milestones: v5.1.13, v5.2.0.dev4 Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants