@bicharts/shape-core 0.5.92 → 0.5.94
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.
- package/dist/chunk-5MZ6HMKL.mjs +2 -0
- package/dist/{chunk-KSG5NPJB.mjs → chunk-Q6BDANS6.mjs} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/indexedText.mjs +1 -1
- package/dist/ingest.mjs +1 -1
- package/dist/types/aggregation.d.ts +28 -1
- package/dist/types/cadence.d.ts +98 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models.d.ts +3 -0
- package/package.json +1 -1
- package/dist/chunk-6W2GOB6U.mjs +0 -2
|
@@ -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 be}from"./chunk-QEH7WTLB.mjs";import{a as ye,b as _e}from"./chunk-2LR73DNS.mjs";import{c as he}from"./chunk-RC567DAC.mjs";import{b as ge,f as pe}from"./chunk-E6SVTFAW.mjs";import{a as me,b as de,c as fe}from"./chunk-NOC2K3R2.mjs";import{a as q,b as ue,c as le,d as X,f as ne,h as ce}from"./chunk-6NQENOVB.mjs";var Ue=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],Be=[7,72,-172,-52];function Se(n,e,t){return n>=t[0]&&n<=t[1]&&e>=t[2]&&e<=t[3]}function ee(n,e){if(!n.length)return NaN;if(n.length===1)return n[0];let t=(n.length-1)*e,i=Math.floor(t),a=Math.ceil(t);return i===a?n[i]:n[i]+(n[a]-n[i])*(t-i)}var $=n=>Math.round(n*10)/10;function Me(n,e=3){let t=[],i=[],a=0,r=0;for(let l of n){let u=l?.lat,m=l?.lon;if(typeof u!="number"||typeof m!="number"||!isFinite(u)||!isFinite(m)||u<-90||u>90||m<-180||m>180)continue;t.push(u),i.push(m);let h=l?.country?String(l.country).trim().toUpperCase():"",g=h?te(h):null;g?((h==="US"||h==="USA")&&a++,g==="north-america"&&r++):(Ue.some(w=>Se(u,m,w))&&a++,Se(u,m,Be)&&r++)}let o=t.length;return o<e?null:(t.sort((l,u)=>l-u),i.sort((l,u)=>l-u),{pctUsa:$(a/o*100),pctNa:$(r/o*100),latP5:$(ee(t,.05)),latP95:$(ee(t,.95)),lonP5:$(ee(i,.05)),lonP95:$(ee(i,.95)),n:o})}var Ce={"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"},Q=(()=>{let n=new Map;for(let e of Object.keys(Ce))for(let t of Ce[e].split(/\s+/))t&&n.set(t,e);return n})();function Ve(n){for(let[e,t]of n){let i=Q.get(e);i&&!Q.has(t)&&Q.set(t,i)}}Ve(ge);function te(n){if(!n)return null;let e=String(n).trim().toUpperCase();if(!e)return null;let t=Q.get(e);if(t)return t;let i=pe(String(n));return i?Q.get(i)??null:null}function Ft(n,e=2){return ie(n.map(t=>[t,1]),e)}function ie(n,e=2){let t=new Map,i=0;for(let[o,l]of n){let u=te(o);if(!u)continue;let m=typeof l=="number"&&isFinite(l)&&l>0?l:1;t.set(u,(t.get(u)??0)+m),i+=m}if(i<e||!t.size)return null;let a="europe",r=-1;for(let o of Array.from(t.keys()).sort()){let l=t.get(o);l>r&&(a=o,r=l)}return{dominantGeoRegion:a,dominantGeoRegionPct:$(r/i*100),regionCount:t.size,n:i}}import ke from"papaparse";var Ye=["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","temperatuur","temperatur","temperatura","teplota","lampotila","homerseklet","sicaklik","pression","presion","pressao","pressione","druck","tryck","tlak","paine","nyomas","presiune","humidite","humedad","umidade","umidita","feuchtigkeit","vochtigheid","kosteus","vlhkost","vitesse","velocidad","velocidade","velocita","geschwindigkeit","snelheid","hastighet","hastighed","rychlost","nopeus","sebesseg","brzina","predkosc","densite","densidad","densidade","densita","dichte","dichtheid","hustota","tiheys","gustoca","moyenne","mediane","promedio","mediana","gemiddelde","durchschnitt","mittelwert","genomsnitt","gennemsnit","gjennomsnitt","keskiarvo","atlag","ortalama","prosjek","srednia","prumer","priemer","medie","taux","tasa","taxa","tasso","verhaltnis","verhouding","aandeel","anteil","andel","osuus","podil","udzial","udio","pourcentage","porcentaje","percentual","prozent","procent","prosentti","szazalek","yuzde","participacion","participacao","pondere","omjer","arany","oran","rata","leeftijd","edad","idade","wiek","eletkor","varsta","puntuacion","pontuacao","punteggio","betyg","ocena","indice","indeks","wskaznik","puan"],He=["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"],Ke=["latitude","longitude"],$e=["latitude","longitude"];function Z(n){return Array.from(n).map(e=>{let t=e.normalize("NFD").replace(/[̀-ͯ]/g,"");return t.length===1?t:e}).join("")}var re=["somme de","suma de","soma de","summe von","som van","somma di","summa av","sum av","sum af","soucet z","suma z","totaal van","total de","toplam","osszeg","nombre de","recuento de","contagem de","anzahl von","aantal van","conteggio di","antal av","lukumaara","pocet z"],Te=["moyenne de","promedio de","media de","media di","durchschnitt von","gemiddelde van","medelvarde av","genomsnitt av","gennemsnit af","keskiarvo","atlag","ortalama","prumer z","srednia z","medie de","minimum de","minimo de","minimo di","minimum von","maximum de","maximo de","massimo di","maximum von"];function Ze(n){return[...n].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+")).join("|")}var Re=new RegExp("^\\s*(?:(?:sum|count|count\\s+distinct|distinct\\s+count)\\s+of\\s+|(?:"+Ze(re)+")\\s+)","i"),Xe=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])/g,je=new RegExp("\\b("+Ye.join("|")+")\\b|("+He.join("|")+")$","i"),qe=new RegExp("\\b("+Ke.join("|")+")\\b|("+$e.join("|")+")$","i");function ve(n){if(!n)return"";let e=String(n),t=Re.exec(Z(e));return(t?e.slice(t[0].length):e).trim()}function Qe(n){return!!n&&Re.test(Z(String(n)))}var Je=["count (distinct)","count distinct","distinct count","standard deviation","average","variance","median","product","stddev","std dev","count","sum","avg","min","minimum","max","maximum","var"],Ae=new RegExp("^\\s*("+[...Je].sort((n,e)=>e.length-n.length).map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+")).join("|")+")\\s+of\\s+","i");function Ne(n){if(n==null)return"";let e=String(n),t=Ae.exec(e);if(!t)return e;let i=l=>l.toLowerCase().replace(/\s+/g," ").trim(),a=i(t[1]),r=e.slice(t[0].length),o=0;for(;o<8;){let l=Ae.exec(r);if(!l||i(l[1])!==a)break;let u=r.slice(l[0].length);if(u.trim()==="")break;r=u,o++}return o===0?e:e.slice(0,t[0].length)+r}function Ut(n,e){if(!n||!e)return!1;let t=String(n);for(let i of e){let a=i?.hostName;if(a&&a!==i?.name&&t.includes(a))return!0}return!1}function et(n){let e=ve(n);return e.length===0?"":e.replace(Xe," ")}function xe(n,e){if(!e)return!1;let t=ve(e);return n.test(Z(et(e)))||n.test(Z(t))||n.test(Z(q(t).join(" ")))}function Ie(n){return xe(qe,n)}function tt(n){return xe(je,n)||Ie(n)}var we=/int|double|decimal|single|float|number|currency|money/i;function nt(n){let e=String(n?.valueNature??"").trim().toLowerCase();return e==="categorical"?"Categorical":e==="ordinal"?"Ordinal":e==="continuous"||n?.isMeasure===!0||we.test(String(n?.dataType??""))?"Continuous":"Categorical"}function it(n){return n?.isMeasure===!0||we.test(String(n?.dataType??""))}function Ee(n){let e=n??{},t=nt(e);if(t!=="Continuous")return{nature:t,additivity:"unknown",basis:"role",suppressed:!1};if(Ie(e.name))return{nature:t,additivity:"positional",basis:"name",suppressed:!0};let i=String(e.additivity??"").trim().toLowerCase();if(!(i==="additive"&&Qe(e.name))){if(i==="additive")return{nature:t,additivity:"additive",basis:"measured",suppressed:!1};if(i==="part_of_whole")return{nature:t,additivity:"part_of_whole",basis:"measured",suppressed:!1};if(i==="intensive_rate")return{nature:t,additivity:"intensive_rate",basis:"measured",suppressed:!1}}return e.discourageAggregationAcrossGroups===!0?{nature:t,additivity:"intensive_rate",basis:"host-flag",suppressed:!1}:tt(e.name)?{nature:t,additivity:"intensive_rate",basis:"name",suppressed:!1}:{nature:t,additivity:"additive",basis:"default",suppressed:!1}}function De(n){let e=Ee(n),t=n??{};if(e.nature==="Categorical")return["first","distinctcount","count"];if(e.nature==="Ordinal")return it(t)?["median","average","min","max","first","distinctcount","count"]:["first","distinctcount","count"];switch(e.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 Bt(n){return De(n)[0]}function Vt(n,e){return De(n).indexOf(e)>=0}function Yt(n,e){if(e!=="sum"&&e!=="count")return!1;if(e==="count")return!0;let t=Ee(n);return t.additivity==="additive"||t.additivity==="part_of_whole"||t.additivity==="unknown"}var Kt=5,$t=6;var rt=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,st=/^(\d{4})[-/](\d{1,2})$/,ot=/^(\d{4})[-\s]?Q([1-4])$/i,at=/^Q([1-4])[-\s](\d{4})$/i,ut=/^(\d{4})$/,lt=/^(\d{4})(0[1-9]|1[0-2])$/,ct=/^(\d{4})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/;function K(n,e,t,i=0,a=0,r=0){if(!(n>=1&&e>=1&&e<=12&&t>=1&&t<=31))return null;let o=Date.UTC(n,e-1,t,i,a,r);if(!Number.isFinite(o))return null;let l=u=>u<10?"0"+u:String(u);return{ms:o,y:n,m:e,d:t,iso:`${n}-${l(e)}-${l(t)}`}}function mt(n,e){let t=[],i="";for(let u=0;u<e.length;u++){if(e[u]!=="%"){i+=e[u].replace(/[.*+?^${}()|[\]\\]/g,"\\$&");continue}switch(e[++u]){case"Y":t.push("Y"),i+="(\\d{4})";break;case"m":t.push("m"),i+="(\\d{1,2})";break;case"d":t.push("d"),i+="(\\d{1,2})";break;case"H":case"M":case"S":i+="\\d{1,2}";break;case"%":i+="%";break;default:return null}}let a=new RegExp("^"+i+"$").exec(n);if(!a)return null;let r=0,o=1,l=1;return t.forEach((u,m)=>{let h=+a[m+1];u==="Y"?r=h:u==="m"?o=h:l=h}),r?K(r,o,l):null}function dt(n,e){let t=(n??"").trim();if(t==="")return null;if(e){let a=mt(t,e);return a||null}let i=rt.exec(t);if(i)return K(+i[1],+i[2],+i[3],+(i[4]??0),+(i[5]??0),+(i[6]??0));if(i=ot.exec(t),i)return K(+i[1],(+i[2]-1)*3+1,1);if(i=at.exec(t),i)return K(+i[2],(+i[1]-1)*3+1,1);if(i=st.exec(t),i&&+i[2]>=1&&+i[2]<=12)return K(+i[1],+i[2],1);if(i=ct.exec(t),i)return K(+i[1],+i[2],+i[3]);if(i=lt.exec(t),i)return K(+i[1],+i[2],1);if(i=ut.exec(t),i){let a=+i[1];return a>=1900&&a<=2100?K(a,1,1):null}return null}function Le(n){let e=new Date(n).getUTCDay();return e>=1&&e<=5}function Pe(n,e){if(e<=n)return 0;let t=Math.round((e-n)/864e5),i=Math.floor(t/7),a=i*5,r=n+i*7*864e5;for(;r<e;)Le(r)&&a++,r+=864e5;return a}function ft(n){if(n.length===0)return 0;let e=[...n].sort((i,a)=>i-a),t=e.length>>1;return e.length%2?e[t]:(e[t-1]+e[t])/2}function gt(n){return n>0?n<.95?"hour":n<=1.05?"day":n>=6.5&&n<=7.5?"week":n>=27&&n<=31.5?"month":n>=88&&n<=93?"quarter":n>=362&&n<=368?"year":"irregular":"irregular"}function Oe(n,e,t,i){switch(t){case"year":return e.y-n.y;case"quarter":return e.y*4+Math.floor((e.m-1)/3)-(n.y*4+Math.floor((n.m-1)/3));case"month":return e.y*12+e.m-(n.y*12+n.m);case"week":return Math.round((e.ms-n.ms)/(7*864e5));case"weekday":return Pe(n.ms,e.ms);case"day":return Math.round((e.ms-n.ms)/864e5);default:return i>0?Math.round((e.ms-n.ms)/i):0}}function Ge(n,e){let t=e?.gapFactor??5,i=0,a=0,r=new Map;for(let d of n){if(d==null||d==="")continue;i++;let G=dt(String(d),e?.pattern);G&&(a++,r.set(G.ms,G))}let o=[...r.values()].sort((d,G)=>d.ms-G.ms);if(o.length<3||i>0&&a/i<.8)return null;let l=o[o.length-1].ms-o[0].ms;if(l<=0)return null;let u=[];for(let d=1;d<o.length;d++)u.push(o[d].ms-o[d-1].ms);let m=ft(u);if(!(m>0))return null;let h=gt(m/864e5);h==="day"&&l>=7*864e5&&o.every(d=>Le(d.ms))&&Pe(o[0].ms,o[o.length-1].ms)+1>o.length*.5&&(h="weekday");let g=h==="irregular"?o.length:Oe(o[0],o[o.length-1],h,m)+1,w=1,p=1,v=[],N=o[0],M=1;for(let d=1;d<o.length;d++){let G=Oe(o[d-1],o[d],h,m);G>w&&(w=G),h!=="irregular"&&G>t?(p++,v.push({from:N.iso,to:o[d-1].iso,points:M}),N=o[d],M=1):M++}v.push({from:N.iso,to:o[o.length-1].iso,points:M});let T={grain:h,points:o.length,expectedPoints:Math.max(g,o.length),coveragePct:Math.round(o.length/Math.max(g,o.length)*1e3)/10,runs:p,largestGapUnits:w,gapFactor:t};return e?.includeBounds&&v.length<=6&&(T.runBounds=v),T}var pt=12,ht=100,bt=.3,yt=.9,_t=120,St=1900,Ct=2100,Mt=0,At=20,Tt=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function Rt(n){if(!n)return!1;let e=q(n);return e.length===0?!1:Tt.has(e[e.length-1])}var vt=new Set(["year","yr","fy"]),Nt=n=>q(n).some(e=>vt.has(e)),xt=/^(?:(?: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 se(n){if(!Number.isInteger(n)||n<190001||n>210012)return!1;let e=n%100;return e>=1&&e<=12}function oe(n){if(!Number.isInteger(n)||n<19000101||n>21001231)return!1;let e=Math.floor(n/100)%100,t=n%100;return e>=1&&e<=12&&t>=1&&t<=31}var It=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,wt=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,Et=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function Dt(n){let e=(n||"").toLowerCase();return e==="en-us"||e==="en"||e.startsWith("en-us-")||e==="en-ph"||e==="en-bz"}function ze(n,e){let t=0,i=0,a=0,r=0,o=0,l="",u=0,m="",h=0,g=0,w=0,p=0,v=!1;for(let H of n){if(H==null)continue;let U=String(H).trim();if(U==="")continue;t++;let k;if(k=It.exec(U)){let W=+k[2],s=+k[3];W>=1&&W<=12&&s>=1&&s<=31&&(i++,k[4]!==void 0&&a++,k[6]!==void 0&&r++)}else if(k=wt.exec(U)){let W=+k[3],s=+k[4];W>=1&&W<=12&&s>=1&&s<=31&&(l&&l!==k[2]&&(v=!0),l=k[2],o++)}else if(k=Et.exec(U)){let W=+k[1],s=+k[3];W>=1&&W<=31&&s>=1&&s<=31&&(W<=12||s<=12)&&(m&&m!==k[2]&&(v=!0),m=k[2],u++,W>12&&w++,s>12&&p++,k[5]!==void 0&&h++,k[7]!==void 0&&g++)}if(t>=200)break}if(t<2||(i+o+u)/t<.8||(i>0?1:0)+(o>0?1:0)+(u>0?1:0)!==1||v)return null;if(i>0)return a===i?{pattern:r===i?"%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(w>0&&p>0)return null;let T,d;w>0?(T=!0,d="values"):p>0?(T=!1,d="values"):(T=!Dt(e),d="locale");let G=T?`%d${m}%m${m}%Y`:`%m${m}%d${m}%Y`;return h===u?{pattern:G+(g===u?" %H:%M:%S":" %H:%M"),orderFrom:d}:{pattern:G,orderFrom:d}}function Ot(n,e){if(!e||!/\b(?:19|20)\d{2}\b/.test(n))return!1;let t=n.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!t)return!1;let i=ye(t);return i.length>0&&e[i]!==void 0}function Lt(n){let{dataType:e,name:t,isMeasure:i,distinctCount:a}=n;if(e==="DateTime")return!0;if(i)return!1;if(e==="Integer"||e==="Decimal"){let r=n.minNum,o=n.maxNum;if(!(r!=null&&o!=null&&Number.isFinite(r)&&Number.isFinite(o)&&Number.isInteger(r)&&Number.isInteger(o)&&o>=r))return!1;let u=r>=1900&&o<=2100;if(u&&a>=2&&Nt(t)||u&&a>=3&&a===o-r+1)return!0;let m=se(r)&&se(o),h=oe(r)&&oe(o);if(m||h){if(!n.sampleValues)return!0;let g=0,w=0;for(let p of n.sampleValues){if(p==null||p==="")continue;g++;let v=Number(String(p).trim());if(Number.isFinite(v)&&(m?se(v):oe(v))&&w++,g>=60)break}if(g>=2&&w===g)return!0}return!1}if(n.sampleValues){let r=n.locale?_e(n.locale):null,o=0,l=0,u=[];for(let m of n.sampleValues){if(m==null||m==="")continue;o++;let h=String(m).trim();if(u.push(h),(xt.test(h)||Ot(h,r))&&l++,o>=60)break}if(o>=2&&l/o>=.8||ze(u,n.locale)!==null)return!0}return!1}function Pt(n){let e=Z((n||"").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":Te.some(t=>e.startsWith(t+" "))?/^(minimum|minimo)\b/.test(e)?"min":/^(maximum|maximo|massimo)\b/.test(e)?"max":"avg":re.some(t=>e.startsWith(t+" ")||e===t)?/^(nombre|recuento|contagem|anzahl|aantal|conteggio|antal|lukumaara|pocet)\b/.test(e)?"count":"sum":null}function Gt(n){let{rows:e,measureColIdx:t,measureName:i,candidateDims:a,minNum:r,maxNum:o,discourageAgg:l}=n,u=100,m=.01,h="";for(let w of a){if(w.distinct<2||w.distinct>u)continue;let p=a.filter(d=>d.idx!==w.idx).map(d=>d.idx),v=new Map;for(let d of e){let G=d[t];if(typeof G!="number"||!Number.isFinite(G))continue;let H=p.length?p.map(k=>String(d[k])).join(h):"",U=v.get(H);U||(U={sum:0,cset:new Set},v.set(H,U)),U.sum+=G,U.cset.add(String(d[w.idx]))}let N=0,M=0,T=0;for(let d of v.values())d.cset.size<2||(T++,Math.abs(d.sum-100)<=100*m?N++:Math.abs(d.sum-1)<=1*m&&M++);if(T>=2&&(N/T>=.9||M/T>=.9))return{additivity:"part_of_whole",partOfWholeDim:w.name}}if(l)return{additivity:"intensive_rate"};let g=Pt(i);return g==="avg"||g==="min"||g==="max"?{additivity:"intensive_rate"}:g==="count"?{additivity:"additive"}:g==="sum"?{additivity:"unknown"}:r!=null&&o!=null&&Number.isFinite(r)&&Number.isFinite(o)&&r>=0&&o<=1.0001&&o>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function Fe(n){let{dataType:e,isMeasure:t,name:i,distinct:a,nonblank:r,prec:o,maxval:l,minval:u}=n,m=l-u+1,h=m>0?a/m:1,g=r>0?a/r:0,w=e==="Decimal"||o>0;return Rt(i)?"Categorical":h>=yt&&(me(i)&&a<=_t||u>=St&&l<=Ct||u>=Mt&&l<=At)?"Ordinal":t||a>pt&&(w||a>=ht||g>=bt)?"Continuous":"Categorical"}var We=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;emitLegacyAggAliases=!1;STR(e){return e==null?"":e instanceof Date?this.wholeDayIso(e)??(isNaN(e.getTime())?"":e.toISOString()):e.toString()}getPrecision(e){if(!isFinite(e))return 0;let i=e.toString().split(".")[1];return i?i.length:0}getColumns(){return this._cols}wholeDayIso(e){return ce(e)}hasTimeComponent(e){return!(e instanceof Date)||isNaN(e.getTime())?!1:this.wholeDayIso(e)===null}getColumnsWithStats(e,t){if(this._computedStatsForLevel==e)return this._cols;let i=0,a=parseInt(e),r=[];for(let s of this._cols){let f=new Map,D=[],y=0,c=0,S=0,A=null,_=null,b=null,O=!1,I=!0,E=!0,P=null,F=!1;for(let x of this._rows){let R=x[i],C=this.STR(R);if(C!=""){if(y+=C.length,f.set(C,(f.get(C)||0)+1),c++,s.dataType=="Integer"||s.dataType=="Decimal"||s.dataType=="DateTime")if((A===null||R<A)&&(A=R),(_===null||R>_)&&(_=R),s.dataType=="Integer"||s.dataType=="Decimal"){if(b===null?b=R:b+=R,s.dataType=="Decimal"){let L=this.getPrecision(R);L>S&&(S=L)}D.push(R)}else O=O||this.hasTimeComponent(R);F&&(R<P?I=!1:R>P&&(E=!1)),P=R,F=!0}}if(c>=3&&(I&&!E?s.sortedDirection="asc":E&&!I?s.sortedDirection="desc":s.sortedDirection="none"),c>0&&f.size>0&&!s.isMeasure){let x=0,R=Number.MAX_SAFE_INTEGER;for(let C of f.values())C>x&&(x=C),C<R&&(R=C);if(s.modalShare=x/c,s.minGroupCount=R===Number.MAX_SAFE_INTEGER?null:R,f.size===2){let C=[...f.keys()].map(z=>ue(z).trim().toLowerCase()).sort(),V=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(z=>C[0]===z[0]&&C[1]===z[1]),B=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(s.name);(V||B)&&(s.isBinaryFlag=!0)}}if(s.dataType=="DateTime"&&(s.dateWithTime=O),s.isTemporal=Lt({dataType:s.dataType,name:s.name,isMeasure:s.isMeasure,distinctCount:f.size,minNum:typeof A=="number"?A:null,maxNum:typeof _=="number"?_:null,sampleValues:f.keys(),locale:t}),s.isTemporal&&s.dataType==="String"&&!s.isMeasure){let x=ze(f.keys(),t);x&&(s.temporalTextPattern=x.pattern)}if(s.isTemporal&&!s.isMeasure){let x=Ge(f.keys(),{includeBounds:a>=20,pattern:s.temporalTextPattern});x&&(s.temporalCadence=x)}this.updateColumnStats10(a,s,c,f,S,_,A),this.updateColumnStats20(a,D,c,b,s,y,O,A,_,S,f,t),!s.isMeasure&&(s.dataType==="Integer"||s.dataType==="Decimal")&&Fe({dataType:s.dataType,isMeasure:!1,name:s.name,distinct:f.size,nonblank:c,prec:S,maxval:typeof _=="number"?_:0,minval:typeof A=="number"?A:0})==="Continuous"&&(s.isMeasure=!0,s.geoKind=void 0,s.geoMatchPct=void 0,s.geoAmbiguous=void 0,s.dominantGeoRegion=void 0,s.dominantGeoRegionPct=void 0,s.geoRegionCount=void 0),r[i]=s.isMeasure||f.size>2e3?null:new Set(f.keys()),i++}let o=[];this._cols.forEach((s,f)=>{s.isMeasure||o.push({idx:f,distinct:s.distinctCount??0,name:s.name})}),this._cols.forEach((s,f)=>{if(!s.isMeasure)return;let D=typeof s.lowValue=="number"?s.lowValue:null,y=typeof s.highValue=="number"?s.highValue:null,c=Gt({rows:this._rows,measureColIdx:f,measureName:s.name,candidateDims:o,minNum:D,maxNum:y,discourageAgg:!!s.discourageAggregationAcrossGroups});s.additivity=c.additivity,c.partOfWholeDim&&(s.partOfWholeDim=c.partOfWholeDim)});let l=50,u=o.filter(s=>s.distinct>=2&&s.distinct<=l);this._cols.forEach((s,f)=>{if(!s.isMeasure)return;let D=[];for(let C of this._rows){let L=C[f];if(L==null||L==="")continue;let V=typeof L=="number"?L:parseFloat(L);isNaN(V)||D.push(V)}if(D.length===0)return;let y=[...D].sort((C,L)=>C-L),c=C=>y[Math.min(y.length-1,Math.max(0,Math.floor(C*(y.length-1))))],S=c(.5),A=c(.1),_=c(.9),b=Math.abs(S)>1e-9?Math.abs(S):Math.abs(y[y.length-1])>1e-9?Math.abs(y[y.length-1]):1;s.relativeDispersion=Math.round((_-A)/b*1e3)/1e3;let O=[];for(let C of u){let L=new Set;for(let V of this._rows){let B=V[f];B==null||B===""||L.add(this.STR(V[C.idx])+"")}O.push({otherColumn:C.name,nonBlankGroupCount:L.size})}O.length>0&&(s.nonBlankGroups=O);let I=0;for(let C of D)I+=C;I/=D.length;let E=0;for(let C of D)E+=(C-I)*(C-I);if(E<=1e-12)return;let P=[],F=[],x=C=>{if(C.length<4)return NaN;let L=[...C].sort((B,z)=>B-z),V=B=>L[Math.min(L.length-1,Math.max(0,Math.floor(B*(L.length-1))))];return V(.75)-V(.25)},R=x(D);for(let C of u){let L=new Map;for(let z of this._rows){let Y=z[f];if(Y==null||Y==="")continue;let j=typeof Y=="number"?Y:parseFloat(Y);if(isNaN(j))continue;let ae=this.STR(z[C.idx])+"",J=L.get(ae);J?(J.s+=j,J.n++,J.vals.push(j)):L.set(ae,{s:j,n:1,vals:[j]})}let V=0;for(let z of L.values()){let Y=z.s/z.n;V+=z.n*(Y-I)*(Y-I)}P.push({otherColumn:C.name,eta2:Math.round(V/E*1e4)/1e4});let B=[];for(let z of L.values()){let Y=x(z.vals);isNaN(Y)||B.push(Y)}if(B.length>=2&&isFinite(R)&&R>1e-9){let z=(Math.max(...B)-Math.min(...B))/R;F.push({otherColumn:C.name,spreadRatio:Math.round(z*1e4)/1e4})}}P.length>0&&(s.groupDiscrimination=P),F.length>0&&(s.spreadDiscrimination=F)});let m=.97,h=5,g=this._cols.map((s,f)=>({c:s,i:f})).filter(s=>s.c.isMeasure);for(let s=0;s<g.length;s++)for(let f=s+1;f<g.length;f++){let D=g[s].i,y=g[f].i,c=0,S=0,A=0,_=0,b=0,O=0;for(let F of this._rows){let x=F[D],R=F[y];if(x==null||x===""||R===null||R===void 0||R==="")continue;let C=typeof x=="number"?x:parseFloat(x),L=typeof R=="number"?R:parseFloat(R);isNaN(C)||isNaN(L)||(c++,S+=C,A+=L,_+=C*C,b+=L*L,O+=C*L)}if(c<h)continue;let I=c*_-S*S,E=c*b-A*A;if(I<=1e-12||E<=1e-12)continue;let P=(c*O-S*A)/Math.sqrt(I*E);if(Math.abs(P)>=m){let F=g[s].c,x=g[f].c;F.collinearWithMeasures||(F.collinearWithMeasures=[]),x.collinearWithMeasures||(x.collinearWithMeasures=[]),F.collinearWithMeasures.push(x.name),x.collinearWithMeasures.push(F.name)}}for(let s=0;s<this._cols.length;s++){let f=r[s];if(!f||f.size===0)continue;let D=[];for(let y=0;y<this._cols.length;y++){if(y===s)continue;let c=r[y];if(!c||c.size===0)continue;let S=0;for(let _ of f)c.has(_)&&S++;let A=Math.round(S/f.size*100);A>0&&D.push({otherColumn:this._cols[y].name,percentShared:A})}D.length>0&&(this._cols[s].sharedValueRatioWithOthers=D)}let w=50,p=[];for(let s=0;s<this._cols.length;s++){let f=r[s];f&&f.size>=2&&f.size<=w&&p.push(s)}if(p.length>=2){let s=new Map,f=(y,c)=>y+":"+c;for(let y=0;y<p.length;y++)for(let c=y+1;c<p.length;c++)s.set(f(p[y],p[c]),new Map);for(let y of this._rows)for(let c=0;c<p.length;c++){let S=this.STR(y[p[c]])+"";for(let A=c+1;A<p.length;A++){let _=""+this.STR(y[p[A]]),b=s.get(f(p[c],p[A])),O=S+""+_;b.set(O,(b.get(O)??0)+1)}}let D=new Map;for(let y=0;y<p.length;y++)for(let c=y+1;c<p.length;c++){let S=p[y],A=p[c],_=r[S].size,b=r[A].size,O=s.get(f(S,A)),I=O.size,E=0;for(let R of O.values())(E===0||R<E)&&(E=R);let P=Math.round(I/(_*b)*100),F=I===_,x=I===b;if((this._cols[S].categoricalPairStats||=[]).push({otherColumn:this._cols[A].name,fillPct:P,determinesOther:F,minCellCount:E,distinctCombinations:I}),(this._cols[A].categoricalPairStats||=[]).push({otherColumn:this._cols[S].name,fillPct:P,determinesOther:x,minCellCount:E,distinctCombinations:I}),F&&_>b){let R=D.get(S);(!R||b<R.card)&&D.set(S,{name:this._cols[A].name,card:b,ratio:b/_})}if(x&&b>_){let R=D.get(A);(!R||_<R.card)&&D.set(A,{name:this._cols[S].name,card:_,ratio:_/b})}}for(let[y,c]of D)this._cols[y].primaryParentColumn=c.name,this._cols[y].nestingRatio=Math.round(c.ratio*100)/100}let v=6,N=this._rows.length;for(let s=0;s<this._cols.length;s++){let f=this._cols[s];if(f.isMeasure||f.primaryParentColumn)continue;let D=f.distinctCount??0;if(D<=w||N>0&&D>=N)continue;let y=[];for(let c=0;c<this._cols.length;c++){if(c===s)continue;let S=this._cols[c];if(S.isMeasure)continue;let A=S.distinctCount??0;A<2||A>=D||y.push(c)}y.sort((c,S)=>(this._cols[c].distinctCount??0)-(this._cols[S].distinctCount??0));for(let c of y.slice(0,v)){let S=new Map,A=!0;for(let b of this._rows){let O=this.STR(b[s])+"",I=this.STR(b[c])+"",E=S.get(O);if(E===void 0)S.set(O,I);else if(E!==I){A=!1;break}}if(!A)continue;let _=this._cols[c].distinctCount??0;f.primaryParentColumn=this._cols[c].name,f.nestingRatio=Math.round(_/D*100)/100;break}}let M=.01,T=.05,d=.95,G=8,H=8,U=6,k=500,W=[];for(let s=0;s<this._cols.length&&W.length<H;s++){let f=this._cols[s].dataType;(f==="Double"||f==="Integer"||f==="Decimal")&&W.push(s)}if(W.length>=3&&this._rows.length>=G){let s=Math.min(this._rows.length,k),f=W.map(_=>{let b=[];for(let E=0;E<s;E++){let P=this._rows[E][_],F=typeof P=="number"?P:parseFloat(String(P).replace(/,/g,""));if(P==null||P===""||!isFinite(F))return null;b.push(F)}let O=b[0],I=!1;for(let E of b)if(E!==O){I=!0;break}return I?b:null}),D=W.map((_,b)=>b).filter(_=>f[_]!==null),y=_=>{let b=_.slice().sort((I,E)=>I-E),O=b.length>>1;return b.length%2?b[O]:(b[O-1]+b[O])/2},c=null,S=[],A=_=>{if(S.length>=3){let b=S.map(P=>f[P]),O=b[0].length,I=new Array(O);for(let P=0;P<O;P++){let F=0;for(let x of b)F+=x[P];I[P]=F}let E=y(I);if(E>0){let P=0;for(let x of I)Math.abs(x-E)<=E*M&&P++;let F=P/O;if(F>=d){let x=1;for(let R of b){let C=y(R)/E;C<x&&(x=C)}x>=T&&(!c||S.length>c.cols.length)&&(c={cols:S.slice(),total:E,matched:F})}}}if(!(S.length>=U))for(let b=_;b<D.length;b++)S.push(D[b]),A(b+1),S.pop()};if(A(0),c){let _=c,O={columns:_.cols.map(I=>this._cols[W[I]].name),total:Math.round(_.total*1e3)/1e3,matchedPct:Math.round(_.matched*100)/100};for(let I of _.cols)this._cols[W[I]].constantSumGroup=O}}return this._computedStatsForLevel=e,this._cols}updateColumnStats20(e,t,i,a,r,o,l,u,m,h,g,w){if(e>=20){let p=[...t].sort((M,T)=>M-T),v=Math.floor(p.length/2);if(i>0&&a!=null?r.avgValue=r.dataType=="Integer"?Math.round(a/i):a/i:r.avgValue=null,i>0&&(r.avgLength=o/i),this._rows.length>0){let M=T=>{let d=T instanceof Date?T:typeof T=="string"?ne(T)??new Date(T):new Date(T),G=this.wholeDayIso(d);return G?G+"T00:00:00.000Z":isNaN(d.getTime())?T:d.toISOString().slice(0,10)+"T00:00:00.000Z"};r.dataType!="DateTime"||l||!u?r.lowValue=u:r.lowValue=M(u),r.dataType!="DateTime"||l||!m?r.highValue=m:r.highValue=M(m),r.medianValue=p.length===0?null:p.length%2===0?r.dataType=="Integer"?Math.round((p[v-1]+p[v])/2):(p[v-1]+p[v])/2:p[v],r.numericPrecision=h}if(p.length>0){let M=r.avgValue??0,T=p.length,d=0,G=0;for(let U of p){let k=U-M;d+=k*k,G+=k*k*k}let H=d/T;r.skewness=H===0?0:G/T/Math.pow(Math.sqrt(H),3),r.stdDev=Math.sqrt(H)}a!==null&&(r.sum=a);let N=Array.from(g.entries()).sort((M,T)=>T[1]-M[1]);if(r.topCategories=N.slice(0,10).map(M=>M[1]),!r.isMeasure&&N.length>0){if(r.dataType==="String"){let M=N.map(d=>d[0]);r.formatSignature=be(M);let T=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;r.formatSignature&&!T.test(r.formatSignature)&&(r.avgLength===void 0||r.avgLength>=3)&&(r.isFreeText=!0)}else r.topCategoryValues=N.slice(0,5).map(M=>M[0]);if(e>=20){let M=N.map(d=>d[0]),T=fe(M,w);if(T!==null)r.ordinalPattern=T.pattern,r.orderedDomain=T.orderedDomain;else if(r.dataType==="String"){let d=de(M);d!==null&&(r.safeDistinctValues=d)}}}if(p.length>=8&&(r.dataType==="Integer"||r.dataType==="Decimal")){let M=T=>p[Math.floor((p.length-1)*T)];r.quantiles={p05:M(.05),p25:M(.25),p75:M(.75),p95:M(.95)}}}if(!r.isMeasure&&g.size>0){let p=Array.from(g.entries()).sort((N,M)=>M[1]-N[1]),v=he(p.map(N=>N[0]),r.name,w);if(v!==null&&(r.geoKind=v.geoKind,r.geoMatchPct=v.geoMatchPct,v.geoAmbiguous&&(r.geoAmbiguous=!0),v.geoKind.indexOf("country")===0)){let N=ie(p);N&&(r.dominantGeoRegion=N.dominantGeoRegion,r.dominantGeoRegionPct=N.dominantGeoRegionPct,r.geoRegionCount=N.regionCount)}}}updateColumnStats10(e,t,i,a,r,o,l){e>=10&&(t.blankCount=this._rows.length-i,t.distinctCount=a.size+(t.blankCount!=0?1:0),t.valueNature="Categorical",i>0&&(t.dataType==="Integer"||t.dataType==="Decimal"?t.valueNature=Fe({dataType:t.dataType,isMeasure:!!t.isMeasure,name:t.name,distinct:a.size,nonblank:i,prec:r,maxval:o,minval:l}):t.dataType==="DateTime"&&(t.valueNature=t.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let e=[];if(this._cols.forEach((i,a)=>{i.isMeasure||e.push(a)}),e.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let t=new Set;for(let i of this._rows)t.add(JSON.stringify(e.map(a=>i[a])));return this._leafCardinality=t.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]+/),t=-1,i=-1,a=-1;if(this._cols.forEach((o,l)=>{let u=e(o.name),m=o.dataType==="Integer"||o.dataType==="Decimal";m&&t<0&&u.some(h=>h==="lat"||h==="latitude")?t=l:m&&i<0&&u.some(h=>h==="lon"||h==="lng"||h==="long"||h==="longitude")&&(i=l),a<0&&!o.isMeasure&&typeof o.geoKind=="string"&&o.geoKind.indexOf("country")===0&&(a=l)}),t<0||i<0)return null;let r=[];for(let o of this._rows){let l=o[t],u=o[i],m=l==null||l===""?null:Number(l),h=u==null||u===""?null:Number(u);r.push({lat:m,lon:h,country:a>=0&&te(this.STR(o[a]))?this.STR(o[a]):null})}return this._geoExtent=Me(r),this._geoExtent}_geoExtent=null;_geoExtentComputed=!1;obfuscateString(e){let t="abcdefghijklmnopqrstuvwxyz",i=()=>t[Math.floor(X()*t.length)],a=()=>i().toUpperCase(),r=()=>Math.floor(X()*10).toString(),o=v=>/[A-Z]/.test(v)?a():/[a-z]/.test(v)?i():/[0-9]/.test(v)?r():v,l=e.includes("@")&&e.includes("."),u=l?e.split("@"):[e],m=l?u[1]:"",h=m.endsWith(".com"),g=h?".com":"",w=h?m.slice(0,-4):m,p=v=>{let N="";for(let M of v)N+=o(M),/[a-zA-Z0-9]/.test(M)&&X()<.2&&(N+=o(M));if(N.length>6){let M=Math.floor(X()*Math.min(3,N.length-6));for(let T=0;T<M;T++){let d=0;for(;d<5;){let G=Math.floor(X()*N.length);if(/[a-zA-Z0-9]/.test(N[G])){N=N.slice(0,G)+N.slice(G+1);break}d++}}}return N};if(l){let v=p(u[0]),N=p(w);return`${v}@${N}${g}`}else return p(e)}toObjectArray(){return this._rows.map(e=>{let t={};return this._cols.forEach((i,a)=>{t[i.name]=e[a],this.emitLegacyAggAliases&&i.hostName&&i.hostName!==i.name&&!Object.prototype.hasOwnProperty.call(t,i.hostName)&&(t[i.hostName]=e[a])}),t})}async getCSVAsync(e){let t=[],i=e?25:1e7,a=e?4e3:1e7,r=new Map;for(let l of this._rows){let u={};for(let m=0;m<this._cols.length;m++){let h=this._cols[m],g=l[m];if(this.STR(g)!=""){if(e&&h.dataType=="String")if(r.has(g))g=r.get(g);else{let w=this.obfuscateString(g);r.set(g,w),g=w}else if(h.dataType=="DateTime"&&!h.dateWithTime){let w=g instanceof Date?g:typeof g=="string"?ne(g)??new Date(g):new Date(g);g=(this.wholeDayIso(w)??w.toISOString().slice(0,10))+"T00:00:00.000Z"}a-=this.STR(g).length}else g=null;u[m]=g,--a}if(t.push(u),--i,i<=0||a<=0)break}return await ke.unparse(t,{header:!1})}getCSVHeaderLine(){return ke.unparse([this._cols.map(e=>this.STR(this.emitLegacyAggAliases&&e.hostName?e.hostName:e.name))])}addRow(e,t){if(this.dedupRows){let i="";for(let r of e)i+=this.STR(r)+"~";let a=le(i);if(this._rowHashes.has(a))return!1;this._rowHashes.add(a)}return this._rows.push(e),this._origIndices.push(t??-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){if(this._cols=e,!e||e.length===0)return;let t=new Set(e.map(i=>this.STR(i?.name)));for(let i of e){if(!i)continue;let a=this.STR(i.name),r=Ne(a);!r||r===a||t.has(r)||(t.delete(a),t.add(r),i.hostName=a,i.name=r)}}};export{Me as a,Ve as b,te as c,Ft as d,Ye as e,He as f,Ke as g,$e as h,ve as i,Qe as j,Ne as k,Ut as l,Ie as m,tt as n,Ee as o,De as p,Bt as q,Vt as r,Yt as s,Kt as t,$t as u,dt as v,Ge as w,Rt as x,ze as y,Lt as z,Pt as A,Gt as B,Fe as C,We as D};
|
|
@@ -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{
|
|
2
|
+
import{D as S,x as b}from"./chunk-5MZ6HMKL.mjs";import{f as w}from"./chunk-6NQENOVB.mjs";import R from"papaparse";var D=500,E=/^[+-]?\d{1,15}$/,T=/^[+-]?(\d{1,3}(,\d{3})*|\d+)(\.\d+)?([eE][+-]?\d+)?$/,L=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/,I=/^\d{1,2}[\/\-.]\d{1,2}[\/\-.]\d{2,4}$/;function x(t){let i=0,e=0,r=0,o=0;for(let a of t){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++,E.test(c)){i++,e++;continue}if(T.test(c)){e++;continue}if((L.test(c)||I.test(c))&&!isNaN(Date.parse(c))){r++;continue}}}return o===0?"String":r===o?"DateTime":i===o?"Integer":e===o?"Decimal":"String"}function M(t,i){if(t==null)return null;if(typeof t=="number")return i==="String"?String(t):t;if(t instanceof Date)return i==="DateTime"?t:t.toISOString();if(typeof t=="boolean")return String(t);let e=String(t).trim();if(e==="")return null;switch(i){case"Integer":return E.test(e)?parseInt(e,10):null;case"Decimal":return T.test(e)?parseFloat(e.replace(/,/g,"")):null;case"DateTime":return w(e);default:return e}}function A(t){let i=(t||"").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(t,i,e){if(t.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=t.length,o=t.map((n,s)=>n.dataType??x(i.slice(0,D).map(m=>m?.[s]))),a=new Set((e.measures??[]).map(n=>n.toLowerCase())),c=new Set((e.dimensions??[]).map(n=>n.toLowerCase())),d=new Set((e.nonAdditive??[]).map(n=>n.toLowerCase())),C=t.map((n,s)=>{let m=n.name.toLowerCase(),u=n.isMeasure??((o[s]==="Integer"||o[s]==="Decimal")&&!b(n.name));a.has(m)&&(u=!0),c.has(m)&&(u=!1);let h={name:n.name,dataType:o[s],isMeasure:u};return u&&d.has(m)&&(h.discourageAggregationAcrossGroups=!0),h}),l=new S;l.dedupRows=e.dedup!==!1,l.setColumns(C);for(let n=0;n<i.length;n++){let s=i[n];l.addRow(Array.from({length:r},(m,u)=>M(s?.[u],o[u])),n)}let y=l.getColumnsWithStats(e.privacyLevel??"20",e.locale??"en"),f=new Map(y.map(n=>[n.name,n]));t.forEach(n=>{let s=f.get(n.name);s&&(n.format&&(s.modelFormat=n.format),n.description&&(s.modelDesc=n.description))});for(let[n,s]of Object.entries(e.formats??{})){let m=f.get(n);m&&(m.modelFormat=s)}for(let[n,s]of Object.entries(e.descriptions??{})){let m=f.get(n);m&&(m.modelDesc=s)}for(let n of e.groupBy??[]){let s=f.get(n);s&&(s.isGrouping=!0)}return{columns:y,rows:l.toObjectArray(),totalRows:l.getRowCount(),index:l}}function p(t,i){return t.map(e=>Array.isArray(e)?e:i.map(r=>e[r]))}function k(t,i){let e=[],r=new Set,o=Math.min(t.length,Math.max(1,i));for(let a=0;a<o;a++){let c=t[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 _(t,i={}){switch(t.kind){case"csv":{let e=R.parse(t.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(!t.header?.length)throw new Error("ingest: 'grid' needs a non-empty header.");return g(t.header.map(e=>({name:(e??"").trim()})),t.rows??[],i)}case"table":{if(!t.columns?.length)throw new Error("ingest: 'table' needs at least one column descriptor.");let e=t.columns.map(r=>r.name);return g(t.columns,p(t.rows??[],e),i)}case"objects":{let e=t.rows??[],r=t.columns?.length?t.columns:k(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(!t.schema?.length)throw new Error("ingest: 'sql' needs at least one schema column.");let e=t.schema.map(r=>{let o=A(r.dataType);return{name:r.name,dataType:o,isMeasure:r.isMeasure,format:r.format,description:r.description}});return g(e,p(t.rows??[],e.map(r=>r.name)),i)}default:{let e=t;throw new Error(`ingest: unknown source kind '${e?.kind}'. Expected one of: csv, grid, table, objects, sql.`)}}}export{A as a,_ as b};
|
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
|
|
2
|
+
import{a as ie,b as re}from"./chunk-UQU75XXR.mjs";import{a as ne,b as oe}from"./chunk-Q6BDANS6.mjs";import{A as Jt,B as Qt,C as te,D as ee,a as St,b as Rt,c as It,d as bt,e as Lt,f as Nt,g as kt,h as wt,i as Ot,j as Et,k as zt,l as Gt,m as Dt,n as $t,o as Ft,p as Bt,q as Kt,r as Ht,s as Vt,t as Ut,u as Wt,v as qt,w as Zt,x as Xt,y as jt,z as Yt}from"./chunk-5MZ6HMKL.mjs";import{a as vt}from"./chunk-QEH7WTLB.mjs";import{a as Mt,b as _t}from"./chunk-2LR73DNS.mjs";import{a as V,b as U,c as Ct,d as At,e as xt,f as Tt}from"./chunk-RC567DAC.mjs";import{a as S,f as R,g as y,h as I,i as w,j as ct,k as ut,l as H,m,n as ft,o as pt,p as mt,q as b,r as dt,s as gt,t as yt,u as ht,v as O,w as Pt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as st,b as at,c as lt}from"./chunk-NOC2K3R2.mjs";import{a as J,b as Q,c as tt,d as et,e as nt,f as ot,g as it,h as rt}from"./chunk-6NQENOVB.mjs";var E=2,Z=400;function G(r){return!!R(r)}function C(r){let n=new Set;for(let e of r){if(e==null)continue;let s=S(String(e));if(!I(s)&&!n.has(s)&&(n.add(s),n.size>=Z))break}return Array.from(n)}function P(r){let n=C(r);if(n.length===0||D(r)<95)return!1;let e=n.filter(c=>G(c)&&!m(c)).length,s=n.filter(c=>!G(c)&&!!m(c)).length;return e>=1&&e>=s}function W(r,n){if(!m(r))return!1;let e=R(r);return e?n==="world"?!0:H.has(e):!1}function D(r){let n=C(r);if(n.length===0)return 0;let e=0;for(let s of n)G(s)&&e++;return Math.round(e/n.length*1e3)/10}function v(r){let n=C(r);if(n.length===0)return 0;let e=0;for(let s of n)m(s)&&e++;return Math.round(e/n.length*1e3)/10}function F(r){let n=new Set;for(let e of r){if(e==null)continue;let s=String(e).trim();if(!I(S(s))&&!n.has(s)&&(n.add(s),n.size>=Z))break}return Array.from(n)}function $(r){let n=F(r);if(n.length===0)return 0;let e=0;for(let s of n)b(s).length>0&&e++;return Math.round(e/n.length*1e3)/10}function q(r,n){return U(n,V)?!0:F(r).some(e=>/^\d{5}(-\d{4})?$/.test(e.replace(/\.0+$/,"")))}function se(r,n){let e=C(r);if(e.length===0)return 0;let s=0;for(let c of e)O(c,n)&&s++;return Math.round(s/e.length*1e3)/10}function z(r,n){let e=0;for(let s of C(r))n(s)&&e++;return e}function ae(r,n){let e=0;for(let s of F(r))n(s)&&e++;return e}function le(r,n,e,s,c){let A=[],u=[],o={},M={},_=new Set(r),l=t=>n.map(i=>i[t]);for(let t of["city","country"]){let i=e?.[t];i&&_.has(i)&&(o[t]=i)}let X=new Set(c??r);for(let t of["lat","lon"]){let i=e?.[t];i&&X.has(i)&&(o[t]=i)}let d=e?.zip;if(d&&_.has(d)){let t=l(d),i=$(t);i<95?u.push(`zip=${d} (only ${i}% of values read as ZIPs)`):q(t,d)?o.zip=d:u.push(`zip=${d} (all values are 3-4 digits with nothing to say they are postal)`)}let p=e?.state;if(p&&_.has(p)){let t=l(p),i=C(t);i.length>0&&i.every(a=>W(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 g=new Set(Object.values(o).filter(Boolean)),x=r.filter(t=>!g.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 k=z(a,T=>!!m(T)),Y=z(a,T=>!!m(T)&&!W(T,s));k<E&&Y<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.state=t.name,g.add(t.name),A.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of x){if(g.has(t))continue;let i=l(t),a=$(i);if(!(a<95)&&q(i,t)&&!(ae(i,f=>b(f).length>0)<E)){o.zip=t,g.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(g.has(i)||!P(l(i)))continue;let a=D(l(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(u.push(`country=${h} (only ${D(l(h))}% of values are country identifiers; using ${t.name} instead)`),M.country=h),o.country=t.name,g.add(t.name),A.push(`country=${t.name}`))}if(!o.city){let t=null;for(let i of x){if(g.has(i))continue;let a=l(i),f=se(a,s);f<w||z(a,k=>O(k,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):[],L=!!o.country&&P(B),j=L?new Set(B.map(t=>R(t==null?null:String(t))).filter(Boolean)).size:0,K=L&&j>=2,N=!!(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&&!N&&u.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!K&&!(o.city||o.state||o.zip||N)&&u.push(L?`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||N)?o:null,backfilled:A,refused:u,...Object.keys(M).length?{labelFallback:M}:{}}}export{w as CITY_ROLE_MATCH_PCT,Ut as DEFAULT_GAP_FACTOR,et as GET_RANDOM,Nt as INTENSIVE_SUFFIX_TOKENS,Lt as INTENSIVE_WORD_TOKENS,ee as IndexedText,Wt as MAX_RUN_BOUNDS,wt as POSITIONAL_SUFFIX_TOKENS,kt as POSITIONAL_WORD_TOKENS,ie as PREVIEW_OMITTED_FIELDS,y as ROLE_MATCH_PCT,tt as SIMPLE_STRING_HASH,Q as STR,v as admin1MatchPct,Bt as allowedAggregations,Tt as buildGeoIsoColumn,yt as buildGeoPointColumns,Pt as cityMatchPct,ht as cityTagsFor,Qt as classifyAdditivity,Ft as classifyForAggregation,te as classifyNumericValueNature,Yt as classifyTemporal,Gt as codeNeedsLegacyAggNames,zt as collapseRepeatedAggPrefix,It as countryRegion,Kt as defaultAggregation,vt as detectFormatSignature,Ct as detectGeo,lt as detectOrdinalDomain,jt as detectTextDatePattern,ne as engineTypeForSqlType,Et as hasDefaultAggPrefix,Jt as hostAggHint,oe as ingest,Ht as isAggregationAllowed,I as isBlankLike,ut as isCityTableLoaded,nt as isDeterministicRefusal,dt as isGeoPointAmbiguity,Xt as isIdentifierName,xt as isJoinGeoKind,st as isOrdinalFriendlyName,P as looksLikeCountryColumn,Zt as measureCadence,_t as monthLookupFor,$t as nameLooksIntensiveRate,Dt as nameLooksPositional,J as nameWords,ft as normalizeCountry,Mt as normalizeMonthKey,S as normalizePlaceName,mt as normalizeZip5,ot as parseDateStable,qt as parseTemporalPoint,re as payloadPreview,ct as registerCityTable,Rt as registerIso3Regions,m as resolveAdmin1,gt as resolveGeoPoint,le as resolvePointRoles,at as safeDistinctValuesToShip,Vt as shareOfTotalIsHonest,Ot as stripHostAggPrefix,bt as summarizeCountryRegions,St as summarizeGeoExtent,At as toGeoIso,it as wholeDayFrame,rt as wholeDayIso,$ as zipMatchPct,b as zipPrefixCandidates,pt 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{
|
|
2
|
+
import{A as d,B as e,C as f,D as g,x as a,y as b,z as c}from"./chunk-5MZ6HMKL.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-RC567DAC.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NOC2K3R2.mjs";import"./chunk-6NQENOVB.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-Q6BDANS6.mjs";import"./chunk-5MZ6HMKL.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-RC567DAC.mjs";import"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import"./chunk-NOC2K3R2.mjs";import"./chunk-6NQENOVB.mjs";export{a as engineTypeForSqlType,b as ingest};
|
|
@@ -62,11 +62,38 @@ export declare const INTENSIVE_SUFFIX_TOKENS: readonly string[];
|
|
|
62
62
|
* recorded as a follow-up rather than done here. */
|
|
63
63
|
export declare const POSITIONAL_WORD_TOKENS: readonly string[];
|
|
64
64
|
export declare const POSITIONAL_SUFFIX_TOKENS: readonly string[];
|
|
65
|
+
/** Strip diacritics so a token stored as plain ASCII meets the accented spelling of the same
|
|
66
|
+
* word: `Température` -> `Temperature`, `Média` -> `Media`.
|
|
67
|
+
*
|
|
68
|
+
* LENGTH-PRESERVING, one code point in and one code point out, which the obvious
|
|
69
|
+
* `normalize("NFD").replace(...)` is NOT — that shortens the string, and `stripHostAggPrefix`
|
|
70
|
+
* below needs a match offset in the FOLDED text to slice the ORIGINAL. A character folds only
|
|
71
|
+
* when its decomposition collapses back to a single code point; anything else is passed
|
|
72
|
+
* through untouched, so a surrogate pair survives intact. The server mirrors this exactly. */
|
|
73
|
+
export declare function foldAccents(s: string): string;
|
|
74
|
+
/** DEFAULT host aggregation prefixes in the languages a Power BI model is authored in
|
|
75
|
+
* (2026-09-12) — the localized halves of "Sum of" and "Count of". Accent-folded and
|
|
76
|
+
* lower-case; each entry already carries its own connector because languages differ there
|
|
77
|
+
* ("somme DE", "summe VON", "som VAN") and some have none at all ("Toplam Volume").
|
|
78
|
+
*
|
|
79
|
+
* Measured: 35 of the 1,931 distinct names in a production corpus carry a non-English
|
|
80
|
+
* aggregation prefix, against 541 English ones. Before this the server read `Soma de Volume`
|
|
81
|
+
* as a bare name with no host prefix, so the "a default Sum is not evidence" rule — the whole
|
|
82
|
+
* reason `hasDefaultAggPrefix` exists — simply did not apply outside English. */
|
|
83
|
+
export declare const LOCALIZED_DEFAULT_AGG_PREFIXES: readonly string[];
|
|
84
|
+
/** DELIBERATE host aggregation prefixes — the localized halves of "Average of" / "Min of" /
|
|
85
|
+
* "Max of". Kept apart from the defaults above for exactly the reason the English matcher
|
|
86
|
+
* keeps them apart: choosing an average is real evidence that the quantity is intensive, where
|
|
87
|
+
* a default Sum is evidence only about the host. `media` appears ONLY with a connector
|
|
88
|
+
* ("media de", "media di") — bare, it is the English word in "Media Spend". */
|
|
89
|
+
export declare const LOCALIZED_CHOICE_AGG_PREFIXES: readonly string[];
|
|
65
90
|
/** "Sum of Revenue" -> "Revenue", so the name tests judge the QUANTITY and not the host's
|
|
66
91
|
* aggregation choice. */
|
|
67
92
|
export declare function stripHostAggPrefix(name: string | null | undefined): string;
|
|
68
93
|
/** True when the name carries a DEFAULT aggregation prefix — the one Power BI applies without
|
|
69
|
-
* anyone choosing it, which is why a resulting "additive" verdict is not conclusive.
|
|
94
|
+
* anyone choosing it, which is why a resulting "additive" verdict is not conclusive. A
|
|
95
|
+
* localized default ("Soma de", "Summe von") counts; a localized CHOICE ("Média de") does
|
|
96
|
+
* not, exactly as "Average of" does not. */
|
|
70
97
|
export declare function hasDefaultAggPrefix(name: string | null | undefined): boolean;
|
|
71
98
|
/**
|
|
72
99
|
* `Sum of Sum of Revenue` -> `Sum of Revenue`. Any number of repeats of the SAME label collapse
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** One contiguous stretch of observations, and how many it holds. */
|
|
2
|
+
export type TemporalRun = {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
points: number;
|
|
6
|
+
};
|
|
7
|
+
export type TemporalCadence = {
|
|
8
|
+
/**
|
|
9
|
+
* The regular period the values are spaced on, inferred from the MEDIAN gap rather than
|
|
10
|
+
* from the column's name — a column called "Month" may hold week-endings. "irregular" when
|
|
11
|
+
* no calendar period fits the median gap, which is itself the answer to "can this be
|
|
12
|
+
* treated as a series".
|
|
13
|
+
*/
|
|
14
|
+
grain: "hour" | "day" | "weekday" | "week" | "month" | "quarter" | "year" | "irregular";
|
|
15
|
+
/** Distinct parseable points. */
|
|
16
|
+
points: number;
|
|
17
|
+
/** How many periods of `grain` the span from first to last holds, endpoints included. */
|
|
18
|
+
expectedPoints: number;
|
|
19
|
+
/** points / expectedPoints as a percentage, 0..100. 100 = no period is missing. */
|
|
20
|
+
coveragePct: number;
|
|
21
|
+
/**
|
|
22
|
+
* Contiguous runs. A gap wider than `gapFactor` periods ends a run, so scattered single
|
|
23
|
+
* misses (which a line may honestly bridge) stay one run and a real hole does not.
|
|
24
|
+
*/
|
|
25
|
+
runs: number;
|
|
26
|
+
/** The widest gap between consecutive points, in periods. 1 = perfectly contiguous. */
|
|
27
|
+
largestGapUnits: number;
|
|
28
|
+
/** The factor a gap had to exceed to split a run — recorded so a consumer can re-derive. */
|
|
29
|
+
gapFactor: number;
|
|
30
|
+
/** Present only at privacy level >= 20; capped, see MAX_RUN_BOUNDS. */
|
|
31
|
+
runBounds?: TemporalRun[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A gap must EXCEED this many inferred periods to end a run — so a boundary is a gap of six
|
|
35
|
+
* periods or more.
|
|
36
|
+
*
|
|
37
|
+
* MEASURED AGAINST THE NULL CASE, not guessed (2026-09-12). The null here is a series with no
|
|
38
|
+
* hole at all, only scattered single misses: a line across one absent day is honest, and
|
|
39
|
+
* splitting on it would break every real series that has ever dropped a reading. Simulated with
|
|
40
|
+
* mulberry32 over 400 seeds per cell, swept separately by series length and by miss rate
|
|
41
|
+
* (`cadenceNoiseFloor.test.ts` pins the result, per the standing rule that a threshold on a
|
|
42
|
+
* sample statistic needs its noise floor measured first):
|
|
43
|
+
*
|
|
44
|
+
* miss rate | largest gap seen, worst over n = 16 / 30 / 90 / 365 and weekday / monthly
|
|
45
|
+
* 0% | 1
|
|
46
|
+
* 2% | 4
|
|
47
|
+
* 5% | 5
|
|
48
|
+
* 10% | 6
|
|
49
|
+
* 20% | 8
|
|
50
|
+
*
|
|
51
|
+
* The floor is FLAT in n — 4 at n=16 and 5 at n=365 for the same miss rate — because it is the
|
|
52
|
+
* maximum of many small draws, so a CONSTANT is correctly specified here and a sqrt(n) term
|
|
53
|
+
* would be wrong. At realistic miss rates (<= 5%) the noise ceiling is 5, which is where this
|
|
54
|
+
* sits. Above it, a boundary means a real hole: the 23-day hole in the sensor series below reads 23.
|
|
55
|
+
*
|
|
56
|
+
* THE WEEKDAY REFINEMENT IS WHAT MAKES THIS POSSIBLE. Measured at the day grain a Monday-Friday
|
|
57
|
+
* series reports a three-period gap every weekend, so the threshold would have had to clear 3
|
|
58
|
+
* on the commonest shape in the corpus and would then have been blind to genuine three-period
|
|
59
|
+
* holes. Measured in business days the same series has no gap at all.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DEFAULT_GAP_FACTOR = 5;
|
|
62
|
+
/** Run bounds are for a sentence, not a dataset; a series in 40 pieces needs no more than this. */
|
|
63
|
+
export declare const MAX_RUN_BOUNDS = 6;
|
|
64
|
+
type Stamp = {
|
|
65
|
+
/** Epoch ms at the point's start. */
|
|
66
|
+
ms: number;
|
|
67
|
+
/** Calendar parts, for the month/quarter/year arithmetic that epoch ms cannot do. */
|
|
68
|
+
y: number;
|
|
69
|
+
m: number;
|
|
70
|
+
d: number;
|
|
71
|
+
/** Day-level ISO ("YYYY-MM-DD") for run bounds. */
|
|
72
|
+
iso: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* One distinct value -> a point on the calendar, or null when it is not one.
|
|
76
|
+
*
|
|
77
|
+
* Deliberately narrow. It reads the forms this engine itself produces for a temporal column —
|
|
78
|
+
* IndexedText keys a whole-day Date as "YYYY-MM-DD" and anything else by its ISO instant — plus
|
|
79
|
+
* the period and integer-key forms classifyTemporal already recognises as time axes. A value it
|
|
80
|
+
* cannot read is DROPPED, never guessed at, and a column where most values drop yields no
|
|
81
|
+
* cadence at all (see the parse floor in measureCadence).
|
|
82
|
+
*/
|
|
83
|
+
export declare function parseTemporalPoint(raw: string, pattern?: string): Stamp | null;
|
|
84
|
+
/**
|
|
85
|
+
* Measure how a temporal column's distinct values are spaced.
|
|
86
|
+
*
|
|
87
|
+
* `values` are the distinct value LABELS as IndexedText keys them (see parseTemporalPoint for
|
|
88
|
+
* the forms read). Returns null — meaning "no cadence claim" — for fewer than three parseable
|
|
89
|
+
* points, a zero-width span, or a column where under 80% of the distinct values parse, because
|
|
90
|
+
* a cadence measured over a minority of a column describes something other than the column.
|
|
91
|
+
* Failing closed is deliberate: the consumer's fallback is today's behaviour.
|
|
92
|
+
*/
|
|
93
|
+
export declare function measureCadence(values: Iterable<string>, opts?: {
|
|
94
|
+
gapFactor?: number;
|
|
95
|
+
includeBounds?: boolean;
|
|
96
|
+
pattern?: string;
|
|
97
|
+
}): TemporalCadence | null;
|
|
98
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { IndexedText } from "./indexedText";
|
|
|
2
2
|
export type { IValueCollection } from "./indexedText";
|
|
3
3
|
export { classifyTemporal, detectTextDatePattern, classifyAdditivity, classifyNumericValueNature, hostAggHint, isIdentifierName, } from "./indexedText";
|
|
4
4
|
export type { TextDateDetection } from "./indexedText";
|
|
5
|
+
export { measureCadence, parseTemporalPoint, DEFAULT_GAP_FACTOR, MAX_RUN_BOUNDS } from "./cadence";
|
|
6
|
+
export type { TemporalCadence, TemporalRun } from "./cadence";
|
|
5
7
|
export { classifyForAggregation, allowedAggregations, defaultAggregation, isAggregationAllowed, shareOfTotalIsHonest, nameLooksIntensiveRate, nameLooksPositional, stripHostAggPrefix, hasDefaultAggPrefix, collapseRepeatedAggPrefix, codeNeedsLegacyAggNames, INTENSIVE_WORD_TOKENS, INTENSIVE_SUFFIX_TOKENS, POSITIONAL_WORD_TOKENS, POSITIONAL_SUFFIX_TOKENS, } from "./aggregation";
|
|
6
8
|
export type { AggKind, AggAdditivity, AggBasis, AggNature, AggregationClass, AggregationColumn, } from "./aggregation";
|
|
7
9
|
export type { LLMColumnWithValue } from "./models";
|
package/dist/types/models.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TemporalCadence } from "./cadence";
|
|
2
|
+
export type { TemporalCadence, TemporalRun } from "./cadence";
|
|
1
3
|
export type LLMRequestModifier = {
|
|
2
4
|
code: string;
|
|
3
5
|
not: boolean;
|
|
@@ -56,6 +58,7 @@ export type LLMColumnWithValue = {
|
|
|
56
58
|
isDatePart?: boolean;
|
|
57
59
|
isReassembledDate?: boolean;
|
|
58
60
|
dateGroupId?: string;
|
|
61
|
+
temporalCadence?: TemporalCadence;
|
|
59
62
|
sharedValueRatioWithOthers?: {
|
|
60
63
|
otherColumn: string;
|
|
61
64
|
percentShared: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bicharts/shape-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.94",
|
|
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-6W2GOB6U.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 gt}from"./chunk-QEH7WTLB.mjs";import{a as ht,b as pt}from"./chunk-2LR73DNS.mjs";import{c as dt}from"./chunk-RC567DAC.mjs";import{b as mt,f as ft}from"./chunk-E6SVTFAW.mjs";import{a as ut,b as lt,c as ct}from"./chunk-NOC2K3R2.mjs";import{a as $,b as rt,c as ot,d as Z,f as tt,h as at}from"./chunk-6NQENOVB.mjs";var Ot=[[24.4,49.4,-125,-66.9],[51.2,71.5,-168,-129.9],[18.9,22.3,-160.3,-154.8]],Lt=[7,72,-172,-52];function bt(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 _t(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():"",d=M?Q(M):null;d?((M==="US"||M==="USA")&&o++,d==="north-america"&&s++):(Ot.some(O=>bt(c,f,O))&&o++,bt(c,f,Lt)&&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 yt={"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(yt))for(let e of yt[t].split(/\s+/))e&&n.set(e,t);return n})();function Pt(n){for(let[t,e]of n){let r=j.get(t);r&&!j.has(e)&&j.set(e,r)}}Pt(mt);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=ft(String(n));return r?j.get(r)??null:null}function ye(n,t=2){return et(n.map(e=>[e,1]),t)}function et(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 xt from"papaparse";var Gt=["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"],Wt=["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"],Ft=["latitude","longitude"],Vt=["latitude","longitude"],Ct=/^\s*(sum|count|count\s+distinct|distinct\s+count)\s+of\s+/i,kt=/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])/g,Bt=new RegExp("\\b("+Gt.join("|")+")\\b|("+Wt.join("|")+")$","i"),zt=new RegExp("\\b("+Ft.join("|")+")\\b|("+Vt.join("|")+")$","i");function Mt(n){return n?String(n).replace(Ct,"").trim():""}function Ut(n){return!!n&&Ct.test(String(n))}var Kt=["count (distinct)","count distinct","distinct count","standard deviation","average","variance","median","product","stddev","std dev","count","sum","avg","min","minimum","max","maximum","var"],St=new RegExp("^\\s*("+[...Kt].sort((n,t)=>t.length-n.length).map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+")).join("|")+")\\s+of\\s+","i");function At(n){if(n==null)return"";let t=String(n),e=St.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=St.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 Ce(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 Ht(n){let t=Mt(n);return t.length===0?"":t.replace(kt," ")}function Tt(n,t){if(!t)return!1;let e=Mt(t);return n.test(Ht(t))||n.test(e)||n.test($(e).join(" "))}function Nt(n){return Tt(zt,n)}function Yt(n){return Tt(Bt,n)||Nt(n)}var Rt=/int|double|decimal|single|float|number|currency|money/i;function Zt(n){let t=String(n?.valueNature??"").trim().toLowerCase();return t==="categorical"?"Categorical":t==="ordinal"?"Ordinal":t==="continuous"||n?.isMeasure===!0||Rt.test(String(n?.dataType??""))?"Continuous":"Categorical"}function Xt(n){return n?.isMeasure===!0||Rt.test(String(n?.dataType??""))}function vt(n){let t=n??{},e=Zt(t);if(e!=="Continuous")return{nature:e,additivity:"unknown",basis:"role",suppressed:!1};if(Nt(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}:Yt(t.name)?{nature:e,additivity:"intensive_rate",basis:"name",suppressed:!1}:{nature:e,additivity:"additive",basis:"default",suppressed:!1}}function It(n){let t=vt(n),e=n??{};if(t.nature==="Categorical")return["first","distinctcount","count"];if(t.nature==="Ordinal")return Xt(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 Me(n){return It(n)[0]}function Ae(n,t){return It(n).indexOf(t)>=0}function Te(n,t){if(t!=="sum"&&t!=="count")return!1;if(t==="count")return!0;let e=vt(n);return e.additivity==="additive"||e.additivity==="part_of_whole"||e.additivity==="unknown"}var $t=12,jt=100,qt=.3,Jt=.9,Qt=120,te=1900,ee=2100,ne=0,ie=20,se=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function re(n){if(!n)return!1;let t=$(n);return t.length===0?!1:se.has(t[t.length-1])}var oe=new Set(["year","yr","fy"]),ae=n=>$(n).some(t=>oe.has(t)),ue=/^(?:(?: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 nt(n){if(!Number.isInteger(n)||n<190001||n>210012)return!1;let t=n%100;return t>=1&&t<=12}function it(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 le=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?Z?)?$/,ce=/^(\d{4})([\/.])(\d{1,2})\2(\d{1,2})$/,me=/^(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function fe(n){let t=(n||"").toLowerCase();return t==="en-us"||t==="en"||t.startsWith("en-us-")||t==="en-ph"||t==="en-bz"}function Et(n,t){let e=0,r=0,o=0,s=0,a=0,l="",c=0,f="",M=0,d=0,O=0,g=0,I=!1;for(let H of n){if(H==null)continue;let B=String(H).trim();if(B==="")continue;e++;let G;if(G=le.exec(B)){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=ce.exec(B)){let V=+G[3],i=+G[4];V>=1&&V<=12&&i>=1&&i<=31&&(l&&l!==G[2]&&(I=!0),l=G[2],a++)}else if(G=me.exec(B)){let V=+G[1],i=+G[3];V>=1&&V<=31&&i>=1&&i<=31&&(V<=12||i<=12)&&(f&&f!==G[2]&&(I=!0),f=G[2],c++,V>12&&O++,i>12&&g++,G[5]!==void 0&&M++,G[7]!==void 0&&d++)}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||I)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&&g>0)return null;let A,N;O>0?(A=!0,N="values"):g>0?(A=!1,N="values"):(A=!fe(t),N="locale");let F=A?`%d${f}%m${f}%Y`:`%m${f}%d${f}%Y`;return M===c?{pattern:F+(d===c?" %H:%M:%S":" %H:%M"),orderFrom:N}:{pattern:F,orderFrom:N}}function de(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=ht(e);return r.length>0&&t[r]!==void 0}function ge(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&&ae(e)||c&&o>=3&&o===a-s+1)return!0;let f=nt(s)&&nt(a),M=it(s)&&it(a);if(f||M){if(!n.sampleValues)return!0;let d=0,O=0;for(let g of n.sampleValues){if(g==null||g==="")continue;d++;let I=Number(String(g).trim());if(Number.isFinite(I)&&(f?nt(I):it(I))&&O++,d>=60)break}if(d>=2&&O===d)return!0}return!1}if(n.sampleValues){let s=n.locale?pt(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),(ue.test(M)||de(M,s))&&l++,a>=60)break}if(a>=2&&l/a>=.8||Et(c,n.locale)!==null)return!0}return!1}function he(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 pe(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 g=o.filter(N=>N.idx!==O.idx).map(N=>N.idx),I=new Map;for(let N of t){let F=N[e];if(typeof F!="number"||!Number.isFinite(F))continue;let H=g.length?g.map(G=>String(N[G])).join(M):"",B=I.get(H);B||(B={sum:0,cset:new Set},I.set(H,B)),B.sum+=F,B.cset.add(String(N[O.idx]))}let x=0,T=0,A=0;for(let N of I.values())N.cset.size<2||(A++,Math.abs(N.sum-100)<=100*f?x++:Math.abs(N.sum-1)<=1*f&&T++);if(A>=2&&(x/A>=.9||T/A>=.9))return{additivity:"part_of_whole",partOfWholeDim:O.name}}if(l)return{additivity:"intensive_rate"};let d=he(r);return d==="avg"||d==="min"||d==="max"?{additivity:"intensive_rate"}:d==="count"?{additivity:"additive"}:d==="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 wt(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,d=s>0?o/s:0,O=t==="Decimal"||a>0;return re(r)?"Categorical":M>=Jt&&(ut(r)&&o<=Qt||c>=te&&l<=ee||c>=ne&&l<=ie)?"Ordinal":e||o>$t&&(O||o>=jt||d>=qt)?"Continuous":"Categorical"}var Dt=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){return at(t)}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,D=[],p=0,u=0,y=0,S=null,b=null,h=null,E=!1,R=!0,w=!0,P=null,W=!1;for(let v of this._rows){let C=v[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(h===null?h=C:h+=C,i.dataType=="Decimal"){let L=this.getPrecision(C);L>y&&(y=L)}D.push(C)}else E=E||this.hasTimeComponent(C);W&&(C<P?R=!1:C>P&&(w=!1)),P=C,W=!0}}if(u>=3&&(R&&!w?i.sortedDirection="asc":w&&!R?i.sortedDirection="desc":i.sortedDirection="none"),u>0&&m.size>0&&!i.isMeasure){let v=0,C=Number.MAX_SAFE_INTEGER;for(let _ of m.values())_>v&&(v=_),_<C&&(C=_);if(i.modalShare=v/u,i.minGroupCount=C===Number.MAX_SAFE_INTEGER?null:C,m.size===2){let _=[...m.keys()].map(k=>rt(k).trim().toLowerCase()).sort(),U=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(k=>_[0]===k[0]&&_[1]===k[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=E),i.isTemporal=ge({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 v=Et(m.keys(),e);v&&(i.temporalTextPattern=v.pattern)}this.updateColumnStats10(o,i,u,m,y,b,S),this.updateColumnStats20(o,D,u,h,i,p,E,S,b,y,m,e),!i.isMeasure&&(i.dataType==="Integer"||i.dataType==="Decimal")&&wt({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 D=typeof i.lowValue=="number"?i.lowValue:null,p=typeof i.highValue=="number"?i.highValue:null,u=pe({rows:this._rows,measureColIdx:m,measureName:i.name,candidateDims:a,minNum:D,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 D=[];for(let _ of this._rows){let L=_[m];if(L==null||L==="")continue;let U=typeof L=="number"?L:parseFloat(L);isNaN(U)||D.push(U)}if(D.length===0)return;let p=[...D].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),h=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)/h*1e3)/1e3;let E=[];for(let _ of c){let L=new Set;for(let U of this._rows){let z=U[m];z==null||z===""||L.add(this.STR(U[_.idx])+"")}E.push({otherColumn:_.name,nonBlankGroupCount:L.size})}E.length>0&&(i.nonBlankGroups=E);let R=0;for(let _ of D)R+=_;R/=D.length;let w=0;for(let _ of D)w+=(_-R)*(_-R);if(w<=1e-12)return;let P=[],W=[],v=_=>{if(_.length<4)return NaN;let L=[..._].sort((z,k)=>z-k),U=z=>L[Math.min(L.length-1,Math.max(0,Math.floor(z*(L.length-1))))];return U(.75)-U(.25)},C=v(D);for(let _ of c){let L=new Map;for(let k of this._rows){let K=k[m];if(K==null||K==="")continue;let X=typeof K=="number"?K:parseFloat(K);if(isNaN(X))continue;let st=this.STR(k[_.idx])+"",q=L.get(st);q?(q.s+=X,q.n++,q.vals.push(X)):L.set(st,{s:X,n:1,vals:[X]})}let U=0;for(let k of L.values()){let K=k.s/k.n;U+=k.n*(K-R)*(K-R)}P.push({otherColumn:_.name,eta2:Math.round(U/w*1e4)/1e4});let z=[];for(let k of L.values()){let K=v(k.vals);isNaN(K)||z.push(K)}if(z.length>=2&&isFinite(C)&&C>1e-9){let k=(Math.max(...z)-Math.min(...z))/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,d=this._cols.map((i,m)=>({c:i,i:m})).filter(i=>i.c.isMeasure);for(let i=0;i<d.length;i++)for(let m=i+1;m<d.length;m++){let D=d[i].i,p=d[m].i,u=0,y=0,S=0,b=0,h=0,E=0;for(let W of this._rows){let v=W[D],C=W[p];if(v==null||v===""||C===null||C===void 0||C==="")continue;let _=typeof v=="number"?v:parseFloat(v),L=typeof C=="number"?C:parseFloat(C);isNaN(_)||isNaN(L)||(u++,y+=_,S+=L,b+=_*_,h+=L*L,E+=_*L)}if(u<M)continue;let R=u*b-y*y,w=u*h-S*S;if(R<=1e-12||w<=1e-12)continue;let P=(u*E-y*S)/Math.sqrt(R*w);if(Math.abs(P)>=f){let W=d[i].c,v=d[m].c;W.collinearWithMeasures||(W.collinearWithMeasures=[]),v.collinearWithMeasures||(v.collinearWithMeasures=[]),W.collinearWithMeasures.push(v.name),v.collinearWithMeasures.push(W.name)}}for(let i=0;i<this._cols.length;i++){let m=s[i];if(!m||m.size===0)continue;let D=[];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&&D.push({otherColumn:this._cols[p].name,percentShared:S})}D.length>0&&(this._cols[i].sharedValueRatioWithOthers=D)}let O=50,g=[];for(let i=0;i<this._cols.length;i++){let m=s[i];m&&m.size>=2&&m.size<=O&&g.push(i)}if(g.length>=2){let i=new Map,m=(p,u)=>p+":"+u;for(let p=0;p<g.length;p++)for(let u=p+1;u<g.length;u++)i.set(m(g[p],g[u]),new Map);for(let p of this._rows)for(let u=0;u<g.length;u++){let y=this.STR(p[g[u]])+"";for(let S=u+1;S<g.length;S++){let b=""+this.STR(p[g[S]]),h=i.get(m(g[u],g[S])),E=y+""+b;h.set(E,(h.get(E)??0)+1)}}let D=new Map;for(let p=0;p<g.length;p++)for(let u=p+1;u<g.length;u++){let y=g[p],S=g[u],b=s[y].size,h=s[S].size,E=i.get(m(y,S)),R=E.size,w=0;for(let C of E.values())(w===0||C<w)&&(w=C);let P=Math.round(R/(b*h)*100),W=R===b,v=R===h;if((this._cols[y].categoricalPairStats||=[]).push({otherColumn:this._cols[S].name,fillPct:P,determinesOther:W,minCellCount:w,distinctCombinations:R}),(this._cols[S].categoricalPairStats||=[]).push({otherColumn:this._cols[y].name,fillPct:P,determinesOther:v,minCellCount:w,distinctCombinations:R}),W&&b>h){let C=D.get(y);(!C||h<C.card)&&D.set(y,{name:this._cols[S].name,card:h,ratio:h/b})}if(v&&h>b){let C=D.get(S);(!C||b<C.card)&&D.set(S,{name:this._cols[y].name,card:b,ratio:b/h})}}for(let[p,u]of D)this._cols[p].primaryParentColumn=u.name,this._cols[p].nestingRatio=Math.round(u.ratio*100)/100}let I=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 D=m.distinctCount??0;if(D<=O||x>0&&D>=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>=D||p.push(u)}p.sort((u,y)=>(this._cols[u].distinctCount??0)-(this._cols[y].distinctCount??0));for(let u of p.slice(0,I)){let y=new Map,S=!0;for(let h of this._rows){let E=this.STR(h[i])+"",R=this.STR(h[u])+"",w=y.get(E);if(w===void 0)y.set(E,R);else if(w!==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/D*100)/100;break}}let T=.01,A=.05,N=.95,F=8,H=8,B=6,G=500,V=[];for(let i=0;i<this._cols.length&&V.length<H;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 h=[];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;h.push(W)}let E=h[0],R=!1;for(let w of h)if(w!==E){R=!0;break}return R?h:null}),D=V.map((b,h)=>h).filter(b=>m[b]!==null),p=b=>{let h=b.slice().sort((R,w)=>R-w),E=h.length>>1;return h.length%2?h[E]:(h[E-1]+h[E])/2},u=null,y=[],S=b=>{if(y.length>=3){let h=y.map(P=>m[P]),E=h[0].length,R=new Array(E);for(let P=0;P<E;P++){let W=0;for(let v of h)W+=v[P];R[P]=W}let w=p(R);if(w>0){let P=0;for(let v of R)Math.abs(v-w)<=w*T&&P++;let W=P/E;if(W>=N){let v=1;for(let C of h){let _=p(C)/w;_<v&&(v=_)}v>=A&&(!u||y.length>u.cols.length)&&(u={cols:y.slice(),total:w,matched:W})}}}if(!(y.length>=B))for(let h=b;h<D.length;h++)y.push(D[h]),S(h+1),y.pop()};if(S(0),u){let b=u,E={columns:b.cols.map(R=>this._cols[V[R]].name),total:Math.round(b.total*1e3)/1e3,matchedPct:Math.round(b.matched*100)/100};for(let R of b.cols)this._cols[V[R]].constantSumGroup=E}}return this._computedStatsForLevel=t,this._cols}updateColumnStats20(t,e,r,o,s,a,l,c,f,M,d,O){if(t>=20){let g=[...e].sort((T,A)=>T-A),I=Math.floor(g.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 T=A=>{let N=A instanceof Date?A:typeof A=="string"?tt(A)??new Date(A):new Date(A),F=this.wholeDayIso(N);return F?F+"T00:00:00.000Z":isNaN(N.getTime())?A:N.toISOString().slice(0,10)+"T00:00:00.000Z"};s.dataType!="DateTime"||l||!c?s.lowValue=c:s.lowValue=T(c),s.dataType!="DateTime"||l||!f?s.highValue=f:s.highValue=T(f),s.medianValue=g.length===0?null:g.length%2===0?s.dataType=="Integer"?Math.round((g[I-1]+g[I])/2):(g[I-1]+g[I])/2:g[I],s.numericPrecision=M}if(g.length>0){let T=s.avgValue??0,A=g.length,N=0,F=0;for(let B of g){let G=B-T;N+=G*G,F+=G*G*G}let H=N/A;s.skewness=H===0?0:F/A/Math.pow(Math.sqrt(H),3),s.stdDev=Math.sqrt(H)}o!==null&&(s.sum=o);let x=Array.from(d.entries()).sort((T,A)=>A[1]-T[1]);if(s.topCategories=x.slice(0,10).map(T=>T[1]),!s.isMeasure&&x.length>0){if(s.dataType==="String"){let T=x.map(N=>N[0]);s.formatSignature=gt(T);let A=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;s.formatSignature&&!A.test(s.formatSignature)&&(s.avgLength===void 0||s.avgLength>=3)&&(s.isFreeText=!0)}else s.topCategoryValues=x.slice(0,5).map(T=>T[0]);if(t>=20){let T=x.map(N=>N[0]),A=ct(T,O);if(A!==null)s.ordinalPattern=A.pattern,s.orderedDomain=A.orderedDomain;else if(s.dataType==="String"){let N=lt(T);N!==null&&(s.safeDistinctValues=N)}}}if(g.length>=8&&(s.dataType==="Integer"||s.dataType==="Decimal")){let T=A=>g[Math.floor((g.length-1)*A)];s.quantiles={p05:T(.05),p25:T(.25),p75:T(.75),p95:T(.95)}}}if(!s.isMeasure&&d.size>0){let g=Array.from(d.entries()).sort((x,T)=>T[1]-x[1]),I=dt(g.map(x=>x[0]),s.name,O);if(I!==null&&(s.geoKind=I.geoKind,s.geoMatchPct=I.geoMatchPct,I.geoAmbiguous&&(s.geoAmbiguous=!0),I.geoKind.indexOf("country")===0)){let x=et(g);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=wt({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=_t(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=I=>/[A-Z]/.test(I)?o():/[a-z]/.test(I)?r():/[0-9]/.test(I)?s():I,l=t.includes("@")&&t.includes("."),c=l?t.split("@"):[t],f=l?c[1]:"",M=f.endsWith(".com"),d=M?".com":"",O=M?f.slice(0,-4):f,g=I=>{let x="";for(let T of I)x+=a(T),/[a-zA-Z0-9]/.test(T)&&Z()<.2&&(x+=a(T));if(x.length>6){let T=Math.floor(Z()*Math.min(3,x.length-6));for(let A=0;A<T;A++){let N=0;for(;N<5;){let F=Math.floor(Z()*x.length);if(/[a-zA-Z0-9]/.test(x[F])){x=x.slice(0,F)+x.slice(F+1);break}N++}}}return x};if(l){let I=g(c[0]),x=g(O);return`${I}@${x}${d}`}else return g(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],d=l[f];if(this.STR(d)!=""){if(t&&M.dataType=="String")if(s.has(d))d=s.get(d);else{let O=this.obfuscateString(d);s.set(d,O),d=O}else if(M.dataType=="DateTime"&&!M.dateWithTime){let O=d instanceof Date?d:typeof d=="string"?tt(d)??new Date(d):new Date(d);d=(this.wholeDayIso(O)??O.toISOString().slice(0,10))+"T00:00:00.000Z"}o-=this.STR(d).length}else d=null;c[f]=d,--o}if(e.push(c),--r,r<=0||o<=0)break}return await xt.unparse(e,{header:!1})}getCSVHeaderLine(){return xt.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=ot(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=At(o);!s||s===o||e.has(s)||(e.delete(o),e.add(s),r.hostName=o,r.name=s)}}};export{_t as a,Pt as b,Q as c,ye as d,Gt as e,Wt as f,Ft as g,Vt as h,Mt as i,Ut as j,At as k,Ce as l,Nt as m,Yt as n,vt as o,It as p,Me as q,Ae as r,Te as s,re as t,Et as u,ge as v,he as w,pe as x,wt as y,Dt as z};
|