Skip to content

Commit 0632d2b

Browse files
committed
feat: __countMetrics test cases for all integrations
1 parent b18fd6d commit 0632d2b

6 files changed

Lines changed: 984 additions & 70 deletions

File tree

vis/js/@types/paper.ts

Lines changed: 167 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,168 @@
1+
type NotAvailable = "n/a";
2+
3+
export interface CommonPaperDataForAllIntegrations {
4+
id: string;
5+
doi: string;
6+
safe_id: string;
7+
identifier: string;
8+
9+
title: string;
10+
keywords: string;
11+
cluster_labels: string;
12+
paper_abstract: string;
13+
labels: string;
14+
source: string;
15+
relation: string;
16+
17+
comments: string[];
18+
comments_for_filtering: string;
19+
20+
citation_count: string | number;
21+
tags: string[];
22+
social: string | null;
23+
references: null;
24+
citations: number | null;
25+
readers: number | NotAvailable;
26+
num_readers: number | NotAvailable;
27+
internal_readers: number;
28+
29+
published_in: string;
30+
year: string;
31+
32+
authors_list: string[];
33+
authors: string;
34+
authors_string: string;
35+
36+
subject_orig: string;
37+
38+
area: string;
39+
area_uri: number;
40+
41+
oa: boolean;
42+
oa_state: number | string;
43+
44+
url: string;
45+
outlink: string;
46+
list_link: {
47+
address: string;
48+
isDoi: boolean;
49+
};
50+
51+
file_hash: string;
52+
free_access: boolean;
53+
resulttype: string[];
54+
55+
x: number;
56+
y: number;
57+
diameter: number;
58+
width: number;
59+
height: number;
60+
zoomedX: number;
61+
zoomedY: number;
62+
zoomedWidth: number;
63+
zoomedHeight: number;
64+
}
65+
66+
export interface PubmedPaper extends CommonPaperDataForAllIntegrations {
67+
pmid: string;
68+
pmcid: string;
69+
content: string;
70+
date: string;
71+
publication_type: string;
72+
oa_link: string;
73+
subject: string;
74+
authors_objects: {
75+
firstName: string;
76+
lastName: string;
77+
}[];
78+
}
79+
80+
export interface BasePaper extends CommonPaperDataForAllIntegrations {
81+
authors_objects: { lastName: string; firstName?: string }[];
82+
link: string;
83+
relevance: number;
84+
type: string;
85+
typenorm: string;
86+
lang: string;
87+
language: string;
88+
content_provider: string;
89+
coverage: string;
90+
is_duplicate: boolean;
91+
has_dataset: boolean;
92+
sanitized_authors: string;
93+
oa_link: string;
94+
subject: string;
95+
relations: string[];
96+
annotations: {};
97+
repo: string;
98+
volume: null | string;
99+
issue: null | string;
100+
issn: null | string;
101+
page: null | number;
102+
}
103+
104+
export interface OrcidPaper extends CommonPaperDataForAllIntegrations {
105+
subtitle: string | null;
106+
tweets: number;
107+
authors_objects: { lastName: string; firstName?: string }[];
108+
publication_year: number;
109+
cited_by_msm_count: number | string | null;
110+
cited_by_fbwalls_count: number | string | null;
111+
cited_by_tweeters_count: number | string | null;
112+
cited_by_feeds_count: number | string | null;
113+
cited_by_gplus_count: number | string | null;
114+
cited_by_rdts_count: number | string | null;
115+
cited_by_wikipedia_count: number | string | null;
116+
cited_by_qna_count: number | string | null;
117+
}
118+
1119
export interface Paper {
2-
id: string;
3-
safe_id: string;
4-
oa_link: string;
5-
link: string;
6-
identifier: string;
7-
relation: string;
8-
outlink: string;
9-
fulltext: string;
10-
list_link: any;
11-
12-
title: string;
13-
authors_objects: {
14-
firstName: string;
15-
lastName: string;
16-
}[]
17-
year: string;
18-
source: string;
19-
volume: number;
20-
issue: number;
21-
page: number;
22-
issn: number;
23-
24-
resulttype: string[];
25-
26-
x?: number;
27-
y?: number;
28-
29-
width?: number;
30-
height?: number;
31-
32-
area_uri: string;
33-
area: string;
34-
35-
free_access: boolean;
36-
oa: boolean;
37-
38-
// data from backend
39-
cited_by_fbwalls_count?: number;
40-
cited_by_feeds_count?: number;
41-
cited_by_gplus_count?: number;
42-
cited_by_rdts_count?: number;
43-
cited_by_qna_count?: number;
44-
cited_by_tweeters_count?: number;
45-
cited_by_videos_count?: number;
46-
47-
// data manager
48-
// calculated values
49-
social?: string | number;
50-
}
120+
id: string;
121+
safe_id: string;
122+
oa_link: string;
123+
link: string;
124+
identifier: string;
125+
relation: string;
126+
outlink: string;
127+
fulltext: string;
128+
list_link: any;
129+
130+
title: string;
131+
authors_objects: {
132+
firstName: string;
133+
lastName: string;
134+
}[];
135+
year: string;
136+
source: string;
137+
volume: number;
138+
issue: number;
139+
page: number;
140+
issn: number;
141+
142+
resulttype: string[];
143+
144+
x?: number;
145+
y?: number;
146+
147+
width?: number;
148+
height?: number;
149+
150+
area_uri: string;
151+
area: string;
152+
153+
free_access: boolean;
154+
oa: boolean;
155+
156+
// data from backend
157+
cited_by_fbwalls_count?: number;
158+
cited_by_feeds_count?: number;
159+
cited_by_gplus_count?: number;
160+
cited_by_rdts_count?: number;
161+
cited_by_qna_count?: number;
162+
cited_by_tweeters_count?: number;
163+
cited_by_videos_count?: number;
164+
165+
// data manager
166+
// calculated values
167+
social?: string | number;
168+
}

vis/js/dataprocessing/managers/DataManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ class DataManager {
248248
const config = this.config;
249249

250250
paper.num_readers = 0;
251+
251252
paper.internal_readers = 1;
252253

253254
// ? should we use numb_readers in some cases?
254-
function parseNumber(value, defaultValue = 0) {
255+
function parseNumber(value, defaultValue = "n/a") {
255256
const num = Number(value);
256257
return isNaN(num) ? defaultValue : num;
257258
}
@@ -272,7 +273,7 @@ class DataManager {
272273
paper.cited_by_qna_count,
273274
paper.cited_by_tweeters_count,
274275
paper.cited_by_videos_count,
275-
].every((item) => item === undefined)
276+
].every((item) => item === undefined || item === null)
276277
) {
277278
paper.social = "n/a";
278279
} else {

vis/js/templates/listentry/StandardListEntry.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import EntryBacklink from "./EntryBacklink";
1919
import Keywords from "./Keywords";
2020
import Link from "./Link";
2121
import Metrics from "./Metrics";
22-
import OrcidMetrics from './OrcidMetrics';
22+
import OrcidMetrics from "./OrcidMetrics";
2323
import Title from "./Title";
2424

2525
/**
@@ -124,7 +124,9 @@ const mapStateToProps = (state) => ({
124124
showBacklink: state.chartType === STREAMGRAPH_MODE && !!state.selectedPaper,
125125
isInStreamBacklink: !!state.selectedBubble,
126126
showDocTags: state.service === "base" || state.service === "orcid",
127-
showAllDocTypes: (state.service === "base" || state.service === "orcid") && !!state.selectedPaper,
127+
showAllDocTypes:
128+
(state.service === "base" || state.service === "orcid") &&
129+
!!state.selectedPaper,
128130
service: state.service,
129131
});
130132

Lines changed: 12 additions & 17 deletions
Large diffs are not rendered by default.

vis/test/data/papers.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import {
2+
BasePaper,
3+
CommonPaperDataForAllIntegrations,
4+
OrcidPaper,
5+
PubmedPaper,
6+
} from "../../js/@types/paper";
7+
8+
const MOCK_COMMON_PAPER_DATA: CommonPaperDataForAllIntegrations = {
9+
id: "id",
10+
doi: "doi",
11+
safe_id: "safe id",
12+
identifier: "identifier",
13+
title: "Some title",
14+
keywords: "keyword1, keyword2",
15+
cluster_labels: "label1, label2",
16+
paper_abstract: "Some abstract",
17+
labels: "labels",
18+
source: "Source name",
19+
relation: "relation1;relation2",
20+
comments: [],
21+
comments_for_filtering: "",
22+
citation_count: "n/a",
23+
tags: [],
24+
social: "n/a",
25+
references: null,
26+
citations: null,
27+
readers: 0,
28+
num_readers: 0,
29+
internal_readers: 1,
30+
published_in: "published in",
31+
year: "2000",
32+
authors_list: ["Person1", "Person2"],
33+
authors: "Person1; Person2;",
34+
authors_string: "Person1; Person2;",
35+
subject_orig: "Subject orig1;Subject orig2;",
36+
area_uri: 2,
37+
area: "area1, area2",
38+
oa_state: "1",
39+
oa: true,
40+
url: "link",
41+
outlink: "link",
42+
list_link: {
43+
address: "link",
44+
isDoi: true,
45+
},
46+
file_hash: "hash",
47+
free_access: false,
48+
resulttype: ["type"],
49+
x: 1,
50+
y: 1,
51+
diameter: 1,
52+
width: 1,
53+
height: 1,
54+
zoomedX: -1,
55+
zoomedY: 1,
56+
zoomedWidth: 1,
57+
zoomedHeight: 1,
58+
};
59+
60+
export const MOCK_BASE_PAPER_DATA: BasePaper = {
61+
...MOCK_COMMON_PAPER_DATA,
62+
subject: "Subjet",
63+
link: "link",
64+
relevance: 1,
65+
type: "article",
66+
typenorm: "1",
67+
lang: "eng",
68+
language: "EN",
69+
content_provider: "Provider",
70+
coverage: "",
71+
is_duplicate: true,
72+
has_dataset: false,
73+
sanitized_authors: "Person1; Person2;",
74+
relations: ["relation1", "relation2"],
75+
annotations: {},
76+
repo: "repo",
77+
volume: null,
78+
issue: null,
79+
issn: null,
80+
page: null,
81+
authors_objects: [
82+
{
83+
lastName: "Person1",
84+
},
85+
{
86+
lastName: "Person2",
87+
},
88+
],
89+
oa_link: "link",
90+
};
91+
92+
export const MOCK_PUBMED_PAPER_DATA: PubmedPaper = {
93+
...MOCK_COMMON_PAPER_DATA,
94+
pmid: "id",
95+
date: "",
96+
subject: "Subject",
97+
publication_type: "Type",
98+
url: "http://www.ncbi.nlm.nih.gov/pubmed/32462770",
99+
content: "Content",
100+
pmcid: "id",
101+
authors_objects: [
102+
{
103+
firstName: "Person1",
104+
lastName: "Person1",
105+
},
106+
{
107+
firstName: "Person2",
108+
lastName: "Person2",
109+
},
110+
],
111+
oa_link: "link",
112+
num_readers: 1,
113+
};
114+
115+
export const MOCK_ORCID_PAPER_DATA: OrcidPaper = {
116+
...MOCK_COMMON_PAPER_DATA,
117+
publication_year: 2000,
118+
cited_by_msm_count: null,
119+
cited_by_fbwalls_count: null,
120+
cited_by_tweeters_count: null,
121+
cited_by_feeds_count: null,
122+
cited_by_gplus_count: null,
123+
cited_by_rdts_count: null,
124+
cited_by_wikipedia_count: null,
125+
cited_by_qna_count: null,
126+
subtitle: null,
127+
tweets: 0,
128+
authors_objects: [
129+
{
130+
lastName: "Person1",
131+
},
132+
{
133+
lastName: "Person2",
134+
},
135+
],
136+
};

0 commit comments

Comments
 (0)