diff --git a/bower_components/JSDataChecker/jsdatachecker.min.js b/bower_components/JSDataChecker/jsdatachecker.min.js deleted file mode 100644 index 2618cbe..0000000 --- a/bower_components/JSDataChecker/jsdatachecker.min.js +++ /dev/null @@ -1 +0,0 @@ -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}; \ No newline at end of file diff --git a/bower_components/JSDataChecker/.bower.json b/bower_components/jsdatachecker/.bower.json index 535202d..7001714 100644 --- a/bower_components/JSDataChecker/.bower.json +++ b/bower_components/jsdatachecker/.bower.json @@ -1,7 +1,7 @@ { - "name": "JSDataChecker", - "version": "0.0.8", - "homepage": "https://github.com/donpir/JSDataChecker", + "name": "jsdatachecker", + "version": "0.1.1", + "homepage": "https://github.com/donpir/jsdatachecker", "authors": [ "'Donato Pirozzi <'donatopirozzi@gmail.com'>" ], @@ -22,13 +22,14 @@ "polywc": "https://github.com/donpir/polywc.git#master" }, "private": false, - "_release": "0.0.8", + "_release": "0.1.1", "_resolution": { "type": "version", - "tag": "v0.0.8", - "commit": "862e4d5fe56d629ae7ef8aadb728b1add3af01d9" + "tag": "v0.1.1", + "commit": "60887fda0d7e7388c5d682228ee1288dd7bcdd09" }, "_source": "https://github.com/donpir/JSDataChecker.git", - "_target": "~0.0.6", - "_originalSource": "jsdatachecker" + "_target": "~0.1.1", + "_originalSource": "jsdatachecker", + "_direct": true } \ No newline at end of file diff --git a/bower_components/JSDataChecker/LICENSE b/bower_components/jsdatachecker/LICENSE index 9cecc1d..9cecc1d 100644 --- a/bower_components/JSDataChecker/LICENSE +++ b/bower_components/jsdatachecker/LICENSE diff --git a/bower_components/JSDataChecker/README.md b/bower_components/jsdatachecker/README.md index 595eb6e..b01f539 100644 --- a/bower_components/JSDataChecker/README.md +++ b/bower_components/jsdatachecker/README.md @@ -3,6 +3,18 @@ JavaScript Library to read dataset content (e.g., Open Data), infer data types, In details, it analysis the json (specified paths) to infer the data type. In addition, when request (via code) the library converts the json data based on the inferred type. +Recognised basic types: + - Text; + - Number; + - Date; + - Object; + - Null. + +Recognised types: + - Geographic coordinates; + - JSON; + - GEOJSON. + ## Documentation See wiki pages [here](https://github.com/donpir/JSDataChecker/wiki). @@ -13,8 +25,8 @@ The library has released with the LGPL license [link here](http://www.gnu.org/li Briefly with this license: - - Freedom to modify and distribute modified copies of POLYWC-DATA-TABLE, distributing the source code and releasing it with the same LGPL license; - - You can dynamically (not statically) link POLYWC-DATA-TABLE library in a proprietary software, keeping the JS files as they are. + - Freedom to modify and distribute modified copies of DataChecker, distributing the source code and releasing it with the same LGPL license; + - You can dynamically (not statically) link DataChecker library in a proprietary software, keeping the JS files as they are. diff --git a/bower_components/JSDataChecker/bower.json b/bower_components/jsdatachecker/bower.json index ccc6ddd..0378f9d 100644 --- a/bower_components/JSDataChecker/bower.json +++ b/bower_components/jsdatachecker/bower.json @@ -1,7 +1,7 @@ { - "name": "JSDataChecker", - "version": "v0.0.8", - "homepage": "https://github.com/donpir/JSDataChecker", + "name": "jsdatachecker", + "version": "v0.1.1", + "homepage": "https://github.com/donpir/jsdatachecker", "authors": [ "'Donato Pirozzi <'donatopirozzi@gmail.com'>" ], diff --git a/bower_components/JSDataChecker/build.cmd b/bower_components/jsdatachecker/build.cmd index 96692db..96692db 100644 --- a/bower_components/JSDataChecker/build.cmd +++ b/bower_components/jsdatachecker/build.cmd diff --git a/bower_components/jsdatachecker/jsdatachecker.min.js b/bower_components/jsdatachecker/jsdatachecker.min.js new file mode 100644 index 0000000..325f3e3 --- /dev/null +++ b/bower_components/jsdatachecker/jsdatachecker.min.js @@ -0,0 +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={GEOCOORDINATE:{value:1e3,name:"GEOCOORDINATE"},GEOJSON:{value:1001,name:"GEOJSON"},PERCENTAGE:{value:1100,name:"PERCENTAGE"},LATITUDE:{value:1101,name:"LATITUDE"},LONGITUDE:{value:1102,name:"LONGITUDE"}},DataTypeConverter.GEOJSONTYPES=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon","GeometryCollection"],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;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},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)},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}; \ No newline at end of file diff --git a/bower_components/JSDataChecker/src/ArrayUtils.js b/bower_components/jsdatachecker/src/ArrayUtils.js index 7d272b7..7d272b7 100644 --- a/bower_components/JSDataChecker/src/ArrayUtils.js +++ b/bower_components/jsdatachecker/src/ArrayUtils.js diff --git a/bower_components/JSDataChecker/src/DataTypeConverter.js b/bower_components/jsdatachecker/src/DataTypeConverter.js index cc424bc..201c21a 100644 --- a/bower_components/JSDataChecker/src/DataTypeConverter.js +++ b/bower_components/jsdatachecker/src/DataTypeConverter.js @@ -42,11 +42,17 @@ DataTypeConverter.TYPES = { }; DataTypeConverter.SUBTYPES = { - PERCENTAGE : { value: 1000, name: "PERCENTAGE" }, - LATITUDE : { value: 1001, name: "LATITUDE" }, - LONGITUDE : { value: 1002, name: "LONGITUDE" } + GEOCOORDINATE : { value: 1000, name: "GEOCOORDINATE" }, + GEOJSON : { value: 1001, name: "GEOJSON" }, + + PERCENTAGE : { value: 1100, name: "PERCENTAGE" }, + LATITUDE : { value: 1101, name: "LATITUDE" }, + LONGITUDE : { value: 1102, name: "LONGITUDE" } }; +DataTypeConverter.GEOJSONTYPES = [ "Point", "MultiPoint", "LineString", + "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection" ]; + DataTypeConverter.prototype = (function () { /*** @@ -120,7 +126,6 @@ DataTypeConverter.prototype = (function () { return; } - //Infers the field TYPE. var max = ArrayUtils.FindMinMax(field._inferredTypes, function (curval, lastval) { return curval > lastval; @@ -136,15 +141,31 @@ DataTypeConverter.prototype = (function () { field.typeConfidence = field._inferredTypes[max.first.key] / field.numOfItems; - //TODO: improve this piece of code. - //LAT/LNG. - /*var fieldName = field.name.toLowerCase(); - var isLatType = (field.type === DataTypeConverter.TYPES.LATITUDE.name); - var fieldNameContainsLat = fieldName.indexOf('lat') >= 0; - var fieldNameContainsLon = fieldName.indexOf('ng') >= 0; //It could be 'lng'. - if (isLatType == true && fieldNameContainsLat == false && fieldNameContainsLon == true) { - field.type = DataTypeConverter.TYPES.LONGITUDE.name; - }*/ + //########## + //Infers the field SUBTYPE. + + var max = ArrayUtils.FindMinMax(field._inferredSubTypes, function (curval, lastval) { + return curval > lastval; + }); + field.subtype = null; + if (max != null && max.first != null) { + field.subtype = max.first.key; + field.subtypeConfidence = field._inferredSubTypes[field.subtype] / field.numOfItems; + + //TODO: improve this piece of code. + //LAT/LNG. + var fieldName = field.name.toLowerCase(); + var isLatType = (field.subtype === DataTypeConverter.SUBTYPES.LATITUDE.name); + var fieldNameContainsLat = fieldName.indexOf('lat') >= 0; + var fieldNameContainsLon = fieldName.indexOf('ng') >= 0; //It could be 'lng'. + if (isLatType == true && fieldNameContainsLat == false && fieldNameContainsLon == true) { + field.subtype = DataTypeConverter.SUBTYPES.LONGITUDE.name; + } + } + + /// + /// SUBTYPES. + //BOOLEAN. /*var numOfValues = Object.keys(field._inferredValues).length; @@ -200,13 +221,83 @@ DataTypeConverter.prototype = (function () { if (isNaN(_date) == false && _date != null) return DataTypeConverter.TYPES.DATETIME; - return DataTypeConverter.TYPES.TEXT; };//EndFunction. - var _processInferSubType = function(value) { - //Try to parse lat/lng. + var _processInferSubType = function (value) { + if (value === null || typeof value === 'undefined') return null; + + //GEOCOORDINATE + if (Array.isArray(value) && value.length == 2) {//It recognises the LAT LNG as array of two values. + //Checks if the two array's values are numbers. + if ( DataTypesUtils.FilterFloat(value[0]) != NaN && DataTypesUtils.FilterFloat(value[1]) != NaN ) + if (DataTypesUtils.DecimalPlaces(value[0]) > 4 && DataTypesUtils.DecimalPlaces(value[1]) > 4 ) + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; + }//EndIf. + + if (typeof value === 'string') { + var split = value.split(","); + if (DataTypesUtils.IsLatLng(split[0]) && DataTypesUtils.IsLatLng(split[1])) + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; + } + //Try to parse the float. + var isnumber = DataTypesUtils.FilterFloat(value); + if (isNaN(isnumber) !== true) {//It is a number. + //If the number ranges from -90.0 to 90.0, the value is marked as Latitude. + if (-90.0 <= isnumber && isnumber <= 90.0 && DataTypesUtils.DecimalPlaces(isnumber) >= 5) + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; + + //It the number ranges from -180.0 to 180.0, the value is marked as Longitude. + if (-180.0 <= isnumber && isnumber <= 180.0 && DataTypesUtils.DecimalPlaces(isnumber) >= 5) + return DataTypeConverter.SUBTYPES.GEOCOORDINATE; + + /*if (0.0 <= isnumber && isnumber <= 100.0) + if(/^(\+)?((0|([1-9][0-9]*))\.([0-9]+))$/ .test(value)) + return DataTypeConverter.SUBTYPES.PERCENTAGE;*/ + + return null; + } + + //Try to parse GEOJSON. + if (typeof value === 'object' && value.hasOwnProperty('type')) { + //Check the type variable. + var geotype = value.type; + var isincluded = DataTypeConverter.GEOJSONTYPES.includes(geotype); + if (isincluded) return DataTypeConverter.SUBTYPES.GEOJSON; + } + + return null; + };//EndFunction. + + var _filterBasedOnThreshold = function(metadata, threshold) { + ArrayUtils.IteratorOverKeys(metadata.types, function (fieldType, key) { + if (fieldType.typeConfidence >= threshold) return; + + var arrHierarchyTypes = DataTypeHierarchy.HIERARCHY[fieldType.type]; + if (arrHierarchyTypes == null) + return metadata; + + var lastFieldType = { lastType: arrHierarchyTypes[0], + lastTypeCounter: fieldType._inferredTypes[arrHierarchyTypes[0]], + typeConfidence: 0 }; + lastFieldType.typeConfidence = lastFieldType.lastTypeCounter / fieldType.numOfItems; + + for (var i= 1, curType; i<arrHierarchyTypes.length, curType = arrHierarchyTypes[i]; i++) { + var numItemsOfCurType = fieldType._inferredTypes.hasOwnProperty(curType) ? fieldType._inferredTypes[curType] : 0 ; + lastFieldType.lastType = curType; + lastFieldType.lastTypeCounter += numItemsOfCurType; + lastFieldType.typeConfidence = lastFieldType.lastTypeCounter / fieldType.numOfItems; + + if (lastFieldType.typeConfidence >= threshold) { + fieldType.type = lastFieldType.lastType; + fieldType.typeConfidence = lastFieldType.typeConfidence; + break; + } + } + }); + + return metadata; };//EndFunction. var jsonTraverse = function(json, fieldKeys, callback) { @@ -332,10 +423,15 @@ DataTypeConverter.prototype = (function () { * It parses the json and infers the data types. * @param json * @param path Array of field keys/names. + * @param options Infer Data Type options, in particular the threshold value for the confidence. */ - inferJsonDataType: function (json, fieldKeys) { + inferJsonDataType: function (json, fieldKeys, options) { + if (typeof options === 'undefined' || options == null) + options = { thresholdConfidence: 1 }; + var stack = []; var fieldsType = {}; + var fieldsSubType = {}; var numOfRows = 0; if (typeof fieldKeys == 'undefined') @@ -357,16 +453,25 @@ DataTypeConverter.prototype = (function () { var sProcessedKeys = fieldKeys.slice(0, fieldKeyIndex).toString(); ArrayUtils.IteratorOverKeys(item, function (item, key) { - var inferredType = _processInferType(item); var curKey = sProcessedKeys + ((sProcessedKeys.length == 0) ? "" : ",") + key; - - var fieldType = ArrayUtils.TestAndInitializeKey(fieldsType, curKey, { name: curKey, _inferredTypes: [], _inferredValues: [], numOfItems: 0 }); + var fieldType = ArrayUtils.TestAndInitializeKey(fieldsType, curKey, { name: curKey, _inferredTypes: [], _inferredSubTypes: [], _inferredValues: [], numOfItems: 0 }); fieldType.numOfItems++; + + ///TYPE + var inferredType = _processInferType(item); ArrayUtils.TestAndIncrement(fieldType._inferredTypes, inferredType.name); if (inferredType === DataTypeConverter.TYPES.TEXT) ArrayUtils.TestAndIncrement(fieldType._inferredValues, item); - //if (inferredType === DataTypeConverter.TYPES.LATITUDE || inferredType === DataTypeConverter.TYPES.LONGITUDE) - // ArrayUtils.TestAndIncrement(fieldType._inferredTypes, DataTypeConverter.TYPES.NUMBER); + + ///SUBTYPE + var inferredSubType = _processInferSubType(item); + if (inferredSubType != null && typeof inferredSubType !== 'undefined') { + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, inferredSubType.name); + /*if (inferredSubType === DataTypeConverter.TYPES.LATITUDE) + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, DataTypeConverter.TYPES.LATITUDE); + if (inferredSubType === DataTypeConverter.TYPES.LONGITUDE) + ArrayUtils.TestAndIncrement(fieldType._inferredSubTypes, DataTypeConverter.TYPES.LONGITUDE);*/ + }//EndSubtype. }); @@ -451,7 +556,11 @@ DataTypeConverter.prototype = (function () { warningsTextual += description; }); - return { dataset: json, fieldKeys: fieldKeys, types: fieldsType, qualityIndex: quality, warningsTextual: warningsTextual }; + var metadata = { dataset: json, fieldKeys: fieldKeys, types: fieldsType, qualityIndex: quality, warningsTextual: warningsTextual }; + + _filterBasedOnThreshold(metadata, options.thresholdConfidence); + + return metadata; },//EndFunction. /*inferDataTypes: function (jsonRows) { @@ -468,6 +577,15 @@ DataTypeConverter.prototype = (function () { */ inferDataTypeOfValue: function (value) { return _processInferType(value); + },//EndFunction. + + /** + * Given in input a value, the function infers the data type. + * @param value + * @returns {*} + */ + inferDataSubTypeOfValue: function (value) { + return _processInferSubType(value); }//EndFunction. }; diff --git a/bower_components/JSDataChecker/src/DataTypeHierarchy.js b/bower_components/jsdatachecker/src/DataTypeHierarchy.js index d65eff4..f45e21f 100644 --- a/bower_components/JSDataChecker/src/DataTypeHierarchy.js +++ b/bower_components/jsdatachecker/src/DataTypeHierarchy.js @@ -29,9 +29,7 @@ DataTypeHierarchy.HIERARCHY[DataTypeConverter.TYPES.TEXT.name] = [ DataTypeConve 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, +DataTypeHierarchy.HIERARCHY[DataTypeConverter.SUBTYPES.GEOCOORDINATE.name] = [ DataTypeConverter.SUBTYPES.GEOCOORDINATE.name, DataTypeConverter.TYPES.NUMBER.name, DataTypeConverter.TYPES.TEXT.name]; DataTypeHierarchy.canConvert = function (fromType, toType) { diff --git a/bower_components/JSDataChecker/src/DataTypesUtils.js b/bower_components/jsdatachecker/src/DataTypesUtils.js index 3d8d7c4..45f8b5c 100644 --- a/bower_components/JSDataChecker/src/DataTypesUtils.js +++ b/bower_components/jsdatachecker/src/DataTypesUtils.js @@ -122,4 +122,10 @@ DataTypesUtils.DecimalPlaces = function (num) { (match[1] ? match[1].length : 0) // Adjust for scientific notation. - (match[2] ? +match[2] : 0)); +}//EndFunction. + +DataTypesUtils.IsLatLng = function (num) { + if (DataTypesUtils.FilterFloat(num) == NaN) return false; + if (DataTypesUtils.DecimalPlaces(num) > 4) return true; + return false; }//EndFunction. \ No newline at end of file diff --git a/bower_components/JSDataChecker/src/ODPlatforms/CKAN.js b/bower_components/jsdatachecker/src/ODPlatforms/CKAN.js index 9558ca4..9558ca4 100644 --- a/bower_components/JSDataChecker/src/ODPlatforms/CKAN.js +++ b/bower_components/jsdatachecker/src/ODPlatforms/CKAN.js diff --git a/bower_components/JSDataChecker/src/ODPlatforms/ODStatistics.js b/bower_components/jsdatachecker/src/ODPlatforms/ODStatistics.js index daf1630..daf1630 100644 --- a/bower_components/JSDataChecker/src/ODPlatforms/ODStatistics.js +++ b/bower_components/jsdatachecker/src/ODPlatforms/ODStatistics.js diff --git a/controllets/cocreation-paper-card-controllet/cocreation-paper-card-controllet.html b/controllets/cocreation-paper-card-controllet/cocreation-paper-card-controllet.html index 91fc670..d7635bd 100755 --- a/controllets/cocreation-paper-card-controllet/cocreation-paper-card-controllet.html +++ b/controllets/cocreation-paper-card-controllet/cocreation-paper-card-controllet.html @@ -1,5 +1,6 @@ <link rel="import" href="../../bower_components/polymer/polymer.html"/> <link rel="import" href="../../bower_components/paper-card/paper-card.html"/> +<link rel="import" href="../../bower_components/paper-fab/paper-fab.html"> <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html"/> <link rel="import" href="../../bower_components/paper-button/paper-button.html"/> <link rel="import" href="../../bower_components/iron-icon/iron-icon.html"/> @@ -67,6 +68,13 @@ min-width: 310px; min-height: 188px; } + .badge{ + position: absolute; + right: 5px; + bottom: 5px; + background: #2196F3; + } + </style> @@ -80,12 +88,17 @@ <span class="from">{{from}}</span> <iron-icon class="icon-to" icon="alarm-off"></iron-icon> <span class="to">{{to}}</span> + <template is="dom-if" if="{{!checkRoomType(roomType)}}"> + <paper-fab mini disabled icon="assessment" class="badge data"></paper-fab> + </template> + <template is="dom-if" if="{{checkRoomType(roomType)}}"> + <paper-fab mini disabled icon="description" class="badge knowledge"></paper-fab> + </template> </div> </div> <div class="card-actions"> <paper-button on-click="_onExplore">Explore</paper-button> - <paper-icon-button icon="expand-less" on-click="_toggle" style="float:right;"> - </paper-icon-button> + <paper-icon-button icon="expand-less" on-click="_toggle" style="float:right;"></paper-icon-button> <iron-collapse class="iron-collapse-over" id="more_info" no-animation> <div class="collapse-content"> {{goal}} @@ -127,6 +140,10 @@ roomUrl: { type: String, value: undefined + }, + roomType:{ + type: String, + value: undefined } }, @@ -142,8 +159,14 @@ _onExplore: function(e){ window.location = this.roomUrl; - } + }, + checkRoomType: function(type){ + if(type == "knowledge") + return true; + else + return false; + } }) </script> diff --git a/controllets/data-table-controllet/data-table-controllet.html b/controllets/data-table-controllet/data-table-controllet.html index 45fe31f..479172f 100644 --- a/controllets/data-table-controllet/data-table-controllet.html +++ b/controllets/data-table-controllet/data-table-controllet.html @@ -4,9 +4,10 @@ <link rel="import" href="../../bower_components/paper-input/paper-input.html"> <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html"> <link rel="import" href="../../bower_components/iron-icons/iron-icons.html"> +<link rel="import" href="../../bower_components/iron-icons/maps-icons.html"> <link rel="import" href="../../bower_components/paper-tooltip/paper-tooltip.html"> -<script type="text/javascript" src="../../bower_components/JSDataChecker/jsdatachecker.min.js"></script> +<script type="text/javascript" src="../../bower_components/jsdatachecker/jsdatachecker.min.js"></script> <dom-module id="data-table-controllet"> @@ -52,6 +53,10 @@ --paper-tooltip-background: black; } + iron-icon.icon { + color: #2196F3; + } + #data_table_container { height: 100%; width: 100%; @@ -205,7 +210,17 @@ <template is="dom-repeat" items="{{shownData}}"> <tr> <template is="dom-repeat" items="{{_toArray(item)}}"> - <td title="{{item.value}}">{{item.value}}</td> + <template is="dom-if" if={{!_isObject(item)}}> + <td title="{{item.value}}">{{item.value}}</td> + </template> + <template is="dom-if" if={{_isObject(item)}}> + <template is="dom-if" if={{_isGEOJSON(item)}}> + <td title="GEOJSON"><iron-icon icon="maps:map" class="icon"></iron-icon></td> + </template> + <template is="dom-if" if={{!_isGEOJSON(item)}}> + <td title="OBJECT"><iron-icon icon=":help-outline" class="icon"></iron-icon></td> + </template> + </template> </template> </tr> </template> @@ -216,9 +231,9 @@ <paper-tooltip for="{{_fieldId(index)}}" offset="8"> <p> <span class="type">{{_type()}}:</span> {{item.type}} - <!--<template is="dom-if" if={{item.errorsDescription}}>--> - <!--({{item.subType}})--> - <!--</template>--> + <template is="dom-if" if={{item.subtype}}> + ({{item.subtype}}) + </template> <template is="dom-if" if={{item.errorsDescription.length}}> <br/> <span class="warning">{{_warning()}}:</span> {{item.errorsDescription}} @@ -444,6 +459,19 @@ return "id_" + index; }, + _isObject: function(item) { + if(item.value instanceof Array) + return false; + if(item.value instanceof Object) + return true; + return false; + }, + + _isGEOJSON: function(item) { + var dt = new DataTypeConverter(); + return (dt.inferDataSubTypeOfValue(item.value) && dt.inferDataSubTypeOfValue(item.value).name == DataTypeConverter.SUBTYPES.GEOJSON.name); + }, + _resize : function(){ this.async(function() { var h = $(this.$.data_table_container).height() - 96; diff --git a/controllets/dataset-table-controllet/dataset-table-controllet.html b/controllets/dataset-table-controllet/dataset-table-controllet.html index 3db9a70..197f29f 100644 --- a/controllets/dataset-table-controllet/dataset-table-controllet.html +++ b/controllets/dataset-table-controllet/dataset-table-controllet.html @@ -9,7 +9,7 @@ <link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html"> <link rel="import" href="../data-table-controllet/data-table-controllet.html"> -<script type="text/javascript" src="../../bower_components/JSDataChecker/jsdatachecker.min.js"></script> +<script type="text/javascript" src="../../bower_components/jsdatachecker/jsdatachecker.min.js"></script> <dom-module id="dataset-table-controllet"> diff --git a/controllets/providers-utility-controllet/openDataSoft.js b/controllets/providers-utility-controllet/openDataSoft.js index 6384113..7e88761 100644 --- a/controllets/providers-utility-controllet/openDataSoft.js +++ b/controllets/providers-utility-controllet/openDataSoft.js @@ -2,8 +2,11 @@ function openDataSoft_Provider () {} openDataSoft_Provider.prototype.selectData = function(data) { var selectedData = []; - for(var i=0; i<data.records.length; i++) + for(var i=0; i<data.records.length; i++) { + if(data.records[i].geometry) + data.records[i].fields["geometry"] = data.records[i].geometry; selectedData.push(data.records[i].fields); + } return selectedData; }; diff --git a/controllets/select-data-controllet/select-data-controllet.html b/controllets/select-data-controllet/select-data-controllet.html index c5cd0a0..09349e4 100755 --- a/controllets/select-data-controllet/select-data-controllet.html +++ b/controllets/select-data-controllet/select-data-controllet.html @@ -9,7 +9,7 @@ <script type="text/javascript" src="../../alasql-utility/alasql.min.js"></script> <script type="text/javascript" src="../../alasql-utility/alasql-utility.js"></script> -<script type="text/javascript" src="../../bower_components/JSDataChecker/jsdatachecker.min.js"></script> +<script type="text/javascript" src="../../bower_components/jsdatachecker/jsdatachecker.min.js"></script> <dom-module id="select-data-controllet"> @@ -144,8 +144,6 @@ setSelectedFields : function(selectedFields) { this.async(function() { var selectedIndices = utility_getSelectedIndices(this.fields, selectedFields); - - console.log(selectedIndices); this.$.select_fields.setSelectFields(selectedIndices); }, 0); }, diff --git a/controllets/select-visualization-controllet/select-visualization-controllet.html b/controllets/select-visualization-controllet/select-visualization-controllet.html index 0b8f5ee..127ebbb 100755 --- a/controllets/select-visualization-controllet/select-visualization-controllet.html +++ b/controllets/select-visualization-controllet/select-visualization-controllet.html @@ -358,7 +358,7 @@ var params = this.$.options.getParams(); for (var key in params) { this.params[key] = params[key]; } - var data = alasql_complexSelectData(this.data, this.selectedFields, this.filters, inputs.getAggregators(), inputs.getOrders()); + /*????? senza filtri"*/var data = alasql_complexSelectData(this.data, this.selectedFields, this.filters, inputs.getAggregators(), inputs.getOrders()); data = transformData(data, this.selectedFields, true); //use cache diff --git a/datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js b/datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js index f8885aa..90969a2 100755 --- a/datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js +++ b/datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js @@ -124,7 +124,7 @@ var AjaxJsonAlasqlBehavior = { result = converter.cast(result); data = result.dataset; - data = alasql_complexSelectData(data, fields, filters, aggregators, orders); + data = alasql_complexSelectData(data, fields, [], aggregators, orders); this.data = transformData(data, fields, true);