@bicharts/shape-core 0.5.34 → 0.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{e as w,k as b}from"./chunk-
|
|
2
|
+
import{e as w,k as b}from"./chunk-YD2UTLQB.mjs";import C from"papaparse";var D=500,S=/^[+-]?\d{1,15}$/,E=/^[+-]?(\d{1,3}(,\d{3})*|\d+)(\.\d+)?([eE][+-]?\d+)?$/,R=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/,L=/^\d{1,2}[\/\-.]\d{1,2}[\/\-.]\d{2,4}$/;function I(n){let i=0,e=0,r=0,o=0;for(let a of n){if(a==null)continue;if(typeof a=="number"){o++,e++,Number.isInteger(a)&&i++;continue}if(a instanceof Date){o++,r++;continue}if(typeof a=="boolean"){o++;continue}let c=String(a).trim();if(c!==""){if(o++,S.test(c)){i++,e++;continue}if(E.test(c)){e++;continue}if((R.test(c)||L.test(c))&&!isNaN(Date.parse(c))){r++;continue}}}return o===0?"String":r/o>.9?"DateTime":i===o?"Integer":e===o?"Decimal":"String"}function x(n,i){if(n==null)return null;if(typeof n=="number")return i==="String"?String(n):n;if(n instanceof Date)return i==="DateTime"?n:n.toISOString();if(typeof n=="boolean")return String(n);let e=String(n).trim();if(e==="")return null;switch(i){case"Integer":return S.test(e)?parseInt(e,10):null;case"Decimal":return E.test(e)?parseFloat(e.replace(/,/g,"")):null;case"DateTime":{let r=Date.parse(e);return isNaN(r)?null:new Date(r)}default:return e}}function M(n){let i=(n||"").toLowerCase().replace(/\(.*$/,"").trim();return/^(tinyint|smallint|int|integer|int2|int4|int8|bigint|serial|bigserial)$/.test(i)?"Integer":/^(decimal|numeric|money|smallmoney|float|real|double|double precision|number)$/.test(i)?"Decimal":/^(date|datetime|datetime2|smalldatetime|datetimeoffset|timestamp|timestamptz|time)$/.test(i)?"DateTime":(/^(bit|bool|boolean)$/.test(i),"String")}function g(n,i,e){if(n.length===0)throw new Error("ingest: no columns were resolved from the source. Supply column descriptors, or use a source shape that carries them (grid/table/objects/sql).");let r=n.length,o=n.map((t,s)=>t.dataType??I(i.slice(0,D).map(l=>l?.[s]))),a=new Set((e.measures??[]).map(t=>t.toLowerCase())),c=new Set((e.dimensions??[]).map(t=>t.toLowerCase())),d=new Set((e.nonAdditive??[]).map(t=>t.toLowerCase())),T=n.map((t,s)=>{let l=t.name.toLowerCase(),u=t.isMeasure??((o[s]==="Integer"||o[s]==="Decimal")&&!w(t.name));a.has(l)&&(u=!0),c.has(l)&&(u=!1);let h={name:t.name,dataType:o[s],isMeasure:u};return u&&d.has(l)&&(h.discourageAggregationAcrossGroups=!0),h}),m=new b;m.dedupRows=e.dedup!==!1,m.setColumns(T);for(let t=0;t<i.length;t++){let s=i[t];m.addRow(Array.from({length:r},(l,u)=>x(s?.[u],o[u])),t)}let y=m.getColumnsWithStats(e.privacyLevel??"20",e.locale??"en"),f=new Map(y.map(t=>[t.name,t]));n.forEach(t=>{let s=f.get(t.name);s&&(t.format&&(s.modelFormat=t.format),t.description&&(s.modelDesc=t.description))});for(let[t,s]of Object.entries(e.formats??{})){let l=f.get(t);l&&(l.modelFormat=s)}for(let[t,s]of Object.entries(e.descriptions??{})){let l=f.get(t);l&&(l.modelDesc=s)}for(let t of e.groupBy??[]){let s=f.get(t);s&&(s.isGrouping=!0)}return{columns:y,rows:m.toObjectArray(),totalRows:m.getRowCount(),index:m}}function p(n,i){return n.map(e=>Array.isArray(e)?e:i.map(r=>e[r]))}function A(n,i){let e=[],r=new Set,o=Math.min(n.length,Math.max(1,i));for(let a=0;a<o;a++){let c=n[a];if(!(!c||typeof c!="object"))for(let d of Object.keys(c))r.has(d)||(r.add(d),e.push(d))}return e}function $(n,i={}){switch(n.kind){case"csv":{let e=C.parse(n.text,{skipEmptyLines:!0});if(e.errors?.length&&e.data.length===0)throw new Error(`ingest: CSV parse failed - ${e.errors[0].message}`);let r=e.data;if(r.length<2)throw new Error("ingest: CSV needs a header line plus at least one data row.");let o=r[0].map(a=>(a??"").trim());return g(o.map(a=>({name:a})),r.slice(1),i)}case"grid":{if(!n.header?.length)throw new Error("ingest: 'grid' needs a non-empty header.");return g(n.header.map(e=>({name:(e??"").trim()})),n.rows??[],i)}case"table":{if(!n.columns?.length)throw new Error("ingest: 'table' needs at least one column descriptor.");let e=n.columns.map(r=>r.name);return g(n.columns,p(n.rows??[],e),i)}case"objects":{let e=n.rows??[],r=n.columns?.length?n.columns:A(e,i.columnScanLimit??D).map(o=>({name:o}));if(!r.length)throw new Error("ingest: 'objects' produced no columns - the rows array is empty or holds no object keys.");return g(r,p(e,r.map(o=>o.name)),i)}case"sql":{if(!n.schema?.length)throw new Error("ingest: 'sql' needs at least one schema column.");let e=n.schema.map(r=>{let o=M(r.dataType);return{name:r.name,dataType:o,isMeasure:r.isMeasure,format:r.format,description:r.description}});return g(e,p(n.rows??[],e.map(r=>r.name)),i)}default:{let e=n;throw new Error(`ingest: unknown source kind '${e?.kind}'. Expected one of: csv, grid, table, objects, sql.`)}}}export{M as a,$ as b};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
+
import{a as ot}from"./chunk-QEH7WTLB.mjs";import{a as at,b as ut}from"./chunk-2LR73DNS.mjs";import{a as lt,b as ct,c as H}from"./chunk-NWDPA7DG.mjs";import{c as st}from"./chunk-SAASSIJ7.mjs";import{b as it,f as rt}from"./chunk-E6SVTFAW.mjs";import{a as tt,b as et,c as nt}from"./chunk-WBEROMBG.mjs";var yt=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],Mt=[7,72,-172,-52];function mt(s,e,n){return s>=n[0]&&s<=n[1]&&e>=n[2]&&e<=n[3]}function $(s,e){if(!s.length)return NaN;if(s.length===1)return s[0];let n=(s.length-1)*e,r=Math.floor(n),u=Math.ceil(n);return r===u?s[r]:s[r]+(s[u]-s[r])*(n-r)}var k=s=>Math.round(s*10)/10;function dt(s,e=3){let n=[],r=[],u=0,i=0;for(let l of s){let m=l?.lat,f=l?.lon;if(typeof m!="number"||typeof f!="number"||!isFinite(m)||!isFinite(f)||m<-90||m>90||f<-180||f>180)continue;n.push(m),r.push(f);let S=l?.country?String(l.country).trim().toUpperCase():"",g=S?X(S):null;g?((S==="US"||S==="USA")&&u++,g==="north-america"&&i++):(yt.some(O=>mt(m,f,O))&&u++,mt(m,f,Mt)&&i++)}let o=n.length;return o<e?null:(n.sort((l,m)=>l-m),r.sort((l,m)=>l-m),{pctUsa:k(u/o*100),pctNa:k(i/o*100),latP5:k($(n,.05)),latP95:k($(n,.95)),lonP5:k($(r,.05)),lonP95:k($(r,.95)),n:o})}var ft={"north-america":"AG AI AW BB BL BM BQ BS BZ CA CR CU CW DM DO GD GL GP GT HN HT JM KN KY LC MF MQ MS MX NI PA PM PR SV SX TC TT US VC VG VI","south-america":"AR BO BR CL CO EC FK GF GY PE PY SR UY VE",europe:"AD AL AT AX BA BE BG BY CH CY CZ DE DK EE ES FI FO FR GB GG GI GR HR HU IE IM IS IT JE LI LT LU LV MC MD ME MK MT NL NO PL PT RO RS RU SE SI SJ SK SM UA VA",africa:"AO BF BI BJ BW CD CF CG CI CM CV DJ DZ EG EH ER ET GA GH GM GN GQ GW KE KM LR LS LY MA MG ML MR MU MW MZ NA NE NG RE RW SC SD SH SL SN SO SS ST SZ TD TG TN TZ UG YT ZA ZM ZW",asia:"AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN IO IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO MV MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW UZ VN YE",oceania:"AS AU CK FJ FM GU KI MH MP NC NF NR NU NZ PF PG PN PW SB TK TO TV UM VU WF WS",antarctica:"AQ BV GS HM TF"},Y=(()=>{let s=new Map;for(let e of Object.keys(ft))for(let n of ft[e].split(/\s+/))n&&s.set(n,e);return s})();function St(s){for(let[e,n]of s){let r=Y.get(e);r&&!Y.has(n)&&Y.set(n,r)}}St(it);function X(s){if(!s)return null;let e=String(s).trim().toUpperCase();if(!e)return null;let n=Y.get(e);if(n)return n;let r=rt(String(s));return r?Y.get(r)??null:null}function kt(s,e=2){return q(s.map(n=>[n,1]),e)}function q(s,e=2){let n=new Map,r=0;for(let[o,l]of s){let m=X(o);if(!m)continue;let f=typeof l=="number"&&isFinite(l)&&l>0?l:1;n.set(m,(n.get(m)??0)+f),r+=f}if(r<e||!n.size)return null;let u="europe",i=-1;for(let o of Array.from(n.keys()).sort()){let l=n.get(o);l>i&&(u=o,i=l)}return{dominantGeoRegion:u,dominantGeoRegionPct:k(i/r*100),regionCount:n.size,n:r}}import ht from"papaparse";var _t=12,Ct=100,Tt=.3,Rt=.9,Nt=120,It=1900,At=2100,Dt=0,xt=20,Et=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function vt(s){if(!s)return!1;let e=s.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(n=>n.length>0);return e.length===0?!1:Et.has(e[e.length-1])}var wt=/\b(year|yr|fy|fiscal\s*year|calendar\s*year)\b/i,Lt=/^(?:(?:19|20)\d{2}(?:[-/ ]?(?:q[1-4]|w(?:0?[1-9]|[1-4]\d|5[0-3])|(?:0?[1-9]|1[0-2])))?|q[1-4][-/ ](?:19|20)\d{2}|(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[-/ ]?(?:19|20)?\d{2})$/i;function j(s){if(!Number.isInteger(s)||s<190001||s>210012)return!1;let e=s%100;return e>=1&&e<=12}function J(s){if(!Number.isInteger(s)||s<19000101||s>21001231)return!1;let e=Math.floor(s/100)%100,n=s%100;return e>=1&&e<=12&&n>=1&&n<=31}var Ot=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,Pt=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,Gt=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function Wt(s){let e=(s||"").toLowerCase();return e==="en-us"||e==="en"||e.startsWith("en-us-")||e==="en-ph"||e==="en-bz"}function bt(s,e){let n=0,r=0,u=0,i=0,o=0,l="",m=0,f="",S=0,g=0,O=0,h=0,R=!1;for(let U of s){if(U==null)continue;let G=String(U).trim();if(G==="")continue;n++;let t;if(t=Ot.exec(G)){let a=+t[2],_=+t[3];a>=1&&a<=12&&_>=1&&_<=31&&(r++,t[4]!==void 0&&u++,t[6]!==void 0&&i++)}else if(t=Pt.exec(G)){let a=+t[3],_=+t[4];a>=1&&a<=12&&_>=1&&_<=31&&(l&&l!==t[2]&&(R=!0),l=t[2],o++)}else if(t=Gt.exec(G)){let a=+t[1],_=+t[3];a>=1&&a<=31&&_>=1&&_<=31&&(a<=12||_<=12)&&(f&&f!==t[2]&&(R=!0),f=t[2],m++,a>12&&O++,_>12&&h++,t[5]!==void 0&&S++,t[7]!==void 0&&g++)}if(n>=200)break}if(n<2||(r+o+m)/n<.8||(r>0?1:0)+(o>0?1:0)+(m>0?1:0)!==1||R)return null;if(r>0)return u===r?{pattern:i===r?"%Y-%m-%dT%H:%M:%S":"%Y-%m-%dT%H:%M",orderFrom:"iso"}:{pattern:"%Y-%m-%d",orderFrom:"iso"};if(o>0)return{pattern:`%Y${l}%m${l}%d`,orderFrom:"iso"};if(O>0&&h>0)return null;let v,D;O>0?(v=!0,D="values"):h>0?(v=!1,D="values"):(v=!Wt(e),D="locale");let F=v?`%d${f}%m${f}%Y`:`%m${f}%d${f}%Y`;return S===m?{pattern:F+(g===m?" %H:%M:%S":" %H:%M"),orderFrom:D}:{pattern:F,orderFrom:D}}function Vt(s,e){if(!e||!/\b(?:19|20)\d{2}\b/.test(s))return!1;let n=s.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!n)return!1;let r=at(n);return r.length>0&&e[r]!==void 0}function Ft(s){let{dataType:e,name:n,isMeasure:r,distinctCount:u}=s;if(e==="DateTime")return!0;if(r)return!1;if(e==="Integer"||e==="Decimal"){let i=s.minNum,o=s.maxNum;if(!(i!=null&&o!=null&&Number.isFinite(i)&&Number.isFinite(o)&&Number.isInteger(i)&&Number.isInteger(o)&&o>=i))return!1;let m=i>=1900&&o<=2100;if(m&&u>=2&&wt.test(n)||m&&u>=3&&u===o-i+1)return!0;let f=j(i)&&j(o),S=J(i)&&J(o);if(f||S){if(!s.sampleValues)return!0;let g=0,O=0;for(let h of s.sampleValues){if(h==null||h==="")continue;g++;let R=Number(String(h).trim());if(Number.isFinite(R)&&(f?j(R):J(R))&&O++,g>=60)break}if(g>=2&&O===g)return!0}return!1}if(s.sampleValues){let i=s.locale?ut(s.locale):null,o=0,l=0,m=[];for(let f of s.sampleValues){if(f==null||f==="")continue;o++;let S=String(f).trim();if(m.push(S),(Lt.test(S)||Vt(S,i))&&l++,o>=60)break}if(o>=2&&l/o>=.8||bt(m,s.locale)!==null)return!0}return!1}function Bt(s){let e=(s||"").trim().toLowerCase();return e.startsWith("sum ")||e.startsWith("total ")?"sum":e.startsWith("average ")||e.startsWith("avg. ")?"avg":e.startsWith("count ")||e.startsWith("distinct count ")||e.startsWith("count (distinct) ")?"count":e.startsWith("min ")||e.startsWith("minimum ")?"min":e.startsWith("max ")||e.startsWith("maximum ")?"max":null}function Ut(s){let{rows:e,measureColIdx:n,measureName:r,candidateDims:u,minNum:i,maxNum:o,discourageAgg:l}=s,m=100,f=.01,S="";for(let O of u){if(O.distinct<2||O.distinct>m)continue;let h=u.filter(D=>D.idx!==O.idx).map(D=>D.idx),R=new Map;for(let D of e){let F=D[n];if(typeof F!="number"||!Number.isFinite(F))continue;let U=h.length?h.map(t=>String(D[t])).join(S):"",G=R.get(U);G||(G={sum:0,cset:new Set},R.set(U,G)),G.sum+=F,G.cset.add(String(D[O.idx]))}let I=0,A=0,v=0;for(let D of R.values())D.cset.size<2||(v++,Math.abs(D.sum-100)<=100*f?I++:Math.abs(D.sum-1)<=1*f&&A++);if(v>=2&&(I/v>=.9||A/v>=.9))return{additivity:"part_of_whole",partOfWholeDim:O.name}}if(l)return{additivity:"intensive_rate"};let g=Bt(r);return g==="avg"||g==="min"||g==="max"?{additivity:"intensive_rate"}:g==="count"?{additivity:"additive"}:g==="sum"?{additivity:"unknown"}:i!=null&&o!=null&&Number.isFinite(i)&&Number.isFinite(o)&&i>=0&&o<=1.0001&&o>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function gt(s){let{dataType:e,isMeasure:n,name:r,distinct:u,nonblank:i,prec:o,maxval:l,minval:m}=s,f=l-m+1,S=f>0?u/f:1,g=i>0?u/i:0,O=e==="Decimal"||o>0;return vt(r)?"Categorical":S>=Rt&&(tt(r)&&u<=Nt||m>=It&&l<=At||m>=Dt&&l<=xt)?"Ordinal":n||u>_t&&(O||u>=Ct||g>=Tt)?"Continuous":"Categorical"}var pt=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;STR(e){return e==null?"":e.toString()}getPrecision(e){if(!isFinite(e))return 0;let r=e.toString().split(".")[1];return r?r.length:0}getColumns(){return this._cols}hasTimeComponent(e){return!(e instanceof Date)||isNaN(e.getTime())?!1:e.getHours()!==0||e.getMinutes()!==0||e.getSeconds()!==0||e.getMilliseconds()!==0}getColumnsWithStats(e,n){if(this._computedStatsForLevel==e)return this._cols;let r=0,u=parseInt(e),i=[];for(let t of this._cols){let a=new Map,_=[],b=0,d=0,N=0,T=null,y=null,p=null,x=!1,w=!0,E=!0,L=null,P=!1;for(let C of this._rows){let c=C[r],M=this.STR(c);if(M!=""){if(b+=M.length,a.set(M,(a.get(M)||0)+1),d++,t.dataType=="Integer"||t.dataType=="Decimal"||t.dataType=="DateTime")if((T===null||c<T)&&(T=c),(y===null||c>y)&&(y=c),t.dataType=="Integer"||t.dataType=="Decimal"){if(p===null?p=c:p+=c,t.dataType=="Decimal"){let W=this.getPrecision(c);W>N&&(N=W)}_.push(c)}else x=x||this.hasTimeComponent(c);P&&(c<L?w=!1:c>L&&(E=!1)),L=c,P=!0}}if(d>=3&&(w&&!E?t.sortedDirection="asc":E&&!w?t.sortedDirection="desc":t.sortedDirection="none"),d>0&&a.size>0&&!t.isMeasure){let C=0,c=Number.MAX_SAFE_INTEGER;for(let M of a.values())M>C&&(C=M),M<c&&(c=M);if(t.modalShare=C/d,t.minGroupCount=c===Number.MAX_SAFE_INTEGER?null:c,a.size===2){let M=[...a.keys()].map(V=>lt(V).trim().toLowerCase()).sort(),z=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(V=>M[0]===V[0]&&M[1]===V[1]),B=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(t.name);(z||B)&&(t.isBinaryFlag=!0)}}if(t.dataType=="DateTime"&&(t.dateWithTime=x),t.isTemporal=Ft({dataType:t.dataType,name:t.name,isMeasure:t.isMeasure,distinctCount:a.size,minNum:typeof T=="number"?T:null,maxNum:typeof y=="number"?y:null,sampleValues:a.keys(),locale:n}),t.isTemporal&&t.dataType==="String"&&!t.isMeasure){let C=bt(a.keys(),n);C&&(t.temporalTextPattern=C.pattern)}this.updateColumnStats10(u,t,d,a,N,y,T),this.updateColumnStats20(u,_,d,p,t,b,x,T,y,N,a,n),!t.isMeasure&&(t.dataType==="Integer"||t.dataType==="Decimal")&>({dataType:t.dataType,isMeasure:!1,name:t.name,distinct:a.size,nonblank:d,prec:N,maxval:typeof y=="number"?y:0,minval:typeof T=="number"?T:0})==="Continuous"&&(t.isMeasure=!0),i[r]=t.isMeasure||a.size>2e3?null:new Set(a.keys()),r++}let o=[];this._cols.forEach((t,a)=>{t.isMeasure||o.push({idx:a,distinct:t.distinctCount??0,name:t.name})}),this._cols.forEach((t,a)=>{if(!t.isMeasure)return;let _=typeof t.lowValue=="number"?t.lowValue:null,b=typeof t.highValue=="number"?t.highValue:null,d=Ut({rows:this._rows,measureColIdx:a,measureName:t.name,candidateDims:o,minNum:_,maxNum:b,discourageAgg:!!t.discourageAggregationAcrossGroups});t.additivity=d.additivity,d.partOfWholeDim&&(t.partOfWholeDim=d.partOfWholeDim)});let l=50,m=o.filter(t=>t.distinct>=2&&t.distinct<=l);this._cols.forEach((t,a)=>{if(!t.isMeasure)return;let _=[];for(let c of this._rows){let M=c[a];if(M==null||M==="")continue;let W=typeof M=="number"?M:parseFloat(M);isNaN(W)||_.push(W)}if(_.length===0)return;let b=[..._].sort((c,M)=>c-M),d=c=>b[Math.min(b.length-1,Math.max(0,Math.floor(c*(b.length-1))))],N=d(.5),T=d(.1),y=d(.9),p=Math.abs(N)>1e-9?Math.abs(N):Math.abs(b[b.length-1])>1e-9?Math.abs(b[b.length-1]):1;t.relativeDispersion=Math.round((y-T)/p*1e3)/1e3;let x=0;for(let c of _)x+=c;x/=_.length;let w=0;for(let c of _)w+=(c-x)*(c-x);if(w<=1e-12)return;let E=[],L=[],P=c=>{if(c.length<4)return NaN;let M=[...c].sort((z,B)=>z-B),W=z=>M[Math.min(M.length-1,Math.max(0,Math.floor(z*(M.length-1))))];return W(.75)-W(.25)},C=P(_);for(let c of m){let M=new Map;for(let B of this._rows){let V=B[a];if(V==null||V==="")continue;let K=typeof V=="number"?V:parseFloat(V);if(isNaN(K))continue;let Q=this.STR(B[c.idx])+"",Z=M.get(Q);Z?(Z.s+=K,Z.n++,Z.vals.push(K)):M.set(Q,{s:K,n:1,vals:[K]})}let W=0;for(let B of M.values()){let V=B.s/B.n;W+=B.n*(V-x)*(V-x)}E.push({otherColumn:c.name,eta2:Math.round(W/w*1e4)/1e4});let z=[];for(let B of M.values()){let V=P(B.vals);isNaN(V)||z.push(V)}if(z.length>=2&&isFinite(C)&&C>1e-9){let B=(Math.max(...z)-Math.min(...z))/C;L.push({otherColumn:c.name,spreadRatio:Math.round(B*1e4)/1e4})}}E.length>0&&(t.groupDiscrimination=E),L.length>0&&(t.spreadDiscrimination=L)});let f=.97,S=5,g=this._cols.map((t,a)=>({c:t,i:a})).filter(t=>t.c.isMeasure);for(let t=0;t<g.length;t++)for(let a=t+1;a<g.length;a++){let _=g[t].i,b=g[a].i,d=0,N=0,T=0,y=0,p=0,x=0;for(let P of this._rows){let C=P[_],c=P[b];if(C==null||C===""||c===null||c===void 0||c==="")continue;let M=typeof C=="number"?C:parseFloat(C),W=typeof c=="number"?c:parseFloat(c);isNaN(M)||isNaN(W)||(d++,N+=M,T+=W,y+=M*M,p+=W*W,x+=M*W)}if(d<S)continue;let w=d*y-N*N,E=d*p-T*T;if(w<=1e-12||E<=1e-12)continue;let L=(d*x-N*T)/Math.sqrt(w*E);if(Math.abs(L)>=f){let P=g[t].c,C=g[a].c;P.collinearWithMeasures||(P.collinearWithMeasures=[]),C.collinearWithMeasures||(C.collinearWithMeasures=[]),P.collinearWithMeasures.push(C.name),C.collinearWithMeasures.push(P.name)}}for(let t=0;t<this._cols.length;t++){let a=i[t];if(!a||a.size===0)continue;let _=[];for(let b=0;b<this._cols.length;b++){if(b===t)continue;let d=i[b];if(!d||d.size===0)continue;let N=0;for(let y of a)d.has(y)&&N++;let T=Math.round(N/a.size*100);T>0&&_.push({otherColumn:this._cols[b].name,percentShared:T})}_.length>0&&(this._cols[t].sharedValueRatioWithOthers=_)}let O=50,h=[];for(let t=0;t<this._cols.length;t++){let a=i[t];a&&a.size>=2&&a.size<=O&&h.push(t)}if(h.length>=2){let t=new Map,a=(b,d)=>b+":"+d;for(let b=0;b<h.length;b++)for(let d=b+1;d<h.length;d++)t.set(a(h[b],h[d]),new Map);for(let b of this._rows)for(let d=0;d<h.length;d++){let N=this.STR(b[h[d]])+"";for(let T=d+1;T<h.length;T++){let y=""+this.STR(b[h[T]]),p=t.get(a(h[d],h[T])),x=N+""+y;p.set(x,(p.get(x)??0)+1)}}let _=new Map;for(let b=0;b<h.length;b++)for(let d=b+1;d<h.length;d++){let N=h[b],T=h[d],y=i[N].size,p=i[T].size,x=t.get(a(N,T)),w=x.size,E=0;for(let c of x.values())(E===0||c<E)&&(E=c);let L=Math.round(w/(y*p)*100),P=w===y,C=w===p;if((this._cols[N].categoricalPairStats||=[]).push({otherColumn:this._cols[T].name,fillPct:L,determinesOther:P,minCellCount:E,distinctCombinations:w}),(this._cols[T].categoricalPairStats||=[]).push({otherColumn:this._cols[N].name,fillPct:L,determinesOther:C,minCellCount:E,distinctCombinations:w}),P&&y>p){let c=_.get(N);(!c||p<c.card)&&_.set(N,{name:this._cols[T].name,card:p,ratio:p/y})}if(C&&p>y){let c=_.get(T);(!c||y<c.card)&&_.set(T,{name:this._cols[N].name,card:y,ratio:y/p})}}for(let[b,d]of _)this._cols[b].primaryParentColumn=d.name,this._cols[b].nestingRatio=Math.round(d.ratio*100)/100}let R=.01,I=.05,A=.95,v=8,D=8,F=6,U=500,G=[];for(let t=0;t<this._cols.length&&G.length<D;t++){let a=this._cols[t].dataType;(a==="Double"||a==="Integer"||a==="Decimal")&&G.push(t)}if(G.length>=3&&this._rows.length>=v){let t=Math.min(this._rows.length,U),a=G.map(y=>{let p=[];for(let E=0;E<t;E++){let L=this._rows[E][y],P=typeof L=="number"?L:parseFloat(String(L).replace(/,/g,""));if(L==null||L===""||!isFinite(P))return null;p.push(P)}let x=p[0],w=!1;for(let E of p)if(E!==x){w=!0;break}return w?p:null}),_=G.map((y,p)=>p).filter(y=>a[y]!==null),b=y=>{let p=y.slice().sort((w,E)=>w-E),x=p.length>>1;return p.length%2?p[x]:(p[x-1]+p[x])/2},d=null,N=[],T=y=>{if(N.length>=3){let p=N.map(L=>a[L]),x=p[0].length,w=new Array(x);for(let L=0;L<x;L++){let P=0;for(let C of p)P+=C[L];w[L]=P}let E=b(w);if(E>0){let L=0;for(let C of w)Math.abs(C-E)<=E*R&&L++;let P=L/x;if(P>=A){let C=1;for(let c of p){let M=b(c)/E;M<C&&(C=M)}C>=I&&(!d||N.length>d.cols.length)&&(d={cols:N.slice(),total:E,matched:P})}}}if(!(N.length>=F))for(let p=y;p<_.length;p++)N.push(_[p]),T(p+1),N.pop()};if(T(0),d){let y=d,x={columns:y.cols.map(w=>this._cols[G[w]].name),total:Math.round(y.total*1e3)/1e3,matchedPct:Math.round(y.matched*100)/100};for(let w of y.cols)this._cols[G[w]].constantSumGroup=x}}return this._computedStatsForLevel=e,this._cols}updateColumnStats20(e,n,r,u,i,o,l,m,f,S,g,O){if(e>=20){let h=[...n].sort((A,v)=>A-v),R=Math.floor(h.length/2);if(r>0&&u!=null?i.avgValue=i.dataType=="Integer"?Math.round(u/r):u/r:i.avgValue=null,r>0&&(i.avgLength=o/r),this._rows.length>0&&(i.dataType!="DateTime"||l||!m?i.lowValue=m:i.lowValue=new Date(m).toISOString().slice(0,10)+"T00:00:00.000Z",i.dataType!="DateTime"||l||!f?i.highValue=f:i.highValue=new Date(f).toISOString().slice(0,10)+"T00:00:00.000Z",i.medianValue=h.length===0?null:h.length%2===0?i.dataType=="Integer"?Math.round((h[R-1]+h[R])/2):(h[R-1]+h[R])/2:h[R],i.numericPrecision=S),h.length>0){let A=i.avgValue??0,v=h.length,D=0,F=0;for(let G of h){let t=G-A;D+=t*t,F+=t*t*t}let U=D/v;i.skewness=U===0?0:F/v/Math.pow(Math.sqrt(U),3),i.stdDev=Math.sqrt(U)}u!==null&&(i.sum=u);let I=Array.from(g.entries()).sort((A,v)=>v[1]-A[1]);if(i.topCategories=I.slice(0,10).map(A=>A[1]),!i.isMeasure&&I.length>0){if(i.dataType==="String"){let A=I.map(D=>D[0]);i.formatSignature=ot(A);let v=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;i.formatSignature&&!v.test(i.formatSignature)&&(i.avgLength===void 0||i.avgLength>=3)&&(i.isFreeText=!0)}else i.topCategoryValues=I.slice(0,5).map(A=>A[0]);if(e>=20){let A=I.map(D=>D[0]),v=nt(A,O);if(v!==null)i.ordinalPattern=v.pattern,i.orderedDomain=v.orderedDomain;else if(i.dataType==="String"){let D=et(A);D!==null&&(i.safeDistinctValues=D)}}}if(h.length>=8&&(i.dataType==="Integer"||i.dataType==="Decimal")){let A=v=>h[Math.floor((h.length-1)*v)];i.quantiles={p05:A(.05),p25:A(.25),p75:A(.75),p95:A(.95)}}}if(!i.isMeasure&&g.size>0){let h=Array.from(g.entries()).sort((I,A)=>A[1]-I[1]),R=st(h.map(I=>I[0]),i.name,O);if(R!==null&&(i.geoKind=R.geoKind,i.geoMatchPct=R.geoMatchPct,R.geoAmbiguous&&(i.geoAmbiguous=!0),R.geoKind.indexOf("country")===0)){let I=q(h);I&&(i.dominantGeoRegion=I.dominantGeoRegion,i.dominantGeoRegionPct=I.dominantGeoRegionPct,i.geoRegionCount=I.regionCount)}}}updateColumnStats10(e,n,r,u,i,o,l){e>=10&&(n.blankCount=this._rows.length-r,n.distinctCount=u.size+(n.blankCount!=0?1:0),n.valueNature="Categorical",r>0&&(n.dataType==="Integer"||n.dataType==="Decimal"?n.valueNature=gt({dataType:n.dataType,isMeasure:!!n.isMeasure,name:n.name,distinct:u.size,nonblank:r,prec:i,maxval:o,minval:l}):n.dataType==="DateTime"&&(n.valueNature=n.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let e=[];if(this._cols.forEach((r,u)=>{r.isMeasure||e.push(u)}),e.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let n=new Set;for(let r of this._rows)n.add(JSON.stringify(e.map(u=>r[u])));return this._leafCardinality=n.size,this._leafCardinality}_leafCardinality=null;getGeoExtent(){if(this._geoExtentComputed)return this._geoExtent;this._geoExtentComputed=!0,this._geoExtent=null;let e=o=>String(o||"").replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/),n=-1,r=-1,u=-1;if(this._cols.forEach((o,l)=>{let m=e(o.name),f=o.dataType==="Integer"||o.dataType==="Decimal";f&&n<0&&m.some(S=>S==="lat"||S==="latitude")?n=l:f&&r<0&&m.some(S=>S==="lon"||S==="lng"||S==="long"||S==="longitude")&&(r=l),u<0&&!o.isMeasure&&typeof o.geoKind=="string"&&o.geoKind.indexOf("country")===0&&(u=l)}),n<0||r<0)return null;let i=[];for(let o of this._rows){let l=o[n],m=o[r],f=l==null||l===""?null:Number(l),S=m==null||m===""?null:Number(m);i.push({lat:f,lon:S,country:u>=0&&X(this.STR(o[u]))?this.STR(o[u]):null})}return this._geoExtent=dt(i),this._geoExtent}_geoExtent=null;_geoExtentComputed=!1;obfuscateString(e){let n="abcdefghijklmnopqrstuvwxyz",r=()=>n[Math.floor(H()*n.length)],u=()=>r().toUpperCase(),i=()=>Math.floor(H()*10).toString(),o=R=>/[A-Z]/.test(R)?u():/[a-z]/.test(R)?r():/[0-9]/.test(R)?i():R,l=e.includes("@")&&e.includes("."),m=l?e.split("@"):[e],f=l?m[1]:"",S=f.endsWith(".com"),g=S?".com":"",O=S?f.slice(0,-4):f,h=R=>{let I="";for(let A of R)I+=o(A),/[a-zA-Z0-9]/.test(A)&&H()<.2&&(I+=o(A));if(I.length>6){let A=Math.floor(H()*Math.min(3,I.length-6));for(let v=0;v<A;v++){let D=0;for(;D<5;){let F=Math.floor(H()*I.length);if(/[a-zA-Z0-9]/.test(I[F])){I=I.slice(0,F)+I.slice(F+1);break}D++}}}return I};if(l){let R=h(m[0]),I=h(O);return`${R}@${I}${g}`}else return h(e)}toObjectArray(){return this._rows.map(e=>{let n={};return this._cols.forEach((r,u)=>{n[r.name]=e[u]}),n})}async getCSVAsync(e){let n=[],r=e?25:1e7,u=e?4e3:1e7,i=new Map;for(let l of this._rows){let m={};for(let f=0;f<this._cols.length;f++){let S=this._cols[f],g=l[f];if(this.STR(g)!=""){if(e&&S.dataType=="String")if(i.has(g))g=i.get(g);else{let O=this.obfuscateString(g);i.set(g,O),g=O}else S.dataType=="DateTime"&&!S.dateWithTime&&(g=new Date(g).toISOString().slice(0,10)+"T00:00:00.000Z");u-=this.STR(g).length}else g=null;m[f]=g,--u}if(n.push(m),--r,r<=0||u<=0)break}return await ht.unparse(n,{header:!1})}getCSVHeaderLine(){return ht.unparse([this._cols.map(e=>this.STR(e.name))])}addRow(e,n){if(this.dedupRows){let r="";for(let i of e)r+=this.STR(i)+"~";let u=ct(r);if(this._rowHashes.has(u))return!1;this._rowHashes.add(u)}return this._rows.push(e),this._origIndices.push(n??-1),!0}getOriginalRowIndex(e){return e<0||e>=this._origIndices.length?-1:this._origIndices[e]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(e){this._cols=e}};export{dt as a,St as b,X as c,kt as d,vt as e,bt as f,Ft as g,Bt as h,Ut as i,gt as j,pt as k};
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{a as Lt,b as zt}from"./chunk-
|
|
2
|
+
import{a as Lt,b as zt}from"./chunk-LEFYTHAM.mjs";import{a as pt,b as yt,c as dt,d as gt,e as Mt,f as Tt,g as At,h as St,i as vt,j as kt,k as It}from"./chunk-YD2UTLQB.mjs";import{a as ht}from"./chunk-QEH7WTLB.mjs";import{a as Ct,b as Pt}from"./chunk-2LR73DNS.mjs";import{a as xt,b as bt,c as Rt}from"./chunk-NWDPA7DG.mjs";import{a as K,b as V,c as ut,d as ct,e as ft,f as mt}from"./chunk-SAASSIJ7.mjs";import{a as R,f as M,g,h as T,i as G,j as X,k as tt,l as H,m as p,n as nt,o as et,p as ot,q as A,r as it,s as rt,t as st,u as at,v as _,w as lt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as Y,b as J,c as Q}from"./chunk-WBEROMBG.mjs";var w=2,j=400;function N(r){return!!M(r)}function P(r){let n=new Set;for(let e of r){if(e==null)continue;let s=R(String(e));if(!T(s)&&!n.has(s)&&(n.add(s),n.size>=j))break}return Array.from(n)}function C(r){let n=P(r);if(n.length===0||E(r)<95)return!1;let e=n.filter(l=>N(l)&&!p(l)).length,s=n.filter(l=>!N(l)&&!!p(l)).length;return e>=1&&e>=s}function q(r,n){if(!p(r))return!1;let e=M(r);return e?n==="world"?!0:H.has(e):!1}function E(r){let n=P(r);if(n.length===0)return 0;let e=0;for(let s of n)N(s)&&e++;return Math.round(e/n.length*1e3)/10}function S(r){let n=P(r);if(n.length===0)return 0;let e=0;for(let s of n)p(s)&&e++;return Math.round(e/n.length*1e3)/10}function D(r){let n=new Set;for(let e of r){if(e==null)continue;let s=String(e).trim();if(!T(R(s))&&!n.has(s)&&(n.add(s),n.size>=j))break}return Array.from(n)}function O(r){let n=D(r);if(n.length===0)return 0;let e=0;for(let s of n)A(s).length>0&&e++;return Math.round(e/n.length*1e3)/10}function Z(r,n){return V(n,K)?!0:D(r).some(e=>/^\d{5}(-\d{4})?$/.test(e.replace(/\.0+$/,"")))}function Gt(r,n){let e=P(r);if(e.length===0)return 0;let s=0;for(let l of e)_(l,n)&&s++;return Math.round(s/e.length*1e3)/10}function $(r,n){let e=0;for(let s of P(r))n(s)&&e++;return e}function _t(r,n){let e=0;for(let s of D(r))n(s)&&e++;return e}function wt(r,n,e,s){let l=[],c=[],o={},v={},k=new Set(r),u=t=>n.map(i=>i[t]);for(let t of["city","lat","lon","country"]){let i=e?.[t];i&&k.has(i)&&(o[t]=i)}let y=e?.zip;if(y&&k.has(y)){let t=u(y),i=O(t);i<95?c.push(`zip=${y} (only ${i}% of values read as ZIPs)`):Z(t,y)?o.zip=y:c.push(`zip=${y} (all values are 3-4 digits with nothing to say they are postal)`)}let m=e?.state;if(m&&k.has(m)){let t=u(m),i=P(t);i.length>0&&i.every(a=>q(a,s))?c.push(`state=${m} (every value is "CA", which is both Canada and California)`):C(t)?(c.push(`state=${m} (every value is a country, not a state)`),o.country||(o.country=m)):S(t)<95?c.push(`state=${m} (only ${S(t)}% of values are states/provinces)`):o.state=m}let d=new Set(Object.values(o).filter(Boolean)),x=r.filter(t=>!d.has(t)&&!t.startsWith("__"));if(!o.state){let t=null;for(let i of x){let a=u(i);if(C(a))continue;let f=S(a);if(f<95)continue;let z=$(a,b=>!!p(b)),W=$(a,b=>!!p(b)&&!q(b,s));z<w&&W<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.state=t.name,d.add(t.name),l.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of x){if(d.has(t))continue;let i=u(t),a=O(i);if(!(a<95)&&Z(i,t)&&!(_t(i,f=>A(f).length>0)<w)){o.zip=t,d.add(t),l.push(`zip=${t} (${a}% ZIP codes)`);break}}let h=o.country;if(!h||!C(u(h))){let t=null;for(let i of x){if(d.has(i)||!C(u(i)))continue;let a=E(u(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(c.push(`country=${h} (only ${E(u(h))}% of values are country identifiers; using ${t.name} instead)`),v.country=h),o.country=t.name,d.add(t.name),l.push(`country=${t.name}`))}if(!o.city){let t=null;for(let i of x){if(d.has(i))continue;let a=u(i),f=Gt(a,s);f<G||$(a,z=>_(z,s))<w||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.city=t.name,l.push(`city=${t.name} (${t.pct}% known cities)`))}let B=o.country?u(o.country):[],I=!!o.country&&C(B),U=I?new Set(B.map(t=>M(t==null?null:String(t))).filter(Boolean)).size:0,F=I&&U>=2,L=!!(o.lat&&o.lon)&&n.some(t=>{let i=+String(t[o.lat]??"").trim(),a=+String(t[o.lon]??"").trim();return isFinite(i)&&isFinite(a)&&i>=-90&&i<=90&&a>=-180&&a<=180&&String(t[o.lat]??"").trim()!==""&&String(t[o.lon]??"").trim()!==""});return o.lat&&o.lon&&!L&&c.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!F&&!(o.city||o.state||o.zip||L)&&c.push(I?`country=${o.country} (every row resolves to the same country - nothing to place apart)`:`country=${o.country} (values are not country identifiers)`),{bind:!!(o.city||o.state||o.zip||F||L)?o:null,backfilled:l,refused:c,...Object.keys(v).length?{labelFallback:v}:{}}}export{G as CITY_ROLE_MATCH_PCT,Rt as GET_RANDOM,It as IndexedText,g as ROLE_MATCH_PCT,bt as SIMPLE_STRING_HASH,xt as STR,S as admin1MatchPct,mt as buildGeoIsoColumn,st as buildGeoPointColumns,lt as cityMatchPct,at as cityTagsFor,vt as classifyAdditivity,kt as classifyNumericValueNature,At as classifyTemporal,dt as countryRegion,ht as detectFormatSignature,ut as detectGeo,Q as detectOrdinalDomain,Tt as detectTextDatePattern,Lt as engineTypeForSqlType,St as hostAggHint,zt as ingest,T as isBlankLike,tt as isCityTableLoaded,it as isGeoPointAmbiguity,Mt as isIdentifierName,ft as isJoinGeoKind,Y as isOrdinalFriendlyName,C as looksLikeCountryColumn,Pt as monthLookupFor,nt as normalizeCountry,Ct as normalizeMonthKey,R as normalizePlaceName,ot as normalizeZip5,X as registerCityTable,yt as registerIso3Regions,p as resolveAdmin1,rt as resolveGeoPoint,wt as resolvePointRoles,J as safeDistinctValuesToShip,gt as summarizeCountryRegions,pt as summarizeGeoExtent,ct as toGeoIso,O as zipMatchPct,A as zipPrefixCandidates,et as zipToPrefix3};
|
package/dist/indexedText.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{e as a,f as b,g as c,h as d,i as e,j as f,k as g}from"./chunk-
|
|
2
|
+
import{e as a,f as b,g as c,h as d,i as e,j as f,k as g}from"./chunk-YD2UTLQB.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-SAASSIJ7.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-WBEROMBG.mjs";export{g as IndexedText,e as classifyAdditivity,f as classifyNumericValueNature,c as classifyTemporal,b as detectTextDatePattern,d as hostAggHint,a as isIdentifierName};
|
package/dist/ingest.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-LEFYTHAM.mjs";import"./chunk-YD2UTLQB.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-SAASSIJ7.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-WBEROMBG.mjs";export{a as engineTypeForSqlType,b as ingest};
|
package/dist/types/models.d.ts
CHANGED
|
@@ -68,6 +68,11 @@ export type LLMColumnWithValue = {
|
|
|
68
68
|
}[];
|
|
69
69
|
primaryParentColumn?: string;
|
|
70
70
|
nestingRatio?: number;
|
|
71
|
+
constantSumGroup?: {
|
|
72
|
+
columns: string[];
|
|
73
|
+
total: number;
|
|
74
|
+
matchedPct: number;
|
|
75
|
+
};
|
|
71
76
|
relativeDispersion?: number;
|
|
72
77
|
groupDiscrimination?: {
|
|
73
78
|
otherColumn: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bicharts/shape-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.35",
|
|
4
4
|
"description": "Host-agnostic data-shape profiler: ingest a dataset's rows through IValueCollection.addRow and read back the measured shape as an LLMColumnWithValue[] payload — types, cardinality, temporal/ordinal detection, geographic region and point resolution, cross-column signals. MEASUREMENT only: the policy that decides what a measured shape means for chart selection lives server-side.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
package/dist/chunk-S5PWLLEF.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{a as J}from"./chunk-QEH7WTLB.mjs";import{a as Q,b as tt}from"./chunk-2LR73DNS.mjs";import{a as et,b as nt,c as G}from"./chunk-NWDPA7DG.mjs";import{c as j}from"./chunk-SAASSIJ7.mjs";import{b as q,f as X}from"./chunk-E6SVTFAW.mjs";import{a as Y,b as Z,c as $}from"./chunk-WBEROMBG.mjs";var mt=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],ct=[7,72,-172,-52];function it(a,e,n){return a>=n[0]&&a<=n[1]&&e>=n[2]&&e<=n[3]}function B(a,e){if(!a.length)return NaN;if(a.length===1)return a[0];let n=(a.length-1)*e,r=Math.floor(n),m=Math.ceil(n);return r===m?a[r]:a[r]+(a[m]-a[r])*(n-r)}var P=a=>Math.round(a*10)/10;function st(a,e=3){let n=[],r=[],m=0,i=0;for(let f of a){let d=f?.lat,g=f?.lon;if(typeof d!="number"||typeof g!="number"||!isFinite(d)||!isFinite(g)||d<-90||d>90||g<-180||g>180)continue;n.push(d),r.push(g);let _=f?.country?String(f.country).trim().toUpperCase():"",y=_?U(_):null;y?((_==="US"||_==="USA")&&m++,y==="north-america"&&i++):(mt.some(A=>it(d,g,A))&&m++,it(d,g,ct)&&i++)}let l=n.length;return l<e?null:(n.sort((f,d)=>f-d),r.sort((f,d)=>f-d),{pctUsa:P(m/l*100),pctNa:P(i/l*100),latP5:P(B(n,.05)),latP95:P(B(n,.95)),lonP5:P(B(r,.05)),lonP95:P(B(r,.95)),n:l})}var rt={"north-america":"AG AI AW BB BL BM BQ BS BZ CA CR CU CW DM DO GD GL GP GT HN HT JM KN KY LC MF MQ MS MX NI PA PM PR SV SX TC TT US VC VG VI","south-america":"AR BO BR CL CO EC FK GF GY PE PY SR UY VE",europe:"AD AL AT AX BA BE BG BY CH CY CZ DE DK EE ES FI FO FR GB GG GI GR HR HU IE IM IS IT JE LI LT LU LV MC MD ME MK MT NL NO PL PT RO RS RU SE SI SJ SK SM UA VA",africa:"AO BF BI BJ BW CD CF CG CI CM CV DJ DZ EG EH ER ET GA GH GM GN GQ GW KE KM LR LS LY MA MG ML MR MU MW MZ NA NE NG RE RW SC SD SH SL SN SO SS ST SZ TD TG TN TZ UG YT ZA ZM ZW",asia:"AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN IO IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO MV MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW UZ VN YE",oceania:"AS AU CK FJ FM GU KI MH MP NC NF NR NU NZ PF PG PN PW SB TK TO TV UM VU WF WS",antarctica:"AQ BV GS HM TF"},V=(()=>{let a=new Map;for(let e of Object.keys(rt))for(let n of rt[e].split(/\s+/))n&&a.set(n,e);return a})();function ft(a){for(let[e,n]of a){let r=V.get(e);r&&!V.has(n)&&V.set(n,r)}}ft(q);function U(a){if(!a)return null;let e=String(a).trim().toUpperCase();if(!e)return null;let n=V.get(e);if(n)return n;let r=X(String(a));return r?V.get(r)??null:null}function Pt(a,e=2){return z(a.map(n=>[n,1]),e)}function z(a,e=2){let n=new Map,r=0;for(let[l,f]of a){let d=U(l);if(!d)continue;let g=typeof f=="number"&&isFinite(f)&&f>0?f:1;n.set(d,(n.get(d)??0)+g),r+=g}if(r<e||!n.size)return null;let m="europe",i=-1;for(let l of Array.from(n.keys()).sort()){let f=n.get(l);f>i&&(m=l,i=f)}return{dominantGeoRegion:m,dominantGeoRegionPct:P(i/r*100),regionCount:n.size,n:r}}import ot from"papaparse";var dt=12,gt=100,ht=.3,pt=.9,bt=120,yt=1900,Mt=2100,St=0,Ct=20,_t=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function Tt(a){if(!a)return!1;let e=a.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(n=>n.length>0);return e.length===0?!1:_t.has(e[e.length-1])}var Rt=/\b(year|yr|fy|fiscal\s*year|calendar\s*year)\b/i,Nt=/^(?:(?:19|20)\d{2}(?:[-/ ]?(?:q[1-4]|w(?:0?[1-9]|[1-4]\d|5[0-3])|(?:0?[1-9]|1[0-2])))?|q[1-4][-/ ](?:19|20)\d{2}|(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[-/ ]?(?:19|20)?\d{2})$/i;function H(a){if(!Number.isInteger(a)||a<190001||a>210012)return!1;let e=a%100;return e>=1&&e<=12}function k(a){if(!Number.isInteger(a)||a<19000101||a>21001231)return!1;let e=Math.floor(a/100)%100,n=a%100;return e>=1&&e<=12&&n>=1&&n<=31}var It=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,At=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,Dt=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function xt(a){let e=(a||"").toLowerCase();return e==="en-us"||e==="en"||e.startsWith("en-us-")||e==="en-ph"||e==="en-bz"}function lt(a,e){let n=0,r=0,m=0,i=0,l=0,f="",d=0,g="",_=0,y=0,A=0,p=0,t=!1;for(let M of a){if(M==null)continue;let C=String(M).trim();if(C==="")continue;n++;let b;if(b=It.exec(C)){let R=+b[2],I=+b[3];R>=1&&R<=12&&I>=1&&I<=31&&(r++,b[4]!==void 0&&m++,b[6]!==void 0&&i++)}else if(b=At.exec(C)){let R=+b[3],I=+b[4];R>=1&&R<=12&&I>=1&&I<=31&&(f&&f!==b[2]&&(t=!0),f=b[2],l++)}else if(b=Dt.exec(C)){let R=+b[1],I=+b[3];R>=1&&R<=31&&I>=1&&I<=31&&(R<=12||I<=12)&&(g&&g!==b[2]&&(t=!0),g=b[2],d++,R>12&&A++,I>12&&p++,b[5]!==void 0&&_++,b[7]!==void 0&&y++)}if(n>=200)break}if(n<2||(r+l+d)/n<.8||(r>0?1:0)+(l>0?1:0)+(d>0?1:0)!==1||t)return null;if(r>0)return m===r?{pattern:i===r?"%Y-%m-%dT%H:%M:%S":"%Y-%m-%dT%H:%M",orderFrom:"iso"}:{pattern:"%Y-%m-%d",orderFrom:"iso"};if(l>0)return{pattern:`%Y${f}%m${f}%d`,orderFrom:"iso"};if(A>0&&p>0)return null;let u,s;A>0?(u=!0,s="values"):p>0?(u=!1,s="values"):(u=!xt(e),s="locale");let S=u?`%d${g}%m${g}%Y`:`%m${g}%d${g}%Y`;return _===d?{pattern:S+(y===d?" %H:%M:%S":" %H:%M"),orderFrom:s}:{pattern:S,orderFrom:s}}function Et(a,e){if(!e||!/\b(?:19|20)\d{2}\b/.test(a))return!1;let n=a.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!n)return!1;let r=Q(n);return r.length>0&&e[r]!==void 0}function vt(a){let{dataType:e,name:n,isMeasure:r,distinctCount:m}=a;if(e==="DateTime")return!0;if(r)return!1;if(e==="Integer"||e==="Decimal"){let i=a.minNum,l=a.maxNum;if(!(i!=null&&l!=null&&Number.isFinite(i)&&Number.isFinite(l)&&Number.isInteger(i)&&Number.isInteger(l)&&l>=i))return!1;let d=i>=1900&&l<=2100;if(d&&m>=2&&Rt.test(n)||d&&m>=3&&m===l-i+1)return!0;let g=H(i)&&H(l),_=k(i)&&k(l);if(g||_){if(!a.sampleValues)return!0;let y=0,A=0;for(let p of a.sampleValues){if(p==null||p==="")continue;y++;let t=Number(String(p).trim());if(Number.isFinite(t)&&(g?H(t):k(t))&&A++,y>=60)break}if(y>=2&&A===y)return!0}return!1}if(a.sampleValues){let i=a.locale?tt(a.locale):null,l=0,f=0,d=[];for(let g of a.sampleValues){if(g==null||g==="")continue;l++;let _=String(g).trim();if(d.push(_),(Nt.test(_)||Et(_,i))&&f++,l>=60)break}if(l>=2&&f/l>=.8||lt(d,a.locale)!==null)return!0}return!1}function wt(a){let e=(a||"").trim().toLowerCase();return e.startsWith("sum ")||e.startsWith("total ")?"sum":e.startsWith("average ")||e.startsWith("avg. ")?"avg":e.startsWith("count ")||e.startsWith("distinct count ")||e.startsWith("count (distinct) ")?"count":e.startsWith("min ")||e.startsWith("minimum ")?"min":e.startsWith("max ")||e.startsWith("maximum ")?"max":null}function Lt(a){let{rows:e,measureColIdx:n,measureName:r,candidateDims:m,minNum:i,maxNum:l,discourageAgg:f}=a,d=100,g=.01,_="";for(let A of m){if(A.distinct<2||A.distinct>d)continue;let p=m.filter(s=>s.idx!==A.idx).map(s=>s.idx),t=new Map;for(let s of e){let S=s[n];if(typeof S!="number"||!Number.isFinite(S))continue;let M=p.length?p.map(b=>String(s[b])).join(_):"",C=t.get(M);C||(C={sum:0,cset:new Set},t.set(M,C)),C.sum+=S,C.cset.add(String(s[A.idx]))}let o=0,c=0,u=0;for(let s of t.values())s.cset.size<2||(u++,Math.abs(s.sum-100)<=100*g?o++:Math.abs(s.sum-1)<=1*g&&c++);if(u>=2&&(o/u>=.9||c/u>=.9))return{additivity:"part_of_whole",partOfWholeDim:A.name}}if(f)return{additivity:"intensive_rate"};let y=wt(r);return y==="avg"||y==="min"||y==="max"?{additivity:"intensive_rate"}:y==="count"?{additivity:"additive"}:y==="sum"?{additivity:"unknown"}:i!=null&&l!=null&&Number.isFinite(i)&&Number.isFinite(l)&&i>=0&&l<=1.0001&&l>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function at(a){let{dataType:e,isMeasure:n,name:r,distinct:m,nonblank:i,prec:l,maxval:f,minval:d}=a,g=f-d+1,_=g>0?m/g:1,y=i>0?m/i:0,A=e==="Decimal"||l>0;return Tt(r)?"Categorical":_>=pt&&(Y(r)&&m<=bt||d>=yt&&f<=Mt||d>=St&&f<=Ct)?"Ordinal":n||m>dt&&(A||m>=gt||y>=ht)?"Continuous":"Categorical"}var ut=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;STR(e){return e==null?"":e.toString()}getPrecision(e){if(!isFinite(e))return 0;let r=e.toString().split(".")[1];return r?r.length:0}getColumns(){return this._cols}hasTimeComponent(e){return!(e instanceof Date)||isNaN(e.getTime())?!1:e.getHours()!==0||e.getMinutes()!==0||e.getSeconds()!==0||e.getMilliseconds()!==0}getColumnsWithStats(e,n){if(this._computedStatsForLevel==e)return this._cols;let r=0,m=parseInt(e),i=[];for(let t of this._cols){let o=new Map,c=[],u=0,s=0,S=0,M=null,C=null,b=null,R=!1,I=!0,E=!0,L=null,v=!1;for(let N of this._rows){let h=N[r],T=this.STR(h);if(T!=""){if(u+=T.length,o.set(T,(o.get(T)||0)+1),s++,t.dataType=="Integer"||t.dataType=="Decimal"||t.dataType=="DateTime")if((M===null||h<M)&&(M=h),(C===null||h>C)&&(C=h),t.dataType=="Integer"||t.dataType=="Decimal"){if(b===null?b=h:b+=h,t.dataType=="Decimal"){let D=this.getPrecision(h);D>S&&(S=D)}c.push(h)}else R=R||this.hasTimeComponent(h);v&&(h<L?I=!1:h>L&&(E=!1)),L=h,v=!0}}if(s>=3&&(I&&!E?t.sortedDirection="asc":E&&!I?t.sortedDirection="desc":t.sortedDirection="none"),s>0&&o.size>0&&!t.isMeasure){let N=0,h=Number.MAX_SAFE_INTEGER;for(let T of o.values())T>N&&(N=T),T<h&&(h=T);if(t.modalShare=N/s,t.minGroupCount=h===Number.MAX_SAFE_INTEGER?null:h,o.size===2){let T=[...o.keys()].map(x=>et(x).trim().toLowerCase()).sort(),O=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(x=>T[0]===x[0]&&T[1]===x[1]),w=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(t.name);(O||w)&&(t.isBinaryFlag=!0)}}if(t.dataType=="DateTime"&&(t.dateWithTime=R),t.isTemporal=vt({dataType:t.dataType,name:t.name,isMeasure:t.isMeasure,distinctCount:o.size,minNum:typeof M=="number"?M:null,maxNum:typeof C=="number"?C:null,sampleValues:o.keys(),locale:n}),t.isTemporal&&t.dataType==="String"&&!t.isMeasure){let N=lt(o.keys(),n);N&&(t.temporalTextPattern=N.pattern)}this.updateColumnStats10(m,t,s,o,S,C,M),this.updateColumnStats20(m,c,s,b,t,u,R,M,C,S,o,n),!t.isMeasure&&(t.dataType==="Integer"||t.dataType==="Decimal")&&at({dataType:t.dataType,isMeasure:!1,name:t.name,distinct:o.size,nonblank:s,prec:S,maxval:typeof C=="number"?C:0,minval:typeof M=="number"?M:0})==="Continuous"&&(t.isMeasure=!0),i[r]=t.isMeasure||o.size>2e3?null:new Set(o.keys()),r++}let l=[];this._cols.forEach((t,o)=>{t.isMeasure||l.push({idx:o,distinct:t.distinctCount??0,name:t.name})}),this._cols.forEach((t,o)=>{if(!t.isMeasure)return;let c=typeof t.lowValue=="number"?t.lowValue:null,u=typeof t.highValue=="number"?t.highValue:null,s=Lt({rows:this._rows,measureColIdx:o,measureName:t.name,candidateDims:l,minNum:c,maxNum:u,discourageAgg:!!t.discourageAggregationAcrossGroups});t.additivity=s.additivity,s.partOfWholeDim&&(t.partOfWholeDim=s.partOfWholeDim)});let f=50,d=l.filter(t=>t.distinct>=2&&t.distinct<=f);this._cols.forEach((t,o)=>{if(!t.isMeasure)return;let c=[];for(let h of this._rows){let T=h[o];if(T==null||T==="")continue;let D=typeof T=="number"?T:parseFloat(T);isNaN(D)||c.push(D)}if(c.length===0)return;let u=[...c].sort((h,T)=>h-T),s=h=>u[Math.min(u.length-1,Math.max(0,Math.floor(h*(u.length-1))))],S=s(.5),M=s(.1),C=s(.9),b=Math.abs(S)>1e-9?Math.abs(S):Math.abs(u[u.length-1])>1e-9?Math.abs(u[u.length-1]):1;t.relativeDispersion=Math.round((C-M)/b*1e3)/1e3;let R=0;for(let h of c)R+=h;R/=c.length;let I=0;for(let h of c)I+=(h-R)*(h-R);if(I<=1e-12)return;let E=[],L=[],v=h=>{if(h.length<4)return NaN;let T=[...h].sort((O,w)=>O-w),D=O=>T[Math.min(T.length-1,Math.max(0,Math.floor(O*(T.length-1))))];return D(.75)-D(.25)},N=v(c);for(let h of d){let T=new Map;for(let w of this._rows){let x=w[o];if(x==null||x==="")continue;let W=typeof x=="number"?x:parseFloat(x);if(isNaN(W))continue;let K=this.STR(w[h.idx])+"",F=T.get(K);F?(F.s+=W,F.n++,F.vals.push(W)):T.set(K,{s:W,n:1,vals:[W]})}let D=0;for(let w of T.values()){let x=w.s/w.n;D+=w.n*(x-R)*(x-R)}E.push({otherColumn:h.name,eta2:Math.round(D/I*1e4)/1e4});let O=[];for(let w of T.values()){let x=v(w.vals);isNaN(x)||O.push(x)}if(O.length>=2&&isFinite(N)&&N>1e-9){let w=(Math.max(...O)-Math.min(...O))/N;L.push({otherColumn:h.name,spreadRatio:Math.round(w*1e4)/1e4})}}E.length>0&&(t.groupDiscrimination=E),L.length>0&&(t.spreadDiscrimination=L)});let g=.97,_=5,y=this._cols.map((t,o)=>({c:t,i:o})).filter(t=>t.c.isMeasure);for(let t=0;t<y.length;t++)for(let o=t+1;o<y.length;o++){let c=y[t].i,u=y[o].i,s=0,S=0,M=0,C=0,b=0,R=0;for(let v of this._rows){let N=v[c],h=v[u];if(N==null||N===""||h===null||h===void 0||h==="")continue;let T=typeof N=="number"?N:parseFloat(N),D=typeof h=="number"?h:parseFloat(h);isNaN(T)||isNaN(D)||(s++,S+=T,M+=D,C+=T*T,b+=D*D,R+=T*D)}if(s<_)continue;let I=s*C-S*S,E=s*b-M*M;if(I<=1e-12||E<=1e-12)continue;let L=(s*R-S*M)/Math.sqrt(I*E);if(Math.abs(L)>=g){let v=y[t].c,N=y[o].c;v.collinearWithMeasures||(v.collinearWithMeasures=[]),N.collinearWithMeasures||(N.collinearWithMeasures=[]),v.collinearWithMeasures.push(N.name),N.collinearWithMeasures.push(v.name)}}for(let t=0;t<this._cols.length;t++){let o=i[t];if(!o||o.size===0)continue;let c=[];for(let u=0;u<this._cols.length;u++){if(u===t)continue;let s=i[u];if(!s||s.size===0)continue;let S=0;for(let C of o)s.has(C)&&S++;let M=Math.round(S/o.size*100);M>0&&c.push({otherColumn:this._cols[u].name,percentShared:M})}c.length>0&&(this._cols[t].sharedValueRatioWithOthers=c)}let A=50,p=[];for(let t=0;t<this._cols.length;t++){let o=i[t];o&&o.size>=2&&o.size<=A&&p.push(t)}if(p.length>=2){let t=new Map,o=(u,s)=>u+":"+s;for(let u=0;u<p.length;u++)for(let s=u+1;s<p.length;s++)t.set(o(p[u],p[s]),new Map);for(let u of this._rows)for(let s=0;s<p.length;s++){let S=this.STR(u[p[s]])+"";for(let M=s+1;M<p.length;M++){let C=""+this.STR(u[p[M]]),b=t.get(o(p[s],p[M])),R=S+""+C;b.set(R,(b.get(R)??0)+1)}}let c=new Map;for(let u=0;u<p.length;u++)for(let s=u+1;s<p.length;s++){let S=p[u],M=p[s],C=i[S].size,b=i[M].size,R=t.get(o(S,M)),I=R.size,E=0;for(let h of R.values())(E===0||h<E)&&(E=h);let L=Math.round(I/(C*b)*100),v=I===C,N=I===b;if((this._cols[S].categoricalPairStats||=[]).push({otherColumn:this._cols[M].name,fillPct:L,determinesOther:v,minCellCount:E,distinctCombinations:I}),(this._cols[M].categoricalPairStats||=[]).push({otherColumn:this._cols[S].name,fillPct:L,determinesOther:N,minCellCount:E,distinctCombinations:I}),v&&C>b){let h=c.get(S);(!h||b<h.card)&&c.set(S,{name:this._cols[M].name,card:b,ratio:b/C})}if(N&&b>C){let h=c.get(M);(!h||C<h.card)&&c.set(M,{name:this._cols[S].name,card:C,ratio:C/b})}}for(let[u,s]of c)this._cols[u].primaryParentColumn=s.name,this._cols[u].nestingRatio=Math.round(s.ratio*100)/100}return this._computedStatsForLevel=e,this._cols}updateColumnStats20(e,n,r,m,i,l,f,d,g,_,y,A){if(e>=20){let p=[...n].sort((c,u)=>c-u),t=Math.floor(p.length/2);if(r>0&&m!=null?i.avgValue=i.dataType=="Integer"?Math.round(m/r):m/r:i.avgValue=null,r>0&&(i.avgLength=l/r),this._rows.length>0&&(i.dataType!="DateTime"||f||!d?i.lowValue=d:i.lowValue=new Date(d).toISOString().slice(0,10)+"T00:00:00.000Z",i.dataType!="DateTime"||f||!g?i.highValue=g:i.highValue=new Date(g).toISOString().slice(0,10)+"T00:00:00.000Z",i.medianValue=p.length===0?null:p.length%2===0?i.dataType=="Integer"?Math.round((p[t-1]+p[t])/2):(p[t-1]+p[t])/2:p[t],i.numericPrecision=_),p.length>0){let c=i.avgValue??0,u=p.length,s=0,S=0;for(let C of p){let b=C-c;s+=b*b,S+=b*b*b}let M=s/u;i.skewness=M===0?0:S/u/Math.pow(Math.sqrt(M),3),i.stdDev=Math.sqrt(M)}m!==null&&(i.sum=m);let o=Array.from(y.entries()).sort((c,u)=>u[1]-c[1]);if(i.topCategories=o.slice(0,10).map(c=>c[1]),!i.isMeasure&&o.length>0){if(i.dataType==="String"){let c=o.map(s=>s[0]);i.formatSignature=J(c);let u=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;i.formatSignature&&!u.test(i.formatSignature)&&(i.avgLength===void 0||i.avgLength>=3)&&(i.isFreeText=!0)}else i.topCategoryValues=o.slice(0,5).map(c=>c[0]);if(e>=20){let c=o.map(s=>s[0]),u=$(c,A);if(u!==null)i.ordinalPattern=u.pattern,i.orderedDomain=u.orderedDomain;else if(i.dataType==="String"){let s=Z(c);s!==null&&(i.safeDistinctValues=s)}}}if(p.length>=8&&(i.dataType==="Integer"||i.dataType==="Decimal")){let c=u=>p[Math.floor((p.length-1)*u)];i.quantiles={p05:c(.05),p25:c(.25),p75:c(.75),p95:c(.95)}}}if(!i.isMeasure&&y.size>0){let p=Array.from(y.entries()).sort((o,c)=>c[1]-o[1]),t=j(p.map(o=>o[0]),i.name,A);if(t!==null&&(i.geoKind=t.geoKind,i.geoMatchPct=t.geoMatchPct,t.geoAmbiguous&&(i.geoAmbiguous=!0),t.geoKind.indexOf("country")===0)){let o=z(p);o&&(i.dominantGeoRegion=o.dominantGeoRegion,i.dominantGeoRegionPct=o.dominantGeoRegionPct,i.geoRegionCount=o.regionCount)}}}updateColumnStats10(e,n,r,m,i,l,f){e>=10&&(n.blankCount=this._rows.length-r,n.distinctCount=m.size+(n.blankCount!=0?1:0),n.valueNature="Categorical",r>0&&(n.dataType==="Integer"||n.dataType==="Decimal"?n.valueNature=at({dataType:n.dataType,isMeasure:!!n.isMeasure,name:n.name,distinct:m.size,nonblank:r,prec:i,maxval:l,minval:f}):n.dataType==="DateTime"&&(n.valueNature=n.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let e=[];if(this._cols.forEach((r,m)=>{r.isMeasure||e.push(m)}),e.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let n=new Set;for(let r of this._rows)n.add(JSON.stringify(e.map(m=>r[m])));return this._leafCardinality=n.size,this._leafCardinality}_leafCardinality=null;getGeoExtent(){if(this._geoExtentComputed)return this._geoExtent;this._geoExtentComputed=!0,this._geoExtent=null;let e=l=>String(l||"").replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/),n=-1,r=-1,m=-1;if(this._cols.forEach((l,f)=>{let d=e(l.name),g=l.dataType==="Integer"||l.dataType==="Decimal";g&&n<0&&d.some(_=>_==="lat"||_==="latitude")?n=f:g&&r<0&&d.some(_=>_==="lon"||_==="lng"||_==="long"||_==="longitude")&&(r=f),m<0&&!l.isMeasure&&typeof l.geoKind=="string"&&l.geoKind.indexOf("country")===0&&(m=f)}),n<0||r<0)return null;let i=[];for(let l of this._rows){let f=l[n],d=l[r],g=f==null||f===""?null:Number(f),_=d==null||d===""?null:Number(d);i.push({lat:g,lon:_,country:m>=0&&U(this.STR(l[m]))?this.STR(l[m]):null})}return this._geoExtent=st(i),this._geoExtent}_geoExtent=null;_geoExtentComputed=!1;obfuscateString(e){let n="abcdefghijklmnopqrstuvwxyz",r=()=>n[Math.floor(G()*n.length)],m=()=>r().toUpperCase(),i=()=>Math.floor(G()*10).toString(),l=t=>/[A-Z]/.test(t)?m():/[a-z]/.test(t)?r():/[0-9]/.test(t)?i():t,f=e.includes("@")&&e.includes("."),d=f?e.split("@"):[e],g=f?d[1]:"",_=g.endsWith(".com"),y=_?".com":"",A=_?g.slice(0,-4):g,p=t=>{let o="";for(let c of t)o+=l(c),/[a-zA-Z0-9]/.test(c)&&G()<.2&&(o+=l(c));if(o.length>6){let c=Math.floor(G()*Math.min(3,o.length-6));for(let u=0;u<c;u++){let s=0;for(;s<5;){let S=Math.floor(G()*o.length);if(/[a-zA-Z0-9]/.test(o[S])){o=o.slice(0,S)+o.slice(S+1);break}s++}}}return o};if(f){let t=p(d[0]),o=p(A);return`${t}@${o}${y}`}else return p(e)}toObjectArray(){return this._rows.map(e=>{let n={};return this._cols.forEach((r,m)=>{n[r.name]=e[m]}),n})}async getCSVAsync(e){let n=[],r=e?25:1e7,m=e?4e3:1e7,i=new Map;for(let f of this._rows){let d={};for(let g=0;g<this._cols.length;g++){let _=this._cols[g],y=f[g];if(this.STR(y)!=""){if(e&&_.dataType=="String")if(i.has(y))y=i.get(y);else{let A=this.obfuscateString(y);i.set(y,A),y=A}else _.dataType=="DateTime"&&!_.dateWithTime&&(y=new Date(y).toISOString().slice(0,10)+"T00:00:00.000Z");m-=this.STR(y).length}else y=null;d[g]=y,--m}if(n.push(d),--r,r<=0||m<=0)break}return await ot.unparse(n,{header:!1})}getCSVHeaderLine(){return ot.unparse([this._cols.map(e=>this.STR(e.name))])}addRow(e,n){if(this.dedupRows){let r="";for(let i of e)r+=this.STR(i)+"~";let m=nt(r);if(this._rowHashes.has(m))return!1;this._rowHashes.add(m)}return this._rows.push(e),this._origIndices.push(n??-1),!0}getOriginalRowIndex(e){return e<0||e>=this._origIndices.length?-1:this._origIndices[e]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(e){this._cols=e}};export{st as a,ft as b,U as c,Pt as d,Tt as e,lt as f,vt as g,wt as h,Lt as i,at as j,ut as k};
|