norikra-udf-anomaly 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d812b73e00a3f7b1287c708952d2890ffc814ad3
4
+ data.tar.gz: 41a8a1019738809017a755a9c7bdab9193e1af15
5
+ SHA512:
6
+ metadata.gz: 986c8fde849eddd09e8d54f2de607c8901d8e7b98d9ac19664a2a1c87e5cdf516a7b2f431bb2eef04359c06594e1186de25b29473a9df6c8fbea7fa73cf546f9
7
+ data.tar.gz: cf0a5fc0a51bda696fbd88a3886de36d0565356830aec3f6c08295cd95a714dfb030d01c94a52771665170223e5e02d1debdb44da22a658fc6064216ebf2638b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in norikra-udf-anomaly.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 baba5246
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Norikra::Udf::Anomaly
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/norikra/udf/anomaly`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'norikra-udf-anomaly'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install norikra-udf-anomaly
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/norikra-udf-anomaly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-Ijar", "-Ilib", "-c", "-f progress"] # '--format specdoc'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :compile do
10
+ require 'rubygems'
11
+
12
+ jarname = FileList['norikra-udf-*.gemspec'].first.gsub(/\.gemspec$/, '.jar')
13
+
14
+ jarfiles = FileList['jar/**/*.jar'].select{|f| not f.end_with?('/' + jarname)}
15
+ jarfiles << Gem.find_latest_files('esper-*.jar').first
16
+
17
+ java_classpath = "-classpath src:java:#{jarfiles.join(':')}"
18
+ FileList['src/**/*.java'].each do |fn|
19
+ sh "env LC_ALL=C javac -J-Duser.language=en #{java_classpath} -d java #{fn}"
20
+ end
21
+
22
+ jruby_classpath = "--classpath java:#{jarfiles.join(':')}"
23
+ FileList['lib/esper_plugin/**/*.rb'].each do |fn|
24
+ sh "env LC_ALL=C jrubyc --javac --target java #{jruby_classpath} #{fn}"
25
+ end
26
+
27
+ sh "env LC_ALL=C jar -J-Duser.language=en -cf jar/#{jarname} -C java ."
28
+ end
29
+
30
+ task :clean do
31
+ sh "rm -rf java/*"
32
+ end
33
+
34
+ task :test => [:compile, :spec]
35
+ task :default => :test
36
+
37
+ task :all => [:clean, :compile, :spec, :build]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "norikra/udf/anomaly"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "norikra-udf-anomaly"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["baba5246"]
9
+ spec.email = ["baba_writer@yahoo.co.jp"]
10
+ spec.summary = %q{Norikra UDF anomaly()}
11
+ spec.description = %q{This plugin adds a function named anomaly, which calculates anomaly scores for specified fields}
12
+ spec.homepage = "https://github.com/tagomoris/norikra-udf-anomaly"
13
+ spec.license = "MIT"
14
+ spec.platform = "java"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "jar"]
20
+
21
+ spec.add_runtime_dependency "norikra"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'norikra/udf_spec_helper'
3
+
4
+ include Norikra::UDFSpecHelper
5
+
6
+ require 'norikra/udf/anomaly'
7
+
8
+ describe Norikra::UDF::Anomaly do
9
+ f = udf_function(
10
+ Norikra::UDF::Anomaly,
11
+ :valueType => java.lang.Integer,
12
+ :parameters => [[java.lang.Integer]]
13
+ )
14
+
15
+ it 'returns Integer values' do
16
+ expect(f.getValueType).to eql(java.lang.Integer.java_class)
17
+ end
18
+
19
+ it 'returns 1 value as mean' do
20
+ (0...100).each do |i|
21
+ f._call(:enter, i.to_java())
22
+ end
23
+
24
+ r = f.getValue
25
+ expect(r).to eql(49)
26
+
27
+ (0...100).each do |i|
28
+ f._call(:leave, i.to_java())
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'norikra/udf/mycount'
@@ -0,0 +1,80 @@
1
+ package is.tagomor.norikra.udf;
2
+
3
+ import com.espertech.esper.epl.agg.aggregator.AggregationMethod;
4
+
5
+ import java.util.ArrayList;
6
+
7
+ public class Anomaly implements AggregationMethod {
8
+ private static int initSize = 100000;
9
+ private ArrayList<Integer> countList;
10
+
11
+ public Anomaly() {
12
+ countList = null;
13
+ }
14
+
15
+ public Class getValueType() {
16
+ return Integer.class;
17
+ }
18
+
19
+ public Integer convertValue(Object v) {
20
+ if (v.getClass() == Integer.class)
21
+ return (Integer) v;
22
+ else if (v.getClass() == Float.class)
23
+ return new Integer(((Float) v).intValue());
24
+ else if (v.getClass() == Integer.class)
25
+ return new Integer(((Double) v).intValue());
26
+ else if (v.getClass() == Long.class)
27
+ return new Integer(((Long) v).intValue());
28
+ else
29
+ return new Integer((String) v);
30
+ }
31
+
32
+ public void enter(Object value) {
33
+ if (value == null)
34
+ return;
35
+
36
+ if (countList == null) {
37
+ countList = new ArrayList<Integer>(initSize);
38
+ }
39
+
40
+ Integer count = convertValue(value);
41
+ synchronized (countList) {
42
+ countList.add(count);
43
+ }
44
+ }
45
+
46
+ public void leave(Object value) {
47
+ if (value == null)
48
+ return;
49
+
50
+ Integer count = convertValue(value);
51
+ synchronized (countList) {
52
+ countList.remove(0);
53
+ }
54
+ }
55
+
56
+ public Object getValue() {
57
+ if (countList.size() == 0)
58
+ return null;
59
+
60
+ Integer[] counts = (Integer[]) countList.toArray(new Integer[]{});
61
+ // for thread safety
62
+ if (counts.length == 0)
63
+ return null;
64
+
65
+ Integer mean = mean(counts);
66
+ return mean;
67
+ }
68
+
69
+ public void clear() {
70
+ countList = null;
71
+ }
72
+
73
+ public Integer mean(Integer[] m) {
74
+ Integer sum = 0;
75
+ for (int i = 0; i < m.length; i++) {
76
+ sum += m[i];
77
+ }
78
+ return sum / m.length;
79
+ }
80
+ }
@@ -0,0 +1,38 @@
1
+ package is.tagomor.norikra.udf;
2
+
3
+ import com.espertech.esper.client.hook.AggregationFunctionFactory;
4
+ import com.espertech.esper.epl.agg.service.AggregationValidationContext;
5
+ import com.espertech.esper.epl.agg.aggregator.AggregationMethod;
6
+
7
+ // import java.util.Map;
8
+
9
+ public class AnomalyFactory implements AggregationFunctionFactory {
10
+ public void setFunctionName(String functionName) {
11
+ // no action taken
12
+ }
13
+
14
+ /*
15
+ percentile(field_name, {percentile_specifications_array}[, samples])
16
+ ex: percentile(response_time, 50)
17
+ */
18
+ public void validate(AggregationValidationContext validationContext) {
19
+
20
+ }
21
+
22
+ /*
23
+ In order for the engine to validate the type returned by the aggregation function against
24
+ the types expected by enclosing expressions, the getValueType must return the result type
25
+ of any values produced by the aggregation function:
26
+ */
27
+ public Class getValueType() {
28
+ return Integer.class;
29
+ }
30
+
31
+ /*
32
+ Finally the factory implementation must provide a newAggregator method that returns instances
33
+ of AggregationMethod. The engine invokes this method for each new aggregation state to be allocated.
34
+ */
35
+ public AggregationMethod newAggregator() {
36
+ return new Anomaly();
37
+ }
38
+ }
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norikra-udf-anomaly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - baba5246
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: norikra
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.10'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '10.0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ description: This plugin adds a function named anomaly, which calculates anomaly scores for specified fields
70
+ email:
71
+ - baba_writer@yahoo.co.jp
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - norikra-udf-anomaly.gemspec
87
+ - spec/anomaly_spec.rb
88
+ - spec/spec_helper.rb
89
+ - src/is/tagomor/norikra/udf/Anomaly.java
90
+ - src/is/tagomor/norikra/udf/AnomalyFactory.java
91
+ homepage: https://github.com/tagomoris/norikra-udf-anomaly
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ - jar
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.1.9
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Norikra UDF anomaly()
116
+ test_files:
117
+ - spec/anomaly_spec.rb
118
+ - spec/spec_helper.rb