Skip to content

Commit

Permalink
Fixes and group indexes getting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 15, 2024
1 parent c14c7e7 commit a56520b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/lib/analysis/compounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export class CompoundsCollector implements CompoundsCollectorInterface {
export class CompoundsAnalyzer implements CompoundsAnalyzerSummary {
private readonly compounds: Array<Compound>;
private readonly compoundsTypesMap: Array<Compound[]>;
private readonly typesCount: number;
private readonly atoms: Array<AtomInterface>;
private readonly atomsTypesMap: Array<AtomInterface[]>;
private readonly typesCount: number;

constructor(compounds: Array<Compound>, atoms: Array<AtomInterface>) {
constructor(compounds: Array<Compound>, atoms: Array<AtomInterface>, typesCount: number) {
this.compounds = compounds;
this.atoms = atoms;
this.typesCount = Math.max(...atoms.map((atom) => atom.type)) + 1;
this.typesCount = typesCount;
this.compoundsTypesMap = this.groupCompoundsByTypes();
this.atomsTypesMap = this.groupAtomsByTypes();
}
Expand Down
22 changes: 22 additions & 0 deletions src/lib/analysis/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ export function createTransparentWeights(): TotalSummaryWeights {
};
}

export function getSummaryMatrixGroupIndexes(typesCount: number): number[][] {
const groups = [
0,
createFilledArray(typesCount, 1),
createFilledArray(typesCount, 2),
3,
4,
createFilledArray(typesCount, 5),
createFilledArray(typesCount, 6),
7,
createFilledArray(typesCount, 8),
[9, 10, 11, 12, 13],
repeatArrayValues([14, 15, 16, 17, 18], typesCount),
].flat(Infinity) as number[];

const groupIndexes: number[][] = Array.from({ length: Math.max(...groups) + 1 }, () => []);
for (let i = 0; i < groups.length; i++) {
groupIndexes[groups[i]].push(i);
}
return groupIndexes;
}

export function convertWeightsToMatrixRow(weights: TotalSummaryWeights, typesCount: number): number[] {
return [
weights.ATOMS_MEAN_SPEED,
Expand Down
18 changes: 14 additions & 4 deletions src/scripts/actions/test-simulation-parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type { TypesConfig, WorldConfig } from '@/lib/types/config';
import { createBaseWorldConfig } from '@/lib/config/world';
import { createBaseTypesConfig } from '@/lib/config/types';
import type { TotalSummary } from "@/lib/types/analysis";
import { convertWeightsToMatrixRow, createTransparentWeights, convertSummaryToMatrix } from "@/lib/analysis/helpers";
import {
convertWeightsToMatrixRow,
createTransparentWeights,
convertSummaryToMatrix,
getSummaryMatrixGroupIndexes
} from "@/lib/analysis/helpers";
import { normalizeMatrixColumns } from "@/lib/math";

export const simulationTask = async (
Expand Down Expand Up @@ -35,7 +40,7 @@ export const simulationTask = async (
const runner = new Runner(sim);
runner.runSteps(steps);

const compounds = new CompoundsAnalyzer(sim.exportCompounds(), sim.atoms);
const compounds = new CompoundsAnalyzer(sim.exportCompounds(), sim.atoms, typesConfig.FREQUENCIES.length);

const totalSummary: TotalSummary = {
WORLD: sim.summary,
Expand Down Expand Up @@ -84,9 +89,14 @@ export const actionTestSimulationParallel = async (...args: string[]) => {

const rawMatrix = summaries.map((summary) => convertSummaryToMatrix(summary));
const normalizedMatrix = normalizeMatrixColumns(rawMatrix);
console.log(rawMatrix);
const indexes = getSummaryMatrixGroupIndexes(typesConfig.FREQUENCIES.length);
const weights = convertWeightsToMatrixRow(createTransparentWeights(), typesConfig.FREQUENCIES.length);

console.log(indexes);

console.log(rawMatrix[0].length);
console.log(convertWeightsToMatrixRow(createTransparentWeights(), 6).length);
console.log(weights.length);
console.log(indexes.flat(1).length);

console.log(`[FINISH] in ${Date.now() - ts} ms`);
}
2 changes: 1 addition & 1 deletion src/scripts/actions/test-simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const actionTestSimulation = (...args: string[]) => {

console.log(sim.summary);

const compounds = new CompoundsAnalyzer(sim.exportCompounds(), sim.atoms);
const compounds = new CompoundsAnalyzer(sim.exportCompounds(), sim.atoms, typesConfig.FREQUENCIES.length);
console.log(compounds.sizeByTypes);
console.log(compounds.itemLengthSummary);
console.log(compounds.itemLengthByTypesSummary);
Expand Down
4 changes: 3 additions & 1 deletion tests/analysis/compounds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ describe.each([
const collector = new CompoundsCollector();
collector.handleLinks(links);

const analyzer = new CompoundsAnalyzer(collector.getCompounds(), atoms);
const atomTypesCount = (new Set(atoms.map(atom => atom.type))).size;

const analyzer = new CompoundsAnalyzer(collector.getCompounds(), atoms, atomTypesCount);

const compoundsActual = collector.getCompounds();
expectSameArraysOfSets(compoundsActual, compoundsExpected);
Expand Down

0 comments on commit a56520b

Please sign in to comment.