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
|
# File 'lib/kishu/usage_event.rb', line 13
def wrap_event(event, options={})
totale_investigations = event.dig("totale").fetch("buckets", [])
unique_investigations = event.dig("unique").fetch("buckets", [])
unique_regular_investigations = unique_investigations.find_all {|access_method| access_method.fetch('key',"").match('regular') }
unique_machine_investigations = unique_investigations.find_all {|access_method| access_method.fetch('key',"").match('machine') }
total_regular_investigations = totale_investigations.find_all {|access_method| access_method.fetch('key',"").match('regular') }
total_machine_investigations = totale_investigations.find_all {|access_method| access_method.fetch('key',"").match('machine') }
totale_requests = event.dig("totale").fetch("buckets", [])
unique_requests = event.dig("unique").fetch("buckets", [])
unique_regular_requests = unique_requests.find_all {|access_method| access_method.fetch('key',"").match('regular') }
unique_machine_requests = unique_requests.find_all {|access_method| access_method.fetch('key',"").match('machine') }
total_regular_requests = totale_requests.find_all {|access_method| access_method.fetch('key',"").match('regular') }
total_machine_requests = totale_requests.find_all {|access_method| access_method.fetch('key',"").match('machine') }
dataset = {
doi: event.dig("key","doi"),
unique_counts_regular_investigations: unique_regular_investigations.empty? ? 0 : unique_regular_investigations.size,
unique_counts_machine_investigations: unique_machine_investigations.empty? ? 0 : unique_machine_investigations.size,
total_counts_regular_investigations: total_regular_investigations.empty? ? 0 : total_regular_investigations.dig(0,"doc_count"),
total_counts_machine_investigations: total_machine_investigations.empty? ? 0: total_machine_investigations.dig(0,"doc_count"),
unique_counts_regular_requests: unique_regular_requests.empty? ? 0 : unique_regular_requests.size,
unique_counts_machine_requests: unique_machine_requests.empty? ? 0 : unique_machine_requests.size,
total_counts_regular_requests: total_regular_requests.empty? ? 0 : total_regular_requests.dig(0,"doc_count"),
total_counts_machine_requests: total_machine_requests.empty? ? 0: total_machine_requests.dig(0,"doc_count")
}
logger = Logger.new(STDOUT)
logger.info event.fetch("doc_count")
logger.info dataset
doi = dataset.fetch(:doi,nil)
data = get_metadata doi
instances =[
{
"count": dataset[:total_counts_regular_investigations],
"access-method": "regular",
"metric-type": "total_dataset_investigations"
},
{
"count": dataset[:unique_counts_regular_investigations],
"access-method": "regular",
"metric-type": "unique_dataset_investigations"
},
{
"count": dataset[:unique_counts_machine_investigations],
"access-method": "machine",
"metric-type": "unique_dataset_investigations"
},
{
"count": dataset[:total_counts_machine_investigations],
"access-method": "machine",
"metric-type": "total_dataset_investigations"
},
{
"count": dataset[:total_counts_regular],
"access-method": "regular",
"metric-type": "total_dataset_requests"
},
{
"count": dataset[:unique_counts_regular],
"access-method": "regular",
"metric-type": "unique_dataset_requests"
},
{
"count": dataset[:unique_counts_machine],
"access-method": "machine",
"metric-type": "unique_dataset_requests"
},
{
"count": dataset[:total_counts_machine],
"access-method": "machine",
"metric-type": "total_dataset_requests"
}
]
instances.delete_if {|instance| instance.dig(:count) <= 0}
attributes = data.dig("data","attributes")
resource_type = attributes.fetch("resource-type-id",nil).nil? ? "dataset" : attributes.fetch("resource-type-id",nil)
instanced = {
"dataset-id" => [{type: "doi", value: dataset.fetch(:doi,nil)}],
"data-type" => resource_type,
"yop" => attributes.fetch("published",nil),
"uri" => attributes.fetch("identifier",nil),
"publisher" => attributes.fetch("container-title",nil),
"dataset-title": attributes.fetch("title",nil),
"publisher-id": [{
"type" => "client-id",
"value" => attributes.fetch("data-center-id",nil)
}],
"dataset-dates": [{
"type" => "pub-date",
"value" => attributes.fetch("published",nil)
}],
"dataset-contributors": attributes.fetch("author",[]).map { |a| get_authors(a) },
"platform" => attributes.fetch("data-center-id",nil),
"performance" => [{
"period" => @period,
"instance" => instances
}]
}
logger.info instanced
instanced
end
|