Skip to content

Commit

Permalink
Compounds speed summary added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 19, 2024
1 parent 15905bc commit 3bcc703
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/analysis/compounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
CompoundsCollectorInterface,
CompoundsSummary,
} from '../types/analysis';
import { round } from '../math';
import { createFilledArray, createVector, round } from '../math';

export class CompoundsCollector implements CompoundsCollectorInterface {
private atomCompoundsMap: Map<AtomInterface, number> = new Map();
Expand Down Expand Up @@ -180,8 +180,13 @@ export class CompoundsAnalyzer implements CompoundsAnalyzerSummary {
}

private getCompoundSpeed(compound: Compound): number {
const speeds = [...compound].map((atom) => atom.speed.abs);
return speeds.reduce((acc, x) => acc + x, 0) / compound.size;
if (compound.size === 0) {
return 0;
}

const speedVectors = [...compound].map((atom) => atom.speed);
const zeroVector = createVector(createFilledArray(speedVectors[0].length, 0));
return speedVectors.reduce((acc, vector) => acc.add(vector), zeroVector).abs / compound.size;
}

private convertMapToArray<T>(map: Record<number, T[]>): Array<T[]> {
Expand Down
26 changes: 26 additions & 0 deletions src/lib/analysis/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ export function createTransparentWeights(): TotalSummaryWeights {
mean: 1,
median: 1,
},
COMPOUND_SPEED_SUMMARY: {
size: 1,
frequency: 1,
min: 1,
max: 1,
mean: 1,
median: 1,
},
COMPOUND_SPEED_BY_TYPES_SUMMARY: {
size: 1,
frequency: 1,
min: 1,
max: 1,
mean: 1,
median: 1,
},
};
}

Expand All @@ -45,6 +61,8 @@ export function getSummaryMatrixGroupIndexes(typesCount: number): number[][] {
createFilledArray(typesCount, 8),
[9, 10, 11, 12, 13],
repeatArrayValues([14, 15, 16, 17, 18], typesCount),
[19, 20, 21, 22],
repeatArrayValues([23, 24, 25, 26], typesCount),
].flat(Infinity) as number[];

const groupIndexes: number[][] = Array.from({ length: Math.max(...groups) + 1 }, () => []);
Expand All @@ -67,6 +85,8 @@ export function convertWeightsToSummaryMatrixRow(weights: TotalSummaryWeights, t
createFilledArray(typesCount, weights.COMPOUNDS_PER_ATOM_BY_TYPES),
Object.values(weights.COMPOUND_LENGTH_SUMMARY).slice(1),
repeatArrayValues(Object.values(weights.COMPOUND_LENGTH_BY_TYPES_SUMMARY).slice(1), typesCount),
Object.values(weights.COMPOUND_SPEED_SUMMARY).slice(2),
repeatArrayValues(Object.values(weights.COMPOUND_SPEED_BY_TYPES_SUMMARY).slice(2), typesCount),
].flat(Infinity) as number[];
}

Expand All @@ -77,6 +97,10 @@ export function convertSummaryToSummaryMatrixRow(summary: TotalSummary): number[
const compoundLengthByTypesSummary = summary.COMPOUNDS.itemLengthByTypesSummary.map(
(item) => Object.values(item).slice(1),
);
const compoundSpeedSummary = Object.values(summary.COMPOUNDS.itemSpeedSummary).slice(2);
const compoundSpeedByTypesSummary = summary.COMPOUNDS.itemSpeedByTypesSummary.map(
(item) => Object.values(item).slice(2),
);

return [
summary.WORLD.ATOMS_MEAN_SPEED,
Expand All @@ -90,6 +114,8 @@ export function convertSummaryToSummaryMatrixRow(summary: TotalSummary): number[
compoundsPerAtomByTypes,
compoundLengthSummary,
compoundLengthByTypesSummary,
compoundSpeedSummary,
compoundSpeedByTypesSummary,
].flat(Infinity) as number[];
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ export type TotalSummaryWeights = {
COMPOUNDS_PER_ATOM_BY_TYPES: number;
COMPOUND_LENGTH_SUMMARY: CompoundsSummary;
COMPOUND_LENGTH_BY_TYPES_SUMMARY: CompoundsSummary;
COMPOUND_SPEED_SUMMARY: CompoundsSummary;
COMPOUND_SPEED_BY_TYPES_SUMMARY: CompoundsSummary;
}

0 comments on commit 3bcc703

Please sign in to comment.