1 |
58825
|
stefania.m
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import { RawData, Row } from '../domain/raw-data';
|
3 |
|
|
import {CountryOverviewData, CountryMapData, EuropeData, OverviewMapData, CountryTableData} from '../domain/overview-map-data';
|
4 |
|
|
import {Indicator} from '../domain/overview-data';
|
5 |
|
|
|
6 |
|
|
@Injectable ()
|
7 |
|
|
export class DataHandlerService {
|
8 |
|
|
|
9 |
|
|
public convertRawMapDataToMapData(rawData: RawData) {
|
10 |
|
|
|
11 |
|
|
const overviewMapData: OverviewMapData = new OverviewMapData();
|
12 |
|
|
|
13 |
|
|
for (const series of rawData.datasets) {
|
14 |
|
|
|
15 |
|
|
if (series.series.query.name === 'new.oso.publications.affiliated') {
|
16 |
|
|
overviewMapData.publications = this.rawResultToCountryMapData(series.series.result);
|
17 |
|
|
} else if (series.series.query.name === 'new.oso.datasets.affiliated') {
|
18 |
|
|
overviewMapData.datasets = this.rawResultToCountryMapData(series.series.result);
|
19 |
|
|
} else if (series.series.query.name === 'new.oso.repositories') {
|
20 |
|
|
overviewMapData.repositories = this.rawResultToCountryMapData(series.series.result);
|
21 |
|
|
} else if (series.series.query.name === 'new.oso.journals') {
|
22 |
|
|
overviewMapData.journals = this.rawResultToCountryMapData(series.series.result);
|
23 |
|
|
} else if (series.series.query.name === 'new.oso.oa_policies') {
|
24 |
|
|
overviewMapData.policies = this.rawResultToCountryMapData(series.series.result);
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
// console.log('Overview map data (data-handler)', overviewMapData);
|
29 |
|
|
|
30 |
|
|
return overviewMapData;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
public createJoinedPublicationsCountryMap(rawData: RawData) {
|
34 |
|
|
|
35 |
|
|
const joinedPublicationsMap = new Map();
|
36 |
|
|
|
37 |
|
|
for (const series of rawData.datasets) {
|
38 |
|
|
if (series.series.query.name === 'new.oso.publications.affiliated') {
|
39 |
|
|
|
40 |
|
|
for (const rowResult of series.series.result) {
|
41 |
|
|
if (joinedPublicationsMap.has(rowResult.row[1])) {
|
42 |
|
|
const deposited = joinedPublicationsMap.get(rowResult.row[1]).deposited;
|
43 |
|
|
joinedPublicationsMap.delete(rowResult.row[1]);
|
44 |
|
|
joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
45 |
|
|
affiliated: Number(rowResult.row[0]), deposited: deposited});
|
46 |
|
|
} else {
|
47 |
|
|
joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
48 |
|
|
affiliated: Number(rowResult.row[0]), deposited: 0});
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
} else if (series.series.query.name === 'new.oso.publications.deposited') {
|
53 |
|
|
|
54 |
|
|
for (const rowResult of series.series.result) {
|
55 |
|
|
if (joinedPublicationsMap.has(rowResult.row[1])) {
|
56 |
|
|
const affiliated = joinedPublicationsMap.get(rowResult.row[1]).affiliated;
|
57 |
|
|
joinedPublicationsMap.delete(rowResult.row[1]);
|
58 |
|
|
joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
59 |
|
|
affiliated: affiliated, deposited: Number(rowResult.row[0])});
|
60 |
|
|
}
|
61 |
|
|
joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
62 |
|
|
affiliated: 0, deposited: Number(rowResult.row[0])});
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
return joinedPublicationsMap;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
public createJoinedDatasetsCountryMap(rawData: RawData) {
|
71 |
|
|
|
72 |
|
|
const joinedDatasetsMap = new Map();
|
73 |
|
|
|
74 |
|
|
for (const series of rawData.datasets) {
|
75 |
|
|
if (series.series.query.name === 'new.oso.datasets.affiliated') {
|
76 |
|
|
|
77 |
|
|
for (const rowResult of series.series.result) {
|
78 |
|
|
if (joinedDatasetsMap.has(rowResult.row[1])) {
|
79 |
|
|
const deposited = joinedDatasetsMap.get(rowResult.row[1]).deposited;
|
80 |
|
|
joinedDatasetsMap.delete(rowResult.row[1]);
|
81 |
|
|
joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
82 |
|
|
affiliated: Number(rowResult.row[0]), deposited: deposited});
|
83 |
|
|
} else {
|
84 |
|
|
joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
85 |
|
|
affiliated: Number(rowResult.row[0]), deposited: 0});
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
} else if (series.series.query.name === 'new.oso.datasets.deposited') {
|
90 |
|
|
|
91 |
|
|
for (const rowResult of series.series.result) {
|
92 |
|
|
if (joinedDatasetsMap.has(rowResult.row[1])) {
|
93 |
|
|
const affiliated = joinedDatasetsMap.get(rowResult.row[1]).affiliated;
|
94 |
|
|
joinedDatasetsMap.delete(rowResult.row[1]);
|
95 |
|
|
joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
96 |
|
|
affiliated: affiliated, deposited: Number(rowResult.row[0])});
|
97 |
|
|
}
|
98 |
|
|
joinedDatasetsMap.set(rowResult.row[1], { countryName: rowResult.row[1], countryCode: rowResult.row[2],
|
99 |
|
|
affiliated: 0, deposited: Number(rowResult.row[0])});
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
return joinedDatasetsMap;
|
105 |
|
|
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
public convertRawDataToCountryOverviewData(rawData: RawData) {
|
109 |
|
|
|
110 |
|
|
const countryData: CountryOverviewData = new CountryOverviewData();
|
111 |
|
|
|
112 |
|
|
for (const series of rawData.datasets) {
|
113 |
|
|
|
114 |
|
|
if (series.series.query.name === 'new.oso.publications.affiliated.country') {
|
115 |
|
|
countryData.publicationsAffiliated = Number(series.series.result[0].row[0]);
|
116 |
|
|
} else if (series.series.query.name === 'new.oso.publications.deposited.country') {
|
117 |
|
|
countryData.publicationsDeposited = Number(series.series.result[0].row[0]);
|
118 |
|
|
} else if (series.series.query.name === 'new.oso.datasets.affiliated.country') {
|
119 |
|
|
countryData.datasetsAffiliated = Number(series.series.result[0].row[0]);
|
120 |
|
|
} else if (series.series.query.name === 'new.oso.datasets.deposited.country') {
|
121 |
|
|
countryData.datasetsDeposited = Number(series.series.result[0].row[0]);
|
122 |
|
|
} else if (series.series.query.name === 'new.oso.repositories.doar_re3data.country') {
|
123 |
|
|
countryData.repositories = Number(series.series.result[0].row[0]);
|
124 |
|
|
} else if (series.series.query.name === 'new.oso.journals.doaj.country') {
|
125 |
|
|
countryData.journals = Number(series.series.result[0].row[0]);
|
126 |
|
|
} else if (series.series.query.name === 'new.oso.oa_policies.country') {
|
127 |
|
|
countryData.policies = Number(series.series.result[0].row[0]);
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
return countryData;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
public convertRawDataToEuropeOverviewData(rawData: RawData) {
|
135 |
|
|
|
136 |
|
|
const europeData: EuropeData = new EuropeData();
|
137 |
|
|
|
138 |
|
|
for (const series of rawData.datasets) {
|
139 |
|
|
|
140 |
|
|
if (series.series.query.name === 'new.oso.publications.oa_percentage') {
|
141 |
|
|
|
142 |
|
|
const publicationsIndicator: Indicator = new Indicator();
|
143 |
|
|
publicationsIndicator.percentage = Number(series.series.result[0].row[0]);
|
144 |
|
|
publicationsIndicator.oa = Number(series.series.result[0].row[1]);
|
145 |
|
|
publicationsIndicator.total = Number(series.series.result[0].row[2]);
|
146 |
|
|
europeData.publications = publicationsIndicator;
|
147 |
|
|
|
148 |
|
|
} else if (series.series.query.name === 'new.oso.datasets.oa_percentage') {
|
149 |
|
|
|
150 |
|
|
const datasetsIndicator: Indicator = new Indicator();
|
151 |
|
|
datasetsIndicator.percentage = Number(series.series.result[0].row[0]);
|
152 |
|
|
datasetsIndicator.oa = Number(series.series.result[0].row[1]);
|
153 |
|
|
datasetsIndicator.total = Number(series.series.result[0].row[2]);
|
154 |
|
|
europeData.datasets = datasetsIndicator;
|
155 |
|
|
|
156 |
|
|
} else if (series.series.query.name === 'new.oso.repositories.doar_re3data.validated') {
|
157 |
|
|
|
158 |
|
|
const repositoriesIndicator: Indicator = new Indicator();
|
159 |
|
|
repositoriesIndicator.percentage = Number(series.series.result[0].row[0]);
|
160 |
|
|
repositoriesIndicator.oa = Number(series.series.result[0].row[1]);
|
161 |
|
|
repositoriesIndicator.total = Number(series.series.result[0].row[2]);
|
162 |
|
|
europeData.repositories = repositoriesIndicator;
|
163 |
|
|
|
164 |
|
|
} else if (series.series.query.name === 'new.oso.journals.doaj.validated') {
|
165 |
|
|
|
166 |
|
|
const journalsIndicator: Indicator = new Indicator();
|
167 |
|
|
journalsIndicator.percentage = Number(series.series.result[0].row[0]);
|
168 |
|
|
journalsIndicator.oa = Number(series.series.result[0].row[1]);
|
169 |
|
|
journalsIndicator.total = Number(series.series.result[0].row[2]);
|
170 |
|
|
europeData.journals = journalsIndicator;
|
171 |
|
|
|
172 |
|
|
} else if (series.series.query.name === 'new.oso.oa_policies.europe') {
|
173 |
|
|
|
174 |
|
|
const policiesIndicator: Indicator = new Indicator();
|
175 |
|
|
policiesIndicator.percentage = Number(series.series.result[0].row[0]);
|
176 |
|
|
policiesIndicator.oa = Number(series.series.result[0].row[1]);
|
177 |
|
|
policiesIndicator.total = Number(series.series.result[0].row[2]);
|
178 |
|
|
europeData.policies = policiesIndicator;
|
179 |
|
|
|
180 |
|
|
}
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
return europeData;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
public convertRawDataToAbsoluteTableData(rawData: RawData) {
|
187 |
|
|
|
188 |
|
|
const mapTableData: Map<string, CountryTableData> = new Map();
|
189 |
|
|
|
190 |
|
|
for (const series of rawData.datasets) {
|
191 |
|
|
|
192 |
|
|
if (series.series.query.name.includes('new.oso.publications')) {
|
193 |
|
|
for (const rowResult of series.series.result) {
|
194 |
|
|
|
195 |
|
|
// remove unwanted countries
|
196 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
197 |
|
|
continue;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
201 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
202 |
|
|
countryTableData.publications = Number(rowResult.row[0]);
|
203 |
|
|
} else {
|
204 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
205 |
|
|
countryTableData.publications = Number(rowResult.row[0]);
|
206 |
|
|
countryTableData.name = rowResult.row[1];
|
207 |
|
|
countryTableData.code = rowResult.row[2];
|
208 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
} else if (series.series.query.name.includes('new.oso.datasets')) {
|
213 |
|
|
|
214 |
|
|
for (const rowResult of series.series.result) {
|
215 |
|
|
|
216 |
|
|
// remove unwanted countries
|
217 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
218 |
|
|
continue;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
222 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
223 |
|
|
countryTableData.datasets = Number(rowResult.row[0]);
|
224 |
|
|
} else {
|
225 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
226 |
|
|
countryTableData.datasets = Number(rowResult.row[0]);
|
227 |
|
|
countryTableData.name = rowResult.row[1];
|
228 |
|
|
countryTableData.code = rowResult.row[2];
|
229 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
230 |
|
|
}
|
231 |
|
|
}
|
232 |
|
|
} else if (series.series.query.name.includes('new.oso.software')) {
|
233 |
|
|
|
234 |
|
|
for (const rowResult of series.series.result) {
|
235 |
|
|
|
236 |
|
|
// remove unwanted countries
|
237 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
238 |
|
|
continue;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
242 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
243 |
|
|
countryTableData.software = Number(rowResult.row[0]);
|
244 |
|
|
} else {
|
245 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
246 |
|
|
countryTableData.software = Number(rowResult.row[0]);
|
247 |
|
|
countryTableData.name = rowResult.row[1];
|
248 |
|
|
countryTableData.code = rowResult.row[2];
|
249 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
250 |
|
|
}
|
251 |
|
|
}
|
252 |
|
|
} else if (series.series.query.name.includes('new.oso.other')) {
|
253 |
|
|
|
254 |
|
|
for (const rowResult of series.series.result) {
|
255 |
|
|
|
256 |
|
|
// remove unwanted countries
|
257 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
258 |
|
|
continue;
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
262 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
263 |
|
|
countryTableData.other = Number(rowResult.row[0]);
|
264 |
|
|
} else {
|
265 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
266 |
|
|
countryTableData.other = Number(rowResult.row[0]);
|
267 |
|
|
countryTableData.name = rowResult.row[1];
|
268 |
|
|
countryTableData.code = rowResult.row[2];
|
269 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
} else if (series.series.query.name.includes('new.oso.repositories')) {
|
273 |
|
|
|
274 |
|
|
for (const rowResult of series.series.result) {
|
275 |
|
|
|
276 |
|
|
// remove unwanted countries
|
277 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
278 |
|
|
continue;
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
282 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
283 |
|
|
countryTableData.repositories = Number(rowResult.row[0]);
|
284 |
|
|
} else {
|
285 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
286 |
|
|
countryTableData.repositories = Number(rowResult.row[0]);
|
287 |
|
|
countryTableData.name = rowResult.row[1];
|
288 |
|
|
countryTableData.code = rowResult.row[2];
|
289 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
290 |
|
|
}
|
291 |
|
|
}
|
292 |
|
|
} else if (series.series.query.name.includes('new.oso.journals')) {
|
293 |
|
|
|
294 |
|
|
for (const rowResult of series.series.result) {
|
295 |
|
|
|
296 |
|
|
// remove unwanted countries
|
297 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
298 |
|
|
continue;
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
if (mapTableData.has(rowResult.row[2])) {
|
302 |
|
|
const countryTableData = mapTableData.get(rowResult.row[2]);
|
303 |
|
|
countryTableData.journals = Number(rowResult.row[0]);
|
304 |
|
|
} else {
|
305 |
|
|
const countryTableData: CountryTableData = new CountryTableData();
|
306 |
|
|
countryTableData.journals = Number(rowResult.row[0]);
|
307 |
|
|
countryTableData.name = rowResult.row[1];
|
308 |
|
|
countryTableData.code = rowResult.row[2];
|
309 |
|
|
mapTableData.set(rowResult.row[2], countryTableData);
|
310 |
|
|
}
|
311 |
|
|
}
|
312 |
|
|
}
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
const tableData: CountryTableData[] = [];
|
316 |
|
|
|
317 |
|
|
mapTableData.forEach((value: CountryTableData, key: string) => {
|
318 |
|
|
// console.log(key, value);
|
319 |
|
|
tableData.push(value);
|
320 |
|
|
});
|
321 |
|
|
|
322 |
|
|
return tableData;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
private rawResultToCountryMapData(result: Row[]) {
|
326 |
|
|
|
327 |
|
|
const entityMapData: CountryMapData[] = [];
|
328 |
|
|
for (const rowResult of result) {
|
329 |
|
|
|
330 |
|
|
// remove unwanted countries
|
331 |
|
|
if (this.isCountryToBeRemoved(rowResult.row[2])) {
|
332 |
|
|
continue;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
const countryMapData: CountryMapData = new CountryMapData();
|
336 |
|
|
countryMapData.value = Number(rowResult.row[0]);
|
337 |
|
|
countryMapData.name = rowResult.row[1];
|
338 |
|
|
countryMapData.code = rowResult.row[2];
|
339 |
|
|
|
340 |
|
|
entityMapData.push(countryMapData);
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
return entityMapData;
|
344 |
|
|
}
|
345 |
|
|
|
346 |
|
|
private isCountryToBeRemoved(countryCode: string) {
|
347 |
|
|
return (countryCode === 'GG' || countryCode === 'FO' || countryCode === 'GI' || countryCode === 'VA' || countryCode === 'IM'
|
348 |
|
|
|| countryCode === 'JE' || countryCode === 'LI' || countryCode === 'MC' || countryCode === 'SM' || countryCode === 'SJ'
|
349 |
|
|
|| countryCode === 'AX');
|
350 |
|
|
}
|
351 |
|
|
}
|