.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lookup Table Text value

1 REPLY 1
SOLVED
Reply
Message 1 of 2
James.Pascual
485 Views, 1 Reply

Lookup Table Text value

I need some opinions on what's the best method of storing this data and retrieving data using some type of lookup based on multiple fields.  I started to take a stab at it, but realized that there will be a huge list of data that will be loaded every time.  Is there a better way to go about this, such as should the data be an external file to reference, like XML, or is there a better way to approach this other than making a custom class and storing new data to memory each time?

 

Below is the unfished code I started, and an attached PDF of the source of data I'm pulling this information from.  If anyone is curious, this data is Standard Aluminum Extrusion dimension tolerances.

 

Here's the custom class: (still haven't figured out how .ValueLookup() will work yet)

        // See picture of reference chart for source of data
        // Dim1 = "Col.1" in reference chart
        // Dim2 = "Col.2" thr "Col.9" in reference chart
        // Precision.True = right column of "Col.2." thru "Col.9"
        // Precision.False = left column of "Col.2." thru "Col.9"
        // LessThan10.True = Upper table ("Circumscribing circle sizes less than 10"Ø")
        // LessThan10.False = Lower table ("circumscribing circle sizes 10"Ø and above")
        public sealed class Tolerance
        {
            // public int Id { get; set;  }
            public double Dim1 { get; set; }
            public double Dim2 { get; set; }
            public bool Precision { get; set; }
            public bool LessThan10 { get; set; }
            public double Value { get; set; }

            public double ValueLookup(double dim1, double dim2, bool Precision, bool lessthan10)
            {
                return Value; // Need to program how to return "Value" field based on the parameters
            }
        }

And a portion of code inside my CommandMethod "DimTol":

            var tolerance = new List<Tolerance>
            {
                // Dim1 < 0.125
                new Tolerance {Dim1=0.125, Dim2=0.25, Precision=true, LessThan10=true, Value=0.004 },
                new Tolerance {Dim1=0.125, Dim2=0.25, Precision=false, LessThan10=true, Value=0.006 },
                new Tolerance {Dim1=0.125, Dim2=0.625, Precision=true, LessThan10=true, Value=0.007 },
                new Tolerance {Dim1=0.125, Dim2=0.625, Precision=false, LessThan10=true, Value=0.010 },
                new Tolerance {Dim1=0.125, Dim2=1.250, Precision=true, LessThan10=true, Value=0.008 },
                new Tolerance {Dim1=0.125, Dim2=1.250, Precision=false, LessThan10=true, Value=0.012 },
                // Dim1 < 0.250
                new Tolerance {Dim1=0.250, Dim2=0.25, Precision=true, LessThan10=true, Value=0.005 },
                new Tolerance {Dim1=0.250, Dim2=0.25, Precision=false, LessThan10=true, Value=0.007 },
                new Tolerance {Dim1=0.250, Dim2=0.625, Precision=true, LessThan10=true, Value=0.008 },
                new Tolerance {Dim1=0.250, Dim2=0.625, Precision=false, LessThan10=true, Value=0.012 },
                new Tolerance {Dim1=0.250, Dim2=1.250, Precision=true, LessThan10=true, Value=0.009 },
                new Tolerance {Dim1=0.250, Dim2=1.250, Precision=false, LessThan10=true, Value=0.014 },
                new Tolerance {Dim1=0.250, Dim2=2.500, Precision=true, LessThan10=true, Value=0.011 },
                new Tolerance {Dim1=0.250, Dim2=2.500, Precision=false, LessThan10=true, Value=0.016 },
                // Dim1 < 0.500
                new Tolerance {Dim1=0.500, Dim2=0.25, Precision=true, LessThan10=true, Value=0.005 },
                new Tolerance {Dim1=0.500, Dim2=0.25, Precision=false, LessThan10=true, Value=0.008 },
                new Tolerance {Dim1=0.500, Dim2=0.625, Precision=true, LessThan10=true, Value=0.009 },
                new Tolerance {Dim1=0.500, Dim2=0.625, Precision=false, LessThan10=true, Value=0.014 },
                new Tolerance {Dim1=0.500, Dim2=1.250, Precision=true, LessThan10=true, Value=0.011 },
                new Tolerance {Dim1=0.500, Dim2=1.250, Precision=false, LessThan10=true, Value=0.016 },
                new Tolerance {Dim1=0.500, Dim2=2.500, Precision=true, LessThan10=true, Value=0.012 },
                new Tolerance {Dim1=0.500, Dim2=2.500, Precision=false, LessThan10=true, Value=0.018 },
                new Tolerance {Dim1=0.500, Dim2=4.000, Precision=true, LessThan10=true, Value=0.013 },
                new Tolerance {Dim1=0.500, Dim2=4.000, Precision=false, LessThan10=true, Value=0.020 },
            };

Attached is the source data and I highlighted an example if a user did a "Tolerance.ValueLookup(2.4, 0.6, true, true);" and "0.022" would return.

1 REPLY 1
Message 2 of 2

Just to close this out, I ended up making something work.  It's a bit long and there's for sure a better way to do this with LINQ or something, but I haven't learnt that yet.  So this is what I ended up with, I have multiple dictionaries and just reference each based on inputs into a function.

 

static Dictionary<double, List<double>> _dictLess0125 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.006, 0.004 }},
            { 0.625, new List<double> { 0.010, 0.007 }},
            { 1.250, new List<double> { 0.012, 0.008 }}};

        static Dictionary<double, List<double>> _dictLess0250 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.007, 0.005 }},
            { 0.625, new List<double> { 0.012, 0.008 }},
            { 1.250, new List<double> { 0.009, 0.014 }},
            { 2.500, new List<double> { 0.016, 0.011 }}};

        static Dictionary<double, List<double>> _dictLess0500 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.008, 0.005 }},
            { 0.625, new List<double> { 0.014, 0.009 }},
            { 1.250, new List<double> { 0.016, 0.011 }},
            { 2.500, new List<double> { 0.018, 0.012 }},
            { 4.000, new List<double> { 0.020, 0.013 }}};

        static Dictionary<double, List<double>> _dictLess0750 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.009, 0.006 }},
            { 0.625, new List<double> { 0.016, 0.011 }},
            { 1.250, new List<double> { 0.018, 0.012 }},
            { 2.500, new List<double> { 0.020, 0.013 }},
            { 4.000, new List<double> { 0.022, 0.015 }}};
        
        static Dictionary<double, List<double>> _dictLess1000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.010, 0.007 }},
            { 0.625, new List<double> { 0.018, 0.012 }},
            { 1.250, new List<double> { 0.020, 0.013 }},
            { 2.500, new List<double> { 0.022, 0.015 }},
            { 4.000, new List<double> { 0.025, 0.017 }},
            { 6.000, new List<double> { 0.030, 0.020 }}};
        
        static Dictionary<double, List<double>> _dictLess1500 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.012, 0.008 }},
            { 0.625, new List<double> { 0.021, 0.014 }},
            { 1.250, new List<double> { 0.023, 0.015 }},
            { 2.500, new List<double> { 0.026, 0.017 }},
            { 4.000, new List<double> { 0.030, 0.020 }},
            { 6.000, new List<double> { 0.035, 0.023 }}};
        
        static Dictionary<double, List<double>> _dictLess2000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.014, 0.009 }},
            { 0.625, new List<double> { 0.024, 0.016 }},
            { 1.250, new List<double> { 0.026, 0.017 }},
            { 2.500, new List<double> { 0.031, 0.020 }},
            { 4.000, new List<double> { 0.036, 0.024 }},
            { 6.000, new List<double> { 0.042, 0.028 }},
            { 8.000, new List<double> { 0.050, 0.033 }}};
        
        static Dictionary<double, List<double>> _dictLess4000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.024, 0.016 }},
            { 0.625, new List<double> { 0.034, 0.022 }},
            { 1.250, new List<double> { 0.038, 0.025 }},
            { 2.500, new List<double> { 0.048, 0.032 }},
            { 4.000, new List<double> { 0.057, 0.038 }},
            { 6.000, new List<double> { 0.068, 0.045 }},
            { 8.000, new List<double> { 0.080, 0.053 }}};
        
        static Dictionary<double, List<double>> _dictLess6000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.034, 0.022 }},
            { 0.625, new List<double> { 0.044, 0.029 }},
            { 1.250, new List<double> { 0.050, 0.033 }},
            { 2.500, new List<double> { 0.064, 0.042 }},
            { 4.000, new List<double> { 0.078, 0.051 }},
            { 6.000, new List<double> { 0.094, 0.062 }},
            { 8.000, new List<double> { 0.110, 0.073 }}};
        
        static Dictionary<double, List<double>> _dictLess8000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.044, 0.029 }},
            { 0.625, new List<double> { 0.054, 0.036 }},
            { 1.250, new List<double> { 0.062, 0.041 }},
            { 2.500, new List<double> { 0.082, 0.054 }},
            { 4.000, new List<double> { 0.099, 0.065 }},
            { 6.000, new List<double> { 0.120, 0.079 }},
            { 8.000, new List<double> { 0.140, 0.092 }}};
        
        static Dictionary<double, List<double>> _dictLess10000 = new Dictionary<double, List<double>>{
            { 0.250, new List<double> { 0.054, 0.036 }},
            { 0.625, new List<double> { 0.064, 0.042 }},
            { 1.250, new List<double> { 0.074, 0.049 }},
            { 2.500, new List<double> { 0.100, 0.066 }},
            { 4.000, new List<double> { 0.120, 0.079 }},
            { 6.000, new List<double> { 0.145, 0.096 }},
            { 8.000, new List<double> { 0.170, 0.112 }}};

        public static double GetTol(double dim1, double dim2, bool Precision, bool LessThan10)
        {
            List<double> listresult;
            double result, _dim2;
            string _dim1, _Less;
            int _precision;
            Dictionary<double, List<double>> lookdict;

            _dim1 = (dim1 < 0.125) ? "0125"
                : (dim1 < 0.250) ? "0250"
                : (dim1 < 0.500) ? "0500"
                : (dim1 < 0.750) ? "0750"
                : (dim1 < 1.000) ? "1000"
                : (dim1 < 1.500) ? "1500"
                : (dim1 < 2.000) ? "2000"
                : (dim1 < 4.000) ? "4000"
                : (dim1 < 6.000) ? "6000"
                : (dim1 < 8.000) ? "8000"
                : (dim1 < 10.000) ? "10000"
                : (dim1 < 12.000) ? "12000"
                : (dim1 < 14.000) ? "14000"
                : (dim1 < 16.000) ? "16000"
                : (dim1 < 18.000) ? "18000"
                : (dim1 < 20.000) ? "20000"
                : (dim1 < 22.000) ? "22000"
                : "24000";

            _dim2 = (dim2 < 0.250) ? 0.250
                : (dim2 < 0.625) ? 0.625
                : (dim2 < 1.250) ? 1.250
                : (dim2 < 2.500) ? 2.500
                : (dim2 < 4.000) ? 4.000
                : (dim2 < 6.000) ? 6.000
                : 8.000;

            _precision = (Precision == true) ?  1 : 0;
            _Less = (LessThan10 == true) ? "Less" : "Greater";
            string _dict = "_dict" + _Less + _dim1;


            lookdict = (_dict == "_dictLess0125") ? _dictLess0125
                : (_dict == "_dictLess0250") ? _dictLess0250
                : (_dict == "_dictLess0500") ? _dictLess0500
                : (_dict == "_dictLess0750") ? _dictLess0750
                : (_dict == "_dictLess1000") ? _dictLess1000
                : (_dict == "_dictLess1500") ? _dictLess1500
                : (_dict == "_dictLess2000") ? _dictLess2000
                : (_dict == "_dictLess4000") ? _dictLess4000
                : (_dict == "_dictLess6000") ? _dictLess6000
                : (_dict == "_dictLess8000") ? _dictLess8000
                : _dictLess10000;

            if (lookdict.TryGetValue(_dim2, out listresult))
            {
                result = listresult[_precision];
                return result;
            }
            else
            {
                return 0;
            }
        }

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report