@bicharts/shape-core 0.5.84 → 0.5.85

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{t as w,z as b}from"./chunk-KFKKFBBT.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?"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};
2
+ import{t as w,z as b}from"./chunk-VLKG6RD7.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?"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 ft}from"./chunk-QEH7WTLB.mjs";import{a as dt,b as gt}from"./chunk-2LR73DNS.mjs";import{c as mt}from"./chunk-7MHZMBRK.mjs";import{b as lt,f as ct}from"./chunk-E6SVTFAW.mjs";import{a as ot,b as at,c as ut}from"./chunk-NNUL5RKC.mjs";import{a as X,b as st,c as rt,d as Z}from"./chunk-U43WE7LN.mjs";var Et=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],Dt=[7,72,-172,-52];function ht(n,t,e){return n>=e[0]&&n<=e[1]&&t>=e[2]&&t<=e[3]}function J(n,t){if(!n.length)return NaN;if(n.length===1)return n[0];let e=(n.length-1)*t,r=Math.floor(e),o=Math.ceil(e);return r===o?n[r]:n[r]+(n[o]-n[r])*(e-r)}var Y=n=>Math.round(n*10)/10;function bt(n,t=3){let e=[],r=[],o=0,s=0;for(let l of n){let c=l?.lat,f=l?.lon;if(typeof c!="number"||typeof f!="number"||!isFinite(c)||!isFinite(f)||c<-90||c>90||f<-180||f>180)continue;e.push(c),r.push(f);let M=l?.country?String(l.country).trim().toUpperCase():"",h=M?Q(M):null;h?((M==="US"||M==="USA")&&o++,h==="north-america"&&s++):(Et.some(O=>ht(c,f,O))&&o++,ht(c,f,Dt)&&s++)}let a=e.length;return a<t?null:(e.sort((l,c)=>l-c),r.sort((l,c)=>l-c),{pctUsa:Y(o/a*100),pctNa:Y(s/a*100),latP5:Y(J(e,.05)),latP95:Y(J(e,.95)),lonP5:Y(J(r,.05)),lonP95:Y(J(r,.95)),n:a})}var pt={"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"},j=(()=>{let n=new Map;for(let t of Object.keys(pt))for(let e of pt[t].split(/\s+/))e&&n.set(e,t);return n})();function Ot(n){for(let[t,e]of n){let r=j.get(t);r&&!j.has(e)&&j.set(e,r)}}Ot(lt);function Q(n){if(!n)return null;let t=String(n).trim().toUpperCase();if(!t)return null;let e=j.get(t);if(e)return e;let r=ct(String(n));return r?j.get(r)??null:null}function pe(n,t=2){return tt(n.map(e=>[e,1]),t)}function tt(n,t=2){let e=new Map,r=0;for(let[a,l]of n){let c=Q(a);if(!c)continue;let f=typeof l=="number"&&isFinite(l)&&l>0?l:1;e.set(c,(e.get(c)??0)+f),r+=f}if(r<t||!e.size)return null;let o="europe",s=-1;for(let a of Array.from(e.keys()).sort()){let l=e.get(a);l>s&&(o=a,s=l)}return{dominantGeoRegion:o,dominantGeoRegionPct:Y(s/r*100),regionCount:e.size,n:r}}import vt from"papaparse";var Lt=["rate","ratio","pct","percent","percentage","rating","share","score","index","nps","csat","margin","yield","coverage","utilization","z[_-]?score","average","avg","mean","median","stddev","variance","gpa","percentile","quantile","efficiency","accuracy","probability","multiplier","coefficient","correlation","occupancy","age","bmi","temperature","density","pressure","humidity","ph","velocity","speed","elevation","altitude","latency","throughput","bandwidth","iops"],Pt=["pct","percent","percentage","rate","ratio","rating","share","score","index","nps","csat","margin","yield","coverage","utilization","gpa","percentile","quantile","bmi","density","pressure","humidity","velocity","efficiency","occupancy","latency","throughput","bandwidth","iops"],Gt=["latitude","longitude"],Wt=["latitude","longitude"],_t=/^\s*(sum|count|count\s+distinct|distinct\s+count)\s+of\s+/i,Ft=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])/g,Vt=new RegExp("\\b("+Lt.join("|")+")\\b|("+Pt.join("|")+")$","i"),kt=new RegExp("\\b("+Gt.join("|")+")\\b|("+Wt.join("|")+")$","i");function St(n){return n?String(n).replace(_t,"").trim():""}function Ut(n){return!!n&&_t.test(String(n))}var Bt=["count (distinct)","count distinct","distinct count","standard deviation","average","variance","median","product","stddev","std dev","count","sum","avg","min","minimum","max","maximum","var"],yt=new RegExp("^\\s*("+[...Bt].sort((n,t)=>t.length-n.length).map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+")).join("|")+")\\s+of\\s+","i");function Ct(n){if(n==null)return"";let t=String(n),e=yt.exec(t);if(!e)return t;let r=l=>l.toLowerCase().replace(/\s+/g," ").trim(),o=r(e[1]),s=t.slice(e[0].length),a=0;for(;a<8;){let l=yt.exec(s);if(!l||r(l[1])!==o)break;let c=s.slice(l[0].length);if(c.trim()==="")break;s=c,a++}return a===0?t:t.slice(0,e[0].length)+s}function _e(n,t){if(!n||!t)return!1;let e=String(n);for(let r of t){let o=r?.hostName;if(o&&o!==r?.name&&e.includes(o))return!0}return!1}function zt(n){let t=St(n);return t.length===0?"":t.replace(Ft," ")}function Mt(n,t){if(!t)return!1;let e=St(t);return n.test(zt(t))||n.test(e)||n.test(X(e).join(" "))}function At(n){return Mt(kt,n)}function Ht(n){return Mt(Vt,n)||At(n)}var Tt=/int|double|decimal|single|float|number|currency|money/i;function Kt(n){let t=String(n?.valueNature??"").trim().toLowerCase();return t==="categorical"?"Categorical":t==="ordinal"?"Ordinal":t==="continuous"||n?.isMeasure===!0||Tt.test(String(n?.dataType??""))?"Continuous":"Categorical"}function Yt(n){return n?.isMeasure===!0||Tt.test(String(n?.dataType??""))}function Nt(n){let t=n??{},e=Kt(t);if(e!=="Continuous")return{nature:e,additivity:"unknown",basis:"role",suppressed:!1};if(At(t.name))return{nature:e,additivity:"positional",basis:"name",suppressed:!0};let r=String(t.additivity??"").trim().toLowerCase();if(!(r==="additive"&&Ut(t.name))){if(r==="additive")return{nature:e,additivity:"additive",basis:"measured",suppressed:!1};if(r==="part_of_whole")return{nature:e,additivity:"part_of_whole",basis:"measured",suppressed:!1};if(r==="intensive_rate")return{nature:e,additivity:"intensive_rate",basis:"measured",suppressed:!1}}return t.discourageAggregationAcrossGroups===!0?{nature:e,additivity:"intensive_rate",basis:"host-flag",suppressed:!1}:Ht(t.name)?{nature:e,additivity:"intensive_rate",basis:"name",suppressed:!1}:{nature:e,additivity:"additive",basis:"default",suppressed:!1}}function Rt(n){let t=Nt(n),e=n??{};if(t.nature==="Categorical")return["first","distinctcount","count"];if(t.nature==="Ordinal")return Yt(e)?["median","average","min","max","first","distinctcount","count"]:["first","distinctcount","count"];switch(t.additivity){case"positional":return["min","max","count","distinctcount","first"];case"intensive_rate":return["average","median","min","max","count","distinctcount","first"];default:return["sum","average","median","min","max","count","distinctcount","first"]}}function Se(n){return Rt(n)[0]}function Ce(n,t){return Rt(n).indexOf(t)>=0}function Me(n,t){if(t!=="sum"&&t!=="count")return!1;if(t==="count")return!0;let e=Nt(n);return e.additivity==="additive"||e.additivity==="part_of_whole"||e.additivity==="unknown"}var Zt=12,$t=100,Xt=.3,jt=.9,qt=120,Jt=1900,Qt=2100,te=0,ee=20,ne=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function ie(n){if(!n)return!1;let t=X(n);return t.length===0?!1:ne.has(t[t.length-1])}var se=new Set(["year","yr","fy"]),re=n=>X(n).some(t=>se.has(t)),oe=/^(?:(?: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 et(n){if(!Number.isInteger(n)||n<190001||n>210012)return!1;let t=n%100;return t>=1&&t<=12}function nt(n){if(!Number.isInteger(n)||n<19000101||n>21001231)return!1;let t=Math.floor(n/100)%100,e=n%100;return t>=1&&t<=12&&e>=1&&e<=31}var ae=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,ue=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,le=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function ce(n){let t=(n||"").toLowerCase();return t==="en-us"||t==="en"||t.startsWith("en-us-")||t==="en-ph"||t==="en-bz"}function wt(n,t){let e=0,r=0,o=0,s=0,a=0,l="",c=0,f="",M=0,h=0,O=0,d=0,v=!1;for(let K of n){if(K==null)continue;let U=String(K).trim();if(U==="")continue;e++;let G;if(G=ae.exec(U)){let V=+G[2],i=+G[3];V>=1&&V<=12&&i>=1&&i<=31&&(r++,G[4]!==void 0&&o++,G[6]!==void 0&&s++)}else if(G=ue.exec(U)){let V=+G[3],i=+G[4];V>=1&&V<=12&&i>=1&&i<=31&&(l&&l!==G[2]&&(v=!0),l=G[2],a++)}else if(G=le.exec(U)){let V=+G[1],i=+G[3];V>=1&&V<=31&&i>=1&&i<=31&&(V<=12||i<=12)&&(f&&f!==G[2]&&(v=!0),f=G[2],c++,V>12&&O++,i>12&&d++,G[5]!==void 0&&M++,G[7]!==void 0&&h++)}if(e>=200)break}if(e<2||(r+a+c)/e<.8||(r>0?1:0)+(a>0?1:0)+(c>0?1:0)!==1||v)return null;if(r>0)return o===r?{pattern:s===r?"%Y-%m-%dT%H:%M:%S":"%Y-%m-%dT%H:%M",orderFrom:"iso"}:{pattern:"%Y-%m-%d",orderFrom:"iso"};if(a>0)return{pattern:`%Y${l}%m${l}%d`,orderFrom:"iso"};if(O>0&&d>0)return null;let x,T;O>0?(x=!0,T="values"):d>0?(x=!1,T="values"):(x=!ce(t),T="locale");let F=x?`%d${f}%m${f}%Y`:`%m${f}%d${f}%Y`;return M===c?{pattern:F+(h===c?" %H:%M:%S":" %H:%M"),orderFrom:T}:{pattern:F,orderFrom:T}}function me(n,t){if(!t||!/\b(?:19|20)\d{2}\b/.test(n))return!1;let e=n.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!e)return!1;let r=dt(e);return r.length>0&&t[r]!==void 0}function fe(n){let{dataType:t,name:e,isMeasure:r,distinctCount:o}=n;if(t==="DateTime")return!0;if(r)return!1;if(t==="Integer"||t==="Decimal"){let s=n.minNum,a=n.maxNum;if(!(s!=null&&a!=null&&Number.isFinite(s)&&Number.isFinite(a)&&Number.isInteger(s)&&Number.isInteger(a)&&a>=s))return!1;let c=s>=1900&&a<=2100;if(c&&o>=2&&re(e)||c&&o>=3&&o===a-s+1)return!0;let f=et(s)&&et(a),M=nt(s)&&nt(a);if(f||M){if(!n.sampleValues)return!0;let h=0,O=0;for(let d of n.sampleValues){if(d==null||d==="")continue;h++;let v=Number(String(d).trim());if(Number.isFinite(v)&&(f?et(v):nt(v))&&O++,h>=60)break}if(h>=2&&O===h)return!0}return!1}if(n.sampleValues){let s=n.locale?gt(n.locale):null,a=0,l=0,c=[];for(let f of n.sampleValues){if(f==null||f==="")continue;a++;let M=String(f).trim();if(c.push(M),(oe.test(M)||me(M,s))&&l++,a>=60)break}if(a>=2&&l/a>=.8||wt(c,n.locale)!==null)return!0}return!1}function de(n){let t=(n||"").trim().toLowerCase();return t.startsWith("sum ")||t.startsWith("total ")?"sum":t.startsWith("average ")||t.startsWith("avg. ")?"avg":t.startsWith("count ")||t.startsWith("distinct count ")||t.startsWith("count (distinct) ")?"count":t.startsWith("min ")||t.startsWith("minimum ")?"min":t.startsWith("max ")||t.startsWith("maximum ")?"max":null}function ge(n){let{rows:t,measureColIdx:e,measureName:r,candidateDims:o,minNum:s,maxNum:a,discourageAgg:l}=n,c=100,f=.01,M="";for(let O of o){if(O.distinct<2||O.distinct>c)continue;let d=o.filter(T=>T.idx!==O.idx).map(T=>T.idx),v=new Map;for(let T of t){let F=T[e];if(typeof F!="number"||!Number.isFinite(F))continue;let K=d.length?d.map(G=>String(T[G])).join(M):"",U=v.get(K);U||(U={sum:0,cset:new Set},v.set(K,U)),U.sum+=F,U.cset.add(String(T[O.idx]))}let I=0,A=0,x=0;for(let T of v.values())T.cset.size<2||(x++,Math.abs(T.sum-100)<=100*f?I++:Math.abs(T.sum-1)<=1*f&&A++);if(x>=2&&(I/x>=.9||A/x>=.9))return{additivity:"part_of_whole",partOfWholeDim:O.name}}if(l)return{additivity:"intensive_rate"};let h=de(r);return h==="avg"||h==="min"||h==="max"?{additivity:"intensive_rate"}:h==="count"?{additivity:"additive"}:h==="sum"?{additivity:"unknown"}:s!=null&&a!=null&&Number.isFinite(s)&&Number.isFinite(a)&&s>=0&&a<=1.0001&&a>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function It(n){let{dataType:t,isMeasure:e,name:r,distinct:o,nonblank:s,prec:a,maxval:l,minval:c}=n,f=l-c+1,M=f>0?o/f:1,h=s>0?o/s:0,O=t==="Decimal"||a>0;return ie(r)?"Categorical":M>=jt&&(ot(r)&&o<=qt||c>=Jt&&l<=Qt||c>=te&&l<=ee)?"Ordinal":e||o>Zt&&(O||o>=$t||h>=Xt)?"Continuous":"Categorical"}var xt=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;emitLegacyAggAliases=!1;STR(t){return t==null?"":t instanceof Date?this.wholeDayIso(t)??(isNaN(t.getTime())?"":t.toISOString()):t.toString()}getPrecision(t){if(!isFinite(t))return 0;let r=t.toString().split(".")[1];return r?r.length:0}getColumns(){return this._cols}wholeDayIso(t){if(!(t instanceof Date)||isNaN(t.getTime()))return null;let e=r=>(r<10?"0":"")+r;return t.getUTCHours()===0&&t.getUTCMinutes()===0&&t.getUTCSeconds()===0&&t.getUTCMilliseconds()===0?t.toISOString().slice(0,10):t.getHours()===0&&t.getMinutes()===0&&t.getSeconds()===0&&t.getMilliseconds()===0?`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`:null}hasTimeComponent(t){return!(t instanceof Date)||isNaN(t.getTime())?!1:this.wholeDayIso(t)===null}getColumnsWithStats(t,e){if(this._computedStatsForLevel==t)return this._cols;let r=0,o=parseInt(t),s=[];for(let i of this._cols){let m=new Map,E=[],p=0,u=0,y=0,S=null,b=null,g=null,D=!1,N=!0,w=!0,P=null,W=!1;for(let R of this._rows){let C=R[r],_=this.STR(C);if(_!=""){if(p+=_.length,m.set(_,(m.get(_)||0)+1),u++,i.dataType=="Integer"||i.dataType=="Decimal"||i.dataType=="DateTime")if((S===null||C<S)&&(S=C),(b===null||C>b)&&(b=C),i.dataType=="Integer"||i.dataType=="Decimal"){if(g===null?g=C:g+=C,i.dataType=="Decimal"){let L=this.getPrecision(C);L>y&&(y=L)}E.push(C)}else D=D||this.hasTimeComponent(C);W&&(C<P?N=!1:C>P&&(w=!1)),P=C,W=!0}}if(u>=3&&(N&&!w?i.sortedDirection="asc":w&&!N?i.sortedDirection="desc":i.sortedDirection="none"),u>0&&m.size>0&&!i.isMeasure){let R=0,C=Number.MAX_SAFE_INTEGER;for(let _ of m.values())_>R&&(R=_),_<C&&(C=_);if(i.modalShare=R/u,i.minGroupCount=C===Number.MAX_SAFE_INTEGER?null:C,m.size===2){let _=[...m.keys()].map(k=>st(k).trim().toLowerCase()).sort(),z=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(k=>_[0]===k[0]&&_[1]===k[1]),B=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(i.name);(z||B)&&(i.isBinaryFlag=!0)}}if(i.dataType=="DateTime"&&(i.dateWithTime=D),i.isTemporal=fe({dataType:i.dataType,name:i.name,isMeasure:i.isMeasure,distinctCount:m.size,minNum:typeof S=="number"?S:null,maxNum:typeof b=="number"?b:null,sampleValues:m.keys(),locale:e}),i.isTemporal&&i.dataType==="String"&&!i.isMeasure){let R=wt(m.keys(),e);R&&(i.temporalTextPattern=R.pattern)}this.updateColumnStats10(o,i,u,m,y,b,S),this.updateColumnStats20(o,E,u,g,i,p,D,S,b,y,m,e),!i.isMeasure&&(i.dataType==="Integer"||i.dataType==="Decimal")&&It({dataType:i.dataType,isMeasure:!1,name:i.name,distinct:m.size,nonblank:u,prec:y,maxval:typeof b=="number"?b:0,minval:typeof S=="number"?S:0})==="Continuous"&&(i.isMeasure=!0,i.geoKind=void 0,i.geoMatchPct=void 0,i.geoAmbiguous=void 0,i.dominantGeoRegion=void 0,i.dominantGeoRegionPct=void 0,i.geoRegionCount=void 0),s[r]=i.isMeasure||m.size>2e3?null:new Set(m.keys()),r++}let a=[];this._cols.forEach((i,m)=>{i.isMeasure||a.push({idx:m,distinct:i.distinctCount??0,name:i.name})}),this._cols.forEach((i,m)=>{if(!i.isMeasure)return;let E=typeof i.lowValue=="number"?i.lowValue:null,p=typeof i.highValue=="number"?i.highValue:null,u=ge({rows:this._rows,measureColIdx:m,measureName:i.name,candidateDims:a,minNum:E,maxNum:p,discourageAgg:!!i.discourageAggregationAcrossGroups});i.additivity=u.additivity,u.partOfWholeDim&&(i.partOfWholeDim=u.partOfWholeDim)});let l=50,c=a.filter(i=>i.distinct>=2&&i.distinct<=l);this._cols.forEach((i,m)=>{if(!i.isMeasure)return;let E=[];for(let _ of this._rows){let L=_[m];if(L==null||L==="")continue;let z=typeof L=="number"?L:parseFloat(L);isNaN(z)||E.push(z)}if(E.length===0)return;let p=[...E].sort((_,L)=>_-L),u=_=>p[Math.min(p.length-1,Math.max(0,Math.floor(_*(p.length-1))))],y=u(.5),S=u(.1),b=u(.9),g=Math.abs(y)>1e-9?Math.abs(y):Math.abs(p[p.length-1])>1e-9?Math.abs(p[p.length-1]):1;i.relativeDispersion=Math.round((b-S)/g*1e3)/1e3;let D=[];for(let _ of c){let L=new Set;for(let z of this._rows){let B=z[m];B==null||B===""||L.add(this.STR(z[_.idx])+"")}D.push({otherColumn:_.name,nonBlankGroupCount:L.size})}D.length>0&&(i.nonBlankGroups=D);let N=0;for(let _ of E)N+=_;N/=E.length;let w=0;for(let _ of E)w+=(_-N)*(_-N);if(w<=1e-12)return;let P=[],W=[],R=_=>{if(_.length<4)return NaN;let L=[..._].sort((B,k)=>B-k),z=B=>L[Math.min(L.length-1,Math.max(0,Math.floor(B*(L.length-1))))];return z(.75)-z(.25)},C=R(E);for(let _ of c){let L=new Map;for(let k of this._rows){let H=k[m];if(H==null||H==="")continue;let $=typeof H=="number"?H:parseFloat(H);if(isNaN($))continue;let it=this.STR(k[_.idx])+"",q=L.get(it);q?(q.s+=$,q.n++,q.vals.push($)):L.set(it,{s:$,n:1,vals:[$]})}let z=0;for(let k of L.values()){let H=k.s/k.n;z+=k.n*(H-N)*(H-N)}P.push({otherColumn:_.name,eta2:Math.round(z/w*1e4)/1e4});let B=[];for(let k of L.values()){let H=R(k.vals);isNaN(H)||B.push(H)}if(B.length>=2&&isFinite(C)&&C>1e-9){let k=(Math.max(...B)-Math.min(...B))/C;W.push({otherColumn:_.name,spreadRatio:Math.round(k*1e4)/1e4})}}P.length>0&&(i.groupDiscrimination=P),W.length>0&&(i.spreadDiscrimination=W)});let f=.97,M=5,h=this._cols.map((i,m)=>({c:i,i:m})).filter(i=>i.c.isMeasure);for(let i=0;i<h.length;i++)for(let m=i+1;m<h.length;m++){let E=h[i].i,p=h[m].i,u=0,y=0,S=0,b=0,g=0,D=0;for(let W of this._rows){let R=W[E],C=W[p];if(R==null||R===""||C===null||C===void 0||C==="")continue;let _=typeof R=="number"?R:parseFloat(R),L=typeof C=="number"?C:parseFloat(C);isNaN(_)||isNaN(L)||(u++,y+=_,S+=L,b+=_*_,g+=L*L,D+=_*L)}if(u<M)continue;let N=u*b-y*y,w=u*g-S*S;if(N<=1e-12||w<=1e-12)continue;let P=(u*D-y*S)/Math.sqrt(N*w);if(Math.abs(P)>=f){let W=h[i].c,R=h[m].c;W.collinearWithMeasures||(W.collinearWithMeasures=[]),R.collinearWithMeasures||(R.collinearWithMeasures=[]),W.collinearWithMeasures.push(R.name),R.collinearWithMeasures.push(W.name)}}for(let i=0;i<this._cols.length;i++){let m=s[i];if(!m||m.size===0)continue;let E=[];for(let p=0;p<this._cols.length;p++){if(p===i)continue;let u=s[p];if(!u||u.size===0)continue;let y=0;for(let b of m)u.has(b)&&y++;let S=Math.round(y/m.size*100);S>0&&E.push({otherColumn:this._cols[p].name,percentShared:S})}E.length>0&&(this._cols[i].sharedValueRatioWithOthers=E)}let O=50,d=[];for(let i=0;i<this._cols.length;i++){let m=s[i];m&&m.size>=2&&m.size<=O&&d.push(i)}if(d.length>=2){let i=new Map,m=(p,u)=>p+":"+u;for(let p=0;p<d.length;p++)for(let u=p+1;u<d.length;u++)i.set(m(d[p],d[u]),new Map);for(let p of this._rows)for(let u=0;u<d.length;u++){let y=this.STR(p[d[u]])+"";for(let S=u+1;S<d.length;S++){let b=""+this.STR(p[d[S]]),g=i.get(m(d[u],d[S])),D=y+""+b;g.set(D,(g.get(D)??0)+1)}}let E=new Map;for(let p=0;p<d.length;p++)for(let u=p+1;u<d.length;u++){let y=d[p],S=d[u],b=s[y].size,g=s[S].size,D=i.get(m(y,S)),N=D.size,w=0;for(let C of D.values())(w===0||C<w)&&(w=C);let P=Math.round(N/(b*g)*100),W=N===b,R=N===g;if((this._cols[y].categoricalPairStats||=[]).push({otherColumn:this._cols[S].name,fillPct:P,determinesOther:W,minCellCount:w,distinctCombinations:N}),(this._cols[S].categoricalPairStats||=[]).push({otherColumn:this._cols[y].name,fillPct:P,determinesOther:R,minCellCount:w,distinctCombinations:N}),W&&b>g){let C=E.get(y);(!C||g<C.card)&&E.set(y,{name:this._cols[S].name,card:g,ratio:g/b})}if(R&&g>b){let C=E.get(S);(!C||b<C.card)&&E.set(S,{name:this._cols[y].name,card:b,ratio:b/g})}}for(let[p,u]of E)this._cols[p].primaryParentColumn=u.name,this._cols[p].nestingRatio=Math.round(u.ratio*100)/100}let v=6,I=this._rows.length;for(let i=0;i<this._cols.length;i++){let m=this._cols[i];if(m.isMeasure||m.primaryParentColumn)continue;let E=m.distinctCount??0;if(E<=O||I>0&&E>=I)continue;let p=[];for(let u=0;u<this._cols.length;u++){if(u===i)continue;let y=this._cols[u];if(y.isMeasure)continue;let S=y.distinctCount??0;S<2||S>=E||p.push(u)}p.sort((u,y)=>(this._cols[u].distinctCount??0)-(this._cols[y].distinctCount??0));for(let u of p.slice(0,v)){let y=new Map,S=!0;for(let g of this._rows){let D=this.STR(g[i])+"",N=this.STR(g[u])+"",w=y.get(D);if(w===void 0)y.set(D,N);else if(w!==N){S=!1;break}}if(!S)continue;let b=this._cols[u].distinctCount??0;m.primaryParentColumn=this._cols[u].name,m.nestingRatio=Math.round(b/E*100)/100;break}}let A=.01,x=.05,T=.95,F=8,K=8,U=6,G=500,V=[];for(let i=0;i<this._cols.length&&V.length<K;i++){let m=this._cols[i].dataType;(m==="Double"||m==="Integer"||m==="Decimal")&&V.push(i)}if(V.length>=3&&this._rows.length>=F){let i=Math.min(this._rows.length,G),m=V.map(b=>{let g=[];for(let w=0;w<i;w++){let P=this._rows[w][b],W=typeof P=="number"?P:parseFloat(String(P).replace(/,/g,""));if(P==null||P===""||!isFinite(W))return null;g.push(W)}let D=g[0],N=!1;for(let w of g)if(w!==D){N=!0;break}return N?g:null}),E=V.map((b,g)=>g).filter(b=>m[b]!==null),p=b=>{let g=b.slice().sort((N,w)=>N-w),D=g.length>>1;return g.length%2?g[D]:(g[D-1]+g[D])/2},u=null,y=[],S=b=>{if(y.length>=3){let g=y.map(P=>m[P]),D=g[0].length,N=new Array(D);for(let P=0;P<D;P++){let W=0;for(let R of g)W+=R[P];N[P]=W}let w=p(N);if(w>0){let P=0;for(let R of N)Math.abs(R-w)<=w*A&&P++;let W=P/D;if(W>=T){let R=1;for(let C of g){let _=p(C)/w;_<R&&(R=_)}R>=x&&(!u||y.length>u.cols.length)&&(u={cols:y.slice(),total:w,matched:W})}}}if(!(y.length>=U))for(let g=b;g<E.length;g++)y.push(E[g]),S(g+1),y.pop()};if(S(0),u){let b=u,D={columns:b.cols.map(N=>this._cols[V[N]].name),total:Math.round(b.total*1e3)/1e3,matchedPct:Math.round(b.matched*100)/100};for(let N of b.cols)this._cols[V[N]].constantSumGroup=D}}return this._computedStatsForLevel=t,this._cols}updateColumnStats20(t,e,r,o,s,a,l,c,f,M,h,O){if(t>=20){let d=[...e].sort((A,x)=>A-x),v=Math.floor(d.length/2);if(r>0&&o!=null?s.avgValue=s.dataType=="Integer"?Math.round(o/r):o/r:s.avgValue=null,r>0&&(s.avgLength=a/r),this._rows.length>0){let A=x=>{let T=x instanceof Date?x:new Date(x),F=this.wholeDayIso(T);return F?F+"T00:00:00.000Z":isNaN(T.getTime())?x:T.toISOString().slice(0,10)+"T00:00:00.000Z"};s.dataType!="DateTime"||l||!c?s.lowValue=c:s.lowValue=A(c),s.dataType!="DateTime"||l||!f?s.highValue=f:s.highValue=A(f),s.medianValue=d.length===0?null:d.length%2===0?s.dataType=="Integer"?Math.round((d[v-1]+d[v])/2):(d[v-1]+d[v])/2:d[v],s.numericPrecision=M}if(d.length>0){let A=s.avgValue??0,x=d.length,T=0,F=0;for(let U of d){let G=U-A;T+=G*G,F+=G*G*G}let K=T/x;s.skewness=K===0?0:F/x/Math.pow(Math.sqrt(K),3),s.stdDev=Math.sqrt(K)}o!==null&&(s.sum=o);let I=Array.from(h.entries()).sort((A,x)=>x[1]-A[1]);if(s.topCategories=I.slice(0,10).map(A=>A[1]),!s.isMeasure&&I.length>0){if(s.dataType==="String"){let A=I.map(T=>T[0]);s.formatSignature=ft(A);let x=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;s.formatSignature&&!x.test(s.formatSignature)&&(s.avgLength===void 0||s.avgLength>=3)&&(s.isFreeText=!0)}else s.topCategoryValues=I.slice(0,5).map(A=>A[0]);if(t>=20){let A=I.map(T=>T[0]),x=ut(A,O);if(x!==null)s.ordinalPattern=x.pattern,s.orderedDomain=x.orderedDomain;else if(s.dataType==="String"){let T=at(A);T!==null&&(s.safeDistinctValues=T)}}}if(d.length>=8&&(s.dataType==="Integer"||s.dataType==="Decimal")){let A=x=>d[Math.floor((d.length-1)*x)];s.quantiles={p05:A(.05),p25:A(.25),p75:A(.75),p95:A(.95)}}}if(!s.isMeasure&&h.size>0){let d=Array.from(h.entries()).sort((I,A)=>A[1]-I[1]),v=mt(d.map(I=>I[0]),s.name,O);if(v!==null&&(s.geoKind=v.geoKind,s.geoMatchPct=v.geoMatchPct,v.geoAmbiguous&&(s.geoAmbiguous=!0),v.geoKind.indexOf("country")===0)){let I=tt(d);I&&(s.dominantGeoRegion=I.dominantGeoRegion,s.dominantGeoRegionPct=I.dominantGeoRegionPct,s.geoRegionCount=I.regionCount)}}}updateColumnStats10(t,e,r,o,s,a,l){t>=10&&(e.blankCount=this._rows.length-r,e.distinctCount=o.size+(e.blankCount!=0?1:0),e.valueNature="Categorical",r>0&&(e.dataType==="Integer"||e.dataType==="Decimal"?e.valueNature=It({dataType:e.dataType,isMeasure:!!e.isMeasure,name:e.name,distinct:o.size,nonblank:r,prec:s,maxval:a,minval:l}):e.dataType==="DateTime"&&(e.valueNature=e.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let t=[];if(this._cols.forEach((r,o)=>{r.isMeasure||t.push(o)}),t.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let e=new Set;for(let r of this._rows)e.add(JSON.stringify(t.map(o=>r[o])));return this._leafCardinality=e.size,this._leafCardinality}_leafCardinality=null;getGeoExtent(){if(this._geoExtentComputed)return this._geoExtent;this._geoExtentComputed=!0,this._geoExtent=null;let t=a=>String(a||"").replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/),e=-1,r=-1,o=-1;if(this._cols.forEach((a,l)=>{let c=t(a.name),f=a.dataType==="Integer"||a.dataType==="Decimal";f&&e<0&&c.some(M=>M==="lat"||M==="latitude")?e=l:f&&r<0&&c.some(M=>M==="lon"||M==="lng"||M==="long"||M==="longitude")&&(r=l),o<0&&!a.isMeasure&&typeof a.geoKind=="string"&&a.geoKind.indexOf("country")===0&&(o=l)}),e<0||r<0)return null;let s=[];for(let a of this._rows){let l=a[e],c=a[r],f=l==null||l===""?null:Number(l),M=c==null||c===""?null:Number(c);s.push({lat:f,lon:M,country:o>=0&&Q(this.STR(a[o]))?this.STR(a[o]):null})}return this._geoExtent=bt(s),this._geoExtent}_geoExtent=null;_geoExtentComputed=!1;obfuscateString(t){let e="abcdefghijklmnopqrstuvwxyz",r=()=>e[Math.floor(Z()*e.length)],o=()=>r().toUpperCase(),s=()=>Math.floor(Z()*10).toString(),a=v=>/[A-Z]/.test(v)?o():/[a-z]/.test(v)?r():/[0-9]/.test(v)?s():v,l=t.includes("@")&&t.includes("."),c=l?t.split("@"):[t],f=l?c[1]:"",M=f.endsWith(".com"),h=M?".com":"",O=M?f.slice(0,-4):f,d=v=>{let I="";for(let A of v)I+=a(A),/[a-zA-Z0-9]/.test(A)&&Z()<.2&&(I+=a(A));if(I.length>6){let A=Math.floor(Z()*Math.min(3,I.length-6));for(let x=0;x<A;x++){let T=0;for(;T<5;){let F=Math.floor(Z()*I.length);if(/[a-zA-Z0-9]/.test(I[F])){I=I.slice(0,F)+I.slice(F+1);break}T++}}}return I};if(l){let v=d(c[0]),I=d(O);return`${v}@${I}${h}`}else return d(t)}toObjectArray(){return this._rows.map(t=>{let e={};return this._cols.forEach((r,o)=>{e[r.name]=t[o],this.emitLegacyAggAliases&&r.hostName&&r.hostName!==r.name&&!Object.prototype.hasOwnProperty.call(e,r.hostName)&&(e[r.hostName]=t[o])}),e})}async getCSVAsync(t){let e=[],r=t?25:1e7,o=t?4e3:1e7,s=new Map;for(let l of this._rows){let c={};for(let f=0;f<this._cols.length;f++){let M=this._cols[f],h=l[f];if(this.STR(h)!=""){if(t&&M.dataType=="String")if(s.has(h))h=s.get(h);else{let O=this.obfuscateString(h);s.set(h,O),h=O}else if(M.dataType=="DateTime"&&!M.dateWithTime){let O=h instanceof Date?h:new Date(h);h=(this.wholeDayIso(O)??O.toISOString().slice(0,10))+"T00:00:00.000Z"}o-=this.STR(h).length}else h=null;c[f]=h,--o}if(e.push(c),--r,r<=0||o<=0)break}return await vt.unparse(e,{header:!1})}getCSVHeaderLine(){return vt.unparse([this._cols.map(t=>this.STR(this.emitLegacyAggAliases&&t.hostName?t.hostName:t.name))])}addRow(t,e){if(this.dedupRows){let r="";for(let s of t)r+=this.STR(s)+"~";let o=rt(r);if(this._rowHashes.has(o))return!1;this._rowHashes.add(o)}return this._rows.push(t),this._origIndices.push(e??-1),!0}getOriginalRowIndex(t){return t<0||t>=this._origIndices.length?-1:this._origIndices[t]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(t){if(this._cols=t,!t||t.length===0)return;let e=new Set(t.map(r=>this.STR(r?.name)));for(let r of t){if(!r)continue;let o=this.STR(r.name),s=Ct(o);!s||s===o||e.has(s)||(e.delete(o),e.add(s),r.hostName=o,r.name=s)}}};export{bt as a,Ot as b,Q as c,pe as d,Lt as e,Pt as f,Gt as g,Wt as h,St as i,Ut as j,Ct as k,_e as l,At as m,Ht as n,Nt as o,Rt as p,Se as q,Ce as r,Me as s,ie as t,wt as u,fe as v,de as w,ge as x,It as y,xt as z};
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 Yt,b as Jt}from"./chunk-UQU75XXR.mjs";import{a as Xt,b as jt}from"./chunk-D7BASZT7.mjs";import{a as At,b as xt,c as St,d as Tt,e as vt,f as Mt,g as _t,h as kt,i as Lt,j as Nt,k as wt,l as Ot,m as Et,n as zt,o as Gt,p as $t,q as Dt,r as Ft,s as Bt,t as Kt,u as Ht,v as Vt,w as Wt,x as qt,y as Zt,z as Ut}from"./chunk-KFKKFBBT.mjs";import{a as Rt}from"./chunk-QEH7WTLB.mjs";import{a as It,b as bt}from"./chunk-2LR73DNS.mjs";import{a as V,b as W,c as yt,d as ht,e as Pt,f as Ct}from"./chunk-7MHZMBRK.mjs";import{a as T,f as R,g as y,h as I,i as w,j as st,k as at,l as H,m,n as lt,o as ct,p as ut,q as b,r as ft,s as pt,t as mt,u as gt,v as O,w as dt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as ot,b as it,c as rt}from"./chunk-NNUL5RKC.mjs";import{a as J,b as Q,c as tt,d as nt,e as et}from"./chunk-U43WE7LN.mjs";var E=2,U=400;function G(r){return!!R(r)}function C(r){let e=new Set;for(let n of r){if(n==null)continue;let s=T(String(n));if(!I(s)&&!e.has(s)&&(e.add(s),e.size>=U))break}return Array.from(e)}function P(r){let e=C(r);if(e.length===0||$(r)<95)return!1;let n=e.filter(c=>G(c)&&!m(c)).length,s=e.filter(c=>!G(c)&&!!m(c)).length;return n>=1&&n>=s}function q(r,e){if(!m(r))return!1;let n=R(r);return n?e==="world"?!0:H.has(n):!1}function $(r){let e=C(r);if(e.length===0)return 0;let n=0;for(let s of e)G(s)&&n++;return Math.round(n/e.length*1e3)/10}function v(r){let e=C(r);if(e.length===0)return 0;let n=0;for(let s of e)m(s)&&n++;return Math.round(n/e.length*1e3)/10}function F(r){let e=new Set;for(let n of r){if(n==null)continue;let s=String(n).trim();if(!I(T(s))&&!e.has(s)&&(e.add(s),e.size>=U))break}return Array.from(e)}function D(r){let e=F(r);if(e.length===0)return 0;let n=0;for(let s of e)b(s).length>0&&n++;return Math.round(n/e.length*1e3)/10}function Z(r,e){return W(e,V)?!0:F(r).some(n=>/^\d{5}(-\d{4})?$/.test(n.replace(/\.0+$/,"")))}function Qt(r,e){let n=C(r);if(n.length===0)return 0;let s=0;for(let c of n)O(c,e)&&s++;return Math.round(s/n.length*1e3)/10}function z(r,e){let n=0;for(let s of C(r))e(s)&&n++;return n}function tn(r,e){let n=0;for(let s of F(r))e(s)&&n++;return n}function nn(r,e,n,s,c){let A=[],u=[],o={},M={},_=new Set(r),l=t=>e.map(i=>i[t]);for(let t of["city","country"]){let i=n?.[t];i&&_.has(i)&&(o[t]=i)}let X=new Set(c??r);for(let t of["lat","lon"]){let i=n?.[t];i&&X.has(i)&&(o[t]=i)}let g=n?.zip;if(g&&_.has(g)){let t=l(g),i=D(t);i<95?u.push(`zip=${g} (only ${i}% of values read as ZIPs)`):Z(t,g)?o.zip=g:u.push(`zip=${g} (all values are 3-4 digits with nothing to say they are postal)`)}let p=n?.state;if(p&&_.has(p)){let t=l(p),i=C(t);i.length>0&&i.every(a=>q(a,s))?u.push(`state=${p} (every value is "CA", which is both Canada and California)`):P(t)?(u.push(`state=${p} (every value is a country, not a state)`),o.country||(o.country=p)):v(t)<95?u.push(`state=${p} (only ${v(t)}% of values are states/provinces)`):o.state=p}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=l(i);if(P(a))continue;let f=v(a);if(f<95)continue;let N=z(a,S=>!!m(S)),Y=z(a,S=>!!m(S)&&!q(S,s));N<E&&Y<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.state=t.name,d.add(t.name),A.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of x){if(d.has(t))continue;let i=l(t),a=D(i);if(!(a<95)&&Z(i,t)&&!(tn(i,f=>b(f).length>0)<E)){o.zip=t,d.add(t),A.push(`zip=${t} (${a}% ZIP codes)`);break}}let h=o.country;if(!h||!P(l(h))){let t=null;for(let i of x){if(d.has(i)||!P(l(i)))continue;let a=$(l(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(u.push(`country=${h} (only ${$(l(h))}% of values are country identifiers; using ${t.name} instead)`),M.country=h),o.country=t.name,d.add(t.name),A.push(`country=${t.name}`))}if(!o.city){let t=null;for(let i of x){if(d.has(i))continue;let a=l(i),f=Qt(a,s);f<w||z(a,N=>O(N,s))<E||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.city=t.name,A.push(`city=${t.name} (${t.pct}% known cities)`))}let B=o.country?l(o.country):[],k=!!o.country&&P(B),j=k?new Set(B.map(t=>R(t==null?null:String(t))).filter(Boolean)).size:0,K=k&&j>=2,L=!!(o.lat&&o.lon)&&e.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&&u.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!K&&!(o.city||o.state||o.zip||L)&&u.push(k?`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||K||L)?o:null,backfilled:A,refused:u,...Object.keys(M).length?{labelFallback:M}:{}}}export{w as CITY_ROLE_MATCH_PCT,nt as GET_RANDOM,Mt as INTENSIVE_SUFFIX_TOKENS,vt as INTENSIVE_WORD_TOKENS,Ut as IndexedText,kt as POSITIONAL_SUFFIX_TOKENS,_t as POSITIONAL_WORD_TOKENS,Yt as PREVIEW_OMITTED_FIELDS,y as ROLE_MATCH_PCT,tt as SIMPLE_STRING_HASH,Q as STR,v as admin1MatchPct,$t as allowedAggregations,Ct as buildGeoIsoColumn,mt as buildGeoPointColumns,dt as cityMatchPct,gt as cityTagsFor,qt as classifyAdditivity,Gt as classifyForAggregation,Zt as classifyNumericValueNature,Vt as classifyTemporal,Ot as codeNeedsLegacyAggNames,wt as collapseRepeatedAggPrefix,St as countryRegion,Dt as defaultAggregation,Rt as detectFormatSignature,yt as detectGeo,rt as detectOrdinalDomain,Ht as detectTextDatePattern,Xt as engineTypeForSqlType,Nt as hasDefaultAggPrefix,Wt as hostAggHint,jt as ingest,Ft as isAggregationAllowed,I as isBlankLike,at as isCityTableLoaded,et as isDeterministicRefusal,ft as isGeoPointAmbiguity,Kt as isIdentifierName,Pt as isJoinGeoKind,ot as isOrdinalFriendlyName,P as looksLikeCountryColumn,bt as monthLookupFor,zt as nameLooksIntensiveRate,Et as nameLooksPositional,J as nameWords,lt as normalizeCountry,It as normalizeMonthKey,T as normalizePlaceName,ut as normalizeZip5,Jt as payloadPreview,st as registerCityTable,xt as registerIso3Regions,m as resolveAdmin1,pt as resolveGeoPoint,nn as resolvePointRoles,it as safeDistinctValuesToShip,Bt as shareOfTotalIsHonest,Lt as stripHostAggPrefix,Tt as summarizeCountryRegions,At as summarizeGeoExtent,ht as toGeoIso,D as zipMatchPct,b as zipPrefixCandidates,ct as zipToPrefix3};
2
+ import{a as Yt,b as Jt}from"./chunk-UQU75XXR.mjs";import{a as Xt,b as jt}from"./chunk-3TQECQFH.mjs";import{a as At,b as xt,c as St,d as Tt,e as vt,f as Mt,g as _t,h as kt,i as Lt,j as Nt,k as wt,l as Ot,m as Et,n as zt,o as Gt,p as $t,q as Dt,r as Ft,s as Bt,t as Kt,u as Ht,v as Vt,w as Wt,x as qt,y as Zt,z as Ut}from"./chunk-VLKG6RD7.mjs";import{a as Rt}from"./chunk-QEH7WTLB.mjs";import{a as It,b as bt}from"./chunk-2LR73DNS.mjs";import{a as V,b as W,c as yt,d as ht,e as Pt,f as Ct}from"./chunk-7MHZMBRK.mjs";import{a as T,f as R,g as y,h as I,i as w,j as st,k as at,l as H,m,n as lt,o as ct,p as ut,q as b,r as ft,s as pt,t as mt,u as gt,v as O,w as dt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as ot,b as it,c as rt}from"./chunk-NNUL5RKC.mjs";import{a as J,b as Q,c as tt,d as nt,e as et}from"./chunk-U43WE7LN.mjs";var E=2,U=400;function G(r){return!!R(r)}function C(r){let e=new Set;for(let n of r){if(n==null)continue;let s=T(String(n));if(!I(s)&&!e.has(s)&&(e.add(s),e.size>=U))break}return Array.from(e)}function P(r){let e=C(r);if(e.length===0||$(r)<95)return!1;let n=e.filter(c=>G(c)&&!m(c)).length,s=e.filter(c=>!G(c)&&!!m(c)).length;return n>=1&&n>=s}function q(r,e){if(!m(r))return!1;let n=R(r);return n?e==="world"?!0:H.has(n):!1}function $(r){let e=C(r);if(e.length===0)return 0;let n=0;for(let s of e)G(s)&&n++;return Math.round(n/e.length*1e3)/10}function v(r){let e=C(r);if(e.length===0)return 0;let n=0;for(let s of e)m(s)&&n++;return Math.round(n/e.length*1e3)/10}function F(r){let e=new Set;for(let n of r){if(n==null)continue;let s=String(n).trim();if(!I(T(s))&&!e.has(s)&&(e.add(s),e.size>=U))break}return Array.from(e)}function D(r){let e=F(r);if(e.length===0)return 0;let n=0;for(let s of e)b(s).length>0&&n++;return Math.round(n/e.length*1e3)/10}function Z(r,e){return W(e,V)?!0:F(r).some(n=>/^\d{5}(-\d{4})?$/.test(n.replace(/\.0+$/,"")))}function Qt(r,e){let n=C(r);if(n.length===0)return 0;let s=0;for(let c of n)O(c,e)&&s++;return Math.round(s/n.length*1e3)/10}function z(r,e){let n=0;for(let s of C(r))e(s)&&n++;return n}function tn(r,e){let n=0;for(let s of F(r))e(s)&&n++;return n}function nn(r,e,n,s,c){let A=[],u=[],o={},M={},_=new Set(r),l=t=>e.map(i=>i[t]);for(let t of["city","country"]){let i=n?.[t];i&&_.has(i)&&(o[t]=i)}let X=new Set(c??r);for(let t of["lat","lon"]){let i=n?.[t];i&&X.has(i)&&(o[t]=i)}let g=n?.zip;if(g&&_.has(g)){let t=l(g),i=D(t);i<95?u.push(`zip=${g} (only ${i}% of values read as ZIPs)`):Z(t,g)?o.zip=g:u.push(`zip=${g} (all values are 3-4 digits with nothing to say they are postal)`)}let p=n?.state;if(p&&_.has(p)){let t=l(p),i=C(t);i.length>0&&i.every(a=>q(a,s))?u.push(`state=${p} (every value is "CA", which is both Canada and California)`):P(t)?(u.push(`state=${p} (every value is a country, not a state)`),o.country||(o.country=p)):v(t)<95?u.push(`state=${p} (only ${v(t)}% of values are states/provinces)`):o.state=p}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=l(i);if(P(a))continue;let f=v(a);if(f<95)continue;let N=z(a,S=>!!m(S)),Y=z(a,S=>!!m(S)&&!q(S,s));N<E&&Y<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.state=t.name,d.add(t.name),A.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of x){if(d.has(t))continue;let i=l(t),a=D(i);if(!(a<95)&&Z(i,t)&&!(tn(i,f=>b(f).length>0)<E)){o.zip=t,d.add(t),A.push(`zip=${t} (${a}% ZIP codes)`);break}}let h=o.country;if(!h||!P(l(h))){let t=null;for(let i of x){if(d.has(i)||!P(l(i)))continue;let a=$(l(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(u.push(`country=${h} (only ${$(l(h))}% of values are country identifiers; using ${t.name} instead)`),M.country=h),o.country=t.name,d.add(t.name),A.push(`country=${t.name}`))}if(!o.city){let t=null;for(let i of x){if(d.has(i))continue;let a=l(i),f=Qt(a,s);f<w||z(a,N=>O(N,s))<E||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.city=t.name,A.push(`city=${t.name} (${t.pct}% known cities)`))}let B=o.country?l(o.country):[],k=!!o.country&&P(B),j=k?new Set(B.map(t=>R(t==null?null:String(t))).filter(Boolean)).size:0,K=k&&j>=2,L=!!(o.lat&&o.lon)&&e.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&&u.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!K&&!(o.city||o.state||o.zip||L)&&u.push(k?`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||K||L)?o:null,backfilled:A,refused:u,...Object.keys(M).length?{labelFallback:M}:{}}}export{w as CITY_ROLE_MATCH_PCT,nt as GET_RANDOM,Mt as INTENSIVE_SUFFIX_TOKENS,vt as INTENSIVE_WORD_TOKENS,Ut as IndexedText,kt as POSITIONAL_SUFFIX_TOKENS,_t as POSITIONAL_WORD_TOKENS,Yt as PREVIEW_OMITTED_FIELDS,y as ROLE_MATCH_PCT,tt as SIMPLE_STRING_HASH,Q as STR,v as admin1MatchPct,$t as allowedAggregations,Ct as buildGeoIsoColumn,mt as buildGeoPointColumns,dt as cityMatchPct,gt as cityTagsFor,qt as classifyAdditivity,Gt as classifyForAggregation,Zt as classifyNumericValueNature,Vt as classifyTemporal,Ot as codeNeedsLegacyAggNames,wt as collapseRepeatedAggPrefix,St as countryRegion,Dt as defaultAggregation,Rt as detectFormatSignature,yt as detectGeo,rt as detectOrdinalDomain,Ht as detectTextDatePattern,Xt as engineTypeForSqlType,Nt as hasDefaultAggPrefix,Wt as hostAggHint,jt as ingest,Ft as isAggregationAllowed,I as isBlankLike,at as isCityTableLoaded,et as isDeterministicRefusal,ft as isGeoPointAmbiguity,Kt as isIdentifierName,Pt as isJoinGeoKind,ot as isOrdinalFriendlyName,P as looksLikeCountryColumn,bt as monthLookupFor,zt as nameLooksIntensiveRate,Et as nameLooksPositional,J as nameWords,lt as normalizeCountry,It as normalizeMonthKey,T as normalizePlaceName,ut as normalizeZip5,Jt as payloadPreview,st as registerCityTable,xt as registerIso3Regions,m as resolveAdmin1,pt as resolveGeoPoint,nn as resolvePointRoles,it as safeDistinctValuesToShip,Bt as shareOfTotalIsHonest,Lt as stripHostAggPrefix,Tt as summarizeCountryRegions,At as summarizeGeoExtent,ht as toGeoIso,D as zipMatchPct,b as zipPrefixCandidates,ct as zipToPrefix3};
@@ -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{t as a,u as b,v as c,w as d,x as e,y as f,z as g}from"./chunk-KFKKFBBT.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-7MHZMBRK.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NNUL5RKC.mjs";import"./chunk-U43WE7LN.mjs";export{g as IndexedText,e as classifyAdditivity,f as classifyNumericValueNature,c as classifyTemporal,b as detectTextDatePattern,d as hostAggHint,a as isIdentifierName};
2
+ import{t as a,u as b,v as c,w as d,x as e,y as f,z as g}from"./chunk-VLKG6RD7.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-7MHZMBRK.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NNUL5RKC.mjs";import"./chunk-U43WE7LN.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-D7BASZT7.mjs";import"./chunk-KFKKFBBT.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-7MHZMBRK.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NNUL5RKC.mjs";import"./chunk-U43WE7LN.mjs";export{a as engineTypeForSqlType,b as ingest};
2
+ import{a,b}from"./chunk-3TQECQFH.mjs";import"./chunk-VLKG6RD7.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-7MHZMBRK.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NNUL5RKC.mjs";import"./chunk-U43WE7LN.mjs";export{a as engineTypeForSqlType,b as ingest};
@@ -100,6 +100,30 @@ export declare class IndexedText implements IValueCollection {
100
100
  private STR;
101
101
  private getPrecision;
102
102
  getColumns(): LLMColumnWithValue[];
103
+ /**
104
+ * The calendar day a WHOLE-DAY Date stands for, as "YYYY-MM-DD" - or null when the Date
105
+ * carries a real time of day.
106
+ *
107
+ * THIS IS THE ONE PLACE A DATE IS ALLOWED TO BECOME A DAY, and it exists because the
108
+ * previous code asked `getHours()` - LOCAL time - of Dates that had been built in UTC.
109
+ * The Excel add-in converts a serial with `Date.UTC(1899,11,30)+days`; an ISO text date
110
+ * parses to UTC midnight; the visual's date-unshredder builds `Date.UTC(y,m,d)`. On any
111
+ * machine west of Greenwich every one of those read as 16:00 or 17:00 the PREVIOUS day, so
112
+ * `dateWithTime` was true for every date column, `valueNature` flipped from Ordinal to
113
+ * Continuous - a picker input - and the day printed one earlier than the cell showed.
114
+ *
115
+ * WHY BOTH FRAMES. A Date is whole-day if it is midnight in EITHER UTC or local time,
116
+ * because both kinds exist in the wild: the sources above build UTC midnight, while a
117
+ * Date parsed from a timezone-less ISO datetime (Power BI's host hands those over) is
118
+ * LOCAL midnight. Reading only UTC would have fixed Excel by breaking the visual. The day
119
+ * is then taken from the frame the Date is midnight in, which is the day the author meant.
120
+ *
121
+ * THE RESIDUAL EDGE, stated rather than hidden: a genuine timestamp that happens to fall
122
+ * exactly on the local-vs-UTC offset (17:00 PDT is 00:00Z) reads as a whole day. The
123
+ * column-level flag is an OR over every value, so a column is only misread if EVERY value
124
+ * sits on that exact minute - a dataset that is, for every practical purpose, a date column.
125
+ */
126
+ private wholeDayIso;
103
127
  private hasTimeComponent;
104
128
  getColumnsWithStats(privacyLevel: string, locale?: string): LLMColumnWithValue[];
105
129
  private updateColumnStats20;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/shape-core",
3
- "version": "0.5.84",
3
+ "version": "0.5.85",
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",
@@ -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 ft}from"./chunk-QEH7WTLB.mjs";import{a as dt,b as gt}from"./chunk-2LR73DNS.mjs";import{c as mt}from"./chunk-7MHZMBRK.mjs";import{b as lt,f as ct}from"./chunk-E6SVTFAW.mjs";import{a as ot,b as at,c as ut}from"./chunk-NNUL5RKC.mjs";import{a as $,b as st,c as rt,d as Z}from"./chunk-U43WE7LN.mjs";var Et=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],Dt=[7,72,-172,-52];function pt(n,t,e){return n>=e[0]&&n<=e[1]&&t>=e[2]&&t<=e[3]}function J(n,t){if(!n.length)return NaN;if(n.length===1)return n[0];let e=(n.length-1)*t,r=Math.floor(e),o=Math.ceil(e);return r===o?n[r]:n[r]+(n[o]-n[r])*(e-r)}var Y=n=>Math.round(n*10)/10;function bt(n,t=3){let e=[],r=[],o=0,s=0;for(let l of n){let c=l?.lat,f=l?.lon;if(typeof c!="number"||typeof f!="number"||!isFinite(c)||!isFinite(f)||c<-90||c>90||f<-180||f>180)continue;e.push(c),r.push(f);let M=l?.country?String(l.country).trim().toUpperCase():"",h=M?Q(M):null;h?((M==="US"||M==="USA")&&o++,h==="north-america"&&s++):(Et.some(P=>pt(c,f,P))&&o++,pt(c,f,Dt)&&s++)}let a=e.length;return a<t?null:(e.sort((l,c)=>l-c),r.sort((l,c)=>l-c),{pctUsa:Y(o/a*100),pctNa:Y(s/a*100),latP5:Y(J(e,.05)),latP95:Y(J(e,.95)),lonP5:Y(J(r,.05)),lonP95:Y(J(r,.95)),n:a})}var ht={"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"},j=(()=>{let n=new Map;for(let t of Object.keys(ht))for(let e of ht[t].split(/\s+/))e&&n.set(e,t);return n})();function Ot(n){for(let[t,e]of n){let r=j.get(t);r&&!j.has(e)&&j.set(e,r)}}Ot(lt);function Q(n){if(!n)return null;let t=String(n).trim().toUpperCase();if(!t)return null;let e=j.get(t);if(e)return e;let r=ct(String(n));return r?j.get(r)??null:null}function he(n,t=2){return tt(n.map(e=>[e,1]),t)}function tt(n,t=2){let e=new Map,r=0;for(let[a,l]of n){let c=Q(a);if(!c)continue;let f=typeof l=="number"&&isFinite(l)&&l>0?l:1;e.set(c,(e.get(c)??0)+f),r+=f}if(r<t||!e.size)return null;let o="europe",s=-1;for(let a of Array.from(e.keys()).sort()){let l=e.get(a);l>s&&(o=a,s=l)}return{dominantGeoRegion:o,dominantGeoRegionPct:Y(s/r*100),regionCount:e.size,n:r}}import vt from"papaparse";var Lt=["rate","ratio","pct","percent","percentage","rating","share","score","index","nps","csat","margin","yield","coverage","utilization","z[_-]?score","average","avg","mean","median","stddev","variance","gpa","percentile","quantile","efficiency","accuracy","probability","multiplier","coefficient","correlation","occupancy","age","bmi","temperature","density","pressure","humidity","ph","velocity","speed","elevation","altitude","latency","throughput","bandwidth","iops"],Pt=["pct","percent","percentage","rate","ratio","rating","share","score","index","nps","csat","margin","yield","coverage","utilization","gpa","percentile","quantile","bmi","density","pressure","humidity","velocity","efficiency","occupancy","latency","throughput","bandwidth","iops"],Gt=["latitude","longitude"],Wt=["latitude","longitude"],_t=/^\s*(sum|count|count\s+distinct|distinct\s+count)\s+of\s+/i,Ft=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])/g,Vt=new RegExp("\\b("+Lt.join("|")+")\\b|("+Pt.join("|")+")$","i"),kt=new RegExp("\\b("+Gt.join("|")+")\\b|("+Wt.join("|")+")$","i");function St(n){return n?String(n).replace(_t,"").trim():""}function Bt(n){return!!n&&_t.test(String(n))}var zt=["count (distinct)","count distinct","distinct count","standard deviation","average","variance","median","product","stddev","std dev","count","sum","avg","min","minimum","max","maximum","var"],yt=new RegExp("^\\s*("+[...zt].sort((n,t)=>t.length-n.length).map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+")).join("|")+")\\s+of\\s+","i");function Ct(n){if(n==null)return"";let t=String(n),e=yt.exec(t);if(!e)return t;let r=l=>l.toLowerCase().replace(/\s+/g," ").trim(),o=r(e[1]),s=t.slice(e[0].length),a=0;for(;a<8;){let l=yt.exec(s);if(!l||r(l[1])!==o)break;let c=s.slice(l[0].length);if(c.trim()==="")break;s=c,a++}return a===0?t:t.slice(0,e[0].length)+s}function _e(n,t){if(!n||!t)return!1;let e=String(n);for(let r of t){let o=r?.hostName;if(o&&o!==r?.name&&e.includes(o))return!0}return!1}function Ut(n){let t=St(n);return t.length===0?"":t.replace(Ft," ")}function Mt(n,t){if(!t)return!1;let e=St(t);return n.test(Ut(t))||n.test(e)||n.test($(e).join(" "))}function At(n){return Mt(kt,n)}function Ht(n){return Mt(Vt,n)||At(n)}var Tt=/int|double|decimal|single|float|number|currency|money/i;function Kt(n){let t=String(n?.valueNature??"").trim().toLowerCase();return t==="categorical"?"Categorical":t==="ordinal"?"Ordinal":t==="continuous"||n?.isMeasure===!0||Tt.test(String(n?.dataType??""))?"Continuous":"Categorical"}function Yt(n){return n?.isMeasure===!0||Tt.test(String(n?.dataType??""))}function Rt(n){let t=n??{},e=Kt(t);if(e!=="Continuous")return{nature:e,additivity:"unknown",basis:"role",suppressed:!1};if(At(t.name))return{nature:e,additivity:"positional",basis:"name",suppressed:!0};let r=String(t.additivity??"").trim().toLowerCase();if(!(r==="additive"&&Bt(t.name))){if(r==="additive")return{nature:e,additivity:"additive",basis:"measured",suppressed:!1};if(r==="part_of_whole")return{nature:e,additivity:"part_of_whole",basis:"measured",suppressed:!1};if(r==="intensive_rate")return{nature:e,additivity:"intensive_rate",basis:"measured",suppressed:!1}}return t.discourageAggregationAcrossGroups===!0?{nature:e,additivity:"intensive_rate",basis:"host-flag",suppressed:!1}:Ht(t.name)?{nature:e,additivity:"intensive_rate",basis:"name",suppressed:!1}:{nature:e,additivity:"additive",basis:"default",suppressed:!1}}function Nt(n){let t=Rt(n),e=n??{};if(t.nature==="Categorical")return["first","distinctcount","count"];if(t.nature==="Ordinal")return Yt(e)?["median","average","min","max","first","distinctcount","count"]:["first","distinctcount","count"];switch(t.additivity){case"positional":return["min","max","count","distinctcount","first"];case"intensive_rate":return["average","median","min","max","count","distinctcount","first"];default:return["sum","average","median","min","max","count","distinctcount","first"]}}function Se(n){return Nt(n)[0]}function Ce(n,t){return Nt(n).indexOf(t)>=0}function Me(n,t){if(t!=="sum"&&t!=="count")return!1;if(t==="count")return!0;let e=Rt(n);return e.additivity==="additive"||e.additivity==="part_of_whole"||e.additivity==="unknown"}var Zt=12,Xt=100,$t=.3,jt=.9,qt=120,Jt=1900,Qt=2100,te=0,ee=20,ne=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function ie(n){if(!n)return!1;let t=$(n);return t.length===0?!1:ne.has(t[t.length-1])}var se=new Set(["year","yr","fy"]),re=n=>$(n).some(t=>se.has(t)),oe=/^(?:(?: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 et(n){if(!Number.isInteger(n)||n<190001||n>210012)return!1;let t=n%100;return t>=1&&t<=12}function nt(n){if(!Number.isInteger(n)||n<19000101||n>21001231)return!1;let t=Math.floor(n/100)%100,e=n%100;return t>=1&&t<=12&&e>=1&&e<=31}var ae=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,ue=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,le=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function ce(n){let t=(n||"").toLowerCase();return t==="en-us"||t==="en"||t.startsWith("en-us-")||t==="en-ph"||t==="en-bz"}function wt(n,t){let e=0,r=0,o=0,s=0,a=0,l="",c=0,f="",M=0,h=0,P=0,d=0,v=!1;for(let K of n){if(K==null)continue;let B=String(K).trim();if(B==="")continue;e++;let G;if(G=ae.exec(B)){let F=+G[2],i=+G[3];F>=1&&F<=12&&i>=1&&i<=31&&(r++,G[4]!==void 0&&o++,G[6]!==void 0&&s++)}else if(G=ue.exec(B)){let F=+G[3],i=+G[4];F>=1&&F<=12&&i>=1&&i<=31&&(l&&l!==G[2]&&(v=!0),l=G[2],a++)}else if(G=le.exec(B)){let F=+G[1],i=+G[3];F>=1&&F<=31&&i>=1&&i<=31&&(F<=12||i<=12)&&(f&&f!==G[2]&&(v=!0),f=G[2],c++,F>12&&P++,i>12&&d++,G[5]!==void 0&&M++,G[7]!==void 0&&h++)}if(e>=200)break}if(e<2||(r+a+c)/e<.8||(r>0?1:0)+(a>0?1:0)+(c>0?1:0)!==1||v)return null;if(r>0)return o===r?{pattern:s===r?"%Y-%m-%dT%H:%M:%S":"%Y-%m-%dT%H:%M",orderFrom:"iso"}:{pattern:"%Y-%m-%d",orderFrom:"iso"};if(a>0)return{pattern:`%Y${l}%m${l}%d`,orderFrom:"iso"};if(P>0&&d>0)return null;let w,T;P>0?(w=!0,T="values"):d>0?(w=!1,T="values"):(w=!ce(t),T="locale");let k=w?`%d${f}%m${f}%Y`:`%m${f}%d${f}%Y`;return M===c?{pattern:k+(h===c?" %H:%M:%S":" %H:%M"),orderFrom:T}:{pattern:k,orderFrom:T}}function me(n,t){if(!t||!/\b(?:19|20)\d{2}\b/.test(n))return!1;let e=n.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!e)return!1;let r=dt(e);return r.length>0&&t[r]!==void 0}function fe(n){let{dataType:t,name:e,isMeasure:r,distinctCount:o}=n;if(t==="DateTime")return!0;if(r)return!1;if(t==="Integer"||t==="Decimal"){let s=n.minNum,a=n.maxNum;if(!(s!=null&&a!=null&&Number.isFinite(s)&&Number.isFinite(a)&&Number.isInteger(s)&&Number.isInteger(a)&&a>=s))return!1;let c=s>=1900&&a<=2100;if(c&&o>=2&&re(e)||c&&o>=3&&o===a-s+1)return!0;let f=et(s)&&et(a),M=nt(s)&&nt(a);if(f||M){if(!n.sampleValues)return!0;let h=0,P=0;for(let d of n.sampleValues){if(d==null||d==="")continue;h++;let v=Number(String(d).trim());if(Number.isFinite(v)&&(f?et(v):nt(v))&&P++,h>=60)break}if(h>=2&&P===h)return!0}return!1}if(n.sampleValues){let s=n.locale?gt(n.locale):null,a=0,l=0,c=[];for(let f of n.sampleValues){if(f==null||f==="")continue;a++;let M=String(f).trim();if(c.push(M),(oe.test(M)||me(M,s))&&l++,a>=60)break}if(a>=2&&l/a>=.8||wt(c,n.locale)!==null)return!0}return!1}function de(n){let t=(n||"").trim().toLowerCase();return t.startsWith("sum ")||t.startsWith("total ")?"sum":t.startsWith("average ")||t.startsWith("avg. ")?"avg":t.startsWith("count ")||t.startsWith("distinct count ")||t.startsWith("count (distinct) ")?"count":t.startsWith("min ")||t.startsWith("minimum ")?"min":t.startsWith("max ")||t.startsWith("maximum ")?"max":null}function ge(n){let{rows:t,measureColIdx:e,measureName:r,candidateDims:o,minNum:s,maxNum:a,discourageAgg:l}=n,c=100,f=.01,M="";for(let P of o){if(P.distinct<2||P.distinct>c)continue;let d=o.filter(T=>T.idx!==P.idx).map(T=>T.idx),v=new Map;for(let T of t){let k=T[e];if(typeof k!="number"||!Number.isFinite(k))continue;let K=d.length?d.map(G=>String(T[G])).join(M):"",B=v.get(K);B||(B={sum:0,cset:new Set},v.set(K,B)),B.sum+=k,B.cset.add(String(T[P.idx]))}let x=0,A=0,w=0;for(let T of v.values())T.cset.size<2||(w++,Math.abs(T.sum-100)<=100*f?x++:Math.abs(T.sum-1)<=1*f&&A++);if(w>=2&&(x/w>=.9||A/w>=.9))return{additivity:"part_of_whole",partOfWholeDim:P.name}}if(l)return{additivity:"intensive_rate"};let h=de(r);return h==="avg"||h==="min"||h==="max"?{additivity:"intensive_rate"}:h==="count"?{additivity:"additive"}:h==="sum"?{additivity:"unknown"}:s!=null&&a!=null&&Number.isFinite(s)&&Number.isFinite(a)&&s>=0&&a<=1.0001&&a>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function xt(n){let{dataType:t,isMeasure:e,name:r,distinct:o,nonblank:s,prec:a,maxval:l,minval:c}=n,f=l-c+1,M=f>0?o/f:1,h=s>0?o/s:0,P=t==="Decimal"||a>0;return ie(r)?"Categorical":M>=jt&&(ot(r)&&o<=qt||c>=Jt&&l<=Qt||c>=te&&l<=ee)?"Ordinal":e||o>Zt&&(P||o>=Xt||h>=$t)?"Continuous":"Categorical"}var It=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;emitLegacyAggAliases=!1;STR(t){return t==null?"":t.toString()}getPrecision(t){if(!isFinite(t))return 0;let r=t.toString().split(".")[1];return r?r.length:0}getColumns(){return this._cols}hasTimeComponent(t){return!(t instanceof Date)||isNaN(t.getTime())?!1:t.getHours()!==0||t.getMinutes()!==0||t.getSeconds()!==0||t.getMilliseconds()!==0}getColumnsWithStats(t,e){if(this._computedStatsForLevel==t)return this._cols;let r=0,o=parseInt(t),s=[];for(let i of this._cols){let m=new Map,E=[],p=0,u=0,y=0,S=null,b=null,g=null,D=!1,R=!0,I=!0,L=null,W=!1;for(let N of this._rows){let C=N[r],_=this.STR(C);if(_!=""){if(p+=_.length,m.set(_,(m.get(_)||0)+1),u++,i.dataType=="Integer"||i.dataType=="Decimal"||i.dataType=="DateTime")if((S===null||C<S)&&(S=C),(b===null||C>b)&&(b=C),i.dataType=="Integer"||i.dataType=="Decimal"){if(g===null?g=C:g+=C,i.dataType=="Decimal"){let O=this.getPrecision(C);O>y&&(y=O)}E.push(C)}else D=D||this.hasTimeComponent(C);W&&(C<L?R=!1:C>L&&(I=!1)),L=C,W=!0}}if(u>=3&&(R&&!I?i.sortedDirection="asc":I&&!R?i.sortedDirection="desc":i.sortedDirection="none"),u>0&&m.size>0&&!i.isMeasure){let N=0,C=Number.MAX_SAFE_INTEGER;for(let _ of m.values())_>N&&(N=_),_<C&&(C=_);if(i.modalShare=N/u,i.minGroupCount=C===Number.MAX_SAFE_INTEGER?null:C,m.size===2){let _=[...m.keys()].map(V=>st(V).trim().toLowerCase()).sort(),U=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(V=>_[0]===V[0]&&_[1]===V[1]),z=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(i.name);(U||z)&&(i.isBinaryFlag=!0)}}if(i.dataType=="DateTime"&&(i.dateWithTime=D),i.isTemporal=fe({dataType:i.dataType,name:i.name,isMeasure:i.isMeasure,distinctCount:m.size,minNum:typeof S=="number"?S:null,maxNum:typeof b=="number"?b:null,sampleValues:m.keys(),locale:e}),i.isTemporal&&i.dataType==="String"&&!i.isMeasure){let N=wt(m.keys(),e);N&&(i.temporalTextPattern=N.pattern)}this.updateColumnStats10(o,i,u,m,y,b,S),this.updateColumnStats20(o,E,u,g,i,p,D,S,b,y,m,e),!i.isMeasure&&(i.dataType==="Integer"||i.dataType==="Decimal")&&xt({dataType:i.dataType,isMeasure:!1,name:i.name,distinct:m.size,nonblank:u,prec:y,maxval:typeof b=="number"?b:0,minval:typeof S=="number"?S:0})==="Continuous"&&(i.isMeasure=!0,i.geoKind=void 0,i.geoMatchPct=void 0,i.geoAmbiguous=void 0,i.dominantGeoRegion=void 0,i.dominantGeoRegionPct=void 0,i.geoRegionCount=void 0),s[r]=i.isMeasure||m.size>2e3?null:new Set(m.keys()),r++}let a=[];this._cols.forEach((i,m)=>{i.isMeasure||a.push({idx:m,distinct:i.distinctCount??0,name:i.name})}),this._cols.forEach((i,m)=>{if(!i.isMeasure)return;let E=typeof i.lowValue=="number"?i.lowValue:null,p=typeof i.highValue=="number"?i.highValue:null,u=ge({rows:this._rows,measureColIdx:m,measureName:i.name,candidateDims:a,minNum:E,maxNum:p,discourageAgg:!!i.discourageAggregationAcrossGroups});i.additivity=u.additivity,u.partOfWholeDim&&(i.partOfWholeDim=u.partOfWholeDim)});let l=50,c=a.filter(i=>i.distinct>=2&&i.distinct<=l);this._cols.forEach((i,m)=>{if(!i.isMeasure)return;let E=[];for(let _ of this._rows){let O=_[m];if(O==null||O==="")continue;let U=typeof O=="number"?O:parseFloat(O);isNaN(U)||E.push(U)}if(E.length===0)return;let p=[...E].sort((_,O)=>_-O),u=_=>p[Math.min(p.length-1,Math.max(0,Math.floor(_*(p.length-1))))],y=u(.5),S=u(.1),b=u(.9),g=Math.abs(y)>1e-9?Math.abs(y):Math.abs(p[p.length-1])>1e-9?Math.abs(p[p.length-1]):1;i.relativeDispersion=Math.round((b-S)/g*1e3)/1e3;let D=[];for(let _ of c){let O=new Set;for(let U of this._rows){let z=U[m];z==null||z===""||O.add(this.STR(U[_.idx])+"")}D.push({otherColumn:_.name,nonBlankGroupCount:O.size})}D.length>0&&(i.nonBlankGroups=D);let R=0;for(let _ of E)R+=_;R/=E.length;let I=0;for(let _ of E)I+=(_-R)*(_-R);if(I<=1e-12)return;let L=[],W=[],N=_=>{if(_.length<4)return NaN;let O=[..._].sort((z,V)=>z-V),U=z=>O[Math.min(O.length-1,Math.max(0,Math.floor(z*(O.length-1))))];return U(.75)-U(.25)},C=N(E);for(let _ of c){let O=new Map;for(let V of this._rows){let H=V[m];if(H==null||H==="")continue;let X=typeof H=="number"?H:parseFloat(H);if(isNaN(X))continue;let it=this.STR(V[_.idx])+"",q=O.get(it);q?(q.s+=X,q.n++,q.vals.push(X)):O.set(it,{s:X,n:1,vals:[X]})}let U=0;for(let V of O.values()){let H=V.s/V.n;U+=V.n*(H-R)*(H-R)}L.push({otherColumn:_.name,eta2:Math.round(U/I*1e4)/1e4});let z=[];for(let V of O.values()){let H=N(V.vals);isNaN(H)||z.push(H)}if(z.length>=2&&isFinite(C)&&C>1e-9){let V=(Math.max(...z)-Math.min(...z))/C;W.push({otherColumn:_.name,spreadRatio:Math.round(V*1e4)/1e4})}}L.length>0&&(i.groupDiscrimination=L),W.length>0&&(i.spreadDiscrimination=W)});let f=.97,M=5,h=this._cols.map((i,m)=>({c:i,i:m})).filter(i=>i.c.isMeasure);for(let i=0;i<h.length;i++)for(let m=i+1;m<h.length;m++){let E=h[i].i,p=h[m].i,u=0,y=0,S=0,b=0,g=0,D=0;for(let W of this._rows){let N=W[E],C=W[p];if(N==null||N===""||C===null||C===void 0||C==="")continue;let _=typeof N=="number"?N:parseFloat(N),O=typeof C=="number"?C:parseFloat(C);isNaN(_)||isNaN(O)||(u++,y+=_,S+=O,b+=_*_,g+=O*O,D+=_*O)}if(u<M)continue;let R=u*b-y*y,I=u*g-S*S;if(R<=1e-12||I<=1e-12)continue;let L=(u*D-y*S)/Math.sqrt(R*I);if(Math.abs(L)>=f){let W=h[i].c,N=h[m].c;W.collinearWithMeasures||(W.collinearWithMeasures=[]),N.collinearWithMeasures||(N.collinearWithMeasures=[]),W.collinearWithMeasures.push(N.name),N.collinearWithMeasures.push(W.name)}}for(let i=0;i<this._cols.length;i++){let m=s[i];if(!m||m.size===0)continue;let E=[];for(let p=0;p<this._cols.length;p++){if(p===i)continue;let u=s[p];if(!u||u.size===0)continue;let y=0;for(let b of m)u.has(b)&&y++;let S=Math.round(y/m.size*100);S>0&&E.push({otherColumn:this._cols[p].name,percentShared:S})}E.length>0&&(this._cols[i].sharedValueRatioWithOthers=E)}let P=50,d=[];for(let i=0;i<this._cols.length;i++){let m=s[i];m&&m.size>=2&&m.size<=P&&d.push(i)}if(d.length>=2){let i=new Map,m=(p,u)=>p+":"+u;for(let p=0;p<d.length;p++)for(let u=p+1;u<d.length;u++)i.set(m(d[p],d[u]),new Map);for(let p of this._rows)for(let u=0;u<d.length;u++){let y=this.STR(p[d[u]])+"";for(let S=u+1;S<d.length;S++){let b=""+this.STR(p[d[S]]),g=i.get(m(d[u],d[S])),D=y+""+b;g.set(D,(g.get(D)??0)+1)}}let E=new Map;for(let p=0;p<d.length;p++)for(let u=p+1;u<d.length;u++){let y=d[p],S=d[u],b=s[y].size,g=s[S].size,D=i.get(m(y,S)),R=D.size,I=0;for(let C of D.values())(I===0||C<I)&&(I=C);let L=Math.round(R/(b*g)*100),W=R===b,N=R===g;if((this._cols[y].categoricalPairStats||=[]).push({otherColumn:this._cols[S].name,fillPct:L,determinesOther:W,minCellCount:I,distinctCombinations:R}),(this._cols[S].categoricalPairStats||=[]).push({otherColumn:this._cols[y].name,fillPct:L,determinesOther:N,minCellCount:I,distinctCombinations:R}),W&&b>g){let C=E.get(y);(!C||g<C.card)&&E.set(y,{name:this._cols[S].name,card:g,ratio:g/b})}if(N&&g>b){let C=E.get(S);(!C||b<C.card)&&E.set(S,{name:this._cols[y].name,card:b,ratio:b/g})}}for(let[p,u]of E)this._cols[p].primaryParentColumn=u.name,this._cols[p].nestingRatio=Math.round(u.ratio*100)/100}let v=6,x=this._rows.length;for(let i=0;i<this._cols.length;i++){let m=this._cols[i];if(m.isMeasure||m.primaryParentColumn)continue;let E=m.distinctCount??0;if(E<=P||x>0&&E>=x)continue;let p=[];for(let u=0;u<this._cols.length;u++){if(u===i)continue;let y=this._cols[u];if(y.isMeasure)continue;let S=y.distinctCount??0;S<2||S>=E||p.push(u)}p.sort((u,y)=>(this._cols[u].distinctCount??0)-(this._cols[y].distinctCount??0));for(let u of p.slice(0,v)){let y=new Map,S=!0;for(let g of this._rows){let D=this.STR(g[i])+"",R=this.STR(g[u])+"",I=y.get(D);if(I===void 0)y.set(D,R);else if(I!==R){S=!1;break}}if(!S)continue;let b=this._cols[u].distinctCount??0;m.primaryParentColumn=this._cols[u].name,m.nestingRatio=Math.round(b/E*100)/100;break}}let A=.01,w=.05,T=.95,k=8,K=8,B=6,G=500,F=[];for(let i=0;i<this._cols.length&&F.length<K;i++){let m=this._cols[i].dataType;(m==="Double"||m==="Integer"||m==="Decimal")&&F.push(i)}if(F.length>=3&&this._rows.length>=k){let i=Math.min(this._rows.length,G),m=F.map(b=>{let g=[];for(let I=0;I<i;I++){let L=this._rows[I][b],W=typeof L=="number"?L:parseFloat(String(L).replace(/,/g,""));if(L==null||L===""||!isFinite(W))return null;g.push(W)}let D=g[0],R=!1;for(let I of g)if(I!==D){R=!0;break}return R?g:null}),E=F.map((b,g)=>g).filter(b=>m[b]!==null),p=b=>{let g=b.slice().sort((R,I)=>R-I),D=g.length>>1;return g.length%2?g[D]:(g[D-1]+g[D])/2},u=null,y=[],S=b=>{if(y.length>=3){let g=y.map(L=>m[L]),D=g[0].length,R=new Array(D);for(let L=0;L<D;L++){let W=0;for(let N of g)W+=N[L];R[L]=W}let I=p(R);if(I>0){let L=0;for(let N of R)Math.abs(N-I)<=I*A&&L++;let W=L/D;if(W>=T){let N=1;for(let C of g){let _=p(C)/I;_<N&&(N=_)}N>=w&&(!u||y.length>u.cols.length)&&(u={cols:y.slice(),total:I,matched:W})}}}if(!(y.length>=B))for(let g=b;g<E.length;g++)y.push(E[g]),S(g+1),y.pop()};if(S(0),u){let b=u,D={columns:b.cols.map(R=>this._cols[F[R]].name),total:Math.round(b.total*1e3)/1e3,matchedPct:Math.round(b.matched*100)/100};for(let R of b.cols)this._cols[F[R]].constantSumGroup=D}}return this._computedStatsForLevel=t,this._cols}updateColumnStats20(t,e,r,o,s,a,l,c,f,M,h,P){if(t>=20){let d=[...e].sort((A,w)=>A-w),v=Math.floor(d.length/2);if(r>0&&o!=null?s.avgValue=s.dataType=="Integer"?Math.round(o/r):o/r:s.avgValue=null,r>0&&(s.avgLength=a/r),this._rows.length>0){let A=w=>{let T=new Date(w);return isNaN(T.getTime())?w:T.toISOString().slice(0,10)+"T00:00:00.000Z"};s.dataType!="DateTime"||l||!c?s.lowValue=c:s.lowValue=A(c),s.dataType!="DateTime"||l||!f?s.highValue=f:s.highValue=A(f),s.medianValue=d.length===0?null:d.length%2===0?s.dataType=="Integer"?Math.round((d[v-1]+d[v])/2):(d[v-1]+d[v])/2:d[v],s.numericPrecision=M}if(d.length>0){let A=s.avgValue??0,w=d.length,T=0,k=0;for(let B of d){let G=B-A;T+=G*G,k+=G*G*G}let K=T/w;s.skewness=K===0?0:k/w/Math.pow(Math.sqrt(K),3),s.stdDev=Math.sqrt(K)}o!==null&&(s.sum=o);let x=Array.from(h.entries()).sort((A,w)=>w[1]-A[1]);if(s.topCategories=x.slice(0,10).map(A=>A[1]),!s.isMeasure&&x.length>0){if(s.dataType==="String"){let A=x.map(T=>T[0]);s.formatSignature=ft(A);let w=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;s.formatSignature&&!w.test(s.formatSignature)&&(s.avgLength===void 0||s.avgLength>=3)&&(s.isFreeText=!0)}else s.topCategoryValues=x.slice(0,5).map(A=>A[0]);if(t>=20){let A=x.map(T=>T[0]),w=ut(A,P);if(w!==null)s.ordinalPattern=w.pattern,s.orderedDomain=w.orderedDomain;else if(s.dataType==="String"){let T=at(A);T!==null&&(s.safeDistinctValues=T)}}}if(d.length>=8&&(s.dataType==="Integer"||s.dataType==="Decimal")){let A=w=>d[Math.floor((d.length-1)*w)];s.quantiles={p05:A(.05),p25:A(.25),p75:A(.75),p95:A(.95)}}}if(!s.isMeasure&&h.size>0){let d=Array.from(h.entries()).sort((x,A)=>A[1]-x[1]),v=mt(d.map(x=>x[0]),s.name,P);if(v!==null&&(s.geoKind=v.geoKind,s.geoMatchPct=v.geoMatchPct,v.geoAmbiguous&&(s.geoAmbiguous=!0),v.geoKind.indexOf("country")===0)){let x=tt(d);x&&(s.dominantGeoRegion=x.dominantGeoRegion,s.dominantGeoRegionPct=x.dominantGeoRegionPct,s.geoRegionCount=x.regionCount)}}}updateColumnStats10(t,e,r,o,s,a,l){t>=10&&(e.blankCount=this._rows.length-r,e.distinctCount=o.size+(e.blankCount!=0?1:0),e.valueNature="Categorical",r>0&&(e.dataType==="Integer"||e.dataType==="Decimal"?e.valueNature=xt({dataType:e.dataType,isMeasure:!!e.isMeasure,name:e.name,distinct:o.size,nonblank:r,prec:s,maxval:a,minval:l}):e.dataType==="DateTime"&&(e.valueNature=e.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let t=[];if(this._cols.forEach((r,o)=>{r.isMeasure||t.push(o)}),t.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let e=new Set;for(let r of this._rows)e.add(JSON.stringify(t.map(o=>r[o])));return this._leafCardinality=e.size,this._leafCardinality}_leafCardinality=null;getGeoExtent(){if(this._geoExtentComputed)return this._geoExtent;this._geoExtentComputed=!0,this._geoExtent=null;let t=a=>String(a||"").replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/),e=-1,r=-1,o=-1;if(this._cols.forEach((a,l)=>{let c=t(a.name),f=a.dataType==="Integer"||a.dataType==="Decimal";f&&e<0&&c.some(M=>M==="lat"||M==="latitude")?e=l:f&&r<0&&c.some(M=>M==="lon"||M==="lng"||M==="long"||M==="longitude")&&(r=l),o<0&&!a.isMeasure&&typeof a.geoKind=="string"&&a.geoKind.indexOf("country")===0&&(o=l)}),e<0||r<0)return null;let s=[];for(let a of this._rows){let l=a[e],c=a[r],f=l==null||l===""?null:Number(l),M=c==null||c===""?null:Number(c);s.push({lat:f,lon:M,country:o>=0&&Q(this.STR(a[o]))?this.STR(a[o]):null})}return this._geoExtent=bt(s),this._geoExtent}_geoExtent=null;_geoExtentComputed=!1;obfuscateString(t){let e="abcdefghijklmnopqrstuvwxyz",r=()=>e[Math.floor(Z()*e.length)],o=()=>r().toUpperCase(),s=()=>Math.floor(Z()*10).toString(),a=v=>/[A-Z]/.test(v)?o():/[a-z]/.test(v)?r():/[0-9]/.test(v)?s():v,l=t.includes("@")&&t.includes("."),c=l?t.split("@"):[t],f=l?c[1]:"",M=f.endsWith(".com"),h=M?".com":"",P=M?f.slice(0,-4):f,d=v=>{let x="";for(let A of v)x+=a(A),/[a-zA-Z0-9]/.test(A)&&Z()<.2&&(x+=a(A));if(x.length>6){let A=Math.floor(Z()*Math.min(3,x.length-6));for(let w=0;w<A;w++){let T=0;for(;T<5;){let k=Math.floor(Z()*x.length);if(/[a-zA-Z0-9]/.test(x[k])){x=x.slice(0,k)+x.slice(k+1);break}T++}}}return x};if(l){let v=d(c[0]),x=d(P);return`${v}@${x}${h}`}else return d(t)}toObjectArray(){return this._rows.map(t=>{let e={};return this._cols.forEach((r,o)=>{e[r.name]=t[o],this.emitLegacyAggAliases&&r.hostName&&r.hostName!==r.name&&!Object.prototype.hasOwnProperty.call(e,r.hostName)&&(e[r.hostName]=t[o])}),e})}async getCSVAsync(t){let e=[],r=t?25:1e7,o=t?4e3:1e7,s=new Map;for(let l of this._rows){let c={};for(let f=0;f<this._cols.length;f++){let M=this._cols[f],h=l[f];if(this.STR(h)!=""){if(t&&M.dataType=="String")if(s.has(h))h=s.get(h);else{let P=this.obfuscateString(h);s.set(h,P),h=P}else M.dataType=="DateTime"&&!M.dateWithTime&&(h=new Date(h).toISOString().slice(0,10)+"T00:00:00.000Z");o-=this.STR(h).length}else h=null;c[f]=h,--o}if(e.push(c),--r,r<=0||o<=0)break}return await vt.unparse(e,{header:!1})}getCSVHeaderLine(){return vt.unparse([this._cols.map(t=>this.STR(this.emitLegacyAggAliases&&t.hostName?t.hostName:t.name))])}addRow(t,e){if(this.dedupRows){let r="";for(let s of t)r+=this.STR(s)+"~";let o=rt(r);if(this._rowHashes.has(o))return!1;this._rowHashes.add(o)}return this._rows.push(t),this._origIndices.push(e??-1),!0}getOriginalRowIndex(t){return t<0||t>=this._origIndices.length?-1:this._origIndices[t]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(t){if(this._cols=t,!t||t.length===0)return;let e=new Set(t.map(r=>this.STR(r?.name)));for(let r of t){if(!r)continue;let o=this.STR(r.name),s=Ct(o);!s||s===o||e.has(s)||(e.delete(o),e.add(s),r.hostName=o,r.name=s)}}};export{bt as a,Ot as b,Q as c,he as d,Lt as e,Pt as f,Gt as g,Wt as h,St as i,Bt as j,Ct as k,_e as l,At as m,Ht as n,Rt as o,Nt as p,Se as q,Ce as r,Me as s,ie as t,wt as u,fe as v,de as w,ge as x,xt as y,It as z};