2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2015-02-16 20:01:37 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Globalization;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Utils
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse unsigned float
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool TryParseUFloat(string text, out float result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result) ||
|
2015-04-28 14:17:36 +00:00
|
|
|
|
float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result) ||
|
|
|
|
|
|
(Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint, Program.AltCulture, out result));
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
public static float ParseUFloat(string text, float dfltVal)
|
|
|
|
|
|
{
|
|
|
|
|
|
float result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result)) return result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result)) return result;
|
2015-04-28 14:17:36 +00:00
|
|
|
|
if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint, Program.AltCulture, out result)) return result;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return dfltVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static float ParseUFloat(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParseUFloat(text, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse float, sign allowed
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool TryParseSFloat(string text, out float result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out result) ||
|
2015-04-28 14:17:36 +00:00
|
|
|
|
float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result) ||
|
|
|
|
|
|
(Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Program.AltCulture, out result));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
public static float ParseSFloat(string text, float dfltVal)
|
|
|
|
|
|
{
|
|
|
|
|
|
float result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out result)) return result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result)) return result;
|
2015-04-28 14:17:36 +00:00
|
|
|
|
if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Program.AltCulture, out result)) return result;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return dfltVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static float ParseSFloat(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParseSFloat(text, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse float, sign allowed, exponent allowed
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool TryParseEFloat(string text, out float result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out result) ||
|
2015-04-28 14:17:36 +00:00
|
|
|
|
float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result) ||
|
|
|
|
|
|
(Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, Program.AltCulture, out result));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
public static float ParseEFloat(string text, float dfltVal)
|
|
|
|
|
|
{
|
|
|
|
|
|
float result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out result)) return result;
|
|
|
|
|
|
if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result)) return result;
|
2015-04-28 14:17:36 +00:00
|
|
|
|
if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, Program.AltCulture, out result)) return result;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return dfltVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static float ParseEFloat(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParseEFloat(text, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a list of IValve-s from an entity implementing IHasValves
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity">Entity implementing IHasValves</param>
|
|
|
|
|
|
/// <returns>A list of IValves</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static IList<BenchControl.GenericDevices.IValve> ValvesOpen(IHasValves entity)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
var valvesOpen = new List<BenchControl.GenericDevices.IValve>();
|
|
|
|
|
|
if (entity != null && entity.ValvesOpen != null && entity.ValvesOpen != string.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] vOpen = entity.ValvesOpen.Split(new char[] { ';' });
|
|
|
|
|
|
foreach (var vName in vOpen)
|
|
|
|
|
|
{
|
2015-01-13 07:46:32 +00:00
|
|
|
|
valvesOpen.Add((BenchControl.GenericDevices.IValve)BenchControl.TbfComponents.FindComponent(vName));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return valvesOpen;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a list of IValve-s from an entity implementing IHasValves
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity">Entity implementing IHasValves</param>
|
|
|
|
|
|
/// <returns>A list of IValves</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static IList<BenchControl.GenericDevices.IValve> ValvesClose(IHasValves entity)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
var valvesClose = new List<BenchControl.GenericDevices.IValve>();
|
|
|
|
|
|
if (entity != null && entity.ValvesClose != null && entity.ValvesClose != string.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] vClose = entity.ValvesClose.Split(new char[] { ';' });
|
|
|
|
|
|
foreach (var vName in vClose)
|
|
|
|
|
|
{
|
2015-01-13 07:46:32 +00:00
|
|
|
|
valvesClose.Add((BenchControl.GenericDevices.IValve)BenchControl.TbfComponents.FindComponent(vName));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return valvesClose;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-01 12:43:04 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get an array of RegulValve positions from a TransitionStep entity
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity">TransitionStep entity</param>
|
|
|
|
|
|
/// <returns>float[] of regulation valve positions from 0 to 100.0f</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static float[] GetRegulValvesPositions(TransitionStep step)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
int regvCount = BenchControl.Sequences.SequenceBase.RegulValves.Count;
|
|
|
|
|
|
float[] result = new float[regvCount];
|
|
|
|
|
|
|
|
|
|
|
|
string[] rvPosStr = (step.RegulValvesPct != null) ? step.RegulValvesPct.Split(new char[] { ';' }) : new string[0];
|
|
|
|
|
|
for (int i = 0; i < regvCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
float fdummy;
|
|
|
|
|
|
if ((i < rvPosStr.Length) && Utils.TryParseUFloat(rvPosStr[i], out fdummy) &&
|
|
|
|
|
|
(fdummy >= 0) && (fdummy <= 100.0f))
|
|
|
|
|
|
{
|
|
|
|
|
|
result[i] = fdummy;
|
|
|
|
|
|
}
|
2015-02-01 10:04:05 +00:00
|
|
|
|
else // if ((i < rvPosStr.Length) && rvPosStr[i].Equals("---"))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
result[i] = -1.0f; /// Negative value means no regulation valve position change
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2014-09-08 11:16:31 +00:00
|
|
|
|
|
2015-02-01 12:43:04 +00:00
|
|
|
|
|
2014-09-08 11:16:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get an array of Pump-With-FM power percentages from a TransitionStep entity
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity">TransitionStep entity</param>
|
|
|
|
|
|
/// <returns>float[] of FM-pump power percentages from 0 to 100.0f</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static float[] GetPumpWithFMPcts(TransitionStep step)
|
2014-09-08 11:16:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
int fmPumpCount = BenchControl.Sequences.SequenceBase.PumpsWithFM.Count;
|
|
|
|
|
|
float[] result = new float[fmPumpCount];
|
|
|
|
|
|
|
2015-02-01 10:04:05 +00:00
|
|
|
|
string[] fmPctsStr = (step.PumpWithFMPcts != null) ? step.PumpWithFMPcts.Split(new char[] { ';' }) : new string[0];
|
2014-09-08 11:16:31 +00:00
|
|
|
|
for (int i = 0; i < fmPumpCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
float fdummy;
|
2015-02-01 10:04:05 +00:00
|
|
|
|
if ((i < fmPctsStr.Length) && Utils.TryParseUFloat(fmPctsStr[i], out fdummy) &&
|
2014-09-08 11:16:31 +00:00
|
|
|
|
(fdummy >= 0) && (fdummy <= 100.0f))
|
|
|
|
|
|
{
|
|
|
|
|
|
result[i] = fdummy;
|
|
|
|
|
|
}
|
2015-02-01 10:04:05 +00:00
|
|
|
|
else if ((i < fmPctsStr.Length) && fmPctsStr[i].Equals("Dflt"))
|
2014-09-08 11:16:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
result[i] = -2.0f; /// This value means default pump power defined by the Test parameter
|
|
|
|
|
|
}
|
2015-02-01 10:04:05 +00:00
|
|
|
|
else //if ((i < rvPosStr.Length) && rvPosStr[i].Equals("---"))
|
2014-09-08 11:16:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
result[i] = -1.0f; /// This value means no pump power change
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2015-01-13 04:00:59 +00:00
|
|
|
|
|
2015-02-01 12:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Pre-fetch the test results from the currently available results.
|
2015-03-27 05:24:47 +00:00
|
|
|
|
/// The order of the returned results is the same as the order of tests in the procedure specification.
|
2015-02-01 12:43:04 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="procedure">Current procedure, it is used to determine the order of resulting test results</param>
|
|
|
|
|
|
/// <param name="testResults">Currently available unsorted test results (can also be null)</param>
|
2015-05-22 14:18:25 +00:00
|
|
|
|
/// <param name="meterPartNr">Water meter number (1-based) or 0=all (also compared with nonzero 'Part' number)</param>
|
2015-02-01 12:43:04 +00:00
|
|
|
|
/// <returns>Ordered list of test results containing null-s for missing results</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static IList<TestResult> GetSortedTestResults(Procedure procedure, IList<TestResult> testResults, int meterPartNr)
|
2015-02-01 12:43:04 +00:00
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
IList<TestResult> rslts = new List<TestResult>();
|
2015-02-01 12:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
if (procedure == null) return rslts; /// Return an empty list if no procedure specified
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var test in procedure.Tests)
|
|
|
|
|
|
{
|
2015-02-01 15:20:27 +00:00
|
|
|
|
BenchControl.GenericDevices.ITestMethod method =
|
|
|
|
|
|
BenchControl.TbfComponents.FindComponent(test.Method) as BenchControl.GenericDevices.ITestMethod;
|
|
|
|
|
|
|
2015-09-06 20:21:54 +00:00
|
|
|
|
if ((method != null) && method.Publish(test) && ((test.Part == 0) || (meterPartNr == 0) || (test.Part == meterPartNr)))
|
2015-02-01 12:43:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
for (int rpt = 1; rpt <= test.Repeats; rpt++)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool added = false;
|
|
|
|
|
|
if (testResults != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var testRslt in testResults)
|
|
|
|
|
|
{
|
2015-02-01 15:20:27 +00:00
|
|
|
|
if ((testRslt.TestId == test.Id) && (testRslt.RepetitionNr == rpt))
|
2015-02-01 12:43:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
rslts.Add(testRslt);
|
|
|
|
|
|
added = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!added) rslts.Add(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return rslts;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-03-27 05:24:47 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Pre-fetch the test names given the procedure and the meter number.
|
|
|
|
|
|
/// The order or test names is the same as in the procedure specification.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="procedure">Procedure</param>
|
2015-05-23 13:30:31 +00:00
|
|
|
|
/// <param name="meterPartNr">Water meter number (1-based) or 0=all (also compared with nonzero 'Part' number)</param>
|
2015-03-27 05:24:47 +00:00
|
|
|
|
/// <returns>Ordered list of test names</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static IList<string> GetDecoratedTestNames(Procedure procedure, int meterPartNr)
|
2015-03-27 05:24:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
IList<string> names = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
if (procedure == null) return names; /// Return an empty list if no procedure specified
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var test in procedure.Tests)
|
|
|
|
|
|
{
|
|
|
|
|
|
BenchControl.GenericDevices.ITestMethod method =
|
|
|
|
|
|
BenchControl.TbfComponents.FindComponent(test.Method) as BenchControl.GenericDevices.ITestMethod;
|
|
|
|
|
|
|
2015-09-06 20:21:54 +00:00
|
|
|
|
if ((method != null) && method.Publish(test) && ((test.Part == 0) || (meterPartNr == 0) || (test.Part == meterPartNr)))
|
2015-03-27 05:24:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (test.Repeats == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
names.Add(test.Name);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int rpt = 1; rpt <= test.Repeats; rpt++)
|
|
|
|
|
|
{
|
|
|
|
|
|
names.Add(test.Name + string.Format(" ({0}/{1})", rpt, test.Repeats));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return names;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-05-23 13:30:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// To prepare the last argument of GetSortedTestResults() and GetDecoratedTestNames() functions
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="wmNr1">Watermeter nr. (1-based)</param>
|
|
|
|
|
|
/// <param name="combined">Meter: false=standard, true=combined</param>
|
|
|
|
|
|
/// <returns>Part nr. of the meter</returns>
|
|
|
|
|
|
public static int PartNr(int wmNr1, bool combined)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wmNr1 == 0) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (combined) return wmNr1;
|
|
|
|
|
|
|
2016-06-30 12:02:25 +00:00
|
|
|
|
int wmPartSize = 1 + (wmNr1 - 1) / Config.Data.LineSize;
|
2015-05-23 13:30:31 +00:00
|
|
|
|
return wmPartSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-01 21:03:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Return test title for a given test and repetition number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="test">Test entity</param>
|
|
|
|
|
|
/// <param name="repetitonNr">1 .. Nr. repetitions</param>
|
|
|
|
|
|
/// <returns>Test title (string)</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static string TestTitle(Test test, int repetitonNr)
|
2015-12-01 21:03:53 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (test.Repeats == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (test.Part == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return test.Name; /// Single test
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("{0} ({1})", test.Name, test.Part); /// A part of a single test
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// More test repetitions
|
|
|
|
|
|
return string.Format("{0} ({1}/{2})", test.Name, repetitonNr, test.Repeats);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-13 04:00:59 +00:00
|
|
|
|
/// <summary>
|
2016-01-03 01:05:35 +00:00
|
|
|
|
/// Converts a float number to a string with the specified number of valid digits
|
2015-01-13 04:00:59 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="value">Float value to be converted to a string</param>
|
2015-01-13 07:46:32 +00:00
|
|
|
|
/// <param name="validDigits">Number of valid digits: 4, 3, or 2 (otherwise a full precision number is printed)</param>
|
2016-01-03 01:05:35 +00:00
|
|
|
|
/// <returns>String representation of a float number</returns>
|
2015-01-13 04:00:59 +00:00
|
|
|
|
public static string FloatToStr(float value, int validDigits)
|
|
|
|
|
|
{
|
2016-01-08 18:18:45 +00:00
|
|
|
|
if (-float.Epsilon <= value && value <= float.Epsilon)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 4)
|
2015-01-13 04:00:59 +00:00
|
|
|
|
{
|
2015-02-02 21:44:34 +00:00
|
|
|
|
if (value >= 999.5 || value < -999.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 99.95 || value < -99.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 9.995 || value < -9.995) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.9995 || value < -0.9995) return value.ToString("F3");
|
|
|
|
|
|
else if (value >= 0.09995 || value < -0.09995) return value.ToString("F4");
|
|
|
|
|
|
else if (value >= 0.009995 || value < -0.009995) return value.ToString("F5");
|
2015-01-13 04:00:59 +00:00
|
|
|
|
else return value.ToString("F6");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 3)
|
|
|
|
|
|
{
|
2015-02-02 21:44:34 +00:00
|
|
|
|
if (value >= 99.5 || value < -99.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 9.95 || value < -9.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 0.995 || value < -0.995) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.0995 || value < -0.0995) return value.ToString("F3");
|
|
|
|
|
|
else if (value >= 0.00995 || value < -0.00995) return value.ToString("F4");
|
|
|
|
|
|
else if (value >= 0.000995 || value < -0.000995) return value.ToString("F5");
|
|
|
|
|
|
else return value.ToString("F6");
|
2015-01-13 04:00:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 2)
|
|
|
|
|
|
{
|
2015-02-02 21:44:34 +00:00
|
|
|
|
if (value >= 9.5 || value < -9.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 0.95 || value < -0.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 0.095 || value < -0.095) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.0095 || value < -0.0095) return value.ToString("F3");
|
2016-01-03 01:05:35 +00:00
|
|
|
|
else if (value >= 0.00095 || value < -0.00095) return value.ToString("F4");
|
|
|
|
|
|
else return value.ToString("F5");
|
|
|
|
|
|
}
|
|
|
|
|
|
else return value.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Converts a double number to a string with the specified number of valid digits
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="value">Double value to be converted to a string</param>
|
|
|
|
|
|
/// <param name="validDigits">Number of valid digits: 4, 3, or 2 (otherwise a full precision number is printed)</param>
|
|
|
|
|
|
/// <returns>String representation of a double number</returns>
|
|
|
|
|
|
public static string DoubleToStr(double value, int validDigits)
|
|
|
|
|
|
{
|
2016-01-08 18:18:45 +00:00
|
|
|
|
if (-float.Epsilon <= value && value <= float.Epsilon)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 4)
|
2016-01-03 01:05:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (value >= 999.5 || value < -999.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 99.95 || value < -99.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 9.995 || value < -9.995) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.9995 || value < -0.9995) return value.ToString("F3");
|
|
|
|
|
|
else if (value >= 0.09995 || value < -0.09995) return value.ToString("F4");
|
|
|
|
|
|
else if (value >= 0.009995 || value < -0.009995) return value.ToString("F5");
|
|
|
|
|
|
else return value.ToString("F6");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value >= 99.5 || value < -99.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 9.95 || value < -9.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 0.995 || value < -0.995) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.0995 || value < -0.0995) return value.ToString("F3");
|
|
|
|
|
|
else if (value >= 0.00995 || value < -0.00995) return value.ToString("F4");
|
|
|
|
|
|
else if (value >= 0.000995 || value < -0.000995) return value.ToString("F5");
|
|
|
|
|
|
else return value.ToString("F6");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (validDigits == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value >= 9.5 || value < -9.5) return value.ToString("F0");
|
|
|
|
|
|
else if (value >= 0.95 || value < -0.95) return value.ToString("F1");
|
|
|
|
|
|
else if (value >= 0.095 || value < -0.095) return value.ToString("F2");
|
|
|
|
|
|
else if (value >= 0.0095 || value < -0.0095) return value.ToString("F3");
|
2015-02-02 21:44:34 +00:00
|
|
|
|
else if (value >= 0.00095 || value < -0.00095) return value.ToString("F4");
|
|
|
|
|
|
else return value.ToString("F5");
|
2015-01-13 04:00:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else return value.ToString();
|
|
|
|
|
|
}
|
2015-04-18 11:31:31 +00:00
|
|
|
|
|
|
|
|
|
|
public static string ShowRoute(ulong route)
|
|
|
|
|
|
{
|
|
|
|
|
|
string str = string.Empty;
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
for (ulong bitmask = 0x8000000000000000; bitmask > 0; bitmask /= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
str += ((route & bitmask) != 0) ? "1" : "0";
|
|
|
|
|
|
i++;
|
|
|
|
|
|
if (i < 64)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((i % 16) == 0) str += "-";
|
|
|
|
|
|
else if ((i % 8) == 0) str += " ";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
2015-08-21 18:52:10 +00:00
|
|
|
|
|
|
|
|
|
|
public static string ToMyString(DateTime dateTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("{0}{1}{2}_{3}{4}",
|
|
|
|
|
|
dateTime.Year,
|
|
|
|
|
|
dateTime.Month.ToString("D2"),
|
|
|
|
|
|
dateTime.Day.ToString("D2"),
|
|
|
|
|
|
dateTime.Hour.ToString("D2"),
|
|
|
|
|
|
dateTime.Minute.ToString("D2"));
|
|
|
|
|
|
}
|
2015-02-16 20:01:37 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|