-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-analyze-2.5.process.js
More file actions
201 lines (172 loc) · 5.31 KB
/
Copy path6-analyze-2.5.process.js
File metadata and controls
201 lines (172 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// IMPORTS
import { Env } from '../helper/env.helper.js';
import { logger } from '../helper/logger.helper.js';
import { MongoDB } from '../dao/mongodb.dao.js';
import { Process } from './process.process.js';
import fs from 'fs';
import path from 'path';
/**
* Represents a process to analyze the repositories.
*/
class ProcessAnalyze25 extends Process {
constructor() {
super();
// Dependencies.
this.env = new Env();
// Environment variables.
this.mongoDb = new MongoDB(
this.env.getMongoDbUrl(),
this.env.getMongoDbName(),
); // MongoDB connection.
this.TOP_DATABASE_TECHNOLOGIES = [
'PostgreSQL',
'Redis',
'MongoDB',
'Elasticsearch',
'ApacheCassandra',
'InfluxDB',
'Milvus',
'EventstoreDB',
'Neo4j',
'PostGIS',
];
}
/**
* Executes the process to analyze repositories.
*/
process() {
const chart = (sets, intersections) =>
`
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Databases in Microservices</title>
<style>
body { font-family: Arial, sans-serif; text-align: left; }
</style>
</head>
<body>
<h1>Top Database Technology Associations</h1>
<div id="chart"><h2>Sets</h2>` +
sets.map((s) => '<p>' + s.technology + ' = ' + s.size + '</p>').join('') +
'<h2>Intersections</h2>' +
//'<p style="color:red;">NOTE: Only non-empty are displayed!</p>' +
intersections
.map((i) => '<p>' + i.technology + ' = ' + i.size + '</p>')
.join('') +
`</div>
</body>
</html>
`;
const analyze = async () => {
// ---
// ANALYZE: database technologies co-usage in microservices as sets notations.
// ---
// Functions.
const getSubsets = (arr) => {
let subsets = [];
const totalSubsets = Math.pow(2, arr.length);
for (let i = 0; i < totalSubsets; i++) {
let subset = [];
for (let j = 0; j < arr.length; j++) {
if (i & (1 << j)) {
subset.push(arr[j]);
}
}
subsets.push(subset);
}
return subsets;
};
// Variables.
let microservices = [];
let sets = [];
let intersections = [];
let databaseTechnologiesCombinations = [];
let databaseTechnologiesCombinationsLabels = [];
// Data.
const cursor = await this.mongoDb.getRepositories(
'repositories_microservices',
);
while (await cursor.hasNext()) {
let microservice = await cursor.next();
microservices.push(microservice); // Microservice.
}
databaseTechnologiesCombinations = getSubsets(
this.TOP_DATABASE_TECHNOLOGIES,
); // Database technologies combinations.
databaseTechnologiesCombinations.shift(); // Empty removing.
databaseTechnologiesCombinationsLabels =
databaseTechnologiesCombinations.map((s) => {
if (s.length === 1) {
// Single database
return (
s +
' \\ { ' +
this.TOP_DATABASE_TECHNOLOGIES.reduce((acc, database) => {
if (database !== s) {
acc.push(database);
}
return acc;
}, []).join(' ∪ ') +
' }'
);
} else {
// Multiple databases
return s.map((c) => c).join(' ∩ ');
}
}); // Labels generation.
// Values.
this.TOP_DATABASE_TECHNOLOGIES.forEach((technology) => {
sets.push({
technology: technology,
size: microservices.reduce((acc, microservice) => {
if (microservice.databases.includes(technology)) {
acc += 1;
}
return acc;
}, 0),
});
}); // Sets
for (let i = 0; i < databaseTechnologiesCombinations.length; i++) {
intersections.push({
technology: databaseTechnologiesCombinationsLabels[i],
size: microservices.reduce((acc, microservice) => {
if (
[
...new Set(
microservice.databases.filter((dbName) =>
this.TOP_DATABASE_TECHNOLOGIES.includes(dbName),
),
),
]
.sort()
.toString() ===
databaseTechnologiesCombinations[i].sort().toString()
) {
acc += 1; // The database list is strictly equals to the combination tested.
}
return acc;
}, 0),
}); // Intersections
}
//intersections = intersections.filter((i) => i.size !== 0); // Empty set removing.
// HTML file.
let html = path.join('results', 'analyze-25.html');
fs.writeFileSync(html, chart(sets, intersections), 'utf8');
logger.info(`[analyze] Chart: ${html}`);
this.mongoDb.disconnect();
};
this.mongoDb
.connect()
.then(() => {
analyze(); // Process entry point.
})
.catch((error) => {
logger.error(`[analyze] ${error.message}`);
});
}
}
let process25 = new ProcessAnalyze25();
process25.process();