diff --git a/CHANGELOG.md b/CHANGELOG.md index 33382cb..e87a564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ All notable changes to this project are documented here. The project follows - The Networks list shows 100 networks at a time, with a button for the rest, so it opens quickly now that every country has its own networks. - A tidier start screen: language first, then your network's name, the doors, three compact difficulty buttons with the chosen one explained below, and one drop-down for your home city with the five suggested homes at the top. - Pick your own AS number next to your network's name when you start (#135). Leave it empty and the game picks one, and the round green arrow in the name box suggests another name. +- Every network in a POP's PNI list now shows how you reach it today and whether a PNI there is worth the cross-connect (#175, #172). A chip says PNI here (with size and load), PNI elsewhere, which exchanges you peer at, whose customer cone carries it, transit only or not reached; a value line shows how much of its traffic leaves from that POP over transit, exchanges or other PNIs, and what a PNI there would save or cost a month. The best candidates get a ⭐ Worth it tag, the list sorts them first, filters to All, Via transit, Worth it or Already PNI, and groups networks by type, with idle groups folded. The same chip shows in the Networks tab and in the bulk PNI preview. ## [1.37.0] — 2026-10-28 diff --git a/site/i18n/de.js b/site/i18n/de.js index e070d5e..1c13625 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2842,6 +2842,34 @@ "pni_all.pni_size":"PNI-Größe", "pni_all.setup_total":"Einrichtung gesamt", "pni_all.traffic_charges_apply":"Dazu kommen Traffic-Gebühren von {price} pro Gbps.", +"pni_list.chip_not_reached":"Nicht erreichbar", +"pni_list.chip_peers_at":"Peering an {list}", +"pni_list.chip_pni_at":"PNI in {list}", +"pni_list.chip_pni_elsewhere":"PNI woanders: {list}", +"pni_list.chip_pni_here":"PNI hier · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI hier · bestellt", +"pni_list.chip_via_a_cone":"Über den Cone eines Peers", +"pni_list.chip_via_cone":"Über den Cone von {net}", +"pni_list.chip_via_transit":"Über Transit", +"pni_list.f_all":"Alle", +"pni_list.f_pni":"Schon PNI", +"pni_list.f_transit":"Über Transit", +"pni_list.f_worth":"Lohnt sich", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Hier gibt's wenig zu holen: {g}", +"pni_list.n_here":"{g} hier", +"pni_list.n_networks_w_worth_it":{"one":"{n} Netz · {w} lohnt sich","other":"{n} Netze · {w} lohnen sich"}, +"pni_list.nothing_matches":"Kein Netz hier passt zu diesem Filter.", +"pni_list.saves_minus_cost":"Spart {saved} Transit im Monat; der PNI kostet {cost} im Monat.", +"pni_list.sort_az":"Sortierung: A–Z", +"pni_list.sort_worth":"Sortierung: lohnende zuerst", +"pni_list.via_drop":"{g} verworfen", +"pni_list.via_haul":"{g} über den Backbone", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} Transit", +"pni_list.with_port":"{port}-PNI: {val}", +"pni_list.worth_it":"Lohnt sich", +"pni_list.worth_rule":"⭐ Lohnt sich: Ein PNI hier spart mehr Transit, als er im Monat kostet, trägt mindestens 1 Gbps, die du heute verwirfst, oder nimmt mindestens 1 Gbps von einem Exchange-Port, der zu 80 % voll ist.", "pnis.a_new_region_is_coming_online":"Eine neue Region geht bald online. Sie geht seit 2019 bald online.", "pnis.about_n_days_to_go_nothing":"Noch etwa {n} Tage. Nichts zu tun außer warten oder nachhaken.", "pnis.augment_with_net_delivered_in_city":"Erweiterung mit {net} in {city} geliefert.
Jetzt {port}.", diff --git a/site/i18n/es.js b/site/i18n/es.js index 5baa724..03be971 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2840,6 +2840,34 @@ "pni_all.pni_size":"Capacidad del PNI", "pni_all.setup_total":"Coste total de instalación", "pni_all.traffic_charges_apply":"También se aplican cargos de tráfico de {price} por Gbps.", +"pni_list.chip_not_reached":"Sin alcance", +"pni_list.chip_peers_at":"Peering en {list}", +"pni_list.chip_pni_at":"PNI en {list}", +"pni_list.chip_pni_elsewhere":"PNI en otro sitio: {list}", +"pni_list.chip_pni_here":"PNI aquí · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI aquí · pedido", +"pni_list.chip_via_a_cone":"Por el cono de un peer", +"pni_list.chip_via_cone":"Por el cono de {net}", +"pni_list.chip_via_transit":"Por tránsito", +"pni_list.f_all":"Todas", +"pni_list.f_pni":"Ya con PNI", +"pni_list.f_transit":"Por tránsito", +"pni_list.f_worth":"Merece la pena", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Poco que ganar aquí: {g}", +"pni_list.n_here":"{g} aquí", +"pni_list.n_networks_w_worth_it":{"one":"{n} red · {w} merecen la pena","other":"{n} redes · {w} merecen la pena"}, +"pni_list.nothing_matches":"Ninguna red de aquí coincide con este filtro.", +"pni_list.saves_minus_cost":"Ahorra {saved} de tránsito al mes; el PNI cuesta {cost} al mes.", +"pni_list.sort_az":"Orden: A–Z", +"pni_list.sort_worth":"Orden: las que merecen la pena primero", +"pni_list.via_drop":"{g} descartados", +"pni_list.via_haul":"{g} por el backbone", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} tránsito", +"pni_list.with_port":"PNI de {port}: {val}", +"pni_list.worth_it":"Merece la pena", +"pni_list.worth_rule":"⭐ Merece la pena: un PNI aquí ahorra más tránsito del que cuesta al mes, lleva al menos 1 Gbps que hoy descartas, o quita al menos 1 Gbps de un puerto de exchange lleno al 80 %.", "pnis.a_new_region_is_coming_online":"Pronto se pondrá en marcha una región nueva. Lleva poniéndose en marcha pronto desde 2019.", "pnis.about_n_days_to_go_nothing":"Faltan unos {n} días. No queda más que esperar, o perseguirlo.", "pnis.augment_with_net_delivered_in_city":"Ampliación con {net} entregada en {city}.
Ahora {port}.", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 37a5cb3..4f7ccad 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2840,6 +2840,34 @@ "pni_all.pni_size":"Capacité du PNI", "pni_all.setup_total":"Coût total d'installation", "pni_all.traffic_charges_apply":"Des frais de trafic de {price} par Gbps s'appliquent également.", +"pni_list.chip_not_reached":"Non joignable", +"pni_list.chip_peers_at":"Peering à {list}", +"pni_list.chip_pni_at":"PNI à {list}", +"pni_list.chip_pni_elsewhere":"PNI ailleurs : {list}", +"pni_list.chip_pni_here":"PNI ici · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI ici · en commande", +"pni_list.chip_via_a_cone":"Via le cône d'un peer", +"pni_list.chip_via_cone":"Via le cône de {net}", +"pni_list.chip_via_transit":"Via le transit", +"pni_list.f_all":"Tous", +"pni_list.f_pni":"Déjà en PNI", +"pni_list.f_transit":"Via le transit", +"pni_list.f_worth":"Rentable", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Peu à gagner ici : {g}", +"pni_list.n_here":"{g} ici", +"pni_list.n_networks_w_worth_it":{"one":"{n} réseau · {w} rentable(s)","other":"{n} réseaux · {w} rentable(s)"}, +"pni_list.nothing_matches":"Aucun réseau ici ne correspond à ce filtre.", +"pni_list.saves_minus_cost":"Économise {saved} de transit par mois ; le PNI coûte {cost} par mois.", +"pni_list.sort_az":"Tri : A–Z", +"pni_list.sort_worth":"Tri : les rentables d'abord", +"pni_list.via_drop":"{g} perdus", +"pni_list.via_haul":"{g} par le backbone", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} transit", +"pni_list.with_port":"PNI {port} : {val}", +"pni_list.worth_it":"Rentable", +"pni_list.worth_rule":"⭐ Rentable : un PNI ici économise plus de transit qu'il ne coûte par mois, transporte au moins 1 Gbps que tu perds aujourd'hui, ou retire au moins 1 Gbps d'un port d'exchange rempli à 80 %.", "pnis.a_new_region_is_coming_online":"Une nouvelle région arrive bientôt. Elle arrive bientôt depuis 2019.", "pnis.about_n_days_to_go_nothing":"Encore environ {n} jours. Rien à faire qu’attendre, ou relancer.", "pnis.augment_with_net_delivered_in_city":"Extension avec {net} livrée à {city}.
Désormais {port}.", diff --git a/site/i18n/it.js b/site/i18n/it.js index 6e9d5ec..df570c3 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2840,6 +2840,34 @@ "pni_all.pni_size":"Capacità PNI", "pni_all.setup_total":"Costo totale di attivazione", "pni_all.traffic_charges_apply":"Si applicano anche costi di traffico di {price} per Gbps.", +"pni_list.chip_not_reached":"Non raggiunta", +"pni_list.chip_peers_at":"Peering a {list}", +"pni_list.chip_pni_at":"PNI a {list}", +"pni_list.chip_pni_elsewhere":"PNI altrove: {list}", +"pni_list.chip_pni_here":"PNI qui · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI qui · ordinato", +"pni_list.chip_via_a_cone":"Tramite il cono di un peer", +"pni_list.chip_via_cone":"Tramite il cono di {net}", +"pni_list.chip_via_transit":"Tramite transit", +"pni_list.f_all":"Tutte", +"pni_list.f_pni":"Già in PNI", +"pni_list.f_transit":"Tramite transit", +"pni_list.f_worth":"Conviene", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Poco da guadagnare qui: {g}", +"pni_list.n_here":"{g} qui", +"pni_list.n_networks_w_worth_it":{"one":"{n} rete · {w} conviene","other":"{n} reti · {w} convengono"}, +"pni_list.nothing_matches":"Nessuna rete qui corrisponde a questo filtro.", +"pni_list.saves_minus_cost":"Risparmi {saved} di transit al mese; il PNI costa {cost} al mese.", +"pni_list.sort_az":"Ordine: A–Z", +"pni_list.sort_worth":"Ordine: prima quelle che convengono", +"pni_list.via_drop":"{g} persi", +"pni_list.via_haul":"{g} sul backbone", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} transit", +"pni_list.with_port":"PNI da {port}: {val}", +"pni_list.worth_it":"Conviene", +"pni_list.worth_rule":"⭐ Conviene: un PNI qui ti fa risparmiare più transit di quanto costa al mese, porta almeno 1 Gbps che oggi perdi, oppure toglie almeno 1 Gbps da una porta di exchange piena all'80%.", "pnis.a_new_region_is_coming_online":"Una nuova region arriverà presto. Arriva presto dal 2019.", "pnis.about_n_days_to_go_nothing":"Mancano circa {n} giorni. Non resta che aspettare, o sollecitare.", "pnis.augment_with_net_delivered_in_city":"Ampliamento con {net} consegnato a {city}.
Ora {port}.", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 58402fb..e3ae318 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2840,6 +2840,34 @@ "pni_all.pni_size":"Capacidade do PNI", "pni_all.setup_total":"Custo total de instalação", "pni_all.traffic_charges_apply":"Também se aplicam custos de tráfego de {price} por Gbps.", +"pni_list.chip_not_reached":"Sem alcance", +"pni_list.chip_peers_at":"Peering em {list}", +"pni_list.chip_pni_at":"PNI em {list}", +"pni_list.chip_pni_elsewhere":"PNI noutro sítio: {list}", +"pni_list.chip_pni_here":"PNI aqui · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI aqui · encomendado", +"pni_list.chip_via_a_cone":"Pelo cone de um peer", +"pni_list.chip_via_cone":"Pelo cone de {net}", +"pni_list.chip_via_transit":"Por trânsito", +"pni_list.f_all":"Todas", +"pni_list.f_pni":"Já com PNI", +"pni_list.f_transit":"Por trânsito", +"pni_list.f_worth":"Compensa", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Pouco a ganhar aqui: {g}", +"pni_list.n_here":"{g} aqui", +"pni_list.n_networks_w_worth_it":{"one":"{n} rede · {w} compensam","other":"{n} redes · {w} compensam"}, +"pni_list.nothing_matches":"Nenhuma rede aqui corresponde a este filtro.", +"pni_list.saves_minus_cost":"Poupa {saved} de trânsito por mês; o PNI custa {cost} por mês.", +"pni_list.sort_az":"Ordem: A–Z", +"pni_list.sort_worth":"Ordem: as que compensam primeiro", +"pni_list.via_drop":"{g} perdidos", +"pni_list.via_haul":"{g} pelo backbone", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} trânsito", +"pni_list.with_port":"PNI de {port}: {val}", +"pni_list.worth_it":"Compensa", +"pni_list.worth_rule":"⭐ Compensa: um PNI aqui poupa mais trânsito do que custa por mês, leva pelo menos 1 Gbps que hoje perdes, ou tira pelo menos 1 Gbps de uma porta de exchange cheia a 80%.", "pnis.a_new_region_is_coming_online":"Uma nova região vai entrar no ar em breve. Ela está entrando no ar em breve desde 2019.", "pnis.about_n_days_to_go_nothing":"Faltam cerca de {n} dias. Não há nada a fazer além de esperar, ou cobrar.", "pnis.augment_with_net_delivered_in_city":"Ampliação com {net} entregue em {city}.
Agora {port}.", diff --git a/src/game/70-rules/38-pni-value.js b/src/game/70-rules/38-pni-value.js new file mode 100644 index 0000000..193e8bc --- /dev/null +++ b/src/game/70-rules/38-pni-value.js @@ -0,0 +1,44 @@ +/* ---------- Is a PNI worth it? (#175, #172) ---------- + How you reach each network today, and what a PNI at one POP would take over: the traffic your users there send + to that network over transit, an exchange or a PNI elsewhere, priced with the real billing functions. Information + only: nothing here changes routing or billing. Built once per routing result (R.fl), not per row. */ +const PNI_HOT=0.8; +let PNIX=null; +function pniIdx(){if(PNIX&&PNIX.R===R)return PNIX; + const ix={},pn={}; + for(const c in S.ixp){const nm=ixName(c);for(const id of ixSessions(c)){const a=ix[id]||(ix[id]=[]);if(!a.includes(nm))a.push(nm);}} + for(const p of S.pni)(pn[p.net]||(pn[p.net]=[])).push(p); + return PNIX={R,fl:{},ix,pn};} +// One POP's flows by network, added up the first time that POP is asked about. +function pniFlows(c){const X=pniIdx();let m=X.fl[c];if(m)return m;m=X.fl[c]={}; + for(const f of R.fl||[]){if(f.junk||f.c!==c)continue;let o=m[f.n];if(!o)o=m[f.n]={t:0,ix:0,p:0,h:0,u:0,T:{},I:{}}; + o.u+=f.rem;o.t+=f.gt;o.ix+=f.gi;o.p+=f.gp;o.h+=f.gh;if(f.gt)o.T[f.ti]=(o.T[f.ti]||0)+f.gt;if(f.gi)o.I[f.ii]=(o.I[f.ii]||0)+f.gi;} + return m;} +// One status, most direct first. c: the POP you are looking at (null: anywhere). +function pniStat(id,c){const X=pniIdx(),ps=X.pn[id]||[],h=c?ps.find(p=>p.city===c):null; + if(h)return {k:'here',p:h}; + const el=[...new Set(ps.filter(p=>pniOn(p)).map(p=>p.city))];if(el.length)return {k:'else',cities:el}; + if(X.ix[id])return {k:'ix',ixs:X.ix[id]}; + if(R.cone[id])return {k:'cone',by:NET[R.cone[id]]||coneVia(id)}; + return {k:R.reachable[id]?'t':'none'};} +const pniList=a=>a.length>2?tr('pni_list.list_more',{list:a.slice(0,2).join(', '),n:a.length-2}):a.join(', '); +const PNI_ICON={here:'🔗',else:'🔗',ix:'🤝',cone:'🧺',t:'💸',none:'🚫'}; +function pniChip(id,c){const s=pniStat(id,c);let t; + if(s.k==='here'){const p=s.p;t=!pniOn(p)?tr('pni_list.chip_pni_here_on_order'):tr('pni_list.chip_pni_here',{port:((p.n||1)>1?p.n+'×':'')+pniPN(p),p:pct(Math.min(1,(R.usePni[p.id]||0)/lagCap(pniG(p),p.n)))});} + else if(s.k==='else'){const l=pniList(s.cities.map(x=>CITY[x].name));t=c?tr('pni_list.chip_pni_elsewhere',{list:l}):tr('pni_list.chip_pni_at',{list:l});} + else if(s.k==='ix')t=tr('pni_list.chip_peers_at',{list:pniList(s.ixs)}); + else if(s.k==='cone')t=s.by?tr('pni_list.chip_via_cone',{net:s.by.name}):tr('pni_list.chip_via_a_cone'); + else t=s.k==='t'?tr('pni_list.chip_via_transit'):tr('pni_list.chip_not_reached'); + return `${PNI_ICON[s.k]} ${esc(t)}`;} +/* What a new PNI with `id` at `c` would carry and save per month. It takes your users' traffic there that now + leaves over transit, an exchange or a PNI elsewhere, or does not leave at all for want of room, up to its port; transit is billed on the 95th percentile, + so the saving is the bill now minus the bill with that much less (commits included). */ +function pniVal(id,c){const o=pniFlows(c)[id]||{t:0,ix:0,p:0,h:0,u:0,T:{},I:{}},want=o.t+o.ix+o.p+o.u; + const lo=pniMin(id);let tier=-1;for(let i=lo;i=want)break;} + if(tier<0)tier=lo;const g=Math.min(want,PORT[tier].g),gt=Math.min(o.t,g);let saved=0; + if(gt>0)for(const tid in o.T){const t=S.transit.find(x=>x.id===tid);if(!t)continue;const q=R.p95[tid]??(R.useT[tid]||0),x=gt*o.T[tid]/o.t;saved+=transitMo(t,q)-transitMo(t,Math.max(0,q-x));} + const cost=pniMo({net:id,tier,n:1},g); + // Then what you drop today for want of room, then a hot exchange port's share. + const drop=Math.min(o.u,g-gt);let ixLeft=g-gt-drop,hot=0;for(const x in o.I){if(ixLeft<=0)break;const m=Math.min(ixLeft,o.I[x]);ixLeft-=m;const cp=S.ixp[x]!==undefined?ixCap(x):0;if(cp>0&&(R.useIx[x]||0)>=PNI_HOT*cp)hot+=m;} + const val=saved-cost,worth=g>=1&&(val>0||hot>=1||drop>=1); + return {...o,want,g,tier,saved,cost,val,hot,drop,worth};} diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 175a393..ccfb0e2 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -51,7 +51,7 @@ function compute(){ const cacheNets=new Set(S.caches.filter(c=>popUp(c.city)).map(c=>c.net)); const viral=(ev.viral>day?1.25:1)*(ev.php&&ev.php>day?0.7:1); // Every flow has the same shape and carries what routing asks about it again and again (nj: its network's index). - const NN=NETS.length,flows=[],flow=(c,ci,cn,j,rem,cache,junk,bz=false)=>{const n=NETS[j],f={c,n:n.id,rem,cache,junk,bz,ci,cn,ncn:!!n.cn,nj:j,nr:junk?NN:j};flows.push(f);return f;}; + const NN=NETS.length,flows=[],flow=(c,ci,cn,j,rem,cache,junk,bz=false)=>{const n=NETS[j],f={c,n:n.id,rem,cache,junk,bz,ci,cn,ncn:!!n.cn,nj:j,nr:junk?NN:j,gt:0,gi:0,gp:0,gh:0,ti:null,ii:null};flows.push(f);return f;}; // Customer demand per city, added up in S.biz order (what filtering S.biz for each city would give). const bizBw={};for(const b of S.biz){const T=BIZ_T[b.type];if(!T.l2&&!T.fiber&&(!T.event||eventLive(b))){const v=bizBw[b.city];bizBw[b.city]=(v===undefined?0:v)+b.bw;}} // Traffic shares by network index, and their sums, for each share table (and with Russia's throttle). @@ -199,7 +199,9 @@ function compute(){ // Backhaul to transit: users notice the round trip to the exit. Up to 20 ms (about 1,500 km) is free, then // it gets worse, and past 50 ms broadband and internet services count as bad service (#…). if(path.length){let ms=P.ms;if(ms===undefined){ms=0;for(const l of path)ms+=l.lat;P.ms=ms;}const rtt=2*ms; - if(rtt>LAT_OK){LATP[f.ci]+=ok*latLoss(rtt);if(!P.fg){P.fg=0;FARL.push(P,f.ci,e.ci);}P.fg+=ok;}}}R2.egT[e.k]=(R2.egT[e.k]||0)+ok;const ne=NEG[f.nj]||(NEG[f.nj]=R2.netEg[f.n]={c:0,p:0,ix:0,t:0});ne[e.k]+=ok;} + if(rtt>LAT_OK){LATP[f.ci]+=ok*latLoss(rtt);if(!P.fg){P.fg=0;FARL.push(P,f.ci,e.ci);}P.fg+=ok;}}}R2.egT[e.k]=(R2.egT[e.k]||0)+ok;const ne=NEG[f.nj]||(NEG[f.nj]=R2.netEg[f.n]={c:0,p:0,ix:0,t:0});ne[e.k]+=ok; + // Where each flow left (the PNI list asks what a PNI here would take over, #175). + if(e.k==='t'){f.gt+=ok;f.ti=e.id;}else if(e.k==='ix'){f.gi+=ok;f.ii=e.id;}else if(e.k==='p'){if(e.net===f.n&&e.city===f.c)f.gh+=ok;else f.gp+=ok;}} return amt; }; // Shortest path first. With Auto-TE, whatever does not fit spills onto up to two alternate paths @@ -294,5 +296,5 @@ function compute(){ C.revshare=(S.loans||[]).reduce((a,l)=>a+(BANKS[l.bank].equity||l.bal>0?l.share||0:0),0)*(V.eyeballs+V.business+V.ix); R2.costMo=Object.values(C).reduce((a,b)=>a+b,0); R2.revMo=V.eyeballs+V.business+V.ix+V.grant; - R=R2;UI.hotMap=hotByCity(); + Object.defineProperty(R2,'fl',{value:flows});R=R2;UI.hotMap=hotByCity(); } diff --git a/src/game/90-actions/45-pni-list.js b/src/game/90-actions/45-pni-list.js new file mode 100644 index 0000000..93c3abb --- /dev/null +++ b/src/game/90-actions/45-pni-list.js @@ -0,0 +1,6 @@ +// The PNI list's filter, sort and folded groups (#175, #172): view state only, never saved. +Object.assign(ACT,{ + pniFilter:({f})=>{UI.pniF=['all','t','worth','pni'].includes(f)?f:'all';listReset('pni');renderPanel();}, + pniGrp:({g,o})=>{if(!PNI_GRP.includes(g))return;UI.pniOpen=UI.pniOpen||{};UI.pniOpen[g]=!!o;renderPanel();}, + pniSort:()=>{UI.pniSort=UI.pniSort==='az'?'worth':'az';renderPanel();}, +}); diff --git a/src/game/90-actions/70-dashboard-lists.js b/src/game/90-actions/70-dashboard-lists.js index 3bb414b..96ae70d 100644 --- a/src/game/90-actions/70-dashboard-lists.js +++ b/src/game/90-actions/70-dashboard-lists.js @@ -1,6 +1,6 @@ Object.assign(ACT,{ custGo:({id})=>{const b=S.biz.find(x=>x.id===id);if(!b)return;$('dash').hidden=true;ACT.focusCity({city:b.city});UI.tab='cust';renderPanel();}, - listMore:({k})=>{if(k!=='conn'&&k!=='cust'&&k!=='nets')return;UI.listN=UI.listN||{};UI.listN[k]=listN(k)+LIST_PAGE;if(k==='nets'){renderLeft();return;}renderDash();}, + listMore:({k})=>{if(k!=='conn'&&k!=='cust'&&k!=='nets'&&k!=='pni')return;UI.listN=UI.listN||{};UI.listN[k]=listN(k)+LIST_PAGE;if(k==='nets'){renderLeft();return;}if(k==='pni'){renderPanel();return;}renderDash();}, custF:({v})=>{UI.kf=UI.kf||{};UI.kf.f=v==='sad'?'sad':'';listReset('cust');renderDash();}, custCity:({v})=>{UI.kf=UI.kf||{};UI.kf.city=isCity(v)?v:'';listReset('cust');renderDash();}, custSort:({k})=>{if(!['mood','mo','name','city'].includes(k))return;listReset('cust');if(UI.custSort===k)UI.custDir=-(UI.custDir||1);else{UI.custSort=k;UI.custDir=k==='mo'?-1:1;}renderDash();}, diff --git a/src/game/93-ui/40-hud-and-panels.js b/src/game/93-ui/40-hud-and-panels.js index adcb1b1..c2be442 100644 --- a/src/game/93-ui/40-hud-and-panels.js +++ b/src/game/93-ui/40-hud-and-panels.js @@ -82,7 +82,7 @@ function renderLeft(){checkLayer(); // Shown 100 at a time like the dashboard lists: every country's own eyeballs made this list long (2.0). const nl=(foc?[foc]:out?ntLost():NETS).filter(n=>!n.tail||UI.tailOpen||foc||out); for(const n of nl.slice(0,listN('nets'))){ - h+=`
${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`

${esc(offTransitHint(n.id))}

`:''}${(foc||out)&&coneVia(n.id)&&(R.cone[n.id]||!R.nt[n.id])?`

${R.cone[n.id]?tr('hud_and_panels.reached_through_the_customer_cone_of',{net:esc((NET[R.cone[n.id]]||coneVia(n.id)).name)}):tr('hud_and_panels.buys_transit_from_net_peer_with',{net:esc(coneVia(n.id).name)})}

`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;} + h+=`
${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${pniChip(n.id,null)}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`

${esc(offTransitHint(n.id))}

`:''}${(foc||out)&&coneVia(n.id)&&(R.cone[n.id]||!R.nt[n.id])?`

${R.cone[n.id]?tr('hud_and_panels.reached_through_the_customer_cone_of',{net:esc((NET[R.cone[n.id]]||coneVia(n.id)).name)}):tr('hud_and_panels.buys_transit_from_net_peer_with',{net:esc(coneVia(n.id).name)})}

`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;} h+=listMore('nets',nl.length,n=>trn('hud_and_panels.n_more_networks',n)); if(!foc&&!out)h+=`
${tr('hud_and_panels.the_long_tail')} ${tr('hud_and_panels.n_small_networks',{n:tl.length})}
${tr('hud_and_panels.p_of_traffic_between_them_scattered',{p:(tl.reduce((a,n)=>a+NSH[n.id],0)*100).toFixed(1),n:tlOn})}
${btn(UI.tailOpen?tr('common.hide'):tr('common.show'),'tailTog',{},'ghost sm')}
`; } diff --git a/src/game/93-ui/50-city-panel.js b/src/game/93-ui/50-city-panel.js index 3450c4c..b8af9ba 100644 --- a/src/game/93-ui/50-city-panel.js +++ b/src/game/93-ui/50-city-panel.js @@ -54,13 +54,7 @@ function cityPanel(c){ h+=portNote(c); h+=ixSection(c); h+=`

${tr('city_panel.private_interconnects_pni')}

${tr('city_panel.a_dedicated_cross_connect_to_one',{dc:esc(siteName(c,'a'))})}

`; - const here=NETS.filter(n=>n.pops.includes(c)); - for(const n of here){const pn=S.pni.find(x=>x.city===c&&x.net===n.id),chk=peerOk(n.id,'pni',c); - h+=`
${logo(n)}
${esc(n.name)} ${n.pol}
`; - if(pn&&!pniOn(pn))h+=pniWait(pn,c); - else if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(pniG(pn),pn.n);h+=`
${(pn.n||1)>1?`${pn.n}×${pniPN(pn)} LAG`:pniPN(pn)} PNI${fmtG(u)}
${pn.up?`
${tr('city_panel.augment_on_order_port_about_n',{port:(pn.up.n>1?pn.up.n+'×':'')+(pn.up.g1?'1G':PORT[pn.up.tier].n),n:Math.max(0,pn.up.ready-S.day)})} ${btn(tr('common.chase_it'),'pniChase',{id:pn.id},'ghost sm')}
`:''}
${prefCtl('p',pn.id,pn.pref)}${siteCtl('p',pn.id,c,pn.site)}
${PORT.map((P2,i)=>!pn.up&&!msfNope(n.id,c)&&(i>pn.tier||(pn.g1&&i===0))?btn((a=>(pn.n||1)>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_cost_mo_mo',a))({port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1)),mo:fmt$(P2.pni*(pn.n||1))}),'pni',{city:c,net:n.id,tier:i},'sm',!portOk(c,i)||S.cash<(1500+P2.setup/2)*(pn.n||1)):'').join('')}${(pn.n||1)1?btn(tr('common.member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('common.sacrificial_choke'):tr('city_panel.make_sacrificial_contains_floods_1_2'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('common.really_remove'):tr('common.remove'),'cancelPni',{id:pn.id},'ghost sm')}
`;} - else{h+=chk.ok?`
${pniG1(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:'1G',cost:fmt$(PNI_G1_COST),mo:fmt$(Math.round(PORT[0].pni/2))}),'pni',{city:c,net:n.id,tier:-1},'sm',S.cashportShown(i)&&i>=pniMin(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:P2.n,cost:fmt$(1500+P2.setup/2),mo:fmt$(P2.pni)}),'pni',{city:c,net:n.id,tier:i},'sm',S.cash<1500+P2.setup/2||!portOk(c,i)):'').join('')}
${pniEta(n.id)}${pniMin(n.id)?' · '+tr('city_panel.no_10g_net_starts_at_100g',{net:esc(n.name)}):pniG1(n.id)?' · '+tr('city_panel.sells_pnis_down_to_1g'):''}
${chk.fee?`
${tr('city_panel.paid_peering_price_mo_on_top',{price:fmt$(chk.fee)})}
`:''}`:`
${esc(chk.why)}
`;} - h+=`
`;} + h+=pniListHtml(c); h+=`

${tr('common.embedded_caches')}

${tr('city_panel.cdns_put_free_cache_servers_inside')}

`; for(const n of NETS.filter(n=>n.cache)){const have=S.caches.filter(x=>x.city===c&&x.net===n.id),dem=R.demTo[n.id]||0,ok=dem>=n.cache.min; h+=`
${logo(n)}
${esc(n.cache.name)}
${tr('common.from_net',{net:esc(n.name)})} · ${have.length?`${trn('common.n_box',have.length)} · ${tr('city_panel.serving_v',{v:fmtG(have.reduce((a,x)=>a+(R.useCache[x.id]||0),0))})}`:tr('city_panel.100g_per_box')}
${!ok?`
${tr('city_panel.needs_min_gbps_of_traffic_to',{min:n.cache.min,net:esc(n.name),now:dem.toFixed(1)})}
`:''}
diff --git a/src/game/93-ui/52-pni-list.js b/src/game/93-ui/52-pni-list.js new file mode 100644 index 0000000..b0af4d6 --- /dev/null +++ b/src/game/93-ui/52-pni-list.js @@ -0,0 +1,30 @@ +/* ---------- The PNI list of a POP (#175, #172) ---------- + Every network here answers three questions: how you reach it today (one chip), whether a PNI here is worth it + (a value line from live routing) and whether you can get one (the order buttons, policy and lead time). Sorted by + monthly value, filtered, grouped by type; groups with nothing to do (no PNI there, nothing you could order that moves 1 Gbps) stay folded. */ +const PNI_GRP=['t1','t2','eye','cdn','paid'],pniGrpOf=n=>n.pol==='paid'?'paid':n.type; +const pniGrpL=k=>k==='paid'?tr('ops.p_paid'):TYPE_L[k]; +function pniValLine(n,c,v){ + if(v.g<1)return `
${tr('pni_list.little_to_gain_here',{g:fmtG(v.want)})}
`; + const via=[v.t>=0.05?tr('pni_list.via_transit',{g:fmtG(v.t)}):'',v.ix>=0.05?tr('pni_list.via_ix',{g:fmtG(v.ix)}):'',v.p>=0.05?tr('pni_list.via_haul',{g:fmtG(v.p)}):'',v.u>=0.05?tr('pni_list.via_drop',{g:fmtG(v.u)}):''].filter(Boolean).join(' · '); + const val=(v.val>0?'+':'')+tr('common.price_mo',{price:fmt$(Math.round(v.val))}); + return `
${tr('pni_list.n_here',{g:fmtG(v.want)})}: ${via} → ${tr('pni_list.with_port',{port:PORT[v.tier].n,val})}
`;} +function pniRow(c,n,pn,v,chk){let h=`
${logo(n)}
${esc(n.name)} ${n.pol}${v&&v.worth?` ⭐ ${tr('pni_list.worth_it')}`:''}
${pniChip(n.id,c)}
${v?pniValLine(n,c,v):''}`; + if(pn&&!pniOn(pn))h+=pniWait(pn,c); + else if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(pniG(pn),pn.n);h+=`
${(pn.n||1)>1?`${pn.n}×${pniPN(pn)} LAG`:pniPN(pn)} PNI${fmtG(u)}
${pn.up?`
${tr('city_panel.augment_on_order_port_about_n',{port:(pn.up.n>1?pn.up.n+'×':'')+(pn.up.g1?'1G':PORT[pn.up.tier].n),n:Math.max(0,pn.up.ready-S.day)})} ${btn(tr('common.chase_it'),'pniChase',{id:pn.id},'ghost sm')}
`:''}
${prefCtl('p',pn.id,pn.pref)}${siteCtl('p',pn.id,c,pn.site)}
${PORT.map((P2,i)=>!pn.up&&!msfNope(n.id,c)&&(i>pn.tier||(pn.g1&&i===0))?btn((a=>(pn.n||1)>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_cost_mo_mo',a))({port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1)),mo:fmt$(P2.pni*(pn.n||1))}),'pni',{city:c,net:n.id,tier:i},'sm',!portOk(c,i)||S.cash<(1500+P2.setup/2)*(pn.n||1)):'').join('')}${(pn.n||1)1?btn(tr('common.member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('common.sacrificial_choke'):tr('city_panel.make_sacrificial_contains_floods_1_2'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('common.really_remove'):tr('common.remove'),'cancelPni',{id:pn.id},'ghost sm')}
`;} + else{h+=chk.ok?`
${pniG1(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:'1G',cost:fmt$(PNI_G1_COST),mo:fmt$(Math.round(PORT[0].pni/2))}),'pni',{city:c,net:n.id,tier:-1},'sm',S.cashportShown(i)&&i>=pniMin(n.id)?btn(tr('city_panel.port_cost_mo_mo',{port:P2.n,cost:fmt$(1500+P2.setup/2),mo:fmt$(P2.pni)}),'pni',{city:c,net:n.id,tier:i},'sm',S.cash<1500+P2.setup/2||!portOk(c,i)):'').join('')}
${pniEta(n.id)}${pniMin(n.id)?' · '+tr('city_panel.no_10g_net_starts_at_100g',{net:esc(n.name)}):pniG1(n.id)?' · '+tr('city_panel.sells_pnis_down_to_1g'):''}
${chk.fee?`
${tr('city_panel.paid_peering_price_mo_on_top',{price:fmt$(chk.fee)})}
`:''}`:`
${esc(chk.why)}
`;} + return h+`
`;} +function pniListHtml(c){const f=UI.pniF||'all',az=UI.pniSort==='az',open=UI.pniOpen||{}; + const rows=NETS.filter(n=>n.pops.includes(c)).map(n=>{const pn=S.pni.find(x=>x.city===c&&x.net===n.id)||null;const chk=pn?null:peerOk(n.id,'pni',c),v=pn?null:pniVal(n.id,c);return {n,pn,v,chk,s:pniStat(n.id,c).k,go:!!pn||(chk.ok&&v.g>=1)};}); + const keep=r=>f==='all'||(f==='t'&&(r.s==='t'||r.s==='none'))||(f==='worth'&&r.v&&r.v.worth)||(f==='pni'&&(r.s==='here'||r.s==='else')); + const val=r=>r.v?r.v.val:-Infinity; + rows.sort((a,b)=>az?a.n.name.localeCompare(b.n.name):(b.v&&b.v.worth)-(a.v&&a.v.worth)||val(b)-val(a)||a.n.name.localeCompare(b.n.name)); + let h=`
${[['all',tr('pni_list.f_all')],['t',tr('pni_list.f_transit')],['worth',tr('pni_list.f_worth')],['pni',tr('pni_list.f_pni')]].map(([k,l])=>btn(l,'pniFilter',{f:k},f===k?'sm':'ghost sm')).join('')}${btn(az?tr('pni_list.sort_az'):tr('pni_list.sort_worth'),'pniSort',{},'ghost sm')}

${tr('pni_list.worth_rule')}

`; + const shown=rows.filter(keep);if(!shown.length)return h+`

${tr('pni_list.nothing_matches')}

`; + let left=listN('pni'),tot=0; + for(const g of PNI_GRP){const gr=shown.filter(r=>pniGrpOf(r.n)===g);if(!gr.length)continue; + const w=gr.filter(r=>r.v&&r.v.worth).length,act=w||gr.some(r=>r.go),isOpen=f!=='all'||(open[g]??act); + h+=`
${btn(`${isOpen?'▾':'▸'} ${esc(pniGrpL(g))} ${trn('pni_list.n_networks_w_worth_it',gr.length,{w})}`,'pniGrp',{g,o:isOpen?0:1},'ghost sm')}
`; + if(!isOpen)continue;tot+=gr.length; + for(const r of gr){if(left--<=0)break;h+=pniRow(c,r.n,r.pn,r.v,r.chk);}} + return h+listMore('pni',tot,n=>trn('hud_and_panels.n_more_networks',n));} diff --git a/src/game/95-modals/35-pni-all.js b/src/game/95-modals/35-pni-all.js index f9dfcfc..4fa8047 100644 --- a/src/game/95-modals/35-pni-all.js +++ b/src/game/95-modals/35-pni-all.js @@ -13,7 +13,7 @@ function pniAllModal(net,tier=1){const b=pniBatch(net,tier);if(!b)return;UI.pniA ${all?`

${tr('pni_all.delivery_and_traffic_charges')}

`:n.perG?`

${tr('pni_all.traffic_charges_apply',{price:fmt$(n.perG)})}

`:''} ${S.cash${tr('interface.not_enough_cash_wait_for_revenue')}

`:''} ${all?controls:''} - ${all&&b.orders.length?`
${trn('pni_all.n_networks',Object.keys(byNet).length)}${Object.entries(byNet).map(([id,cities])=>`
${esc(NET[id].name)}${trn('save.n_pop',cities.length)}

${cities.map(c=>esc(CITY[c].name)).join(' · ')}

`).join('')}
`:b.orders.length?`

${b.orders.map(q=>esc(CITY[q.city].name)).join(' · ')}

${pniEta(net)}

`:''} + ${all&&b.orders.length?`
${trn('pni_all.n_networks',Object.keys(byNet).length)}${Object.entries(byNet).map(([id,cities])=>`
${esc(NET[id].name)}${trn('save.n_pop',cities.length)}
${pniChip(id,null)}

${cities.map(c=>esc(CITY[c].name)).join(' · ')}

`).join('')}
`:b.orders.length?`
${pniChip(net,null)}

${b.orders.map(q=>esc(CITY[q.city].name)).join(' · ')}

${pniEta(net)}

`:''} ${b.kept?`

${trn('pni_all.n_existing_or_pending_unchanged',b.kept)}

`:''} ${b.blocked.length?(all?`
${trn('pni_all.n_blocked_connections',b.blocked.length)}${blocked}
`:`

${trn('pni_all.n_blocked_pops',b.blocked.length)}

${blocked}`):''} ${!b.shared.length?`

${all?tr('pni_all.no_shared_locations'):tr('pni_all.no_shared_pops')}

`:''} diff --git a/src/i18n/en.js b/src/i18n/en.js index 41a1e3a..329113b 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2841,6 +2841,34 @@ "pni_all.pni_size":"PNI size", "pni_all.setup_total":"Total setup cost", "pni_all.traffic_charges_apply":"Traffic charges of {price} per Gbps also apply.", +"pni_list.chip_not_reached":"Not reached", +"pni_list.chip_peers_at":"Peers at {list}", +"pni_list.chip_pni_at":"PNI at {list}", +"pni_list.chip_pni_elsewhere":"PNI elsewhere: {list}", +"pni_list.chip_pni_here":"PNI here · {port} · {p}", +"pni_list.chip_pni_here_on_order":"PNI here · on order", +"pni_list.chip_via_a_cone":"Via a peer's cone", +"pni_list.chip_via_cone":"Via {net}'s cone", +"pni_list.chip_via_transit":"Via transit", +"pni_list.f_all":"All", +"pni_list.f_pni":"Already PNI", +"pni_list.f_transit":"Via transit", +"pni_list.f_worth":"Worth it", +"pni_list.list_more":"{list} +{n}", +"pni_list.little_to_gain_here":"Little to gain here: {g}", +"pni_list.n_here":"{g} here", +"pni_list.n_networks_w_worth_it":{"one":"{n} network · {w} worth it","other":"{n} networks · {w} worth it"}, +"pni_list.nothing_matches":"No network here matches this filter.", +"pni_list.saves_minus_cost":"Saves {saved} of transit a month; the PNI costs {cost} a month.", +"pni_list.sort_az":"Sort: A–Z", +"pni_list.sort_worth":"Sort: worth it first", +"pni_list.via_drop":"{g} dropped", +"pni_list.via_haul":"{g} hauled", +"pni_list.via_ix":"{g} IX", +"pni_list.via_transit":"{g} transit", +"pni_list.with_port":"{port} PNI: {val}", +"pni_list.worth_it":"Worth it", +"pni_list.worth_rule":"⭐ Worth it: a PNI here saves more transit than it costs each month, carries at least 1 Gbps you drop today, or takes at least 1 Gbps off an exchange port that is 80% full.", "pnis.a_new_region_is_coming_online":"A new region is coming online soon. It has been coming online soon since 2019.", "pnis.about_n_days_to_go_nothing":"About {n} days to go. Nothing to do but wait, or chase it.", "pnis.augment_with_net_delivered_in_city":"Augment with {net} delivered in {city}.
Now {port}.", diff --git a/src/styles/20-drawers.css b/src/styles/20-drawers.css index cf5509c..bd9b547 100644 --- a/src/styles/20-drawers.css +++ b/src/styles/20-drawers.css @@ -51,6 +51,15 @@ section h3{font-size:17px;margin-bottom:6px;display:flex;align-items:center;gap: .tag.t1{background:var(--t1)} .tag.t2{background:var(--t2)} .tag.cdn{background:var(--cdn)} .tag.eye{background:var(--eye)} .tag.open{background:var(--ok)} .tag.selective{background:var(--warn);color:var(--ink)} .tag.restrictive{background:var(--bad)} .tag.paid{background:var(--me)} .tag.st{background:var(--paper);color:var(--ink)} +/* PNI list (#175): one status chip per network, a one-line value, folded groups. Chips wrap on narrow screens. */ +.tag.worth{background:var(--warn);color:var(--ink)} +.pchips{display:flex;flex-wrap:wrap;gap:4px;margin:3px 0} +.pchip{display:inline-block;max-width:100%;border:1.5px solid var(--ink);border-radius:999px;padding:0 7px;font-size:11px;font-weight:800;line-height:1.5;background:var(--paper);color:var(--ink);overflow-wrap:anywhere} +.pchip.pk-here,.pchip.pk-else{background:var(--ok);color:#fff} +.pchip.pk-ix{background:var(--t2);color:#fff} +.pchip.pk-none{background:var(--bad);color:#fff} +.pval{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%} +.pgrp{margin:8px 0 2px}.pgrp .b{width:100%;text-align:left} .tag.st.on{background:var(--ink);color:#fff} .bar{height:11px;border:2px solid var(--ink);border-radius:7px;background:var(--paper);overflow:hidden;margin:3px 0} .stack{display:flex;height:16px;border:2px solid var(--ink);border-radius:8px;overflow:hidden;margin:4px 0 6px;background:var(--paper)} diff --git a/tests/issues.test.js b/tests/issues.test.js index 6778ef4..e77f4fd 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -571,7 +571,8 @@ test('buttons behind an open modal stay quiet, and a declined PNI clears its sta const { ev, errors } = load(); ev("ACT.start({});S.cash=1e7;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buildPop({city:'mrs'});ACT.buyTransit({city:'mrs',net:'cog',tier:1});compute()"); // the PNI button was drawn while Tangerine still wanted our traffic; by the click it doesn't - ev("R.demTo.tng=50;UI.sel={type:'city',id:'mrs'};UI.tab='peer';renderAll();R.demTo.tng=0;window.__n=0;const o=toast;toast=function(h){if(/declined/.test(h))window.__n++;return o.apply(this,arguments);}"); + // Tier 2 is folded when nothing there is worth a PNI (#175): open it, as a player would. + ev("UI.pniOpen={t2:true};R.demTo.tng=50;UI.sel={type:'city',id:'mrs'};UI.tab='peer';renderAll();R.demTo.tng=0;window.__n=0;const o=toast;toast=function(h){if(/declined/.test(h))window.__n++;return o.apply(this,arguments);}"); const btn = "document.querySelector('#panel [data-act=pni][data-args*=tng]')"; assert.ok(ev(`!!${btn}`), 'a stale button to start with'); ev(`${btn}.focus();${btn}.click()`); diff --git a/tests/pni-list.test.js b/tests/pni-list.test.js new file mode 100644 index 0000000..c479412 --- /dev/null +++ b/tests/pni-list.test.js @@ -0,0 +1,135 @@ +// The PNI list (#175, #172): how you reach each network, whether a PNI here is worth it, sorted, filtered and grouped. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +// Frankfurt with 100G of Cogentle transit and 50G of eyeballs: nothing dropped, everything over transit. +const fra = (ev, d = 50) => { + ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})"); + ev(`S.pops.fra.bb.d=${d};S.grace=null;ACT.buyTransit({city:'fra',net:'cog',tier:1});for(const t of S.transit)t.ready=0;compute()`); +}; +const chip = (ev, id, c = 'fra') => ev(`(()=>{const d=document.createElement('div');d.innerHTML=pniChip('${id}',${c ? `'${c}'` : 'null'});return d.textContent})()`); + +test('one status chip per network, most direct first', () => { + const { ev, errors } = load(); + fra(ev); + assert.equal(chip(ev, 'ggl'), '💸 Via transit'); + // PNI here, with its size and load + ev("S.pni.push({id:'pg',net:'ggl',city:'fra',tier:1});compute()"); + const load_ = ev("pct(R.usePni[S.pni[0].id]/100)"); + assert.equal(chip(ev, 'ggl'), `🔗 PNI here · 100G · ${load_}`); + // On order shows as such + ev("S.pni[0].ready=S.day+20;compute()"); + assert.equal(chip(ev, 'ggl'), '🔗 PNI here · on order'); + ev("S.pni[0].ready=0;compute()"); + // Elsewhere: the city names, and in the Networks tab (no POP) "PNI at" + ev("for(const c of ['ams','lon','par'])S.pni.push({id:'x'+c,net:'nfx',city:c,tier:1});compute()"); + assert.equal(chip(ev, 'nfx'), '🔗 PNI elsewhere: Amsterdam, London +1'); + assert.equal(chip(ev, 'ggl', null), '🔗 PNI at Frankfurt'); + // IX session + ev("ACT.buyIx({city:'fra',tier:1,signed:true});S.peers['akm@fra']=true;compute()"); + assert.equal(chip(ev, 'akm'), `🤝 Peers at ${ev("ixName('fra')")}`); + // Through a peer's customer cone: named after the peer that carries it (R.cone) + ev("S.pni.push({id:'pntt',net:'ntt',city:'fra',tier:1});compute()"); + assert.equal(ev("R.cone.voc"), 'ntt'); + assert.equal(chip(ev, 'voc'), `🧺 Via ${ev("NET.ntt.name")}'s cone`); + // Not reached once transit goes + ev("S.transit=[];compute()"); + assert.equal(ev("R.reachable.lvl"), false); + assert.equal(chip(ev, 'lvl'), '🚫 Not reached'); + assert.deepEqual(errors, []); +}); + +test('the value line matches the transit bill by hand, and the worth-it rule', () => { + const { ev, errors } = load(); + fra(ev); + const v = ev("pniVal('ggl','fra')"); + const t = ev("(()=>{const t=S.transit[0];return {q:R.p95[t.id],per:transitPerG(NET[t.net],t.city,premOn(t))*S.priceMul,floor:PORT[t.tier].g*0.2}})()"); + assert.ok(v.t > 1 && v.ix === 0 && v.p === 0 && v.u < 1e-6, 'all of it over transit'); + assert.ok(t.q - v.t > t.floor, 'above the commit, so each Gbps saved is the per-Gbps price'); + assert.ok(Math.abs(v.saved - v.t * t.per) < 1e-6, 'saved = Gbps × transit price'); + assert.equal(v.cost, ev("PORT[1].pni"), 'a 100G PNI with Goggle (no fee, no per-G)'); + assert.equal(v.tier, 1, 'the smallest port Goggle accepts'); + assert.equal(v.val, v.saved - v.cost); + assert.equal(v.worth, v.val > 0); + // Below the commit floor nothing is saved: a tiny network has little to gain. + const small = ev("pniVal('pst','fra')"); + assert.ok(small.g < 1 && !small.worth); + // A full transit port drops traffic: a PNI that carries it is worth it even if it saves no transit. + ev("S.pops.fra.bb.d=400;compute()"); + const big = ev("pniVal('nfx','fra')"); + assert.ok(big.u >= 1 && big.drop >= 1 && big.worth, 'dropped traffic makes it worth it'); + // Information only: routing is the same with or without the list reading it. + const before = ev("JSON.stringify(R.usePni)+R.served"); + ev("renderAll();UI.sel={type:'city',id:'fra'};UI.tab='peer';renderPanel();compute()"); + assert.equal(ev("JSON.stringify(R.usePni)+R.served"), before); + assert.deepEqual(errors, []); +}); + +test('the PNI list: worth it first, filters, groups by type folded when idle, phones', () => { + const { ev, errors, dom } = load(); + dom.window.innerWidth = 360; + fra(ev, 400); + ev("S.pni.push({id:'pg',net:'ggl',city:'fra',tier:1});compute()"); + const panel = () => { ev("UI.sel={type:'city',id:'fra'};UI.tab='peer';UI._ph=null;renderPanel()"); return dom.window.document.getElementById('panelBody'); }; + let p = panel(); + const heads = [...p.querySelectorAll('.pgrp')].map(x => x.textContent); + assert.ok(heads.length >= 4, 'grouped by type'); + assert.match(heads[0], /Tier 1/); + assert.ok(heads.some(h => /Paid peering/.test(h)), 'paid networks get their own group'); + // A group with nothing worth it and no PNI stays folded; one with a worth-it network is open, best first. + const rows = ev("(()=>{const r=NETS.filter(n=>n.pops.includes('fra')&&n.type==='cdn'&&n.pol!=='paid').map(n=>({id:n.id,v:pniVal(n.id,'fra')})).filter(x=>!S.pni.some(p=>p.net===x.id));return r})()"); + const w = rows.filter(r => r.v.worth).sort((a, b) => b.v.val - a.v.val); + assert.ok(w.length, 'some content network is worth it at 400G of demand'); + const names = [...p.querySelectorAll('.prow .nm')].map(x => x.textContent); + const first = ev(`NET.${w[0].id}.name`); + assert.ok(names.some(n => n.startsWith(first) && /Worth it/.test(n)), 'best candidate is tagged'); + assert.equal(p.querySelectorAll('.prow .pchip').length, names.length, 'every row has a status chip'); + assert.ok(p.querySelector('.pval'), 'value line'); + // Filters + ev("ACT.pniFilter({f:'pni'})");p = panel(); + assert.deepEqual([...p.querySelectorAll('.prow .nm')].map(x => x.textContent.split(' ')[0]), [ev("NET.ggl.name").split(' ')[0]]); + ev("ACT.pniFilter({f:'worth'})");p = panel(); + assert.ok([...p.querySelectorAll('.prow .nm')].every(x => /Worth it/.test(x.textContent))); + ev("ACT.pniFilter({f:'t'})");p = panel(); + assert.ok([...p.querySelectorAll('.pchip')].every(x => /Via transit|Not reached/.test(x.textContent))); + // Folding and unfolding by hand, A-Z sort + ev("ACT.pniFilter({f:'all'})"); + ev("ACT.pniGrp({g:'t1',o:0})");p = panel(); + assert.match(p.querySelector('.pgrp').textContent, /▸/); + ev("ACT.pniGrp({g:'t1',o:1});ACT.pniSort()");p = panel(); + assert.match(p.textContent, /Sort: A–Z/); + // Phone: chips wrap, value text stays on one line + const css = ev("[...document.querySelectorAll('style')].map(s=>s.textContent).join('')"); + assert.match(css, /\.pchips\{display:flex;flex-wrap:wrap/); + assert.match(css, /\.pval\{white-space:nowrap;overflow:hidden;text-overflow:ellipsis/); + assert.equal(ev("isPhone()"), true); + assert.deepEqual(errors, []); +}); + +test('the same chip in the Networks tab and the bulk PNI preview', () => { + const { ev, errors, dom } = load(); + fra(ev); + ev("S.pni.push({id:'pg',net:'ggl',city:'fra',tier:1});compute()"); + ev("UI.sel=null;UI.left='nets';UI.leftOpen=true;UI._lh=null;renderLeft()"); + const left = dom.window.document.getElementById('leftBody'); + assert.ok(left.querySelectorAll('.pchip').length >= 10); + assert.ok(/PNI at Frankfurt/.test(left.textContent), 'Goggle shows its PNI'); + ev("ACT.pniAllOpen({net:null})"); + const m = dom.window.document.getElementById('modal'); + assert.ok(m.querySelectorAll('.pchip').length > 0); + assert.ok(/Via transit/.test(m.textContent), 'bulk preview chips'); + assert.deepEqual(errors, []); +}); + +test('every language renders the PNI list without raw labels', () => { + for (const lang of ['de', 'es', 'fr', 'it', 'pt']) { + const { ev, errors, dom } = load({ lang }); + fra(ev, 400); + ev("UI.sel={type:'city',id:'fra'};UI.tab='peer';renderPanel();UI.left='nets';UI.leftOpen=true;renderLeft()"); + const txt = dom.window.document.getElementById('panelBody').textContent + dom.window.document.getElementById('leftBody').textContent; + assert.doesNotMatch(txt, /pni_list\./, lang); + assert.ok(dom.window.document.querySelector('#panelBody .pchip'), lang); + assert.deepEqual(errors, [], lang); + } +});