embulk-output-pixela 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/Rakefile +3 -0
- data/embulk-output-pixela.gemspec +21 -0
- data/lib/embulk/output/pixela.rb +96 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 507efa03da3737fd343016adf03358dab1873bbf
|
4
|
+
data.tar.gz: 9c380f7a076fe6d7038e689051de9539617d275d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef43de9c7d44b5ddc288bbc786e7d885b02c03cceb7d5dd8f1b7621fa2aca7297a32cdc62431f8f041eb9a5d96f2ce9f219284bd8328d1d653319dcafa43a88e
|
7
|
+
data.tar.gz: 15b69927465c44e7a88108106a6b5b29468692479fc70359ca328340d30aa8fb2ad9ae4105513859e5dd4e7b767e8b64d82568cd9748e2f60685f3bd04d776c9
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.1.15.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Pixela output plugin for Embulk
|
2
|
+
|
3
|
+
Embulk Output plugin for [Pixela](https://pixe.la/) to store your historical records
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: output
|
8
|
+
* **Load all or nothing**: no
|
9
|
+
* **Resume supported**: no
|
10
|
+
* **Cleanup supported**: yes
|
11
|
+
|
12
|
+
## Limitations
|
13
|
+
|
14
|
+
This plugin supports only recoring your historical data to an existing graph.
|
15
|
+
Create user and Create graph are not supported.
|
16
|
+
Rerun the following commands in order to do them.
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
- **name**: Your Username (string, required)
|
21
|
+
- **token**: Your Token (string, required)
|
22
|
+
- **graph_id**: Your Graph ID (String, required)
|
23
|
+
- **quantity_float_column**: Column name to indicate a quantity as float type (quantity_float_column or quantity_int_column are required) (string)
|
24
|
+
- **quantity_int_column**: Column name to indicate a quantity as int type (quantity_float_column or quantity_int_column are required) (string)
|
25
|
+
- **date_column**: Column name to indicate date of a quantity (string, required)
|
26
|
+
|
27
|
+
## Before you use this plugin
|
28
|
+
|
29
|
+
```
|
30
|
+
$ gem install pixela
|
31
|
+
|
32
|
+
$ irb
|
33
|
+
require "pixela"
|
34
|
+
client = Pixela::Client.new(username: "xxxx", token: "yyyy")
|
35
|
+
client.create_user(agree_terms_of_service: true, not_minor: true)
|
36
|
+
client.create_graph(graph_id: "zzzz", name: "hhhh", unit: "commit", type: "int", color: "shibafu")
|
37
|
+
```
|
38
|
+
|
39
|
+
More example is [here](https://pixe.la/)
|
40
|
+
|
41
|
+
## Example
|
42
|
+
|
43
|
+
You already have the following graph.
|
44
|
+
|
45
|
+

|
46
|
+
|
47
|
+
Th example CSV file is below.
|
48
|
+
|
49
|
+
```csv
|
50
|
+
point,date
|
51
|
+
0,2018/10/01
|
52
|
+
1,2018/10/02
|
53
|
+
2,2018/10/03
|
54
|
+
3,2018/10/04
|
55
|
+
4,2018/10/05
|
56
|
+
5,2018/10/06
|
57
|
+
6,2018/10/07
|
58
|
+
7,2018/10/08
|
59
|
+
8,2018/10/09
|
60
|
+
9,2018/10/10
|
61
|
+
10,2018/10/11
|
62
|
+
11,2018/10/12
|
63
|
+
12,2018/10/13
|
64
|
+
13,2018/10/14
|
65
|
+
14,2018/10/15
|
66
|
+
```
|
67
|
+
|
68
|
+
You can submit this csv file to Pixela by th following command with this yml file
|
69
|
+
|
70
|
+
```yaml
|
71
|
+
in:
|
72
|
+
type: file
|
73
|
+
path_prefix: test.csv
|
74
|
+
parser:
|
75
|
+
charset: UTF-8
|
76
|
+
newline: CRLF
|
77
|
+
type: csv
|
78
|
+
delimiter: ','
|
79
|
+
quote: '"'
|
80
|
+
escape: '"'
|
81
|
+
trim_if_not_quoted: false
|
82
|
+
skip_header_lines: 1
|
83
|
+
allow_extra_columns: false
|
84
|
+
allow_optional_columns: false
|
85
|
+
columns:
|
86
|
+
- {name: point, type: long}
|
87
|
+
- {name: date, type: timestamp, format: '%Y/%m/%d'}
|
88
|
+
out:
|
89
|
+
type: pixela
|
90
|
+
name: torut
|
91
|
+
token: xxxx
|
92
|
+
graph_id: embulk-test
|
93
|
+
quantity_int_column: point
|
94
|
+
date_column: date
|
95
|
+
```
|
96
|
+
|
97
|
+
```
|
98
|
+
$ embulk run example.yml
|
99
|
+
```
|
100
|
+
|
101
|
+
After this steps are completed, you'll see the following.
|
102
|
+
|
103
|
+

|
104
|
+
|
105
|
+
## Build
|
106
|
+
|
107
|
+
```
|
108
|
+
$ rake
|
109
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-output-pixela"
|
4
|
+
spec.version = "0.0.1"
|
5
|
+
spec.authors = ["Toru Takahashi"]
|
6
|
+
spec.summary = "Pixela output plugin for Embulk"
|
7
|
+
spec.description = "Dumps records to Pixela."
|
8
|
+
spec.email = ["torutakahashi.ayashi@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/torutakahashi.ayashi/embulk-output-pixela"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
|
17
|
+
spec.add_development_dependency 'embulk', ['>= 0.9.8']
|
18
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
19
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
20
|
+
spec.add_dependency 'pixela', ['>=0.1.0']
|
21
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'pixela'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Embulk
|
5
|
+
module Output
|
6
|
+
|
7
|
+
class PixelaOut < OutputPlugin
|
8
|
+
Plugin.register_output("pixela", self)
|
9
|
+
|
10
|
+
def self.transaction(config, schema, count, &control)
|
11
|
+
# configuration code:
|
12
|
+
task = {
|
13
|
+
"name" => config.param("name", :string),
|
14
|
+
"token" => config.param("token", :string),
|
15
|
+
"graph_id" => config.param("graph_id", :string),
|
16
|
+
"quantity_float_column" => config.param("quantity_float_column", :string, default: nil),
|
17
|
+
"quantity_int_column" => config.param("quantity_int_column", :string, default: nil),
|
18
|
+
"date_column" => config.param("date_column", :string),
|
19
|
+
}
|
20
|
+
|
21
|
+
# resumable output:
|
22
|
+
# resume(task, schema, count, &control)
|
23
|
+
|
24
|
+
# non-resumable output:
|
25
|
+
task_reports = yield(task)
|
26
|
+
next_config_diff = {}
|
27
|
+
return next_config_diff
|
28
|
+
end
|
29
|
+
|
30
|
+
# def self.resume(task, schema, count, &control)
|
31
|
+
# task_reports = yield(task)
|
32
|
+
#
|
33
|
+
# next_config_diff = {}
|
34
|
+
# return next_config_diff
|
35
|
+
# end
|
36
|
+
|
37
|
+
def init
|
38
|
+
# initialization code:
|
39
|
+
@name = task["name"]
|
40
|
+
unless @name
|
41
|
+
raise "'name' is required."
|
42
|
+
end
|
43
|
+
@token = task["token"]
|
44
|
+
unless @token
|
45
|
+
raise "'token' is required."
|
46
|
+
end
|
47
|
+
@graph_id = task["graph_id"]
|
48
|
+
unless @graph_id
|
49
|
+
raise "'graph_id' is required."
|
50
|
+
end
|
51
|
+
@quantity_float_column = task["quantity_float_column"]
|
52
|
+
@quantity_int_column = task["quantity_int_column"]
|
53
|
+
unless @quantity_float_column || @quantity_int_column
|
54
|
+
raise "Choose 'quantity_int_column' or 'float_column'."
|
55
|
+
end
|
56
|
+
@date_column = task["date_column"]
|
57
|
+
unless @date_column
|
58
|
+
raise "'date_column' is required."
|
59
|
+
end
|
60
|
+
|
61
|
+
@client = Pixela::Client.new(username: @name, token: @token)
|
62
|
+
end
|
63
|
+
|
64
|
+
def close
|
65
|
+
end
|
66
|
+
|
67
|
+
def add(page)
|
68
|
+
Embulk.logger.info { "Connecting to https://pixe.la/v1/users/#{@client.username}/graphs/#{@graph_id}" }
|
69
|
+
page.each do |record|
|
70
|
+
data = Hash[schema.names.zip(record)]
|
71
|
+
# Choose only target columns
|
72
|
+
quantity = data["#{@quantity_float_column}"] if @quantity_float_column
|
73
|
+
quantity = data["#{@quantity_int_column}"] if @quantity_int_column
|
74
|
+
d = data["#{@date_column}"]
|
75
|
+
begin
|
76
|
+
@client.create_pixel(graph_id: @graph_id, date: d, quantity: quantity)
|
77
|
+
rescue Pixela::PixelaError => e
|
78
|
+
Embulk.logger.warn {"#{d}: #{e}"}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def finish
|
84
|
+
end
|
85
|
+
|
86
|
+
def abort
|
87
|
+
end
|
88
|
+
|
89
|
+
def commit
|
90
|
+
task_report = {}
|
91
|
+
return task_report
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-pixela
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toru Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.9.8
|
19
|
+
name: embulk
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.10.6
|
33
|
+
name: bundler
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
name: rake
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.0
|
61
|
+
name: pixela
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.0
|
69
|
+
description: Dumps records to Pixela.
|
70
|
+
email:
|
71
|
+
- torutakahashi.ayashi@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- embulk-output-pixela.gemspec
|
83
|
+
- lib/embulk/output/pixela.rb
|
84
|
+
homepage: https://github.com/torutakahashi.ayashi/embulk-output-pixela
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.6.14
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Pixela output plugin for Embulk
|
108
|
+
test_files: []
|