Commit 2f14a3f997cd4a4a9d0d72bcbdf9fe3a9e633cb9
1 parent
0203e785
jsdatachecker+coroom green style
Showing
7 changed files
with
151 additions
and
36 deletions
bower_components/jsdatachecker/.bower.json
1 | 1 | { |
2 | 2 | "name": "jsdatachecker", |
3 | - "version": "0.1.2", | |
3 | + "version": "0.1.3", | |
4 | 4 | "homepage": "https://github.com/donpir/jsdatachecker", |
5 | 5 | "authors": [ |
6 | 6 | "'Donato Pirozzi <'donatopirozzi@gmail.com'>" |
... | ... | @@ -22,14 +22,13 @@ |
22 | 22 | "polywc-data-table": "https://github.com/donpir/polywc-data-table.git#master" |
23 | 23 | }, |
24 | 24 | "private": false, |
25 | - "_release": "0.1.2", | |
25 | + "_release": "0.1.3", | |
26 | 26 | "_resolution": { |
27 | 27 | "type": "version", |
28 | - "tag": "v0.1.2", | |
29 | - "commit": "1cd37fc00315232a97de7978e5423784899eca29" | |
28 | + "tag": "v0.1.3", | |
29 | + "commit": "186392b9d8576e98e269150ab2a88562215a2b2a" | |
30 | 30 | }, |
31 | 31 | "_source": "https://github.com/donpir/JSDataChecker.git", |
32 | 32 | "_target": "~0.1.2", |
33 | - "_originalSource": "jsdatachecker", | |
34 | - "_direct": true | |
33 | + "_originalSource": "jsdatachecker" | |
35 | 34 | } |
36 | 35 | \ No newline at end of file | ... | ... |
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={EMPTY:{value:0,name:"NULL"},TEXT:{value:1,name:"TEXT"},NUMBER:{value:2,name:"NUMBER"},OBJECT:{value:3,name:"OBJECT"},DATETIME:{value:4,name:"DATETIME"}},DataTypeConverter.SUBTYPES={GEOCOORDINATE:{value:1e3,name:"GEOCOORDINATE"},GEOJSON:{value:1001,name:"GEOJSON"},BOOL:{value:1002,name:"BOOL"},CONST:{value:1003,name:"CONST"},CATEGORY:{value:1004,name:"CATEGORY"},PERCENTAGE:{value:1100,name:"PERCENTAGE"},LATITUDE:{value:1101,name:"LATITUDE"},LONGITUDE:{value:1102,name:"LONGITUDE"}},DataTypeConverter.LANGS={EN:{value:1e3,name:"EN"},IT:{value:1001,name:"IT"},FR:{value:1100,name:"FR"},NL:{value:1101,name:"NL"}},DataTypeConverter.GEOJSONTYPES=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon","GeometryCollection","Feature","FeatureCollection"],DataTypeConverter.prototype=function(){var _analyseDataTypes=function(fields){ArrayUtils.IteratorOverKeys(fields,function(field){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;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;if(Array.isArray(value)&&2==value.length&&NaN!=DataTypesUtils.FilterFloat(value[0])&&NaN!=DataTypesUtils.FilterFloat(value[1])&&DataTypesUtils.DecimalPlaces(value[0])>4&&DataTypesUtils.DecimalPlaces(value[1])>4)return DataTypeConverter.SUBTYPES.GEOCOORDINATE;if("string"==typeof value){var split=value.split(",");if(DataTypesUtils.IsLatLng(split[0])&&DataTypesUtils.IsLatLng(split[1]))return DataTypeConverter.SUBTYPES.GEOCOORDINATE}var isnumber=DataTypesUtils.FilterFloat(value);if(isNaN(isnumber)!==!0)return isnumber>=-90&&90>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:isnumber>=-180&&180>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:null;if("object"==typeof value&&value.hasOwnProperty("type")){var geotype=value.type,isincluded=DataTypeConverter.GEOJSONTYPES.includes(geotype);if(isincluded)return DataTypeConverter.SUBTYPES.GEOJSON}return null},_filterBasedOnThreshold=function(metadata,threshold){return ArrayUtils.IteratorOverKeys(metadata.types,function(fieldType,key){if(!(fieldType.typeConfidence>=threshold)){var arrHierarchyTypes=DataTypeHierarchy.HIERARCHY[fieldType.type];if(null==arrHierarchyTypes)return metadata;var 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},_capitalizeFirstLetter=function(string){return string.charAt(0).toUpperCase()+string.slice(1)},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={}),0==options.hasOwnProperty("thresholdConfidence")&&(options.thresholdConfidence=1),0==options.hasOwnProperty("language")?options.language=DataTypeConverter.LANGS.EN.name:options.language=options.language.toUpperCase();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){var _descr1=_capitalizeFirstLetter(JDC_LNG.key_declaretype[options.language])+".",_descr2=_capitalizeFirstLetter(JDC_LNG.key_notoftype_singular[options.language])+".";incorrect>1&&(_descr2=_capitalizeFirstLetter(JDC_LNG.key_notoftype_plural[options.language])+".");var descr=_descr1+" "+_descr2;descr=descr.replace(/%COL_NAME/g,fieldType.name),descr=descr.replace(/%COL_TYPE/g,fieldType.type),descr=descr.replace(/%COL_ERRORS/g,incorrect),description+=descr}}var descr="";1==fieldType.totalNullValues?descr=_capitalizeFirstLetter(JDC_LNG.key_emptyvalue_singolar[options.language])+".":fieldType.totalNullValues>1&&(descr=_capitalizeFirstLetter(JDC_LNG.key_emptyvalue_plural[options.language])+"."),descr=descr.replace(/%COL_NAME/g,fieldType.name),descr=descr.replace(/%COL_TYPE/g,fieldType.type),descr=descr.replace(/%COL_NULLVALUES/g,fieldType.totalNullValues),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)},inferDataSubTypeOfValue:function(value){return _processInferSubType(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},DataTypesUtils.IsLatLng=function(num){return NaN==DataTypesUtils.FilterFloat(num)?!1:DataTypesUtils.DecimalPlaces(num)>4},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};var JDC_LNG={key_declaretype:{EN:"the column <%COL_NAME> is of type <%COL_TYPE>",IT:"la colonna <%COL_NAME> è di tipo <%COL_TYPE>",FR:"le colum <%COL_NAME> est de type <%COL_TYPE>",NL:"de kolom <%COL_NAME> is van het type <%COL_TYPE>"},key_notoftype_singular:{EN:"a value is not <%COL_TYPE>",IT:"un valore non è un <%COL_TYPE>",FR:"une valeur est pas <%COL_TYPE> se trouvant",NL:"een waarde is niet <%COL_TYPE>"},key_notoftype_plural:{EN:"%COL_ERRORS values are not <%COL_TYPE>",IT:"%COL_ERRORS valori non sono di tipo <%COL_TYPE>",FR:"les valeurs %COL_ERRORS sont du type <%COL_TYPE>",NL:"%COL_ERRORS waarden niet <%COL_TYPE>"},key_emptyvalue_singolar:{EN:"the column <%COL_NAME> has an empty value",IT:"la colonna <%COL_NAME> ha un valore vuoto",FR:"la colonne <%COL_NAME> a une valeur vide",NL:"de kolom <%COL_NAME> heeft een lege waarde"},key_emptyvalue_plural:{EN:"the column <%COL_NAME> has <%COL_NULLVALUES> empty values",IT:"la colonna <%COL_NAME> ha <%COL_NULLVALUES> valori vuoti",FR:"la colonne <%COL_NAME> a <%COL_NULLVALUES> valeurs vide",NL:"de kolom <%COL_NAME> heeft <%COL_NULLVALUES> lege waarde"},key_type:{EN:"type",IT:"tipo",FR:"type",NL:"type"},key_subtype:{EN:"subtype",IT:"sottotipo",FR:"sous-type",NL:"subtype"},key_typetext:{EN:"text",IT:"testo",FR:"texte",NL:"tekst"},key_typenumber:{EN:"number",IT:"numero",FR:"nombre",NL:"aantal"},key_typeobject:{EN:"object",IT:"oggetto",FR:"objet",NL:"voorwerp"},key_typedatetime:{EN:"date or time",IT:"data o orario",FR:"date ou l'heure",NL:"datum of tijd"},key_typeempty:{EN:"empty",IT:"vuoto",FR:"vide",NL:"leeg"},key_typelatitude:{EN:"latitude",IT:"latitudine",FR:"latitude",NL:"breedtegraad"},key_typelongitude:{EN:"longitude",IT:"longitudine",FR:"longitude",NL:"lengtegraad"}}; | |
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={EMPTY:{value:0,name:"NULL"},TEXT:{value:1,name:"TEXT"},NUMBER:{value:2,name:"NUMBER"},OBJECT:{value:3,name:"OBJECT"},DATETIME:{value:4,name:"DATETIME"}},DataTypeConverter.SUBTYPES={GEOCOORDINATE:{value:1e3,name:"GEOCOORDINATE"},GEOJSON:{value:1001,name:"GEOJSON"},BOOL:{value:1002,name:"BOOL"},CONST:{value:1003,name:"CONST"},CATEGORY:{value:1004,name:"CATEGORY"},PERCENTAGE:{value:1100,name:"PERCENTAGE"},LATITUDE:{value:1101,name:"LATITUDE"},LONGITUDE:{value:1102,name:"LONGITUDE"}},DataTypeConverter.LANGS={EN:{value:1e3,name:"EN"},IT:{value:1001,name:"IT"},FR:{value:1100,name:"FR"},NL:{value:1101,name:"NL"}},DataTypeConverter.GEOJSONTYPES=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon","GeometryCollection","Feature","FeatureCollection"],DataTypeConverter.prototype=function(){var _analyseDataTypes=function(fields){ArrayUtils.IteratorOverKeys(fields,function(field){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;var isnumber=DataTypesUtils.FilterNumber(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;if(Array.isArray(value)&&2==value.length&&NaN!=DataTypesUtils.FilterNumber(value[0])&&NaN!=DataTypesUtils.FilterNumber(value[1])&&DataTypesUtils.DecimalPlaces(value[0])>4&&DataTypesUtils.DecimalPlaces(value[1])>4)return DataTypeConverter.SUBTYPES.GEOCOORDINATE;if("string"==typeof value){var split=value.split(",");if(DataTypesUtils.IsLatLng(split[0])&&DataTypesUtils.IsLatLng(split[1]))return DataTypeConverter.SUBTYPES.GEOCOORDINATE}var isnumber=DataTypesUtils.FilterNumber(value);if(isNaN(isnumber)!==!0)return isnumber>=-90&&90>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:isnumber>=-180&&180>=isnumber&&DataTypesUtils.DecimalPlaces(isnumber)>=5?DataTypeConverter.SUBTYPES.GEOCOORDINATE:null;if("object"==typeof value&&value.hasOwnProperty("type")){var geotype=value.type,isincluded=DataTypeConverter.GEOJSONTYPES.includes(geotype);if(isincluded)return DataTypeConverter.SUBTYPES.GEOJSON}return null},_filterBasedOnThreshold=function(metadata,threshold){return ArrayUtils.IteratorOverKeys(metadata.types,function(fieldType,key){if(!(fieldType.typeConfidence>=threshold)){var arrHierarchyTypes=DataTypeHierarchy.HIERARCHY[fieldType.type];if(null==arrHierarchyTypes)return metadata;var 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},_capitalizeFirstLetter=function(string){return string.charAt(0).toUpperCase()+string.slice(1)},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,makeChangesToDataset:!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,makeChangesToDataset:!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){0==isNaN(DataTypesUtils.FilterNumber(value))&&"string"==typeof value&&(value=value.replace(",","."));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={}),0==options.hasOwnProperty("thresholdConfidence")&&(options.thresholdConfidence=1),0==options.hasOwnProperty("language")?options.language=DataTypeConverter.LANGS.EN.name:options.language=options.language.toUpperCase();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++}}var _numOfRows=0;ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){fieldType.numOfItems>_numOfRows&&(_numOfRows=fieldType.numOfItems)}),ArrayUtils.IteratorOverKeys(fieldsType,function(fieldType){fieldType._inferredTypes.hasOwnProperty(DataTypeConverter.TYPES.EMPTY.name)||(fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name]=0),fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name]=fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name]+(_numOfRows-fieldType.numOfItems)}),_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){var _descr1=_capitalizeFirstLetter(JDC_LNG.key_declaretype[options.language])+".",_descr2=_capitalizeFirstLetter(JDC_LNG.key_notoftype_singular[options.language])+".";incorrect>1&&(_descr2=_capitalizeFirstLetter(JDC_LNG.key_notoftype_plural[options.language])+".");var descr=_descr1+" "+_descr2;descr=descr.replace(/%COL_NAME/g,fieldType.name),descr=descr.replace(/%COL_TYPE/g,fieldType.type),descr=descr.replace(/%COL_ERRORS/g,incorrect),description+=descr}}var descr="";1==fieldType.totalNullValues?descr=_capitalizeFirstLetter(JDC_LNG.key_emptyvalue_singolar[options.language])+".":fieldType.totalNullValues>1&&(descr=_capitalizeFirstLetter(JDC_LNG.key_emptyvalue_plural[options.language])+"."),descr=descr.replace(/%COL_NAME/g,fieldType.name),descr=descr.replace(/%COL_TYPE/g,fieldType.type),descr=descr.replace(/%COL_NULLVALUES/g,fieldType.totalNullValues),description=description+" "+descr,fieldType.errorsDescription=description.trim(),warningsTextual+=description.trim()});var metadata={dataset:json,fieldKeys:fieldKeys,types:fieldsType,qualityIndex:quality,warningsTextual:warningsTextual};return _filterBasedOnThreshold(metadata,options.thresholdConfidence),metadata},inferDataTypeOfValue:function(value){return _processInferType(value)},inferDataSubTypeOfValue:function(value){return _processInferSubType(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.FilterNumber=function(value){var valnum=DataTypesUtils.FilterFloat(value);if(0==isNaN(valnum))return valnum;if("string"!=typeof value)return NaN;var idxDot=(value.split(/(,|\.)/g),{idx:value.indexOf("."),sym:"."}),idxComma={idx:value.lastIndexOf(","),sym:","},idxFirst={};idxFirst=-1==idxDot.idx?idxComma:-1==idxComma.idx?idxDot:idxDot.idx<idxComma.idx?idxDot:idxComma;var idxLastDot={idx:value.lastIndexOf("."),sym:"."},idxLastComma={idx:value.lastIndexOf(","),sym:","},idxLast={};idxLast=-1==idxLastDot.idx?idxLastComma:-1==idxLastComma.idx?idxLastDot:idxLastDot.idx>idxLastComma.idx?idxLastDot:idxLastComma;var splitted=value.split(/(\.|,|\-|\+)/g);if(0==splitted.length)return NaN;var numOfDots=0,numOfComma=0,i=0;"-"!=splitted[0]&&"+"!=splitted[0]||(i=1);for(var str;i<splitted.length,str=splitted[i];i++)if("."==str)numOfDots++;else if(","==str)numOfComma++;else if(0==/^(0|([1-9][0-9]*))$/g.test(str))return NaN;var lastValue=splitted[splitted.length-1];if("."==lastValue||","==lastValue||0==lastValue.length)return NaN;if(-1==idxFirst.idx&&-1==idxLast.idx)return DataTypesUtils.FilterFloat(value);if(idxFirst.idx==idxLast.idx&&"."==idxFirst.sym)return Number(value);if(idxFirst.idx==idxLast.idx&&","==idxFirst.sym){var nval=value.replace(",",".");return Number(nval)}return 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},DataTypesUtils.IsLatLng=function(num){return NaN==DataTypesUtils.FilterFloat(num)?!1:DataTypesUtils.DecimalPlaces(num)>4},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};var JDC_LNG={key_declaretype:{EN:"the column <%COL_NAME> is of type <%COL_TYPE>",IT:"la colonna <%COL_NAME> è di tipo <%COL_TYPE>",FR:"le colum <%COL_NAME> est de type <%COL_TYPE>",NL:"de kolom <%COL_NAME> is van het type <%COL_TYPE>"},key_notoftype_singular:{EN:"a value is not <%COL_TYPE>",IT:"un valore non è un <%COL_TYPE>",FR:"une valeur est pas <%COL_TYPE> se trouvant",NL:"een waarde is niet <%COL_TYPE>"},key_notoftype_plural:{EN:"%COL_ERRORS values are not <%COL_TYPE>",IT:"%COL_ERRORS valori non sono di tipo <%COL_TYPE>",FR:"les valeurs %COL_ERRORS sont du type <%COL_TYPE>",NL:"%COL_ERRORS waarden niet <%COL_TYPE>"},key_emptyvalue_singolar:{EN:"the column <%COL_NAME> has an empty value",IT:"la colonna <%COL_NAME> ha un valore vuoto",FR:"la colonne <%COL_NAME> a une valeur vide",NL:"de kolom <%COL_NAME> heeft een lege waarde"},key_emptyvalue_plural:{EN:"the column <%COL_NAME> has <%COL_NULLVALUES> empty values",IT:"la colonna <%COL_NAME> ha <%COL_NULLVALUES> valori vuoti",FR:"la colonne <%COL_NAME> a <%COL_NULLVALUES> valeurs vide",NL:"de kolom <%COL_NAME> heeft <%COL_NULLVALUES> lege waarde"},key_type:{EN:"type",IT:"tipo",FR:"type",NL:"type"},key_subtype:{EN:"subtype",IT:"sottotipo",FR:"sous-type",NL:"subtype"},key_typetext:{EN:"text",IT:"testo",FR:"texte",NL:"tekst"},key_typenumber:{EN:"number",IT:"numero",FR:"nombre",NL:"aantal"},key_typeobject:{EN:"object",IT:"oggetto",FR:"objet",NL:"voorwerp"},key_typedatetime:{EN:"date or time",IT:"data o orario",FR:"date ou l'heure",NL:"datum of tijd"},key_typeempty:{EN:"empty",IT:"vuoto",FR:"vide",NL:"leeg"},key_typelatitude:{EN:"latitude",IT:"latitudine",FR:"latitude",NL:"breedtegraad"},key_typelongitude:{EN:"longitude",IT:"longitudine",FR:"longitude",NL:"lengtegraad"}}; | |
3 | 3 | \ No newline at end of file | ... | ... |
bower_components/jsdatachecker/src/DataTypeConverter.js
... | ... | @@ -205,7 +205,8 @@ DataTypeConverter.prototype = (function () { |
205 | 205 | return DataTypeConverter.TYPES.OBJECT; |
206 | 206 | |
207 | 207 | //Try to parse the float. |
208 | - var isnumber = DataTypesUtils.FilterFloat(value); | |
208 | + //var isnumber = DataTypesUtils.FilterFloat(value); | |
209 | + var isnumber = DataTypesUtils.FilterNumber(value); | |
209 | 210 | if (isNaN(isnumber) !== true) {//It is a number. |
210 | 211 | //If the number ranges from -90.0 to 90.0, the value is marked as Latitude. |
211 | 212 | //if (-90.0 <= isnumber && isnumber <= 90.0 && _dataTypesUtils.decimalPlaces(isnumber) >= 5) |
... | ... | @@ -235,7 +236,8 @@ DataTypeConverter.prototype = (function () { |
235 | 236 | //GEOCOORDINATE |
236 | 237 | if (Array.isArray(value) && value.length == 2) {//It recognises the LAT LNG as array of two values. |
237 | 238 | //Checks if the two array's values are numbers. |
238 | - if ( DataTypesUtils.FilterFloat(value[0]) != NaN && DataTypesUtils.FilterFloat(value[1]) != NaN ) | |
239 | + //if ( DataTypesUtils.FilterFloat(value[0]) != NaN && DataTypesUtils.FilterFloat(value[1]) != NaN ) | |
240 | + if ( DataTypesUtils.FilterNumber(value[0]) != NaN && DataTypesUtils.FilterNumber(value[1]) != NaN ) | |
239 | 241 | if (DataTypesUtils.DecimalPlaces(value[0]) > 4 && DataTypesUtils.DecimalPlaces(value[1]) > 4 ) |
240 | 242 | return DataTypeConverter.SUBTYPES.GEOCOORDINATE; |
241 | 243 | }//EndIf. |
... | ... | @@ -248,7 +250,8 @@ DataTypeConverter.prototype = (function () { |
248 | 250 | } |
249 | 251 | |
250 | 252 | //Try to parse the float. |
251 | - var isnumber = DataTypesUtils.FilterFloat(value); | |
253 | + //var isnumber = DataTypesUtils.FilterFloat(value); | |
254 | + var isnumber = DataTypesUtils.FilterNumber(value); | |
252 | 255 | if (isNaN(isnumber) !== true) {//It is a number. |
253 | 256 | //If the number ranges from -90.0 to 90.0, the value is marked as Latitude. |
254 | 257 | if (-90.0 <= isnumber && isnumber <= 90.0 && DataTypesUtils.DecimalPlaces(isnumber) >= 5) |
... | ... | @@ -369,15 +372,19 @@ DataTypeConverter.prototype = (function () { |
369 | 372 | return { |
370 | 373 | constructor: DataTypeConverter, |
371 | 374 | |
375 | + | |
372 | 376 | /** |
373 | - * It parses the json in input and converts the content | |
374 | - * in according to the inferred data types. | |
375 | - * @param json | |
376 | - * @param path Format: field1->field2->field3 | |
377 | + * | |
378 | + * @param metadata Previous information on the inferred types. | |
379 | + * @param options Some options to cast the data. | |
380 | + * - castThresholdConfidence: for which threshold the library must perform the cast (default 1) | |
381 | + * - makeChangesToDataset: is a boolean value, to indicate whether the library can do improvement on the storage | |
382 | + * values, for instance, numbers with the comma will be replaced with the dot. | |
383 | + * @returns {*} | |
377 | 384 | */ |
378 | 385 | cast: function(metadata, options) { |
379 | 386 | if (typeof options === 'undefined' || options == null) |
380 | - options = { castThresholdConfidence: 1, castIfNull: false }; | |
387 | + options = { castThresholdConfidence: 1, castIfNull: false, makeChangesToDataset: false }; | |
381 | 388 | return this.convert(metadata, options); |
382 | 389 | }, |
383 | 390 | |
... | ... | @@ -400,7 +407,7 @@ DataTypeConverter.prototype = (function () { |
400 | 407 | var datasetMissingValues = 0; |
401 | 408 | |
402 | 409 | if (typeof options === 'undefined' || options == null) |
403 | - options = { castThresholdConfidence: 1, castIfNull: false }; | |
410 | + options = { castThresholdConfidence: 1, castIfNull: false, makeChangesToDataset: false }; | |
404 | 411 | |
405 | 412 | jsonTraverse(metadata.dataset, metadata.fieldKeys, function(value, key, traversedKeys, rowIndex) { |
406 | 413 | var inferredType = metadata.types[traversedKeys]; |
... | ... | @@ -419,6 +426,9 @@ DataTypeConverter.prototype = (function () { |
419 | 426 | //var isCast = !(options.castIfNull == false && inferredType.totalNullValues > 0); |
420 | 427 | var isCast = inferredType.typeConfidence >= options.castThresholdConfidence; |
421 | 428 | if (inferredType.type == DataTypeConverter.TYPES.NUMBER.name && isCast) { |
429 | + if (isNaN(DataTypesUtils.FilterNumber(value)) == false && typeof value === "string") | |
430 | + value = value.replace(',', '.'); | |
431 | + | |
422 | 432 | var number = parseFloat(value); |
423 | 433 | |
424 | 434 | if (isNaN(number)) { |
... | ... | @@ -529,6 +539,25 @@ DataTypeConverter.prototype = (function () { |
529 | 539 | } |
530 | 540 | }//EndWhile. |
531 | 541 | |
542 | + | |
543 | + //Calculates the number of rows in the dataset. | |
544 | + var _numOfRows = 0; | |
545 | + ArrayUtils.IteratorOverKeys(fieldsType, function(fieldType) { | |
546 | + if (fieldType.numOfItems > _numOfRows) | |
547 | + _numOfRows = fieldType.numOfItems; | |
548 | + }); | |
549 | + | |
550 | + //Computes the number of null values. | |
551 | + ArrayUtils.IteratorOverKeys(fieldsType, function(fieldType) { | |
552 | + if (!fieldType._inferredTypes.hasOwnProperty(DataTypeConverter.TYPES.EMPTY.name)) { | |
553 | + //Initialises the field. | |
554 | + fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name] = 0; | |
555 | + } | |
556 | + | |
557 | + fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name] = fieldType._inferredTypes[DataTypeConverter.TYPES.EMPTY.name] + (_numOfRows - fieldType.numOfItems); | |
558 | + }); | |
559 | + | |
560 | + //Infers the data type. | |
532 | 561 | _analyseDataTypes(fieldsType); |
533 | 562 | |
534 | 563 | //Data quality. |
... | ... | @@ -594,6 +623,7 @@ DataTypeConverter.prototype = (function () { |
594 | 623 | descr = descr.replace(/%COL_NAME/g, fieldType.name); |
595 | 624 | descr = descr.replace(/%COL_TYPE/g, fieldType.type); |
596 | 625 | descr = descr.replace(/%COL_NULLVALUES/g, fieldType.totalNullValues); |
626 | + description = description + " " + descr; | |
597 | 627 | |
598 | 628 | /*if (fieldType.totalNullValues > 0) { |
599 | 629 | var descr = _capitalizeFirstLetter(JDC_LNG['key_declaretype'][options.language]) + "."; |
... | ... | @@ -605,8 +635,8 @@ DataTypeConverter.prototype = (function () { |
605 | 635 | if (description.length > 0) |
606 | 636 | description += ".";*/ |
607 | 637 | |
608 | - fieldType.errorsDescription = description; | |
609 | - warningsTextual += description; | |
638 | + fieldType.errorsDescription = description.trim(); | |
639 | + warningsTextual += description.trim(); | |
610 | 640 | }); |
611 | 641 | |
612 | 642 | var metadata = { dataset: json, fieldKeys: fieldKeys, types: fieldsType, qualityIndex: quality, warningsTextual: warningsTextual }; | ... | ... |
bower_components/jsdatachecker/src/DataTypesUtils.js
... | ... | @@ -107,6 +107,71 @@ DataTypesUtils.FilterFloat = function (value) { |
107 | 107 | return NaN; |
108 | 108 | };//EndFunction. |
109 | 109 | |
110 | +DataTypesUtils.FilterNumber = function (value) { | |
111 | + //Check immediatly if it is a classical number. | |
112 | + var valnum = DataTypesUtils.FilterFloat(value); | |
113 | + if (isNaN(valnum) == false) return valnum; | |
114 | + | |
115 | + //Checks if the value is a string. | |
116 | + if (typeof value !== "string") | |
117 | + return NaN; | |
118 | + | |
119 | + var parts = value.split(/(,|\.)/g); | |
120 | + | |
121 | + //Find the smallest symbol. | |
122 | + var idxDot = { idx: value.indexOf('.'), sym: '.' }; | |
123 | + var idxComma = { idx: value.lastIndexOf(','), sym: ',' }; | |
124 | + var idxFirst = {}; | |
125 | + if (idxDot.idx == -1) idxFirst = idxComma; | |
126 | + else if (idxComma.idx == -1) idxFirst = idxDot; | |
127 | + else if (idxDot.idx < idxComma.idx) idxFirst = idxDot; | |
128 | + else idxFirst = idxComma; | |
129 | + | |
130 | + //Find the greatest symbol. | |
131 | + var idxLastDot = { idx: value.lastIndexOf('.'), sym: '.' }; | |
132 | + var idxLastComma = { idx: value.lastIndexOf(','), sym: ',' }; | |
133 | + var idxLast = {}; | |
134 | + if (idxLastDot.idx == -1) idxLast = idxLastComma; | |
135 | + else if (idxLastComma.idx == -1) idxLast = idxLastDot; | |
136 | + else if (idxLastDot.idx > idxLastComma.idx) idxLast = idxLastDot; | |
137 | + else idxLast = idxLastComma; | |
138 | + | |
139 | + //Splits over the dot and comma and check that are all numbers. | |
140 | + var splitted = value.split(/(\.|,|\-|\+)/g); | |
141 | + if (splitted.length == 0) return NaN; | |
142 | + | |
143 | + var numOfDots = 0; | |
144 | + var numOfComma = 0; | |
145 | + var i=0; | |
146 | + if (splitted[0] == '-' || splitted[0] == '+') i=1; | |
147 | + | |
148 | + for (var str; i<splitted.length, str=splitted[i]; i++) { | |
149 | + if (str == '.') numOfDots++; | |
150 | + else if (str == ',') numOfComma++; | |
151 | + else if (/^(0|([1-9][0-9]*))$/g.test(str) == false) | |
152 | + return NaN; | |
153 | + }//EndFor. | |
154 | + | |
155 | + var lastValue = splitted[splitted.length-1]; | |
156 | + if (lastValue == '.' || lastValue == ',' || lastValue.length == 0) return NaN; | |
157 | + | |
158 | + //No dot/comma char found | |
159 | + if (idxFirst.idx == -1 && idxLast.idx == -1) | |
160 | + return DataTypesUtils.FilterFloat(value); | |
161 | + | |
162 | + //Only one dot symbol found | |
163 | + if (idxFirst.idx == idxLast.idx && idxFirst.sym == '.') | |
164 | + return Number(value); | |
165 | + | |
166 | + //Only one comma symbol found | |
167 | + if (idxFirst.idx == idxLast.idx && idxFirst.sym == ',') { | |
168 | + var nval = value.replace(',', '.'); | |
169 | + return Number(nval); | |
170 | + } | |
171 | + | |
172 | + return NaN; | |
173 | +};//EndFunction. | |
174 | + | |
110 | 175 | /** |
111 | 176 | * Solution from here: |
112 | 177 | * http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number | ... | ... |
controllets/cocreation-paper-card-controllet/cocreation-paper-card-controllet.html
... | ... | @@ -37,8 +37,8 @@ |
37 | 37 | .card-actions { |
38 | 38 | padding: 12px; |
39 | 39 | height: 48px; |
40 | - /*overflow: hidden;*/ | |
41 | - border-color: #2196F3; | |
40 | + /*border-color: #2196F3;*/ | |
41 | + /*border-color: #4CAF50;*/ | |
42 | 42 | } |
43 | 43 | |
44 | 44 | paper-button { |
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | |
51 | 51 | background: #FFFFFF; |
52 | 52 | color: #000000; |
53 | - --paper-button-ink-color: #2196F3; | |
53 | + --paper-button-ink-color: #00BCD4; | |
54 | 54 | } |
55 | 55 | |
56 | 56 | paper-button.info { |
... | ... | @@ -63,7 +63,7 @@ |
63 | 63 | } |
64 | 64 | |
65 | 65 | paper-button:hover { |
66 | - color: #2196F3; | |
66 | + color: #00BCD4; | |
67 | 67 | } |
68 | 68 | |
69 | 69 | paper-icon-button[icon="info-outline"] { |
... | ... | @@ -84,7 +84,6 @@ |
84 | 84 | paper-fab { |
85 | 85 | position: absolute; |
86 | 86 | z-index: 10; |
87 | - --paper-fab-background:#2196F3; | |
88 | 87 | } |
89 | 88 | |
90 | 89 | paper-fab.delete { |
... | ... | @@ -110,7 +109,8 @@ |
110 | 109 | |
111 | 110 | #card_container p .title{ |
112 | 111 | font-weight: 700; |
113 | - color: #2196F3; | |
112 | + /*color: #2196F3;*/ | |
113 | + /*color: #4CAF50;*/ | |
114 | 114 | white-space: nowrap; |
115 | 115 | } |
116 | 116 | |
... | ... | @@ -120,7 +120,8 @@ |
120 | 120 | #card_container .name{ |
121 | 121 | font-size: 18px; |
122 | 122 | font-weight: 700; |
123 | - color: #2196F3; | |
123 | + /*color: #2196F3;*/ | |
124 | + /*color: #4CAF50;*/ | |
124 | 125 | height: 32px; |
125 | 126 | |
126 | 127 | overflow: hidden; |
... | ... | @@ -153,12 +154,21 @@ |
153 | 154 | font-size: 12px; |
154 | 155 | } |
155 | 156 | |
156 | - paper-fab.type { | |
157 | + paper-fab.assessment, | |
158 | + paper-fab.description { | |
157 | 159 | bottom: -20px; |
158 | 160 | right: 12px; |
159 | 161 | cursor: auto; |
160 | 162 | } |
161 | 163 | |
164 | + paper-fab.description { | |
165 | + background: #2196F3; | |
166 | + } | |
167 | + | |
168 | + paper-fab.assessment { | |
169 | + background: #4CAF50; | |
170 | + } | |
171 | + | |
162 | 172 | </style> |
163 | 173 | |
164 | 174 | <paper-card id="card_container"> |
... | ... | @@ -166,7 +176,7 @@ |
166 | 176 | <template is="dom-if" if="{{isOwner}}"> |
167 | 177 | <paper-fab id="card_delete" class="delete" mini icon="delete" on-click="_handleDeleteClick"></paper-fab> |
168 | 178 | </template> |
169 | - <div class="name">{{name}}</div> | |
179 | + <div class="name" style$="color: {{color}};">{{name}}</div> | |
170 | 180 | <div class="owner">{{owner}}</div> |
171 | 181 | <div class="time"> |
172 | 182 | <div class="from"> |
... | ... | @@ -177,20 +187,20 @@ |
177 | 187 | </div> |
178 | 188 | </div> |
179 | 189 | <template is="dom-if" if="{{!checkRoomType(roomType)}}"> |
180 | - <paper-fab mini icon="assessment" class="type" noink></paper-fab> | |
190 | + <paper-fab mini icon="assessment" class="assessment" noink></paper-fab> | |
181 | 191 | </template> |
182 | 192 | <template is="dom-if" if="{{checkRoomType(roomType)}}"> |
183 | - <paper-fab mini icon="description" class="type" noink></paper-fab> | |
193 | + <paper-fab mini icon="description" class="description" noink></paper-fab> | |
184 | 194 | </template> |
185 | 195 | </div> |
186 | - <div class="card-actions"> | |
196 | + <div class="card-actions" style$="border-color: {{color}};"> | |
187 | 197 | <paper-button on-click="_onExplore"><span id="explore"></span></paper-button> |
188 | - <paper-button id="goal_button" class="info"><span id="goal"></span></paper-button> | |
198 | + <paper-button id="goal_button" class="info" noink><span id="goal"></span></paper-button> | |
189 | 199 | <!--<paper-icon-button id="goal_button" icon="info-outline" noink></paper-icon-button>--> |
190 | 200 | |
191 | 201 | <paper-tooltip for="goal_button" position="bottom" offset="-8"> |
192 | 202 | <p> |
193 | - <span class="title" id="tooltip_goal"></span> | |
203 | + <span class="title" style$="color: {{color}};" id="tooltip_goal"></span> | |
194 | 204 | <br> |
195 | 205 | <span class="description">{{goal}}</span> |
196 | 206 | </p> |
... | ... | @@ -242,9 +252,20 @@ |
242 | 252 | roomId:{ |
243 | 253 | type: Number, |
244 | 254 | value: undefined |
255 | + }, | |
256 | + color:{ | |
257 | + type: String, | |
258 | + value: "" | |
245 | 259 | } |
246 | 260 | }, |
247 | 261 | |
262 | + ready: function() { | |
263 | + var color = "#4CAF50"; | |
264 | + if(this.roomType == "knowledge") | |
265 | + color = "#2196F3"; | |
266 | + this.color = color; | |
267 | + }, | |
268 | + | |
248 | 269 | attached: function(){ |
249 | 270 | cocreation_room_ln["ln"] = ODE.user_language; |
250 | 271 | ... | ... |
locales/controllet_ln.js
... | ... | @@ -269,7 +269,7 @@ ln["standardDescription_it"] = "La ricerca funziona solo sui nommi dei dataset." |
269 | 269 | ln["extended_it"] = "Extended [NOT AVAILABLE]"; |
270 | 270 | ln["extendedDescription_it"] = "La ricerca funziona sull'intero contenuto dei dataset;."; |
271 | 271 | |
272 | -ln["version_it"] = "Versionw"; | |
272 | +ln["version_it"] = "Version"; | |
273 | 273 | ln["showLast_it"] = "Mostra l'ultima"; |
274 | 274 | ln["showLastDescription_it"] = "Mostra solo l'ultima versione dei dataset."; |
275 | 275 | ln["showAll_it"] = "Mostra tutti"; |
... | ... | @@ -469,7 +469,7 @@ ln["slide2Title_fr"] = "SÉLECTIONNER DONNÉES"; |
469 | 469 | ln["slide2Subtitle_fr"] = "Sélectionner les champs sur la gauche. Le tableau présentera les valeurs liées aux champs sélectionnés."; |
470 | 470 | ln["slide3Title_fr"] = "SÉLECTIONNER UN MODE DE VISUALISATION"; |
471 | 471 | ln["slide3Subtitle_fr"] = "Sélectionner une visualisation, compléter les données et les options."; |
472 | -ln["back_fr"] = "RETOUR"; | |
472 | +ln["back_fr"] = "RETOUR VERS LE FUTUR"; | |
473 | 473 | ln["forward_fr"] = "AVANT"; |
474 | 474 | |
475 | 475 | //SELECT DATASET |
... | ... | @@ -694,7 +694,7 @@ ln["slide2Title_nl"] = "SELECT DATA"; |
694 | 694 | ln["slide2Subtitle_nl"] = "Select the fields on the left. The table will show the values related to the selected fields."; |
695 | 695 | ln["slide3Title_nl"] = "SELECT VISUALIZATION"; |
696 | 696 | ln["slide3Subtitle_nl"] = "Select a visualization, fill out inputs and options."; |
697 | -ln["back_nl"] = "BACK TO THE FUTURE"; | |
697 | +ln["back_nl"] = "TERUG NAAR DE TOEKOMST"; | |
698 | 698 | ln["forward_nl"] = "FORWARD"; |
699 | 699 | |
700 | 700 | //SELECT DATASET | ... | ... |