forked from ourresearch/jump-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsortium_journal.py
296 lines (241 loc) · 9.38 KB
/
consortium_journal.py
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# coding: utf-8
from datetime import datetime
from cached_property import cached_property
from time import time
from journal import Journal
# start_time = time()
# journal_dicts_by_issn_l = defaultdict(list)
# for row in self.journal_member_data:
# journal_dicts_by_issn_l[row["issn_l"]].append(row["journals_dict"])
#
# response_list = []
# for issn_l, list_this_long in journal_dicts_by_issn_l.iteritems():
# sum_of_usage = float(sum(j["usage"] for j in list_this_long))
# for j in list_this_long:
# if j["cpu"] and j["usage"] and (isinstance(j["cpu"], int) or isinstance(j["cpu"], float)):
# j["cpu_combo_by_usage"] = j["cpu"] * j["usage"] / sum_of_usage
# elif (isinstance(j["cpu"], int) or isinstance(j["cpu"], float)):
# j["cpu_combo_by_usage"] = j["cpu"]
# else:
# j["cpu_combo_by_usage"] = "-"
# if sum_of_usage < 10:
# j["cpu_combo_by_usage"] = "-"
#
# normalized_cpu = sum(j["cpu_combo_by_usage"] for j in list_this_long if j["cpu_combo_by_usage"] != "-")
# my_journal_dict = list_this_long[0]
# my_journal_dict["cpu"] = normalized_cpu
# my_journal_dict["institution_names"] = [j.get("institution_name") for j in list_this_long]
# response_list.append(my_journal_dict)
class ConsortiumJournal(Journal):
years = list(range(0, 5))
def __init__(self, issn_l, included_package_ids, all_member_data, is_jisc, package):
start_time = time()
self.issn_l = issn_l
self.is_jisc = is_jisc
self.included_package_ids = included_package_ids
self.member_data = all_member_data
self.meta_data = self.member_data[0]
self.subscribed_bulk = False
self.subscribed_custom = False
self.use_default_download_curve = False
self.my_package = package
# print ".",
@cached_property
def years_by_year(self):
return [2019 + year_index for year_index in self.years]
@cached_property
def historical_years_by_year(self):
# used for citation, authorship lookup
now = datetime.utcnow()
return list(range(now.year - 5, now.year))
def sum_attribute(self, attribute_name, nesting_key=None):
response = 0
for my_member_dict in self.member_data:
if nesting_key:
response += my_member_dict[nesting_key].get(attribute_name, 0) or 0
else:
response += my_member_dict.get(attribute_name, 0) or 0
return float(response)
def sum_attribute_multiplied_by_usage(self, attribute_name, nesting_key=None):
response = 0
for my_member_dict in self.member_data:
if nesting_key:
response += (my_member_dict[nesting_key].get(attribute_name, 0) or 0) * float(my_member_dict["usage"])
else:
response += (my_member_dict.get(attribute_name, 0) or 0) * float(my_member_dict["usage"])
return float(response)
def list_attribute(self, attribute_name):
return [my_member_dict.get(attribute_name, None) for my_member_dict in self.member_data]
@cached_property
def has_perpetual_access(self):
response = False
for my_member_dict in self.member_data:
if my_member_dict.get("has_perpetual_access"):
response = True
return response
@cached_property
def perpetual_access_years(self):
for my_member_dict in self.member_data:
if my_member_dict.get("perpetual_access_years"):
if isinstance(my_member_dict.get("perpetual_access_years"), str) :
return [int(z) for z in my_member_dict.get("perpetual_access_years").split("-") if len(z)]
else:
return my_member_dict.get("perpetual_access_years")
return []
@cached_property
def baseline_access(self):
for my_member_dict in self.member_data:
if my_member_dict.get("baseline_access"):
return my_member_dict.get("baseline_access")
return None
@cached_property
def institution_id(self):
return self.list_attribute("institution_id")
@cached_property
def institution_name(self):
return self.list_attribute("institution_name")
@cached_property
def institution_short_name(self):
return self.list_attribute("institution_short_name")
@cached_property
def package_id(self):
return self.list_attribute("package_id")
@cached_property
def subject(self):
return self.meta_data["subject"]
@property
def era_subjects(self):
return self.meta_data.get("era_subjects", [])
@cached_property
def is_society_journal(self):
return self.meta_data["is_society_journal"]
@cached_property
def bronze_oa_embargo_months(self):
return self.meta_data["bronze_oa_embargo_months"]
@cached_property
def is_hybrid_2019(self):
return self.meta_data["is_hybrid_2019"]
@cached_property
def num_authorships(self):
return self.sum_attribute("authorships")
@cached_property
def num_citations(self):
return self.sum_attribute("citations")
@cached_property
def use_total(self):
response = self.sum_attribute("usage")
if response == 0:
response = 0.0001
return response
@cached_property
def downloads_total(self):
return self.sum_attribute("downloads")
@cached_property
def cost_actual(self):
if self.subscribed:
return self.subscription_cost
return self.ill_cost
@cached_property
def use_paywalled(self):
return self.use_total - self.use_free_instant
# @cached_property
# def cpu(self):
# if self.use_total < 10:
# return None
# cpu = 0
# for j in self.member_data:
# if j["cpu"] and j["usage"] and self.use_total:
# cpu += j["cpu"] * j["usage"] / self.use_total
# if cpu:
# return cpu
# return None
@cached_property
def subscription_cost(self):
if self.is_jisc:
if len(self.included_package_ids) >= 144:
return self.meta_data["subscription_cost"] * 155.0
return self.meta_data["subscription_cost"] * len(self.included_package_ids)
@cached_property
def ill_cost(self):
return self.sum_attribute("ill_cost")
@cached_property
def cost_subscription_minus_ill(self):
return self.subscription_cost - self.ill_cost
@cached_property
def use_oa_plus_social_networks(self):
# return self.sum_attribute("oa", "use_groups_free_instant")
return self.sum_attribute("use_oa")
@cached_property
def use_subscription(self):
# return self.sum_attribute("subscription", "use_groups_if_subscribed")
return self.sum_attribute("use_subscription")
@cached_property
def use_backfile(self):
# return self.sum_attribute("backfile", "use_groups_free_instant")
return self.sum_attribute("use_backfile")
@cached_property
def use_ill(self):
# return self.sum_attribute("ill", "use_groups_if_not_subscribed")
return self.sum_attribute("use_ill")
@cached_property
def use_other_delayed(self):
# return self.sum_attribute("other_delayed", "use_groups_if_not_subscribed")
return self.sum_attribute("use_other_delayed")
@cached_property
def use_social_networks(self):
return self.sum_attribute_multiplied_by_usage("use_social_networks_percent")/100.0
@cached_property
def use_oa_green(self):
return self.sum_attribute_multiplied_by_usage("use_green_percent")/100.0
@cached_property
def use_oa_hybrid(self):
return self.sum_attribute_multiplied_by_usage("use_hybrid_percent")/100.0
@cached_property
def use_oa_bronze(self):
return self.sum_attribute_multiplied_by_usage("use_bronze_percent")/100.0
@cached_property
def use_oa_peer_reviewed(self):
return self.sum_attribute_multiplied_by_usage("use_peer_reviewed_percent")/100.0
@cached_property
def use_free_instant(self):
response = self.use_oa_plus_social_networks + self.use_backfile
return min(response, self.use_total)
@cached_property
def use_instant(self):
response = self.use_free_instant + self.use_subscription
return min(response, self.use_total)
@cached_property
def use_instant_percent(self):
if not self.use_total:
return 0
return min(100.0, round(100 * float(self.use_instant) / self.use_total, 4))
@cached_property
def use_free_instant_percent(self):
if not self.use_total:
return 0
return min(100.0, round(100 * float(self.use_free_instant) / self.use_total, 4))
@cached_property
def num_papers_slope_percent(self):
# need to figure out how to do this well here @todo
return None
@cached_property
def cost_subscription_fuzzed(self):
return None
@cached_property
def cost_subscription_minus_ill_fuzzed(self):
return None
@cached_property
def cpu_fuzzed(self):
return None
@cached_property
def use_total_fuzzed(self):
return None
@cached_property
def downloads_fuzzed(self):
return None
@cached_property
def num_authorships_fuzzed(self):
return None
@cached_property
def num_citations_fuzzed(self):
return None