-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-analyze-3.5.process.js
More file actions
194 lines (176 loc) · 5.46 KB
/
Copy path6-analyze-3.5.process.js
File metadata and controls
194 lines (176 loc) · 5.46 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
// 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 ProcessAnalyze35 extends Process {
constructor() {
super();
// Dependencies.
this.env = new Env();
// Environment variables.
this.mongoDb = new MongoDB(
this.env.getMongoDbUrl(),
this.env.getMongoDbName(),
); // MongoDB connection.
}
/**
* Executes the process to analyze repositories.
*/
process() {
const chart = (
data,
overallRatio1,
overallRatio2,
servicesCountMean,
databasesCountMean,
sizeCountMean,
) =>
`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Databases per Microservice</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstat/1.9.4/jstat.min.js"></script>
<style>
body { font-family: Arial, sans-serif; text-align: left; }
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<div id="graph">
<h1>Services, Size, and Databases in Microservices</h1>
<p style="color: blue;">Overall ratio 1 (( # services / # databases technologies ) / # ratios): ${overallRatio1.toFixed(2)}</p>
<p style="color: blue;">Overall ratio 2 (( # databases technologies / # services ) / # ratios): ${overallRatio2.toFixed(2)}</p>
<p style="color: blue;">Services count mean: ${servicesCountMean.toFixed(2)}</p>
<p style="color: blue;">Database count mean: ${databasesCountMean.toFixed(2)}</p>
<p style="color: blue;">Size count mean (in KB): ${sizeCountMean.toFixed(2)}</p>
<table>
<tr>
<th>Microservices architecture</th>
<th>Services</th>
<th>Size</th>
<th>Databases</th>
<th>Ratio 1 ( # services / # databases technologies )</th>
<th>Ratio 2 ( # databases technologies / # services )</th>
</tr>
` +
data
.map((d) => {
return (
'<tr><td><a href="https://www.github.com/' +
d.id +
'" target="_blank">' +
d.id +
'</a>' +
'</td><td>' +
d.nbServices +
'</td><td>' +
d.size +
'</td><td>' +
d.nbDatabases +
'</td><td>' +
d.ratio1.toFixed(2) +
'</td><td>' +
d.ratio2.toFixed(2) +
'</td></tr>'
);
})
.join('') +
`
</table>
</div>
</body>
</html>
`;
const analyze = async () => {
// ---
// ANALYZE: microservice services and databases metrics.
// ---
// Variables.
let data = [];
let ratios1 = [];
let ratios2 = [];
let overallRatio1 = 0;
let overallRatio2 = 0;
let servicesCountMean = 0;
let servicesCounts = [];
let databasesCountMean = 0;
let databasesCounts = [];
let sizeCountMean = 0;
let sizeCounts = [];
// Data.
const cursor = await this.mongoDb.getRepositories(
'repositories_microservices',
);
while (await cursor.hasNext()) {
let microservice = await cursor.next();
let { _id, databases, services_count, size } = microservice;
let nbServices = services_count - databases.length;
let nbDatabases = databases.length;
let ratio1 = nbServices / nbDatabases;
let ratio2 = nbDatabases / nbServices;
data.push({
id: _id,
nbServices: nbServices,
nbDatabases: nbDatabases,
size: size,
ratio1: ratio1,
ratio2: ratio2,
});
ratios1.push(ratio1);
ratios2.push(ratio2);
databasesCounts.push(databases.length);
servicesCounts.push(services_count);
sizeCounts.push(size);
}
overallRatio1 = ratios1.reduce((acc, r) => acc + r) / ratios1.length;
overallRatio2 = ratios2.reduce((acc, r) => acc + r) / ratios2.length;
servicesCountMean =
servicesCounts.reduce((acc, c) => acc + c) / servicesCounts.length;
databasesCountMean =
databasesCounts.reduce((acc, c) => acc + c) / databasesCounts.length;
databasesCountMean =
databasesCounts.reduce((acc, c) => acc + c) / databasesCounts.length;
sizeCountMean =
sizeCounts.reduce((acc, c) => acc + c) / sizeCounts.length;
// HTML file.
let html = path.join('results', 'analyze-35.html');
fs.writeFileSync(
html,
chart(
data,
overallRatio1,
overallRatio2,
servicesCountMean,
databasesCountMean,
sizeCountMean,
),
'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 process35 = new ProcessAnalyze35();
process35.process();