convert.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const buildVectorData = (vector, toHue, toHex) => {
  2. const sqMag = vectorDot(vector, vector);
  3. const mag = Math.sqrt(sqMag);
  4. const unit = vector.map(c => c / mag);
  5. const hue = toHue(vector);
  6. const hex = toHex(vector);
  7. return { vector, sqMag, mag, unit, hue, hex };
  8. };
  9. const buildClusterData = (size, inertia, mu1, mu2, mu3, nu1, nu2, nu3, toHue, toHex) => ({
  10. size, inertia,
  11. mu: buildVectorData([mu1, mu2, mu3], toHue, toHex),
  12. nu: [nu1, nu2, nu3],
  13. });
  14. const buildPokemonData = ([name, size, ...values]) => ({
  15. name,
  16. jab: {
  17. total: buildClusterData(size, ...values.slice(0, 7), jab2hue, jab2hex),
  18. clusters: [
  19. buildClusterData(...values.slice(7, 15), jab2hue, jab2hex),
  20. buildClusterData(...values.slice(15, 23), jab2hue, jab2hex),
  21. buildClusterData(...values.slice(23, 31), jab2hue, jab2hex),
  22. ],
  23. },
  24. rgb: {
  25. total: buildClusterData(size, ...values.slice(31, 38), rgb2hue, rgb2hex),
  26. clusters: [
  27. buildClusterData(...values.slice(38, 46), rgb2hue, rgb2hex),
  28. buildClusterData(...values.slice(46, 54), rgb2hue, rgb2hex),
  29. buildClusterData(...values.slice(54, 62), rgb2hue, rgb2hex),
  30. ],
  31. },
  32. });
  33. const pokemonData = databaseV2.map(row => buildPokemonData(row));