1
0
mirror of https://github.com/chylex/Code-Statistics.git synced 2025-07-23 05:04:39 +02:00

Add Percent method to VariableUtils and update a call in JavaHandler

This commit is contained in:
chylex 2016-03-17 15:22:00 +01:00
parent 9c46d439de
commit d8d3bcb068
2 changed files with 6 additions and 1 deletions
CodeStatistics/Handling

View File

@ -245,7 +245,7 @@ namespace CodeStatistics.Handling.Languages{
variables.SetVariable("javaControlFlowCaseMin",state.GlobalInfo.MinSwitchCases);
variables.SetVariable("javaControlFlowCaseMax",state.GlobalInfo.MaxSwitchCases);
variables.Average("javaControlFlowCaseAvg","javaControlFlowCaseTotal","javaControlFlowSwitch");
variables.SetVariable("javaControlFlowCaseDefaultPerc",(int)Math.Round(100.0*state.GlobalInfo.Statements[FlowStatement.SwitchDefault]/state.GlobalInfo.Statements[FlowStatement.Switch]));
variables.Percent("javaControlFlowCaseDefaultPerc","javaControlFlowCaseDefaultTotal","javaControlFlowSwitch");
}
protected override object GetFileObject(FileIntValue fi, Variables.Root variables){

View File

@ -7,6 +7,11 @@ namespace CodeStatistics.Handling.Utils{
variables.SetVariable(targetName,avg >= roundingThreshold ? (int)Math.Round(avg) : avg);
}
public static void Percent(this Variables.Root variables, string targetName, string totalValueName, string unitValueName){
int val = (int)Math.Round(100.0*variables.GetVariable(totalValueName,0)/Math.Max(1,variables.GetVariable(unitValueName,1)));
variables.SetVariable(targetName,val);
}
public static void Minimum(this Variables.Root variables, string name, int nextValue){
int currentValue = variables.GetVariable(name,int.MaxValue);
if (nextValue < currentValue)variables.SetVariable(name,nextValue);