Commit 4636af6dd0f0e5ea45701aaa3597c2e18e9ca2dc
Merge branch 'master' of http://service.routetopa.eu:7480/WebCompDev/COMPONENTS
Showing
9 changed files
with
118 additions
and
42 deletions
bower_components/JSDataChecker/.bower.json
1 | 1 | { |
2 | 2 | "name": "JSDataChecker", |
3 | - "version": "0.0.8", | |
3 | + "version": "0.0.9", | |
4 | 4 | "homepage": "https://github.com/donpir/JSDataChecker", |
5 | 5 | "authors": [ |
6 | 6 | "'Donato Pirozzi <'donatopirozzi@gmail.com'>" |
... | ... | @@ -22,13 +22,14 @@ |
22 | 22 | "polywc": "https://github.com/donpir/polywc.git#master" |
23 | 23 | }, |
24 | 24 | "private": false, |
25 | - "_release": "0.0.8", | |
25 | + "_release": "0.0.9", | |
26 | 26 | "_resolution": { |
27 | 27 | "type": "version", |
28 | - "tag": "v0.0.8", | |
29 | - "commit": "862e4d5fe56d629ae7ef8aadb728b1add3af01d9" | |
28 | + "tag": "v0.0.9", | |
29 | + "commit": "277c51efeee4daa0bd11051de022975ba86f47fa" | |
30 | 30 | }, |
31 | 31 | "_source": "https://github.com/donpir/JSDataChecker.git", |
32 | - "_target": "~0.0.6", | |
33 | - "_originalSource": "jsdatachecker" | |
32 | + "_target": "~0.0.9", | |
33 | + "_originalSource": "jsdatachecker", | |
34 | + "_direct": true | |
34 | 35 | } |
35 | 36 | \ No newline at end of file |
... | ... |
bower_components/JSDataChecker/README.md
... | ... | @@ -13,8 +13,8 @@ The library has released with the LGPL license [link here](http://www.gnu.org/li |
13 | 13 | |
14 | 14 | Briefly with this license: |
15 | 15 | |
16 | - - Freedom to modify and distribute modified copies of POLYWC-DATA-TABLE, distributing the source code and releasing it with the same LGPL license; | |
17 | - - You can dynamically (not statically) link POLYWC-DATA-TABLE library in a proprietary software, keeping the JS files as they are. | |
16 | + - Freedom to modify and distribute modified copies of DataChecker, distributing the source code and releasing it with the same LGPL license; | |
17 | + - You can dynamically (not statically) link DataChecker library in a proprietary software, keeping the JS files as they are. | |
18 | 18 | |
19 | 19 | |
20 | 20 | |
... | ... |
bower_components/JSDataChecker/bower.json
bower_components/JSDataChecker/jsdatachecker.min.js
1 | -function ArrayUtils(){}function DataTypeConverter(){this._fields=[],this._numOfRows=0}function DataTypesUtils(){}function DataTypeHierarchy(){}ArrayUtils.TestAndSet=function(arr,key,object){return"undefined"==typeof arr?null:0==Array.isArray(arr)?null:("undefined"==typeof arr[key]&&(arr[key]=object),arr[key])},ArrayUtils.TestAndInitializeKey=function(obj,key,value){return"undefined"==typeof obj?null:("undefined"==typeof obj[key]&&(obj[key]=value),obj[key])},ArrayUtils.TestAndIncrement=function(arr,key){var exists=arr[key];return"undefined"==typeof exists&&(arr[key]=0),arr[key]++,arr},ArrayUtils.toFieldsArray=function(obj){var fields=[];return ArrayUtils.IteratorOverKeys(obj,function(field,key){field.key=key,fields.push(field)}),fields},ArrayUtils.IteratorOverKeys=function(arr,callback){for(var property in arr)if(arr.hasOwnProperty(property)){var item=arr[property];callback(item,property)}},ArrayUtils.FindMinMax=function(arr,fncompare){var max1=null,max2=null;for(var key in arr)null==max1||fncompare(arr[key],max1.value)?(max2=max1,max1={index:-1,key:key,value:arr[key]}):(null==max2||fncompare(arr[key],max2.value))&&(max2={index:-1,key:key,value:arr[key]});return{first:max1,second:max2}},ArrayUtils.isArray=function(arr){return Array.isArray(arr)?arr.length>0:!1},DataTypeConverter.TYPES={TEXT:{value:0,name:"TEXT"},CODE:{value:1,name:"CODE"},NUMBER:{value:2,name:"NUMBER"},OBJECT:{value:3,name:"OBJECT"},BOOL:{value:5,name:"BOOL"},CONST:{value:6,name:"CONST"},CATEGORY:{value:7,name:"CATEGORY"},DATETIME:{value:8,name:"DATETIME"},EMPTY:{value:101,name:"NULL"}},DataTypeConverter.SUBTYPES={PERCENTAGE:{value:1e3,name:"PERCENTAGE"},LATITUDE:{value:1001,name:"LATITUDE"},LONGITUDE:{value:1002,name:"LONGITUDE"}},DataTypeConverter.prototype=function(){var _analyseDataTypes=function(fields){ArrayUtils.IteratorOverKeys(fields,function(field){if(field._inferredTypes[DataTypeConverter.TYPES.CODE.name]){var confidence=field._inferredTypes[DataTypeConverter.TYPES.CODE.name]/field.numOfItems,_numericalInferredType=field._inferredTypes[DataTypeConverter.TYPES.NUMBER.name];return"undefined"!=typeof _numericalInferredType&&(confidence+=_numericalInferredType/field.numOfItems),field.type=DataTypeConverter.TYPES.CODE.name,void(field.typeConfidence=confidence)}var max=ArrayUtils.FindMinMax(field._inferredTypes,function(curval,lastval){return curval>lastval}),tkey=max.first.key;tkey===DataTypeConverter.TYPES.EMPTY.name&&null!=max.second&&"undefined"!=typeof max.second&&(tkey=max.second.key),field.type=tkey,field.typeConfidence=field._inferredTypes[max.first.key]/field.numOfItems})},_processInferType=function(value){if(null===value||"undefined"==typeof value)return DataTypeConverter.TYPES.EMPTY;if("object"==typeof value)return DataTypeConverter.TYPES.OBJECT;if(/^0[0-9]+$/.test(value))return DataTypeConverter.TYPES.CODE;var isnumber=DataTypesUtils.FilterFloat(value);if(isNaN(isnumber)!==!0)return DataTypeConverter.TYPES.NUMBER;var _date=DataTypesUtils.FilterDateTime(value);return 0==isNaN(_date)&&null!=_date?DataTypeConverter.TYPES.DATETIME:DataTypeConverter.TYPES.TEXT},jsonTraverse=function(json,fieldKeys,callback){var stack=[],numOfRows=0;for(stack.push({item:json,fieldKeyIndex:0});stack.length>0;){var stackTask=stack.pop(),item=stackTask.item,fieldKeyIndex=stackTask.fieldKeyIndex,fieldKey=fieldKeys[fieldKeyIndex];if("*"!=fieldKey||0!=ArrayUtils.isArray(item))if("*"!=fieldKey||1!=ArrayUtils.isArray(item)){var jsonSubtree=item[fieldKey];if(Array.isArray(jsonSubtree))for(var j=0;j<jsonSubtree.length;j++){var jsonItem=jsonSubtree[j];stack.push({item:jsonItem,fieldKeyIndex:fieldKeyIndex+1})}else stack.push({item:jsonSubtree,fieldKeyIndex:fieldKeyIndex+1})}else for(var cell,j=0;j<item.length&&(cell=item[j]);j++)stack.push({item:cell,fieldKeyIndex:fieldKeyIndex}),numOfRows++;else{var sProcessedKeys=fieldKeys.slice(0,fieldKeyIndex).toString();ArrayUtils.IteratorOverKeys(item,function(value,key){var curKey=sProcessedKeys+(sProcessedKeys.length>0?",":"")+key,_value=callback(value,key,curKey,numOfRows);item[key]=_value}),numOfRows++}}};return{constructor:DataTypeConverter,cast:function(metadata,options){return"undefined"!=typeof options&&null!=options||(options={castThresholdConfidence:1,castIfNull:!1}),this.convert(metadata,options)},convert:function(metadata,options){var lastRowIndex=0,numOfRows=0,numOfValues=0,datasetErrors=0,datasetMissingValues=0;return"undefined"!=typeof options&&null!=options||(options={castThresholdConfidence:1,castIfNull:!1}),jsonTraverse(metadata.dataset,metadata.fieldKeys,function(value,key,traversedKeys,rowIndex){var inferredType=metadata.types[traversedKeys];numOfValues++,lastRowIndex!=rowIndex&&(lastRowIndex=rowIndex,numOfRows++),null==value||"undefined"==typeof value||0==(value+"").length;var isCast=inferredType.typeConfidence>=options.castThresholdConfidence;if(inferredType.type==DataTypeConverter.TYPES.NUMBER.name&&isCast){var number=parseFloat(value);return isNaN(number)?(datasetErrors++,value):number}return value}),metadata.qualityIndex.notNullValues=(numOfValues-datasetMissingValues)/numOfValues,metadata.qualityIndex.errors=(numOfValues-datasetErrors)/numOfValues,metadata},inferJsonDataType:function(json,fieldKeys){var stack=[],fieldsType={},numOfRows=0;if("undefined"==typeof fieldKeys)throw"IllegalArgumentException: undefined json path to analyse.";for(stack.push({item:json,fieldKeyIndex:0});stack.length>0;){var stackTask=stack.pop(),item=stackTask.item,fieldKeyIndex=stackTask.fieldKeyIndex,fieldKey=fieldKeys[fieldKeyIndex];if("*"!=fieldKey||0!=ArrayUtils.isArray(item))if("*"==fieldKey&&ArrayUtils.isArray(item))for(var cell,j=0;j<item.length&&(cell=item[j]);j++)stack.push({item:cell,fieldKeyIndex:fieldKeyIndex}),numOfRows++;else{var jsonSubtree=item[fieldKey];if(Array.isArray(jsonSubtree))for(var j=0;j<jsonSubtree.length;j++){var jsonItem=jsonSubtree[j];stack.push({item:jsonItem,fieldKeyIndex:fieldKeyIndex+1})}else stack.push({item:jsonSubtree,fieldKeyIndex:fieldKeyIndex+1})}else{var sProcessedKeys=fieldKeys.slice(0,fieldKeyIndex).toString();ArrayUtils.IteratorOverKeys(item,function(item,key){var inferredType=_processInferType(item),curKey=sProcessedKeys+(0==sProcessedKeys.length?"":",")+key,fieldType=ArrayUtils.TestAndInitializeKey(fieldsType,curKey,{name:curKey,_inferredTypes:[],_inferredValues:[],numOfItems:0});fieldType.numOfItems++,ArrayUtils.TestAndIncrement(fieldType._inferredTypes,inferredType.name),inferredType===DataTypeConverter.TYPES.TEXT&&ArrayUtils.TestAndIncrement(fieldType._inferredValues,item)}),numOfRows++}}_analyseDataTypes(fieldsType);var quality={homogeneity:1,completeness:1,totalNullValues:0,totalValues:0};ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){quality.totalValues+=fieldType.numOfItems,quality.homogeneity*=fieldType.typeConfidence,fieldType.totalNullValues=0,fieldType._inferredTypes.hasOwnProperty(DataTypeConverter.TYPES.EMPTY.name)&&(fieldType.totalNullValues=fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name],quality.totalNullValues+=fieldType.totalNullValues)}),quality.homogeneity=Math.round(100*quality.homogeneity)/100;var totFullValues=quality.totalValues-quality.totalNullValues;quality.completeness=Math.round(totFullValues/quality.totalValues*100)/100;var warningsTextual="";return ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){fieldType.errorsDescription="";var description="";if(fieldType.typeConfidence<1){var incorrect=fieldType.numOfItems-fieldType.totalNullValues-fieldType._inferredTypes[fieldType.type];if(incorrect>0){description+="The column <"+fieldType.name+"> has the type <"+fieldType.type+">";var verb=1==incorrect?" value is":" values are";description+=", but "+incorrect+verb+" not a "+fieldType.type}}fieldType.totalNullValues>0&&(description+="The column <"+fieldType.name+"> has "+fieldType.totalNullValues+" EMPTY value",fieldType.totalNullValues>1&&(description+="s")),description.length>0&&(description+="."),fieldType.errorsDescription=description,warningsTextual+=description}),{dataset:json,fieldKeys:fieldKeys,types:fieldsType,qualityIndex:quality,warningsTextual:warningsTextual}},inferDataTypeOfValue:function(value){return _processInferType(value)}}}(),DataTypesUtils.FilterTime=function(value){var expTime=/^[0-9]{2}:[0-9]{2}(:[0-9]{2})?(\+[0-9]{2}:[0-9]{2})?$/;if(0==expTime.test(value))return null;var splitted=value.split(/[:|\+]/),expNumber=/^[0-9]{2}$/,HH=expNumber.test(splitted[0])?parseInt(splitted[0]):0,MM=expNumber.test(splitted[1])?parseInt(splitted[1]):0,SS=splitted.length>=3&&expNumber.test(splitted[2])?parseInt(splitted[2]):0,dt=new Date;return dt.setHours(HH),dt.setMinutes(MM),dt.setSeconds(SS),dt},DataTypesUtils.FilterDateTime=function(value){var _dtSplitted=value.split(/[T|\s]/);if(2==_dtSplitted.length){var dtTime=DataTypesUtils.FilterTime(_dtSplitted[1]);if(null==dtTime)return null;var dtDateTime=DataTypesUtils.FilterDate(_dtSplitted[0],dtTime);return dtDateTime}var dtDate=DataTypesUtils.FilterDate(value);if(null!=dtDate)return dtDate;var dtTime=DataTypesUtils.FilterTime(value);return dtTime},DataTypesUtils.FilterDate=function(value,dtDate){if(null==dtDate&&(dtDate=new Date),/^[0-9][0-9][0-9][0-9]\-[0-9][0-9]$/.test(value)){var year=parseInt(value.substring(0,4)),month=parseInt(value.substring(5));return dtDate.setYear(year),dtDate.setMonth(month),dtDate}var expDate=/^[0-9]{4}(\-|\/)[0-9]{2}((\-|\/)[0-9]{2})?$/;if(expDate.test(value)){var splitted=value.split(/[\-|\/]/),year=parseInt(splitted[0]),month=parseInt(splitted[1]),day=3==splitted.length?parseInt(splitted[2]):0;return dtDate.setYear(year),dtDate.setMonth(month),dtDate.setDate(day),dtDate}if(expDate=/^[0-9]{2}(\-|\/)[0-9]{2}(\-|\/)[0-9]{4}$/,expDate.test(value)){var splitted=value.split(/[\-|\/]/),year=parseInt(splitted[2]),month=parseInt(splitted[1]),day=parseInt(splitted[0]);return dtDate.setYear(year),dtDate.setMonth(month),dtDate.setDate(day),dtDate}return null},DataTypesUtils.FilterFloat=function(value){return/^(\-|\+)?((0|([1-9][0-9]*))(\.[0-9]+)?|Infinity)$/.test(value)?Number(value):NaN},DataTypesUtils.DecimalPlaces=function(num){var match=(""+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return match?Math.max(0,(match[1]?match[1].length:0)-(match[2]?+match[2]:0)):0},DataTypeHierarchy.HIERARCHY=[],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.TEXT.name]=[DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.NUMBER.name]=[DataTypeConverter.TYPES.NUMBER.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.DATETIME.name]=[DataTypeConverter.TYPES.DATETIME.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.LATITUDE.name]=[DataTypeConverter.SUBTYPES.LATITUDE.name,DataTypeConverter.TYPES.NUMBER.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.LONGITUDE.name]=[DataTypeConverter.SUBTYPES.LONGITUDE.name,DataTypeConverter.TYPES.NUMBER.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.canConvert=function(fromType,toType){var arrConvertableTypes=DataTypeHierarchy.HIERARCHY[fromType],idx=arrConvertableTypes.indexOf(toType);return idx>=0}; | |
2 | 1 | \ No newline at end of file |
2 | +function ArrayUtils(){}function DataTypeConverter(){this._fields=[],this._numOfRows=0}function DataTypesUtils(){}function DataTypeHierarchy(){}ArrayUtils.TestAndSet=function(arr,key,object){return"undefined"==typeof arr?null:0==Array.isArray(arr)?null:("undefined"==typeof arr[key]&&(arr[key]=object),arr[key])},ArrayUtils.TestAndInitializeKey=function(obj,key,value){return"undefined"==typeof obj?null:("undefined"==typeof obj[key]&&(obj[key]=value),obj[key])},ArrayUtils.TestAndIncrement=function(arr,key){var exists=arr[key];return"undefined"==typeof exists&&(arr[key]=0),arr[key]++,arr},ArrayUtils.toFieldsArray=function(obj){var fields=[];return ArrayUtils.IteratorOverKeys(obj,function(field,key){field.key=key,fields.push(field)}),fields},ArrayUtils.IteratorOverKeys=function(arr,callback){for(var property in arr)if(arr.hasOwnProperty(property)){var item=arr[property];callback(item,property)}},ArrayUtils.FindMinMax=function(arr,fncompare){var max1=null,max2=null;for(var key in arr)null==max1||fncompare(arr[key],max1.value)?(max2=max1,max1={index:-1,key:key,value:arr[key]}):(null==max2||fncompare(arr[key],max2.value))&&(max2={index:-1,key:key,value:arr[key]});return{first:max1,second:max2}},ArrayUtils.isArray=function(arr){return Array.isArray(arr)?arr.length>0:!1},DataTypeConverter.TYPES={TEXT:{value:0,name:"TEXT"},CODE:{value:1,name:"CODE"},NUMBER:{value:2,name:"NUMBER"},OBJECT:{value:3,name:"OBJECT"},BOOL:{value:5,name:"BOOL"},CONST:{value:6,name:"CONST"},CATEGORY:{value:7,name:"CATEGORY"},DATETIME:{value:8,name:"DATETIME"},EMPTY:{value:101,name:"NULL"}},DataTypeConverter.SUBTYPES={GEOCOORDINATE:{value:1e3,name:"GEOCOORDINATE"},PERCENTAGE:{value:1e3,name:"PERCENTAGE"},LATITUDE:{value:1001,name:"LATITUDE"},LONGITUDE:{value:1002,name:"LONGITUDE"}},DataTypeConverter.prototype=function(){var _analyseDataTypes=function(fields){ArrayUtils.IteratorOverKeys(fields,function(field){if(field._inferredTypes[DataTypeConverter.TYPES.CODE.name]){var confidence=field._inferredTypes[DataTypeConverter.TYPES.CODE.name]/field.numOfItems,_numericalInferredType=field._inferredTypes[DataTypeConverter.TYPES.NUMBER.name];return"undefined"!=typeof _numericalInferredType&&(confidence+=_numericalInferredType/field.numOfItems),field.type=DataTypeConverter.TYPES.CODE.name,void(field.typeConfidence=confidence)}var max=ArrayUtils.FindMinMax(field._inferredTypes,function(curval,lastval){return curval>lastval}),tkey=max.first.key;tkey===DataTypeConverter.TYPES.EMPTY.name&&null!=max.second&&"undefined"!=typeof max.second&&(tkey=max.second.key),field.type=tkey,field.typeConfidence=field._inferredTypes[max.first.key]/field.numOfItems;var max=ArrayUtils.FindMinMax(field._inferredSubTypes,function(curval,lastval){return curval>lastval});if(field.subtype=null,null!=max&&null!=max.first){field.subtype=max.first.key,field.subtypeConfidence=field._inferredSubTypes[field.subtype]/field.numOfItems;var fieldName=field.name.toLowerCase(),isLatType=field.subtype===DataTypeConverter.SUBTYPES.LATITUDE.name,fieldNameContainsLat=fieldName.indexOf("lat")>=0,fieldNameContainsLon=fieldName.indexOf("ng")>=0;1==isLatType&&0==fieldNameContainsLat&&1==fieldNameContainsLon&&(field.subtype=DataTypeConverter.SUBTYPES.LONGITUDE.name)}})},_processInferType=function(value){if(null===value||"undefined"==typeof value)return DataTypeConverter.TYPES.EMPTY;if("object"==typeof value)return DataTypeConverter.TYPES.OBJECT;if(/^0[0-9]+$/.test(value))return DataTypeConverter.TYPES.CODE;var isnumber=DataTypesUtils.FilterFloat(value);if(isNaN(isnumber)!==!0)return DataTypeConverter.TYPES.NUMBER;var _date=DataTypesUtils.FilterDateTime(value);return 0==isNaN(_date)&&null!=_date?DataTypeConverter.TYPES.DATETIME:DataTypeConverter.TYPES.TEXT},_processInferSubType=function(value){if(null===value||"undefined"==typeof value)return null;var isnumber=DataTypesUtils.FilterFloat(value);return isNaN(isnumber)!==!0?isnumber>=-90&&90>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:isnumber>=-180&&180>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:null:null},_filterBasedOnThreshold=function(metadata,threshold){return ArrayUtils.IteratorOverKeys(metadata.types,function(fieldType,key){if(!(fieldType.typeConfidence>=threshold)){var arrHierarchyTypes=DataTypeHierarchy.HIERARCHY[fieldType.type],lastFieldType={lastType:arrHierarchyTypes[0],lastTypeCounter:fieldType._inferredTypes[arrHierarchyTypes[0]],typeConfidence:0};lastFieldType.typeConfidence=lastFieldType.lastTypeCounter/fieldType.numOfItems;for(var curType,i=1;i<arrHierarchyTypes.length,curType=arrHierarchyTypes[i];i++){var numItemsOfCurType=fieldType._inferredTypes.hasOwnProperty(curType)?fieldType._inferredTypes[curType]:0;if(lastFieldType.lastType=curType,lastFieldType.lastTypeCounter+=numItemsOfCurType,lastFieldType.typeConfidence=lastFieldType.lastTypeCounter/fieldType.numOfItems,lastFieldType.typeConfidence>=threshold){fieldType.type=lastFieldType.lastType,fieldType.typeConfidence=lastFieldType.typeConfidence;break}}}}),metadata},jsonTraverse=function(json,fieldKeys,callback){var stack=[],numOfRows=0;for(stack.push({item:json,fieldKeyIndex:0});stack.length>0;){var stackTask=stack.pop(),item=stackTask.item,fieldKeyIndex=stackTask.fieldKeyIndex,fieldKey=fieldKeys[fieldKeyIndex];if("*"!=fieldKey||0!=ArrayUtils.isArray(item))if("*"!=fieldKey||1!=ArrayUtils.isArray(item)){var jsonSubtree=item[fieldKey];if(Array.isArray(jsonSubtree))for(var j=0;j<jsonSubtree.length;j++){var jsonItem=jsonSubtree[j];stack.push({item:jsonItem,fieldKeyIndex:fieldKeyIndex+1})}else stack.push({item:jsonSubtree,fieldKeyIndex:fieldKeyIndex+1})}else for(var cell,j=0;j<item.length&&(cell=item[j]);j++)stack.push({item:cell,fieldKeyIndex:fieldKeyIndex}),numOfRows++;else{var sProcessedKeys=fieldKeys.slice(0,fieldKeyIndex).toString();ArrayUtils.IteratorOverKeys(item,function(value,key){var curKey=sProcessedKeys+(sProcessedKeys.length>0?",":"")+key,_value=callback(value,key,curKey,numOfRows);item[key]=_value}),numOfRows++}}};return{constructor:DataTypeConverter,cast:function(metadata,options){return"undefined"!=typeof options&&null!=options||(options={castThresholdConfidence:1,castIfNull:!1}),this.convert(metadata,options)},convert:function(metadata,options){var lastRowIndex=0,numOfRows=0,numOfValues=0,datasetErrors=0,datasetMissingValues=0;return"undefined"!=typeof options&&null!=options||(options={castThresholdConfidence:1,castIfNull:!1}),jsonTraverse(metadata.dataset,metadata.fieldKeys,function(value,key,traversedKeys,rowIndex){var inferredType=metadata.types[traversedKeys];numOfValues++,lastRowIndex!=rowIndex&&(lastRowIndex=rowIndex,numOfRows++),null==value||"undefined"==typeof value||0==(value+"").length;var isCast=inferredType.typeConfidence>=options.castThresholdConfidence;if(inferredType.type==DataTypeConverter.TYPES.NUMBER.name&&isCast){var number=parseFloat(value);return isNaN(number)?(datasetErrors++,value):number}return value}),metadata.qualityIndex.notNullValues=(numOfValues-datasetMissingValues)/numOfValues,metadata.qualityIndex.errors=(numOfValues-datasetErrors)/numOfValues,metadata},inferJsonDataType:function(json,fieldKeys,options){"undefined"!=typeof options&&null!=options||(options={thresholdConfidence:1});var stack=[],fieldsType={},numOfRows=0;if("undefined"==typeof fieldKeys)throw"IllegalArgumentException: undefined json path to analyse.";for(stack.push({item:json,fieldKeyIndex:0});stack.length>0;){var stackTask=stack.pop(),item=stackTask.item,fieldKeyIndex=stackTask.fieldKeyIndex,fieldKey=fieldKeys[fieldKeyIndex];if("*"!=fieldKey||0!=ArrayUtils.isArray(item))if("*"==fieldKey&&ArrayUtils.isArray(item))for(var cell,j=0;j<item.length&&(cell=item[j]);j++)stack.push({item:cell,fieldKeyIndex:fieldKeyIndex}),numOfRows++;else{var jsonSubtree=item[fieldKey];if(Array.isArray(jsonSubtree))for(var j=0;j<jsonSubtree.length;j++){var jsonItem=jsonSubtree[j];stack.push({item:jsonItem,fieldKeyIndex:fieldKeyIndex+1})}else stack.push({item:jsonSubtree,fieldKeyIndex:fieldKeyIndex+1})}else{var sProcessedKeys=fieldKeys.slice(0,fieldKeyIndex).toString();ArrayUtils.IteratorOverKeys(item,function(item,key){var curKey=sProcessedKeys+(0==sProcessedKeys.length?"":",")+key,fieldType=ArrayUtils.TestAndInitializeKey(fieldsType,curKey,{name:curKey,_inferredTypes:[],_inferredSubTypes:[],_inferredValues:[],numOfItems:0});fieldType.numOfItems++;var inferredType=_processInferType(item);ArrayUtils.TestAndIncrement(fieldType._inferredTypes,inferredType.name),inferredType===DataTypeConverter.TYPES.TEXT&&ArrayUtils.TestAndIncrement(fieldType._inferredValues,item);var inferredSubType=_processInferSubType(item);null!=inferredSubType&&"undefined"!=typeof inferredSubType&&ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes,inferredSubType.name)}),numOfRows++}}_analyseDataTypes(fieldsType);var quality={homogeneity:1,completeness:1,totalNullValues:0,totalValues:0};ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){quality.totalValues+=fieldType.numOfItems,quality.homogeneity*=fieldType.typeConfidence,fieldType.totalNullValues=0,fieldType._inferredTypes.hasOwnProperty(DataTypeConverter.TYPES.EMPTY.name)&&(fieldType.totalNullValues=fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name],quality.totalNullValues+=fieldType.totalNullValues)}),quality.homogeneity=Math.round(100*quality.homogeneity)/100;var totFullValues=quality.totalValues-quality.totalNullValues;quality.completeness=Math.round(totFullValues/quality.totalValues*100)/100;var warningsTextual="";ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){fieldType.errorsDescription="";var description="";if(fieldType.typeConfidence<1){var incorrect=fieldType.numOfItems-fieldType.totalNullValues-fieldType._inferredTypes[fieldType.type];if(incorrect>0){description+="The column <"+fieldType.name+"> has the type <"+fieldType.type+">";var verb=1==incorrect?" value is":" values are";description+=", but "+incorrect+verb+" not a "+fieldType.type}}fieldType.totalNullValues>0&&(description+="The column <"+fieldType.name+"> has "+fieldType.totalNullValues+" EMPTY value",fieldType.totalNullValues>1&&(description+="s")),description.length>0&&(description+="."),fieldType.errorsDescription=description,warningsTextual+=description});var metadata={dataset:json,fieldKeys:fieldKeys,types:fieldsType,qualityIndex:quality,warningsTextual:warningsTextual};return _filterBasedOnThreshold(metadata,options.thresholdConfidence),metadata},inferDataTypeOfValue:function(value){return _processInferType(value)}}}(),DataTypesUtils.FilterTime=function(value){var expTime=/^[0-9]{2}:[0-9]{2}(:[0-9]{2})?(\+[0-9]{2}:[0-9]{2})?$/;if(0==expTime.test(value))return null;var splitted=value.split(/[:|\+]/),expNumber=/^[0-9]{2}$/,HH=expNumber.test(splitted[0])?parseInt(splitted[0]):0,MM=expNumber.test(splitted[1])?parseInt(splitted[1]):0,SS=splitted.length>=3&&expNumber.test(splitted[2])?parseInt(splitted[2]):0,dt=new Date;return dt.setHours(HH),dt.setMinutes(MM),dt.setSeconds(SS),dt},DataTypesUtils.FilterDateTime=function(value){var _dtSplitted=value.split(/[T|\s]/);if(2==_dtSplitted.length){var dtTime=DataTypesUtils.FilterTime(_dtSplitted[1]);if(null==dtTime)return null;var dtDateTime=DataTypesUtils.FilterDate(_dtSplitted[0],dtTime);return dtDateTime}var dtDate=DataTypesUtils.FilterDate(value);if(null!=dtDate)return dtDate;var dtTime=DataTypesUtils.FilterTime(value);return dtTime},DataTypesUtils.FilterDate=function(value,dtDate){if(null==dtDate&&(dtDate=new Date),/^[0-9][0-9][0-9][0-9]\-[0-9][0-9]$/.test(value)){var year=parseInt(value.substring(0,4)),month=parseInt(value.substring(5));return dtDate.setYear(year),dtDate.setMonth(month),dtDate}var expDate=/^[0-9]{4}(\-|\/)[0-9]{2}((\-|\/)[0-9]{2})?$/;if(expDate.test(value)){var splitted=value.split(/[\-|\/]/),year=parseInt(splitted[0]),month=parseInt(splitted[1]),day=3==splitted.length?parseInt(splitted[2]):0;return dtDate.setYear(year),dtDate.setMonth(month),dtDate.setDate(day),dtDate}if(expDate=/^[0-9]{2}(\-|\/)[0-9]{2}(\-|\/)[0-9]{4}$/,expDate.test(value)){var splitted=value.split(/[\-|\/]/),year=parseInt(splitted[2]),month=parseInt(splitted[1]),day=parseInt(splitted[0]);return dtDate.setYear(year),dtDate.setMonth(month),dtDate.setDate(day),dtDate}return null},DataTypesUtils.FilterFloat=function(value){return/^(\-|\+)?((0|([1-9][0-9]*))(\.[0-9]+)?|Infinity)$/.test(value)?Number(value):NaN},DataTypesUtils.DecimalPlaces=function(num){var match=(""+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return match?Math.max(0,(match[1]?match[1].length:0)-(match[2]?+match[2]:0)):0},DataTypeHierarchy.HIERARCHY=[],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.TEXT.name]=[DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.NUMBER.name]=[DataTypeConverter.TYPES.NUMBER.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.DATETIME.name]=[DataTypeConverter.TYPES.DATETIME.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.GEOCOORDINATE.name]=[DataTypeConverter.SUBTYPES.GEOCOORDINATE.name,DataTypeConverter.TYPES.NUMBER.name,DataTypeConverter.TYPES.TEXT.name],DataTypeHierarchy.canConvert=function(fromType,toType){var arrConvertableTypes=DataTypeHierarchy.HIERARCHY[fromType],idx=arrConvertableTypes.indexOf(toType);return idx>=0}; | |
3 | 3 | \ No newline at end of file |
... | ... |
bower_components/JSDataChecker/src/DataTypeConverter.js
... | ... | @@ -42,9 +42,10 @@ DataTypeConverter.TYPES = { |
42 | 42 | }; |
43 | 43 | |
44 | 44 | DataTypeConverter.SUBTYPES = { |
45 | - PERCENTAGE : { value: 1000, name: "PERCENTAGE" }, | |
46 | - LATITUDE : { value: 1001, name: "LATITUDE" }, | |
47 | - LONGITUDE : { value: 1002, name: "LONGITUDE" } | |
45 | + GEOCOORDINATE : { value: 1000, name: "GEOCOORDINATE" }, | |
46 | + PERCENTAGE : { value: 1000, name: "PERCENTAGE" }, | |
47 | + LATITUDE : { value: 1001, name: "LATITUDE" }, | |
48 | + LONGITUDE : { value: 1002, name: "LONGITUDE" } | |
48 | 49 | }; |
49 | 50 | |
50 | 51 | DataTypeConverter.prototype = (function () { |
... | ... | @@ -120,7 +121,6 @@ DataTypeConverter.prototype = (function () { |
120 | 121 | return; |
121 | 122 | } |
122 | 123 | |
123 | - | |
124 | 124 | //Infers the field TYPE. |
125 | 125 | var max = ArrayUtils.FindMinMax(field._inferredTypes, function (curval, lastval) { |
126 | 126 | return curval > lastval; |
... | ... | @@ -136,15 +136,31 @@ DataTypeConverter.prototype = (function () { |
136 | 136 | field.typeConfidence = field._inferredTypes[max.first.key] / field.numOfItems; |
137 | 137 | |
138 | 138 | |
139 | - //TODO: improve this piece of code. | |
140 | - //LAT/LNG. | |
141 | - /*var fieldName = field.name.toLowerCase(); | |
142 | - var isLatType = (field.type === DataTypeConverter.TYPES.LATITUDE.name); | |
143 | - var fieldNameContainsLat = fieldName.indexOf('lat') >= 0; | |
144 | - var fieldNameContainsLon = fieldName.indexOf('ng') >= 0; //It could be 'lng'. | |
145 | - if (isLatType == true && fieldNameContainsLat == false && fieldNameContainsLon == true) { | |
146 | - field.type = DataTypeConverter.TYPES.LONGITUDE.name; | |
147 | - }*/ | |
139 | + //########## | |
140 | + //Infers the field SUBTYPE. | |
141 | + | |
142 | + var max = ArrayUtils.FindMinMax(field._inferredSubTypes, function (curval, lastval) { | |
143 | + return curval > lastval; | |
144 | + }); | |
145 | + field.subtype = null; | |
146 | + if (max != null && max.first != null) { | |
147 | + field.subtype = max.first.key; | |
148 | + field.subtypeConfidence = field._inferredSubTypes[field.subtype] / field.numOfItems; | |
149 | + | |
150 | + //TODO: improve this piece of code. | |
151 | + //LAT/LNG. | |
152 | + var fieldName = field.name.toLowerCase(); | |
153 | + var isLatType = (field.subtype === DataTypeConverter.SUBTYPES.LATITUDE.name); | |
154 | + var fieldNameContainsLat = fieldName.indexOf('lat') >= 0; | |
155 | + var fieldNameContainsLon = fieldName.indexOf('ng') >= 0; //It could be 'lng'. | |
156 | + if (isLatType == true && fieldNameContainsLat == false && fieldNameContainsLon == true) { | |
157 | + field.subtype = DataTypeConverter.SUBTYPES.LONGITUDE.name; | |
158 | + } | |
159 | + } | |
160 | + | |
161 | + /// | |
162 | + /// SUBTYPES. | |
163 | + | |
148 | 164 | |
149 | 165 | //BOOLEAN. |
150 | 166 | /*var numOfValues = Object.keys(field._inferredValues).length; |
... | ... | @@ -200,13 +216,58 @@ DataTypeConverter.prototype = (function () { |
200 | 216 | if (isNaN(_date) == false && _date != null) |
201 | 217 | return DataTypeConverter.TYPES.DATETIME; |
202 | 218 | |
203 | - | |
204 | 219 | return DataTypeConverter.TYPES.TEXT; |
205 | 220 | };//EndFunction. |
206 | 221 | |
207 | - var _processInferSubType = function(value) { | |
208 | - //Try to parse lat/lng. | |
222 | + var _processInferSubType = function (value) { | |
223 | + if (value === null || typeof value === 'undefined') return null; | |
224 | + | |
225 | + //Try to parse the float. | |
226 | + var isnumber = DataTypesUtils.FilterFloat(value); | |
227 | + if (isNaN(isnumber) !== true) {//It is a number. | |
228 | + //If the number ranges from -90.0 to 90.0, the value is marked as Latitude. | |
229 | + if (-90.0 <= isnumber && isnumber <= 90.0 && DataTypesUtils.DecimalPlaces(isnumber) >= 5) | |
230 | + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; | |
231 | + | |
232 | + //It the number ranges from -180.0 to 180.0, the value is marked as Longitude. | |
233 | + if (-180.0 <= isnumber && isnumber <= 180.0 && DataTypesUtils.DecimalPlaces(isnumber) >= 5) | |
234 | + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; | |
235 | + | |
236 | + /*if (0.0 <= isnumber && isnumber <= 100.0) | |
237 | + if(/^(\+)?((0|([1-9][0-9]*))\.([0-9]+))$/ .test(value)) | |
238 | + return DataTypeConverter.SUBTYPES.PERCENTAGE;*/ | |
209 | 239 | |
240 | + return null; | |
241 | + } | |
242 | + | |
243 | + return null; | |
244 | + };//EndFunction. | |
245 | + | |
246 | + var _filterBasedOnThreshold = function(metadata, threshold) { | |
247 | + ArrayUtils.IteratorOverKeys(metadata.types, function (fieldType, key) { | |
248 | + if (fieldType.typeConfidence >= threshold) return; | |
249 | + | |
250 | + var arrHierarchyTypes = DataTypeHierarchy.HIERARCHY[fieldType.type]; | |
251 | + var lastFieldType = { lastType: arrHierarchyTypes[0], | |
252 | + lastTypeCounter: fieldType._inferredTypes[arrHierarchyTypes[0]], | |
253 | + typeConfidence: 0 }; | |
254 | + lastFieldType.typeConfidence = lastFieldType.lastTypeCounter / fieldType.numOfItems; | |
255 | + | |
256 | + for (var i= 1, curType; i<arrHierarchyTypes.length, curType = arrHierarchyTypes[i]; i++) { | |
257 | + var numItemsOfCurType = fieldType._inferredTypes.hasOwnProperty(curType) ? fieldType._inferredTypes[curType] : 0 ; | |
258 | + lastFieldType.lastType = curType; | |
259 | + lastFieldType.lastTypeCounter += numItemsOfCurType; | |
260 | + lastFieldType.typeConfidence = lastFieldType.lastTypeCounter / fieldType.numOfItems; | |
261 | + | |
262 | + if (lastFieldType.typeConfidence >= threshold) { | |
263 | + fieldType.type = lastFieldType.lastType; | |
264 | + fieldType.typeConfidence = lastFieldType.typeConfidence; | |
265 | + break; | |
266 | + } | |
267 | + } | |
268 | + }); | |
269 | + | |
270 | + return metadata; | |
210 | 271 | };//EndFunction. |
211 | 272 | |
212 | 273 | var jsonTraverse = function(json, fieldKeys, callback) { |
... | ... | @@ -332,10 +393,15 @@ DataTypeConverter.prototype = (function () { |
332 | 393 | * It parses the json and infers the data types. |
333 | 394 | * @param json |
334 | 395 | * @param path Array of field keys/names. |
396 | + * @param options Infer Data Type options, in particular the threshold value for the confidence. | |
335 | 397 | */ |
336 | - inferJsonDataType: function (json, fieldKeys) { | |
398 | + inferJsonDataType: function (json, fieldKeys, options) { | |
399 | + if (typeof options === 'undefined' || options == null) | |
400 | + options = { thresholdConfidence: 1 }; | |
401 | + | |
337 | 402 | var stack = []; |
338 | 403 | var fieldsType = {}; |
404 | + var fieldsSubType = {}; | |
339 | 405 | var numOfRows = 0; |
340 | 406 | |
341 | 407 | if (typeof fieldKeys == 'undefined') |
... | ... | @@ -357,16 +423,25 @@ DataTypeConverter.prototype = (function () { |
357 | 423 | var sProcessedKeys = fieldKeys.slice(0, fieldKeyIndex).toString(); |
358 | 424 | |
359 | 425 | ArrayUtils.IteratorOverKeys(item, function (item, key) { |
360 | - var inferredType = _processInferType(item); | |
361 | 426 | var curKey = sProcessedKeys + ((sProcessedKeys.length == 0) ? "" : ",") + key; |
362 | - | |
363 | - var fieldType = ArrayUtils.TestAndInitializeKey(fieldsType, curKey, { name: curKey, _inferredTypes: [], _inferredValues: [], numOfItems: 0 }); | |
427 | + var fieldType = ArrayUtils.TestAndInitializeKey(fieldsType, curKey, { name: curKey, _inferredTypes: [], _inferredSubTypes: [], _inferredValues: [], numOfItems: 0 }); | |
364 | 428 | fieldType.numOfItems++; |
429 | + | |
430 | + ///TYPE | |
431 | + var inferredType = _processInferType(item); | |
365 | 432 | ArrayUtils.TestAndIncrement(fieldType._inferredTypes, inferredType.name); |
366 | 433 | if (inferredType === DataTypeConverter.TYPES.TEXT) |
367 | 434 | ArrayUtils.TestAndIncrement(fieldType._inferredValues, item); |
368 | - //if (inferredType === DataTypeConverter.TYPES.LATITUDE || inferredType === DataTypeConverter.TYPES.LONGITUDE) | |
369 | - // ArrayUtils.TestAndIncrement(fieldType._inferredTypes, DataTypeConverter.TYPES.NUMBER); | |
435 | + | |
436 | + ///SUBTYPE | |
437 | + var inferredSubType = _processInferSubType(item); | |
438 | + if (inferredSubType != null && typeof inferredSubType !== 'undefined') { | |
439 | + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, inferredSubType.name); | |
440 | + /*if (inferredSubType === DataTypeConverter.TYPES.LATITUDE) | |
441 | + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, DataTypeConverter.TYPES.LATITUDE); | |
442 | + if (inferredSubType === DataTypeConverter.TYPES.LONGITUDE) | |
443 | + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, DataTypeConverter.TYPES.LONGITUDE);*/ | |
444 | + }//EndSubtype. | |
370 | 445 | |
371 | 446 | }); |
372 | 447 | |
... | ... | @@ -451,7 +526,11 @@ DataTypeConverter.prototype = (function () { |
451 | 526 | warningsTextual += description; |
452 | 527 | }); |
453 | 528 | |
454 | - return { dataset: json, fieldKeys: fieldKeys, types: fieldsType, qualityIndex: quality, warningsTextual: warningsTextual }; | |
529 | + var metadata = { dataset: json, fieldKeys: fieldKeys, types: fieldsType, qualityIndex: quality, warningsTextual: warningsTextual }; | |
530 | + | |
531 | + _filterBasedOnThreshold(metadata, options.thresholdConfidence); | |
532 | + | |
533 | + return metadata; | |
455 | 534 | },//EndFunction. |
456 | 535 | |
457 | 536 | /*inferDataTypes: function (jsonRows) { |
... | ... |
bower_components/JSDataChecker/src/DataTypeHierarchy.js
... | ... | @@ -29,9 +29,7 @@ DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.TEXT.name] = [ DataTypeConve |
29 | 29 | DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.NUMBER.name] = [ DataTypeConverter.TYPES.NUMBER.name, DataTypeConverter.TYPES.TEXT.name]; |
30 | 30 | DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.DATETIME.name] = [ DataTypeConverter.TYPES.DATETIME.name, DataTypeConverter.TYPES.TEXT.name ]; |
31 | 31 | |
32 | -DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.LATITUDE.name] = [ DataTypeConverter.SUBTYPES.LATITUDE.name, | |
33 | - DataTypeConverter.TYPES.NUMBER.name, DataTypeConverter.TYPES.TEXT.name]; | |
34 | -DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.LONGITUDE.name] = [ DataTypeConverter.SUBTYPES.LONGITUDE.name, | |
32 | +DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.GEOCOORDINATE.name] = [ DataTypeConverter.SUBTYPES.GEOCOORDINATE.name, | |
35 | 33 | DataTypeConverter.TYPES.NUMBER.name, DataTypeConverter.TYPES.TEXT.name]; |
36 | 34 | |
37 | 35 | DataTypeHierarchy.canConvert = function (fromType, toType) { |
... | ... |
controllets/data-table-controllet/data-table-controllet.html
... | ... | @@ -216,9 +216,9 @@ |
216 | 216 | <paper-tooltip for="{{_fieldId(index)}}" offset="8"> |
217 | 217 | <p> |
218 | 218 | <span class="type">{{_type()}}:</span> {{item.type}} |
219 | - <!--<template is="dom-if" if={{item.errorsDescription}}>--> | |
220 | - <!--({{item.subType}})--> | |
221 | - <!--</template>--> | |
219 | + <template is="dom-if" if={{item.subtype}}> | |
220 | + ({{item.subtype}}) | |
221 | + </template> | |
222 | 222 | <template is="dom-if" if={{item.errorsDescription.length}}> |
223 | 223 | <br/> |
224 | 224 | <span class="warning">{{_warning()}}:</span> {{item.errorsDescription}} |
... | ... |
controllets/select-data-controllet/select-data-controllet.html
... | ... | @@ -144,8 +144,6 @@ |
144 | 144 | setSelectedFields : function(selectedFields) { |
145 | 145 | this.async(function() { |
146 | 146 | var selectedIndices = utility_getSelectedIndices(this.fields, selectedFields); |
147 | - | |
148 | - console.log(selectedIndices); | |
149 | 147 | this.$.select_fields.setSelectFields(selectedIndices); |
150 | 148 | }, 0); |
151 | 149 | }, |
... | ... |
datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js
... | ... | @@ -124,7 +124,7 @@ var AjaxJsonAlasqlBehavior = { |
124 | 124 | result = converter.cast(result); |
125 | 125 | data = result.dataset; |
126 | 126 | |
127 | - data = alasql_complexSelectData(data, fields, filters, aggregators, orders); | |
127 | + data = alasql_complexSelectData(data, fields, [], aggregators, orders); | |
128 | 128 | |
129 | 129 | this.data = transformData(data, fields, true); |
130 | 130 | |
... | ... |