Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Fixes problem with type 'SLI' after using new Measurements app. Relea…
Browse files Browse the repository at this point in the history
…se 6.14.4
  • Loading branch information
bdrum committed Dec 6, 2021
1 parent 005062d commit 5314720
Show file tree
Hide file tree
Showing 9 changed files with 2,825 additions and 2,800 deletions.
6 changes: 3 additions & 3 deletions ConcForms.vb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Module ConcForms
Try
DataGridViewTable(columnMap(type), rown).Value = System.IO.Path.GetFileName(conFileName)
If conc <> 0 Then
DataGridViewTable(columnMap(nucl & vbCrLf & MainUnit & vbCrLf & type), rown).Value = Rounding(conc, Convert.ToDecimal(Form_Main.TextBoxAcc.Text) / 100)
DataGridViewTable(columnMap(nucl & vbCrLf & MainUnit & vbCrLf & type), rown).Value = Rounding(conc, err)
Else
DataGridViewTable.Rows(rown).Cells(columnMap(nucl & vbCrLf & MainUnit & vbCrLf & type)).Value = ""
End If
Expand All @@ -322,12 +322,12 @@ Module ConcForms
DataGridViewTable(columnMap(nucl & vbCrLf & "Err, %" & vbCrLf & type), rown).Value = ""
End If
If lim <> 0 Then
DataGridViewTable(columnMap(nucl & vbCrLf & MDAUnit & vbCrLf & type), rown).Value = Rounding(lim, Convert.ToDecimal(Form_Main.TextBoxAcc.Text) / 100)
DataGridViewTable(columnMap(nucl & vbCrLf & MDAUnit & vbCrLf & type), rown).Value = Rounding(lim, err)
Else
DataGridViewTable.Rows(rown).Cells(columnMap(nucl & vbCrLf & MDAUnit & vbCrLf & type)).Value = ""
End If

DataGridViewTable(columnMap(nucl & vbCrLf & MDAUnit & vbCrLf & type), rown).Value = Rounding(lim, Convert.ToDecimal(Form_Main.TextBoxAcc.Text) / 100)
DataGridViewTable(columnMap(nucl & vbCrLf & MDAUnit & vbCrLf & type), rown).Value = Rounding(lim, err)
'If (mark = "*" Or mark = "&") And Not FinalFlag Then
' DataGridViewTable.Rows(rown).Cells(columnMap(nucl & vbCrLf & "Conc, mg/kg" & vbCrLf & type)).Style.BackColor = Color.LightGray
' DataGridViewTable.Rows(rown).Cells(columnMap(nucl & vbCrLf & "Err, %" & vbCrLf & type)).Style.BackColor = Color.LightGray
Expand Down
1 change: 1 addition & 0 deletions Extensions/Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="src\ConcEditor.Designer.cs">
<DependentUpon>ConcEditor.cs</DependentUpon>
</Compile>
<Compile Include="src\Numerics.cs" />
<Compile Include="src\Sample.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
41 changes: 41 additions & 0 deletions Extensions/src/Numerics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;

namespace Extensions
{
public static class Numerics
{
public static double Rounding(double val, double rel_err)
{
var abs_err = RoundError(val * (rel_err / 100));

int zeroCnt = (int)Math.Floor(Math.Log10(Math.Abs(abs_err)));

if (zeroCnt < 0)
return abs_err * Math.Pow(10, -zeroCnt) < 3 ? Math.Round(val, Math.Abs(zeroCnt) + 1) : Math.Round(val, Math.Abs(zeroCnt));


double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(abs_err))) + 1);

if ((abs_err / scale) < 0.3) // for value 248.34 and rounded error 130 should return 250
return (val / Math.Pow(10, zeroCnt - 1)) - Math.Floor((val / Math.Pow(10, zeroCnt - 1))) < 0.5 ? Math.Floor((val / Math.Pow(10, zeroCnt - 1))) * Math.Pow(10, zeroCnt - 1) : Math.Ceiling((val / Math.Pow(10, zeroCnt - 1))) * Math.Pow(10, zeroCnt - 1);


return (val / Math.Pow(10, zeroCnt)) - Math.Floor((val / Math.Pow(10, zeroCnt))) < 0.5 ? Math.Floor((val / Math.Pow(10, zeroCnt))) * Math.Pow(10, zeroCnt) : Math.Ceiling((val / Math.Pow(10, zeroCnt))) * Math.Pow(10, zeroCnt);
}

private static double RoundError(double abs_err)
{
int digits = 1;

if (abs_err == 0)
return 0;

double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(abs_err))) + 1);

if ((abs_err / scale) < 0.3)
digits = 2;

return scale * Math.Round(abs_err / scale, digits);
}
}
}
1 change: 0 additions & 1 deletion Extensions/src/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Extensions
{
Expand Down
531 changes: 267 additions & 264 deletions FormCheckGRS.vb

Large diffs are not rendered by default.

129 changes: 68 additions & 61 deletions Form_Final_Table_Concentration.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5314720

Please sign in to comment.