← back to Wallco Ai

scripts/compare_progress.js

55 lines

'use strict';
/**
 * Shared progress.json writer for the refiner-compare 6-column grid.
 *
 * Every backend (refiner_compare, replicate_compare, gemini_compare,
 * flux_compare, dalle_compare) derives the row state fresh from disk on
 * every write, so concurrent writers never clobber each other — the last
 * writer is always correct, and the file always reflects the union of all
 * 6 columns currently on disk.
 */
const fs = require('fs');
const path = require('path');
const { FASHION_PALETTES } = require('./fashion_palettes');

const STYLES = [
  'damask', 'arabesque trellis', 'geometric art-deco', 'botanical floral', 'ogee medallion',
  'stripe and sprig', 'block-print paisley', 'scrollwork acanthus', 'chinoiserie scenic', 'herringbone tonal',
  'guilloché lattice', 'stylized fan', 'marbled swirl', 'star tessellation', 'vine and berry',
  'diamond harlequin', 'rosette grid', 'wave and shell', 'feathered plume', 'interlocking fretwork key',
  'arts-and-crafts leaf', 'moroccan zellige', 'pinstripe ticking', 'sunburst medallion', 'quatrefoil net',
];

const OUT = path.join(__dirname, '..', 'public', 'refiner-compare');
const haveImg = p => { try { return fs.statSync(p).size > 1000; } catch { return false; } };

function buildRows() {
  return STYLES.map((style, i) => ({
    i, style,
    brand: FASHION_PALETTES[i % FASHION_PALETTES.length].brand,
    seed: 770000 + i,
    base:      haveImg(path.join(OUT, `${i}_base.png`))      ? `${i}_base.png`      : null,
    refiner:   haveImg(path.join(OUT, `${i}_refiner.png`))   ? `${i}_refiner.png`   : null,
    replicate: haveImg(path.join(OUT, `${i}_replicate.png`)) ? `${i}_replicate.png` : null,
    gemini:    haveImg(path.join(OUT, `${i}_gemini.png`))    ? `${i}_gemini.png`    : null,
    flux:      haveImg(path.join(OUT, `${i}_flux.png`))      ? `${i}_flux.png`      : null,
    dalle:     haveImg(path.join(OUT, `${i}_dalle.png`))     ? `${i}_dalle.png`     : null,
  }));
}

function save() {
  const rows = buildRows();
  // `done` still tracks the local-ComfyUI base+refiner count (the original
  // progress bar semantics). Cloud columns are surfaced as separate counts
  // in the status line on compare.html, derived directly from `rows`.
  const done = rows.reduce((n, r) => n + (r.base ? 1 : 0) + (r.refiner ? 1 : 0), 0);
  const total = STYLES.length * 2;
  fs.writeFileSync(
    path.join(OUT, 'progress.json'),
    JSON.stringify({ done, total, rows }, null, 1),
  );
  return { done, total, rows };
}

module.exports = { STYLES, OUT, haveImg, buildRows, save };