@@ -142,27 +142,36 @@ public void AddCodedValues(Dictionary<string, int> slcodes)
142
142
{
143
143
// if any contains Carriage Retunr/Line Feed, then it's probably text not codes
144
144
var containsCrLf = false ;
145
+ var total = 0 ;
145
146
foreach ( var s in slcodes )
146
147
{
147
148
if ( s . Key . Contains ( '\r ' ) || s . Key . Contains ( '\n ' ) ) containsCrLf = true ;
149
+ total += s . Value ;
148
150
}
149
151
150
152
// check if could be coded values
151
153
if ( ( containsCrLf == false ) && ( slcodes . Count > 0 ) && ( slcodes . Count <= Main . Settings . UniqueValuesMax ) )
152
154
{
153
- // set coded values
154
- this . isCodedValue = true ;
155
+ // check enumeration ratio, this is to avoid interpreting a column with 100 rows and only 3 text values to be interpreted as enumeration
156
+ var ratio = 1.0 * total / slcodes . Count ;
155
157
156
- this . CodedList = new List < string > ( ) ;
157
-
158
- foreach ( var s in slcodes )
158
+ // in a coded values column each unique value must be used at least 2 tiumes or more (on average)
159
+ if ( ratio >= 2.0 )
159
160
{
160
- this . CodedList . Add ( s . Key ) ;
161
- }
161
+ // set coded values
162
+ this . isCodedValue = true ;
162
163
163
- // Sort list, with a hack to sort integers correctly
164
- // i.e. list of integers should not be sorted like [1, 10, 11, 2, 3, .. etc]
165
- this . CodedList . Sort ( new StrCmpLogicalComparer ( ) ) ;
164
+ this . CodedList = new List < string > ( ) ;
165
+
166
+ foreach ( var s in slcodes )
167
+ {
168
+ this . CodedList . Add ( s . Key ) ;
169
+ }
170
+
171
+ // Sort list, with a hack to sort integers correctly
172
+ // i.e. list of integers should not be sorted like [1, 10, 11, 2, 3, .. etc]
173
+ this . CodedList . Sort ( new StrCmpLogicalComparer ( ) ) ;
174
+ }
166
175
}
167
176
}
168
177
}
0 commit comments