Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created December 20, 2011 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/1501356 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1501356 to your computer and use it in GitHub Desktop.
public int TestTimeWithSampling
{
get
{
return CalculateTestTimeWithSampling();
}
}
private int CalculateTestTimeWithSampling()
{
if (GeneratorSetupTime.HasValue == false)
{
return int.MaxValue;
}
if (RequestedTestTime == 0)
{
var power = (Voltage1 * Current1) + (Voltage2 * Current2) + (Voltage3 * Current3);
if (power == 0.0)
{
return int.MaxValue;
}
var angle = Math.Cos((PhaseShift - EnergyTypeToAngle()) * Math.PI / 180.0);
if (angle == 0.0)
{
return int.MaxValue;
}
checked
{
double testTime = GeneratorSetupTime.Value + (Energy / power * 3600000 / angle);
if (testTime > int.MaxValue)
return int.MaxValue;
else
return (int)testTime;
}
}
return GeneratorSetupTime.Value + RequestedTestTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment