stats_view.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. const { div, h2, p, section, button, form, input, ul, li, a, h3, span, strong, table, tr, td, th } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. Object.assign(i18n, {
  4. statsParliamentCandidature: "Parliament candidatures",
  5. statsParliamentTerm: "Parliament terms",
  6. statsParliamentProposal: "Parliament proposals",
  7. statsParliamentRevocation: "Parliament revocations",
  8. statsParliamentLaw: "Parliament laws",
  9. statsCourtsCase: "Court cases",
  10. statsCourtsEvidence: "Court evidence",
  11. statsCourtsAnswer: "Court answers",
  12. statsCourtsVerdict: "Court verdicts",
  13. statsCourtsSettlement: "Court settlements",
  14. statsCourtsSettlementProposal: "Settlement proposals",
  15. statsCourtsSettlementAccepted: "Settlements accepted",
  16. statsCourtsNomination: "Judge nominations",
  17. statsCourtsNominationVote: "Nomination votes"
  18. });
  19. const C = (stats, t) => Number((stats && stats.content && stats.content[t]) || 0);
  20. const O = (stats, t) => Number((stats && stats.opinions && stats.opinions[t]) || 0);
  21. exports.statsView = (stats, filter) => {
  22. const title = i18n.statsTitle;
  23. const description = i18n.statsDescription;
  24. const modes = ['ALL', 'MINE', 'TOMBSTONE'];
  25. const types = [
  26. 'bookmark', 'event', 'task', 'votes', 'report', 'feed', 'project',
  27. 'image', 'audio', 'video', 'document', 'transfer', 'post', 'tribe',
  28. 'market', 'forum', 'job', 'aiExchange',
  29. 'parliamentCandidature','parliamentTerm','parliamentProposal','parliamentRevocation','parliamentLaw',
  30. 'courtsCase','courtsEvidence','courtsAnswer','courtsVerdict','courtsSettlement','courtsSettlementProposal','courtsSettlementAccepted','courtsNomination','courtsNominationVote'
  31. ];
  32. const labels = {
  33. bookmark: i18n.statsBookmark,
  34. event: i18n.statsEvent,
  35. task: i18n.statsTask,
  36. votes: i18n.statsVotes,
  37. report: i18n.statsReport,
  38. feed: i18n.statsFeed,
  39. project: i18n.statsProject,
  40. image: i18n.statsImage,
  41. audio: i18n.statsAudio,
  42. video: i18n.statsVideo,
  43. document: i18n.statsDocument,
  44. transfer: i18n.statsTransfer,
  45. post: i18n.statsPost,
  46. tribe: i18n.statsTribe,
  47. market: i18n.statsMarket,
  48. forum: i18n.statsForum,
  49. job: i18n.statsJob,
  50. aiExchange: i18n.statsAiExchange,
  51. parliamentCandidature: i18n.statsParliamentCandidature,
  52. parliamentTerm: i18n.statsParliamentTerm,
  53. parliamentProposal: i18n.statsParliamentProposal,
  54. parliamentRevocation: i18n.statsParliamentRevocation,
  55. parliamentLaw: i18n.statsParliamentLaw,
  56. courtsCase: i18n.statsCourtsCase,
  57. courtsEvidence: i18n.statsCourtsEvidence,
  58. courtsAnswer: i18n.statsCourtsAnswer,
  59. courtsVerdict: i18n.statsCourtsVerdict,
  60. courtsSettlement: i18n.statsCourtsSettlement,
  61. courtsSettlementProposal: i18n.statsCourtsSettlementProposal,
  62. courtsSettlementAccepted: i18n.statsCourtsSettlementAccepted,
  63. courtsNomination: i18n.statsCourtsNomination,
  64. courtsNominationVote: i18n.statsCourtsNominationVote
  65. };
  66. const totalContent = types.filter(t => t !== 'karmaScore').reduce((sum, t) => sum + C(stats, t), 0);
  67. const totalOpinions = types.reduce((sum, t) => sum + O(stats, t), 0);
  68. const blockStyle = 'padding:16px;border:1px solid #ddd;border-radius:8px;margin-bottom:24px;';
  69. const headerStyle = 'background-color:#f8f9fa; padding:24px; border-radius:8px; border:1px solid #e0e0e0; box-shadow:0 2px 8px rgba(0,0,0,0.1);';
  70. return template(
  71. title,
  72. section(
  73. div({ class: 'tags-header' },
  74. h2(title),
  75. p(description)
  76. ),
  77. div({ class: 'mode-buttons', style: 'display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:16px;margin-bottom:24px;' },
  78. modes.map(m =>
  79. form({ method: 'GET', action: '/stats' },
  80. input({ type: 'hidden', name: 'filter', value: m }),
  81. button({ type: 'submit', class: filter === m ? 'filter-btn active' : 'filter-btn' }, i18n[m + 'Button'])
  82. )
  83. )
  84. ),
  85. section(
  86. div({ style: headerStyle },
  87. h3({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsCreatedAt}: `, span({ style: 'color:#888;' }, stats.createdAt)),
  88. h3({ style: 'font-size:18px; color:#555; margin:8px 0; font-weight:600;' },
  89. a({ class: "user-link", href: `/author/${encodeURIComponent(stats.id)}`, style: 'color:#007bff; text-decoration:none;' }, stats.id)
  90. ),
  91. div({ style: 'margin-bottom:16px;' },
  92. ul({ style: 'list-style-type:none; padding:0; margin:0;' },
  93. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsBlobsSize}: `, span({ style: 'color:#888;' }, stats.statsBlobsSize)),
  94. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsBlockchainSize}: `, span({ style: 'color:#888;' }, stats.statsBlockchainSize)),
  95. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, strong(`${i18n.statsSize}: `, span({ style: 'color:#888;' }, span({ style: 'color:#555;' }, stats.folderSize))))
  96. )
  97. )
  98. ),
  99. div({ style: headerStyle }, h3(`${i18n.bankingUserEngagementScore}: ${C(stats, 'karmaScore')}`)),
  100. div({ style: headerStyle },
  101. h3(i18n.statsCarbonFootprintTitle || 'Carbon Footprint'),
  102. (() => {
  103. const parseSize = (s) => {
  104. if (!s) return 0;
  105. const m = String(s).match(/([\d.]+)\s*(GB|MB|KB|B)/i);
  106. if (!m) return 0;
  107. const v = parseFloat(m[1]);
  108. const u = m[2].toUpperCase();
  109. if (u === 'GB') return v * 1024;
  110. if (u === 'MB') return v;
  111. if (u === 'KB') return v / 1024;
  112. return v / (1024 * 1024);
  113. };
  114. const blobsMB = parseSize(stats.statsBlobsSize);
  115. const chainMB = parseSize(stats.statsBlockchainSize);
  116. const totalMB = blobsMB + chainMB;
  117. const kWhPerMB = 0.0002;
  118. const gCO2PerKWh = 475;
  119. const networkCO2 = parseFloat((totalMB * kWhPerMB * gCO2PerKWh).toFixed(2));
  120. const inhabitants = stats.usersKPIs?.totalInhabitants || stats.inhabitants || 1;
  121. const userCO2 = parseFloat((networkCO2 / Math.max(1, inhabitants)).toFixed(2));
  122. const maxAnnualCO2 = 500;
  123. if (filter === 'MINE') {
  124. const pct = networkCO2 > 0 ? Math.min(100, (userCO2 / networkCO2) * 100).toFixed(1) : '0.0';
  125. return div({ class: 'carbon-chart' },
  126. div({ class: 'carbon-bar-label' },
  127. span(i18n.statsCarbonUser || 'Your footprint'),
  128. span(`${userCO2} g CO₂`)
  129. ),
  130. div({ class: 'carbon-bar-track' },
  131. div({ class: 'carbon-bar-fill carbon-bar-mine', style: `width:${pct}%;` })
  132. ),
  133. div({ class: 'carbon-bar-label' },
  134. span(i18n.statsCarbonNetwork || 'Network total'),
  135. span(`${networkCO2} g CO₂`)
  136. ),
  137. div({ class: 'carbon-bar-track' },
  138. div({ class: 'carbon-bar-fill carbon-bar-network', style: 'width:100%;' })
  139. ),
  140. p({ class: 'carbon-bar-note' }, strong(`${pct}%`), ` ${i18n.statsCarbonOfNetwork || 'of network total'}`),
  141. p({ class: 'carbon-bar-formula' }, 'Based on local data storage weight ', strong('(0.0002 kWh/MB × 475 g CO₂/kWh)'))
  142. );
  143. }
  144. if (filter === 'TOMBSTONE') {
  145. const tombCount = stats.tombstoneKPIs?.networkTombstoneCount || 0;
  146. const avgTombBytes = 500;
  147. const tombMB = (tombCount * avgTombBytes) / (1024 * 1024);
  148. const tombCO2 = parseFloat((tombMB * kWhPerMB * gCO2PerKWh).toFixed(4));
  149. const tombPct = networkCO2 > 0 ? Math.min(100, (tombCO2 / networkCO2) * 100).toFixed(1) : '0.0';
  150. return div({ class: 'carbon-chart' },
  151. div({ class: 'carbon-bar-label' },
  152. span(i18n.statsCarbonTombstone || 'Tombstoning footprint'),
  153. span(`${tombCO2} g CO₂`)
  154. ),
  155. div({ class: 'carbon-bar-track' },
  156. div({ class: 'carbon-bar-fill carbon-bar-mine', style: `width:${tombPct}%;` })
  157. ),
  158. div({ class: 'carbon-bar-label' },
  159. span(i18n.statsCarbonNetwork || 'Network total'),
  160. span(`${networkCO2} g CO₂`)
  161. ),
  162. div({ class: 'carbon-bar-track' },
  163. div({ class: 'carbon-bar-fill carbon-bar-network', style: 'width:100%;' })
  164. ),
  165. p({ class: 'carbon-bar-note' }, strong(`${tombPct}%`), ` ${i18n.statsCarbonOfNetwork || 'of network total'} (${tombCount} tombstones × ~${avgTombBytes} bytes)`),
  166. p({ class: 'carbon-bar-formula' }, 'Based on estimated tombstone message size ', strong('(0.0002 kWh/MB × 475 g CO₂/kWh)'))
  167. );
  168. }
  169. const pct = Math.min(100, (networkCO2 / maxAnnualCO2) * 100).toFixed(1);
  170. return div({ class: 'carbon-chart' },
  171. div({ class: 'carbon-bar-label' },
  172. span(i18n.statsCarbonNetwork || 'Network footprint'),
  173. span(`${networkCO2} g CO₂`)
  174. ),
  175. div({ class: 'carbon-bar-track' },
  176. div({ class: 'carbon-bar-fill carbon-bar-network', style: `width:${pct}%;` })
  177. ),
  178. div({ class: 'carbon-bar-label' },
  179. span(i18n.statsCarbonMaxAnnual || 'Annual max estimate'),
  180. span(`${maxAnnualCO2} g CO₂`)
  181. ),
  182. div({ class: 'carbon-bar-track' },
  183. div({ class: 'carbon-bar-fill carbon-bar-max', style: 'width:100%;' })
  184. ),
  185. p({ class: 'carbon-bar-note' }, strong(`${pct}%`), ` ${i18n.statsCarbonOfEstMax || 'of estimated max capacity'}`),
  186. p({ class: 'carbon-bar-formula' }, 'Based on local data storage weight ', strong('(0.0002 kWh/MB × 475 g CO₂/kWh)'))
  187. );
  188. })()
  189. ),
  190. div({ style: headerStyle },
  191. h3({ style: 'font-size:18px; color:#555; margin:8px 0; font-weight:600;' }, i18n.statsBankingTitle),
  192. ul({ style: 'list-style-type:none; padding:0; margin:0;' },
  193. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsEcoWalletLabel}: `, a({ href: '/wallet', style: 'color:#007bff; text-decoration:none; word-break:break-all;' }, stats?.banking?.myAddress || i18n.statsEcoWalletNotConfigured)),
  194. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsTotalEcoAddresses}: `, span({ style: 'color:#888;' }, String(stats?.banking?.totalAddresses || 0)))
  195. )
  196. ),
  197. div({ style: headerStyle },
  198. h3({ style: 'font-size:18px; color:#555; margin:8px 0; font-weight:600;' }, i18n.statsAITraining),
  199. ul({ style: 'list-style-type:none; padding:0; margin:0;' },
  200. li({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsAIExchanges}: `, span({ style: 'color:#888;' }, String(C(stats, 'aiExchange') || 0)))
  201. )
  202. ),
  203. div({ style: headerStyle }, h3(`${i18n.statsPUBs}: ${String(stats.pubsCount || 0)}`)),
  204. filter === 'ALL'
  205. ? div({ class: 'stats-container' }, [
  206. div({ style: blockStyle },
  207. h2(i18n.statsActivity7d),
  208. table({ style: 'width:100%; border-collapse: collapse;' },
  209. tr(th(i18n.day), th(i18n.messages)),
  210. ...(Array.isArray(stats.activity?.daily7) ? stats.activity.daily7 : []).map(row => tr(td(row.day), td(String(row.count))))
  211. ),
  212. p(`${i18n.statsActivity7dTotal}: ${stats.activity?.daily7Total || 0}`),
  213. p(`${i18n.statsActivity30dTotal}: ${stats.activity?.daily30Total || 0}`)
  214. ),
  215. div({ style: blockStyle },
  216. h2(`${i18n.statsDiscoveredTribes}: ${stats.allTribesPublic.length}`),
  217. table({ style: 'width:100%; border-collapse: collapse; margin-top: 8px;' },
  218. ...stats.allTribesPublic.map(t => tr(td(a({ href: `/tribe/${encodeURIComponent(t.id)}`, class: 'tribe-link' }, t.name))))
  219. )
  220. ),
  221. div({ style: blockStyle },
  222. h2(`${i18n.statsPrivateDiscoveredTribes}: ${stats.tribePrivateCount || 0}`)
  223. ),
  224. div({ style: blockStyle }, h2(`${i18n.statsUsersTitle}: ${stats.usersKPIs?.totalInhabitants || stats.inhabitants || 0}`)),
  225. div({ style: blockStyle }, h2(`${i18n.statsDiscoveredForum}: ${C(stats, 'forum')}`)),
  226. div({ style: blockStyle }, h2(`${i18n.statsDiscoveredTransfer}: ${C(stats, 'transfer')}`)),
  227. div({ style: blockStyle },
  228. h2(i18n.statsMarketTitle),
  229. ul([
  230. li(`${i18n.statsMarketTotal}: ${stats.marketKPIs?.total || 0}`),
  231. li(`${i18n.statsMarketForSale}: ${stats.marketKPIs?.forSale || 0}`),
  232. li(`${i18n.statsMarketReserved}: ${stats.marketKPIs?.reserved || 0}`),
  233. li(`${i18n.statsMarketClosed}: ${stats.marketKPIs?.closed || 0}`),
  234. li(`${i18n.statsMarketSold}: ${stats.marketKPIs?.sold || 0}`),
  235. li(`${i18n.statsMarketRevenue}: ${((stats.marketKPIs?.revenueECO || 0)).toFixed(6)} ECO`),
  236. li(`${i18n.statsMarketAvgSoldPrice}: ${((stats.marketKPIs?.avgSoldPrice || 0)).toFixed(6)} ECO`)
  237. ])
  238. ),
  239. div({ style: blockStyle },
  240. h2(i18n.statsProjectsTitle),
  241. ul([
  242. li(`${i18n.statsProjectsTotal}: ${stats.projectsKPIs?.total || 0}`),
  243. li(`${i18n.statsProjectsActive}: ${stats.projectsKPIs?.active || 0}`),
  244. li(`${i18n.statsProjectsCompleted}: ${stats.projectsKPIs?.completed || 0}`),
  245. li(`${i18n.statsProjectsPaused}: ${stats.projectsKPIs?.paused || 0}`),
  246. li(`${i18n.statsProjectsCancelled}: ${stats.projectsKPIs?.cancelled || 0}`),
  247. li(`${i18n.statsProjectsGoalTotal}: ${(stats.projectsKPIs?.ecoGoalTotal || 0)} ECO`),
  248. li(`${i18n.statsProjectsPledgedTotal}: ${(stats.projectsKPIs?.ecoPledgedTotal || 0)} ECO`),
  249. li(`${i18n.statsProjectsSuccessRate}: ${((stats.projectsKPIs?.successRate || 0)).toFixed(1)}%`),
  250. li(`${i18n.statsProjectsAvgProgress}: ${((stats.projectsKPIs?.avgProgress || 0)).toFixed(1)}%`),
  251. li(`${i18n.statsProjectsMedianProgress}: ${((stats.projectsKPIs?.medianProgress || 0)).toFixed(1)}%`),
  252. li(`${i18n.statsProjectsActiveFundingAvg}: ${((stats.projectsKPIs?.activeFundingAvg || 0)).toFixed(1)}%`)
  253. ])
  254. ),
  255. div({ style: blockStyle },
  256. h2(`${i18n.statsNetworkOpinions}: ${totalOpinions}`),
  257. ul(types.map(t => O(stats, t) > 0 ? li(`${labels[t]}: ${O(stats, t)}`) : null).filter(Boolean))
  258. ),
  259. div({ style: blockStyle },
  260. h2(`${i18n.statsNetworkContent}: ${totalContent}`),
  261. ul(
  262. types.filter(t => t !== 'karmaScore').map(t => {
  263. if (C(stats, t) <= 0) return null;
  264. if (t !== 'tribe') return li(`${labels[t]}: ${C(stats, t)}`);
  265. return li(
  266. span(`${labels[t]}: ${C(stats, t)}`),
  267. ul([
  268. li(`${i18n.statsPublic}: ${stats.tribePublicCount || 0}`),
  269. li(`${i18n.statsPrivate}: ${stats.tribePrivateCount || 0}`)
  270. ])
  271. );
  272. }).filter(Boolean)
  273. )
  274. )
  275. ])
  276. : filter === 'MINE'
  277. ? div({ class: 'stats-container' }, [
  278. div({ style: blockStyle },
  279. h2(i18n.statsActivity7d),
  280. table({ style: 'width:100%; border-collapse: collapse;' },
  281. tr(th(i18n.day), th(i18n.messages)),
  282. ...(Array.isArray(stats.activity?.daily7) ? stats.activity.daily7 : []).map(row => tr(td(row.day), td(String(row.count))))
  283. ),
  284. p(`${i18n.statsActivity7dTotal}: ${stats.activity?.daily7Total || 0}`),
  285. p(`${i18n.statsActivity30dTotal}: ${stats.activity?.daily30Total || 0}`)
  286. ),
  287. div({ style: blockStyle },
  288. h2(`${i18n.statsDiscoveredTribes}: ${stats.memberTribesDetailed.length}`),
  289. table({ style: 'width:100%; border-collapse: collapse; margin-top: 8px;' },
  290. ...stats.memberTribesDetailed.map(t => tr(td(a({ href: `/tribe/${encodeURIComponent(t.id)}`, class: 'tribe-link' }, t.name))))
  291. )
  292. ),
  293. Array.isArray(stats.myPrivateTribesDetailed) && stats.myPrivateTribesDetailed.length
  294. ? div({ style: blockStyle },
  295. h2(`${i18n.statsPrivateDiscoveredTribes}: ${stats.myPrivateTribesDetailed.length}`),
  296. table({ style: 'width:100%; border-collapse: collapse; margin-top: 8px;' },
  297. ...stats.myPrivateTribesDetailed.map(tp => tr(td(a({ href: `/tribe/${encodeURIComponent(tp.id)}`, class: 'tribe-link' }, tp.name))))
  298. )
  299. )
  300. : null,
  301. div({ style: blockStyle }, h2(`${i18n.statsYourForum}: ${C(stats, 'forum')}`)),
  302. div({ style: blockStyle }, h2(`${i18n.statsYourTransfer}: ${C(stats, 'transfer')}`)),
  303. div({ style: blockStyle },
  304. h2(i18n.statsMarketTitle),
  305. ul([
  306. li(`${i18n.statsMarketTotal}: ${stats.marketKPIs?.total || 0}`),
  307. li(`${i18n.statsMarketForSale}: ${stats.marketKPIs?.forSale || 0}`),
  308. li(`${i18n.statsMarketReserved}: ${stats.marketKPIs?.reserved || 0}`),
  309. li(`${i18n.statsMarketClosed}: ${stats.marketKPIs?.closed || 0}`),
  310. li(`${i18n.statsMarketSold}: ${stats.marketKPIs?.sold || 0}`),
  311. li(`${i18n.statsMarketRevenue}: ${((stats.marketKPIs?.revenueECO || 0)).toFixed(6)} ECO`),
  312. li(`${i18n.statsMarketAvgSoldPrice}: ${((stats.marketKPIs?.avgSoldPrice || 0)).toFixed(6)} ECO`)
  313. ])
  314. ),
  315. div({ style: blockStyle },
  316. h2(i18n.statsProjectsTitle),
  317. ul([
  318. li(`${i18n.statsProjectsTotal}: ${stats.projectsKPIs?.total || 0}`),
  319. li(`${i18n.statsProjectsActive}: ${stats.projectsKPIs?.active || 0}`),
  320. li(`${i18n.statsProjectsCompleted}: ${stats.projectsKPIs?.completed || 0}`),
  321. li(`${i18n.statsProjectsPaused}: ${stats.projectsKPIs?.paused || 0}`),
  322. li(`${i18n.statsProjectsCancelled}: ${stats.projectsKPIs?.cancelled || 0}`),
  323. li(`${i18n.statsProjectsGoalTotal}: ${(stats.projectsKPIs?.ecoGoalTotal || 0)} ECO`),
  324. li(`${i18n.statsProjectsPledgedTotal}: ${(stats.projectsKPIs?.ecoPledgedTotal || 0)} ECO`),
  325. li(`${i18n.statsProjectsSuccessRate}: ${((stats.projectsKPIs?.successRate || 0)).toFixed(1)}%`),
  326. li(`${i18n.statsProjectsAvgProgress}: ${((stats.projectsKPIs?.avgProgress || 0)).toFixed(1)}%`),
  327. li(`${i18n.statsProjectsMedianProgress}: ${((stats.projectsKPIs?.medianProgress || 0)).toFixed(1)}%`),
  328. li(`${i18n.statsProjectsActiveFundingAvg}: ${((stats.projectsKPIs?.activeFundingAvg || 0)).toFixed(1)}%`)
  329. ])
  330. ),
  331. div({ style: blockStyle },
  332. h2(`${i18n.statsYourOpinions}: ${totalOpinions}`),
  333. ul(types.map(t => O(stats, t) > 0 ? li(`${labels[t]}: ${O(stats, t)}`) : null).filter(Boolean))
  334. ),
  335. div({ style: blockStyle },
  336. h2(`${i18n.statsYourContent}: ${totalContent}`),
  337. ul(
  338. types.filter(t => t !== 'karmaScore').map(t => {
  339. if (C(stats, t) <= 0) return null;
  340. if (t !== 'tribe') return li(`${labels[t]}: ${C(stats, t)}`);
  341. return li(
  342. span(`${labels[t]}: ${C(stats, t)}`),
  343. ul([
  344. li(`${i18n.statsPublic}: ${stats.tribePublicCount || 0}`),
  345. li(`${i18n.statsPrivate}: ${stats.tribePrivateCount || 0}`),
  346. ...(Array.isArray(stats.myPrivateTribesDetailed) && stats.myPrivateTribesDetailed.length
  347. ? [
  348. li(i18n.statsPrivateDiscoveredTribes),
  349. ...stats.myPrivateTribesDetailed.map(tp =>
  350. li(a({ href: `/tribe/${encodeURIComponent(tp.id)}`, class: 'tribe-link' }, tp.name))
  351. )
  352. ]
  353. : [])
  354. ])
  355. );
  356. }).filter(Boolean)
  357. )
  358. )
  359. ])
  360. : div({ class: 'stats-container' }, [
  361. div({ style: blockStyle },
  362. h2(`${i18n.TOMBSTONEButton}: ${stats.userTombstoneCount}`),
  363. h2(`${i18n.statsTombstoneRatio.toUpperCase()}: ${((stats.tombstoneKPIs?.ratio || 0)).toFixed(2)}%`)
  364. )
  365. ])
  366. )
  367. )
  368. );
  369. };