Skip to content

Commit ad4186d

Browse files
committed
Tranaformations summary added.
1 parent 1a00da2 commit ad4186d

File tree

6 files changed

+91
-9
lines changed

6 files changed

+91
-9
lines changed

src/lib/analysis/summary.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const createEmptyStepSummary = (typesCount: number): WorldSummary<number[]> => (
3030
LINKS_COUNT: [0],
3131
STEP_DURATION: [0],
3232
STEP_FREQUENCY: [0],
33+
TRANSFORMATION_COUNT: [0],
34+
TRANSFORMATION_TYPE_FROM_COUNT: Array(typesCount).fill(0),
35+
TRANSFORMATION_TYPE_TO_COUNT: Array(typesCount).fill(0),
3336
});
3437

3538
export class StepSummaryManager implements StepSummaryManagerInterface<number[]> {
@@ -105,6 +108,9 @@ export class QueueSummaryManager implements QueueSummaryManagerInterface<number[
105108
LINKS_TYPE_DELETED_MEAN: 4,
106109
STEP_DURATION: 2,
107110
STEP_FREQUENCY: 1,
111+
TRANSFORMATION_COUNT: 0,
112+
TRANSFORMATION_TYPE_FROM_COUNT: 0,
113+
TRANSFORMATION_TYPE_TO_COUNT: 0,
108114
}
109115

110116
constructor(maxSize: number) {
@@ -127,6 +133,9 @@ export class QueueSummaryManager implements QueueSummaryManagerInterface<number[
127133
LINKS_TYPE_DELETED_MEAN: new Queue(maxSize),
128134
STEP_DURATION: new Queue(maxSize),
129135
STEP_FREQUENCY: new Queue(maxSize),
136+
TRANSFORMATION_COUNT: new Queue(maxSize),
137+
TRANSFORMATION_TYPE_FROM_COUNT: new Queue(maxSize),
138+
TRANSFORMATION_TYPE_TO_COUNT: new Queue(maxSize),
130139
}
131140
}
132141

@@ -201,6 +210,13 @@ export class SummaryManager implements SummaryManagerInterface {
201210
this.stepManager.buffer.LINKS_TYPE_DELETED[link.rhs.type]++;
202211
}
203212

213+
noticeTransformation(typeFrom: number, typeTo: number): void {
214+
this.stepManager.buffer.TRANSFORMATION_COUNT[0]++;
215+
216+
this.stepManager.buffer.TRANSFORMATION_TYPE_FROM_COUNT[typeFrom]++;
217+
this.stepManager.buffer.TRANSFORMATION_TYPE_TO_COUNT[typeTo]++;
218+
}
219+
204220
startStep(typesConfig: TypesConfig): void {
205221
this.stepManager.init(typesConfig.FREQUENCIES.length);
206222
}

src/lib/analysis/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export type WorldSummary<T> = {
2323
LINKS_TYPE_DELETED_MEAN: T;
2424
STEP_DURATION: T;
2525
STEP_FREQUENCY: T,
26+
TRANSFORMATION_COUNT: T,
27+
TRANSFORMATION_TYPE_FROM_COUNT: T,
28+
TRANSFORMATION_TYPE_TO_COUNT: T,
2629
}
2730

2831
export type SummaryAttr = keyof WorldSummary<unknown>;
@@ -54,6 +57,9 @@ export type QueueSummary<T> = {
5457
LINKS_TYPE_DELETED_MEAN: QueueInterface<T>;
5558
STEP_DURATION: QueueInterface<T>;
5659
STEP_FREQUENCY: QueueInterface<T>,
60+
TRANSFORMATION_COUNT: QueueInterface<T>,
61+
TRANSFORMATION_TYPE_FROM_COUNT: QueueInterface<T>,
62+
TRANSFORMATION_TYPE_TO_COUNT: QueueInterface<T>,
5763
}
5864

5965
export interface QueueSummaryManagerInterface<T> {
@@ -71,6 +77,7 @@ export interface SummaryManagerInterface {
7177
noticeLink(link: LinkInterface, worldConfig: WorldConfig): void;
7278
noticeLinkCreated(link: LinkInterface, worldConfig: WorldConfig): void;
7379
noticeLinkDeleted(link: LinkInterface, worldConfig: WorldConfig): void;
80+
noticeTransformation(typeFrom: number, typeTo: number): void;
7481
}
7582

7683
export type Compound = Set<AtomInterface>;

src/lib/simulation/interaction.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ export class InteractionManager implements InteractionManagerInterface {
114114
dist2 <= (this.WORLD_CONFIG.MAX_LINK_RADIUS * this.getDistanceFactor(lhs, rhs) * this.getDistanceFactor(rhs, lhs)) ** 2
115115
) {
116116
const link = this.linkManager.create(lhs, rhs);
117-
this.ruleHelper.handleTransform(lhs, rhs);
117+
118+
const transformations = this.ruleHelper.handleTransform(lhs, rhs);
119+
for (const transformation of transformations) {
120+
this.summaryManager.noticeTransformation(...transformation);
121+
}
122+
118123
this.summaryManager.noticeLinkCreated(link, this.WORLD_CONFIG);
119124
}
120125
}

src/lib/simulation/types/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface LinkManagerInterface extends Iterable<LinkInterface> {
1616
export interface RulesHelperInterface {
1717
canLink(lhs: AtomInterface, rhs: AtomInterface): boolean;
1818
isLinkRedundant(lhs: AtomInterface, rhs: AtomInterface): boolean;
19-
handleTransform(lhs: AtomInterface, rhs: AtomInterface): void;
19+
handleTransform(lhs: AtomInterface, rhs: AtomInterface): [number, number][];
2020
}
2121

2222
export interface GeometryHelperInterface {

src/lib/utils/structs.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ export class RulesHelper implements RulesHelperInterface {
8787
return this._isLinkRedundant(lhs, rhs) || this._isLinkRedundant(rhs, lhs);
8888
}
8989

90-
handleTransform(lhs: AtomInterface, rhs: AtomInterface): void {
91-
this._handleTransform(lhs, rhs);
92-
this._handleTransform(rhs, lhs);
90+
handleTransform(lhs: AtomInterface, rhs: AtomInterface): [number, number][] {
91+
return [
92+
...this._handleTransform(lhs, rhs),
93+
...this._handleTransform(rhs, lhs),
94+
];
9395
}
9496

9597
private _canLink(lhs: AtomInterface, rhs: AtomInterface): boolean {
@@ -107,11 +109,12 @@ export class RulesHelper implements RulesHelperInterface {
107109
return lhs.bonds.lengthOf(rhs.type) > this.TYPES_CONFIG.TYPE_LINKS[lhs.type][rhs.type];
108110
}
109111

110-
private _handleTransform(lhs: AtomInterface, rhs: AtomInterface): void {
112+
private _handleTransform(lhs: AtomInterface, rhs: AtomInterface): [number, number][] {
111113
if (!this._issetTransformation(lhs, rhs)) {
112-
return;
114+
return [];
113115
}
114116
lhs.newType = this.TYPES_CONFIG.TRANSFORMATION[lhs.type][rhs.type];
117+
return [[lhs.type, lhs.newType]];
115118
}
116119

117120
private _issetTransformation(lhs: AtomInterface, rhs: AtomInterface): boolean {

src/web/components/config-editor/components/sections/summary-section.vue

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const timeSeriesAtomsTypeMeanSpeedConfig = {
115115
}),
116116
}
117117
const timeSeriesAtomsTypeLinksCountConfig = {
118-
id: 'atoms-type-links-count-speed',
118+
id: 'atoms-type-links-count',
119119
name: 'Atoms Type Links Count',
120120
height: 200,
121121
data: () => getCurrentSimulation().summary['ATOMS_TYPE_LINKS_COUNT'],
@@ -131,7 +131,7 @@ const timeSeriesAtomsTypeLinksCountConfig = {
131131
}),
132132
}
133133
const timeSeriesAtomsTypeLinksMeanCountConfig = {
134-
id: 'atoms-type-links-mean-count-speed',
134+
id: 'atoms-type-links-mean-count',
135135
name: 'Atoms Type Links Mean Count',
136136
height: 200,
137137
data: () => getCurrentSimulation().summary['ATOMS_TYPE_LINKS_MEAN_COUNT'],
@@ -261,10 +261,59 @@ const timeSeriesLinksTypeDeletedMeanConfig = {
261261
}),
262262
}
263263
264+
const timeSeriesTransformationsCountConfig: ChartConfig = {
265+
id: 'transformations-count',
266+
name: 'Transformations Count',
267+
data: () => getCurrentSimulation().summary['TRANSFORMATION_COUNT'],
268+
config: [
269+
{
270+
name: 'Transformations Count',
271+
options: {
272+
strokeStyle: 'rgb(13, 110, 253)',
273+
fillStyle: 'rgba(13, 110, 253, 0.4)',
274+
lineWidth: 3,
275+
},
276+
},
277+
],
278+
};
279+
const timeSeriesTransformationsTypeFromCountConfig = {
280+
id: 'transformations-type-from-count',
281+
name: 'Transformations Type From Count',
282+
height: 200,
283+
data: () => getCurrentSimulation().summary['TRANSFORMATION_TYPE_FROM_COUNT'],
284+
config: getCurrentSimulation().config.typesConfig.COLORS.map((color) => {
285+
const strColor = color.join(', ');
286+
return {
287+
name: 'Transformations Type From Count',
288+
options: {
289+
strokeStyle: `rgb(${strColor})`,
290+
lineWidth: 2,
291+
},
292+
};
293+
}),
294+
}
295+
const timeSeriesTransformationsTypeToCountConfig = {
296+
id: 'transformations-type-to-count',
297+
name: 'Transformations Type To Count',
298+
height: 200,
299+
data: () => getCurrentSimulation().summary['TRANSFORMATION_TYPE_TO_COUNT'],
300+
config: getCurrentSimulation().config.typesConfig.COLORS.map((color) => {
301+
const strColor = color.join(', ');
302+
return {
303+
name: 'Transformations Type To Count',
304+
options: {
305+
strokeStyle: `rgb(${strColor})`,
306+
lineWidth: 2,
307+
},
308+
};
309+
}),
310+
}
311+
264312
const timeSeriesConfigBase: ChartConfig[] = [
265313
timeSeriesFpsConfig,
266314
timeSeriesAtomsMeanSpeedConfig,
267315
timeSeriesLinksCountConfig,
316+
timeSeriesTransformationsCountConfig,
268317
];
269318
270319
const timeSeriesConfigCount: ChartConfig[] = [
@@ -274,6 +323,8 @@ const timeSeriesConfigCount: ChartConfig[] = [
274323
timeSeriesLinksTypeCreatedConfig,
275324
timeSeriesLinksTypeDeletedConfig,
276325
timeSeriesAtomsTypeMeanSpeedConfig,
326+
timeSeriesTransformationsTypeFromCountConfig,
327+
timeSeriesTransformationsTypeToCountConfig,
277328
];
278329
279330
const timeSeriesConfigMean: ChartConfig[] = [

0 commit comments

Comments
 (0)