embulk-input-lkqd 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/embulk-input-lkqd.gemspec +1 -1
- data/lib/embulk/input/lkqd.rb +47 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e78a508c2bc1e83afe5ede32c630eac17f91090c
|
4
|
+
data.tar.gz: 30f105b4e714b3ab8279a9299cd01520e7e87fb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87b274e23130b4f6851ded3e1115d18822402617a576f717d3dc9dad161a34ca3758890b01bf6df733db38745783c9ea5b6606fe3fea8c948cb0ec0b3110895
|
7
|
+
data.tar.gz: 6bad46bac5acfe15126a677e4a7a734ec921b01103d18613e5c1629eb8d5c6e452e34ca3e44197b574268ab12c9bc0eee46b235a30d53d5b84a6225c1d27e701
|
data/README.md
CHANGED
@@ -11,10 +11,12 @@ Loads reporting data from LKQD API.
|
|
11
11
|
|
12
12
|
## Configuration
|
13
13
|
|
14
|
-
- **secret_key_id**: API Secret Key ID (string, required)
|
15
|
-
- **secret_key**: API Secret Key (string, required)
|
16
|
-
- **endpoint**: API endpoint (string, default: `'https://api.lkqd.com/reports'`)
|
17
|
-
- **report_parameters**: Report parameters documented in https://wiki.lkqd.com/display/API/LKQD+API (hash, default: `{}`)
|
14
|
+
- **secret_key_id**: API Secret Key ID (required string, required)
|
15
|
+
- **secret_key**: API Secret Key (required string, required)
|
16
|
+
- **endpoint**: API endpoint (optional string, default: `'https://api.lkqd.com/reports'`)
|
17
|
+
- **report_parameters**: Report parameters documented in https://wiki.lkqd.com/display/API/LKQD+API (required hash, default: `{}`)
|
18
|
+
- **measurable_impressions**: calculate and inject `Measurable Impressions` column, required `"IMPRESSIONS"`, `"VIEWABILITY_MEASURED_RATE"` specified in "metrics" (optional boolean, default: false)
|
19
|
+
- **viewable_impressions**: calculate and inject `Viewable Impressions` column, required `"IMPRESSIONS"`, `"VIEWABILITY_MEASURED_RATE"`, `"VIEWABILITY_RATE"` specified in "metrics" (optional boolean, default: false)
|
18
20
|
|
19
21
|
## Example
|
20
22
|
|
data/embulk-input-lkqd.gemspec
CHANGED
data/lib/embulk/input/lkqd.rb
CHANGED
@@ -16,7 +16,10 @@ module Embulk
|
|
16
16
|
"secret_key_id" => config.param("secret_key_id", :string),
|
17
17
|
"secret_key" => config.param("secret_key", :string),
|
18
18
|
"endpoint" => config.param("endpoint", :string, default: 'https://api.lkqd.com/reports'),
|
19
|
-
"
|
19
|
+
"copy_temp_to" => config.param("copy_temp_to", :string, default: nil),
|
20
|
+
"try_convert" => config.param("try_convert", :bool, default: true),
|
21
|
+
"measurable_impressions" => config.param("measurable_impressions", :bool, default: false),
|
22
|
+
"viewable_impressions" => config.param("viewable_impressions", :bool, default: false),
|
20
23
|
"report_parameters" => config.param("report_parameters", :hash, default: {}),
|
21
24
|
}
|
22
25
|
task['authorization'] = Base64.urlsafe_encode64("#{task['secret_key_id']}:#{task['secret_key']}")
|
@@ -29,10 +32,28 @@ module Embulk
|
|
29
32
|
tempfile.close
|
30
33
|
task['tempfile_path'] = tempfile.path
|
31
34
|
|
35
|
+
FileUtils.cp(task['tempfile_path'], task['copy_temp_to']) if task['copy_temp_to']
|
36
|
+
|
32
37
|
columns = []
|
33
38
|
::CSV.foreach(tempfile.path).first.each_with_index do |column_name, index|
|
34
39
|
column_type = guess_column_type(task['report_parameters']['metrics'], column_name)
|
35
|
-
|
40
|
+
column = Column.new({index: index}.merge(column_type))
|
41
|
+
if column.name == 'Viewability Measured Rate'
|
42
|
+
task['viewability_measured_rate_index'] = index
|
43
|
+
elsif column.name == 'Viewability Rate'
|
44
|
+
task['viewability_rate_index'] = index
|
45
|
+
elsif column.name == 'Impressions'
|
46
|
+
task['impressions_index'] = index
|
47
|
+
end
|
48
|
+
columns << column
|
49
|
+
end
|
50
|
+
|
51
|
+
if measurable_impressions?(task)
|
52
|
+
columns << Column.new({index: columns.size, type: :double, name: 'Measurable Impressions'})
|
53
|
+
end
|
54
|
+
|
55
|
+
if viewable_impressions?(task)
|
56
|
+
columns << Column.new({index: columns.size, type: :double, name: 'Viewable Impressions'})
|
36
57
|
end
|
37
58
|
|
38
59
|
resume(task, columns, 1, &control)
|
@@ -84,14 +105,36 @@ module Embulk
|
|
84
105
|
end
|
85
106
|
end
|
86
107
|
|
108
|
+
def self.measurable_impressions?(task)
|
109
|
+
task['try_convert'] && task['measurable_impressions'] &&
|
110
|
+
task['viewability_measured_rate_index'] && task['impressions_index']
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.viewable_impressions?(task)
|
114
|
+
task['try_convert'] && task['viewable_impressions'] &&
|
115
|
+
task['viewability_rate_index'] && task['viewability_measured_rate_index'] && task['impressions_index']
|
116
|
+
end
|
117
|
+
|
87
118
|
def init
|
88
119
|
@task = task
|
89
120
|
end
|
90
121
|
|
91
122
|
def run
|
92
123
|
convert_options = {timezone: @task['report_parameters']['timezone']}
|
124
|
+
try_convert = @task['try_convert']
|
125
|
+
viewability_measured_rate_index = @task['viewability_measured_rate_index']
|
126
|
+
viewability_rate_index = @task['viewability_rate_index']
|
127
|
+
impressions_index = @task['impressions_index']
|
128
|
+
|
93
129
|
CSV.foreach(@task['tempfile_path'], {headers: true}).each do |row|
|
94
|
-
row =
|
130
|
+
row = try_convert ? Lkqd.try_convert(row, convert_options) : row
|
131
|
+
if Lkqd.measurable_impressions?(@task)
|
132
|
+
row << row[impressions_index] * row[viewability_measured_rate_index]
|
133
|
+
end
|
134
|
+
|
135
|
+
if Lkqd.viewable_impressions?(@task)
|
136
|
+
row << row[impressions_index] * row[viewability_measured_rate_index] * row[viewability_rate_index]
|
137
|
+
end
|
95
138
|
page_builder.add(row)
|
96
139
|
end
|
97
140
|
page_builder.finish
|
@@ -140,6 +183,7 @@ module Embulk
|
|
140
183
|
'Clicks' => { 'type' => 'long' },
|
141
184
|
'CTR' => { 'type' => 'double' },
|
142
185
|
'Ad Starts' => { 'type' => 'long' },
|
186
|
+
'Ad Starts Rate' => { 'type' => 'double' },
|
143
187
|
'25% Views' => { 'type' => 'long' },
|
144
188
|
'50% Views' => { 'type' => 'long' },
|
145
189
|
'75% Views' => { 'type' => 'long' },
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-lkqd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ming Liu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|