nmg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +23 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/bin/nmg +105 -0
- data/lib/nmg/sink/json.rb +11 -0
- data/lib/nmg/type/base.rb +11 -0
- data/lib/nmg/type/machine.rb +19 -0
- data/lib/nmg/type/maintenance.rb +32 -0
- data/lib/nmg/type/process.rb +26 -0
- data/lib/nmg/version.rb +3 -0
- data/lib/nmg.rb +15 -0
- data/nmg.gemspec +27 -0
- data/test/test_helper.rb +5 -0
- data/test/type/process_test.rb +17 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3146dd36c1eb1813e107e700e617a2edb526acb
|
4
|
+
data.tar.gz: 7b84da0990de2fa9c4a9117e9ee7acc9b1957f91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1b6f082b66a6d8737ba1ab655d677b9a5af38cfea17f45b13c8cc0aef87b41674cc38ae637140be089aabd962bc625cc9a32e78fc5bd70662f07ffb9d66eae7
|
7
|
+
data.tar.gz: b373a23fc54c369dedd61867600412fa7a4e71a9de2fdd05ecda99c3d27ec0b8df045f12e87aa43d51605d62bb94ba61567d572f9f2931a44f473d9c0004ef17
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Łukasz Niemier
|
2
|
+
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Nuclear Machine Generator
|
2
|
+
[![Code Climate][cc-img]][cc]
|
3
|
+
|
4
|
+
________________
|
5
|
+
____/ ( ( ) ) \___
|
6
|
+
/( ( ( ) _ )) ) )\
|
7
|
+
(( ( )( ) ) ( ) )
|
8
|
+
((/ ( _( ) ( _) ) ( () ) )
|
9
|
+
( ( ( (_) (( ( ) .((_ ) . )_
|
10
|
+
( ( ) ( ( ) ) ) . ) ( )
|
11
|
+
( ( ( ( ) ( _ ( _) ). ) . ) ) ( )
|
12
|
+
( ( ( ) ( ) ( )) ) _)( ) ) )
|
13
|
+
( ( ( \ ) ( (_ ( ) ( ) ) ) ) )) ( )
|
14
|
+
( ( ( ( (_ ( ) ( _ ) ) ( ) ) )
|
15
|
+
( ( ( ( ( ) (_ ) ) ) _) ) _( ( )
|
16
|
+
(( ( )( ( _ ) _) _(_ ( (_ )
|
17
|
+
(_((__(_(__(( ( ( | ) ) ) )_))__))_)___)
|
18
|
+
((__) \\||lll|l||/// \_))
|
19
|
+
( /(/ ( ) ) )\ )
|
20
|
+
( ( ( ( | | ) ) )\ )
|
21
|
+
( /(| / ( )) ) ) )) )
|
22
|
+
( ( ((((_(|)_))))) )
|
23
|
+
( ||\(|(|)|/|| )
|
24
|
+
( |(||(||)|||| )
|
25
|
+
( //|/l|||)|\\ \ )
|
26
|
+
(/ / // /|//||||\\ \ \ \ _)
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Install it yourself using:
|
31
|
+
|
32
|
+
$ gem install nmg
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
See [documentation][doc].
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
45
|
+
|
46
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/put-poznan/nmg/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
47
|
+
[cc-img]: https://codeclimate.com/github/put-poznan/nmg.png "CodeClimate badge"
|
48
|
+
[doc]: http://rubydoc.info/github/put-poznan/nmg/frames
|
49
|
+
[cc]: https://codeclimate.com/github/put-poznan/nmg
|
data/Rakefile
ADDED
data/bin/nmg
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nmg'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
class Nmg::CLI < Thor
|
7
|
+
desc 'generate FILE',
|
8
|
+
'Generate file with description of machines, pocesses and maintenance times'
|
9
|
+
option :format,
|
10
|
+
type: :string,
|
11
|
+
default: 'JSON',
|
12
|
+
desc: 'Format of output file'
|
13
|
+
option :machines,
|
14
|
+
type: :numeric,
|
15
|
+
default: 3,
|
16
|
+
aliases: %w(-m),
|
17
|
+
desc: 'Count of generated machines'
|
18
|
+
option :maintenances,
|
19
|
+
type: :numeric,
|
20
|
+
default: 10_000
|
21
|
+
option :tasks,
|
22
|
+
type: :numeric,
|
23
|
+
required: true,
|
24
|
+
aliases: %w(-p),
|
25
|
+
desc: 'Count of generated tasks'
|
26
|
+
option :operations,
|
27
|
+
type: :numeric,
|
28
|
+
aliases: %w(-o --opts),
|
29
|
+
desc: 'Count of operations per process (by default the same as machines count)'
|
30
|
+
option :'maintenance-duration-min',
|
31
|
+
type: :numeric,
|
32
|
+
default: 1,
|
33
|
+
desc: 'Minimum maintenance duration'
|
34
|
+
option :'maintenance-duration-max',
|
35
|
+
type: :numeric,
|
36
|
+
default: 20,
|
37
|
+
desc: 'Maximum maintenance duration'
|
38
|
+
option :'maintenance-step-min',
|
39
|
+
type: :numeric,
|
40
|
+
default: 10,
|
41
|
+
desc: 'Minimum time between two maintenances'
|
42
|
+
option :'maintenance-step-max',
|
43
|
+
type: :numeric,
|
44
|
+
default: 50,
|
45
|
+
desc: 'Maximum time between two maintenances'
|
46
|
+
option :'operation-duration-min',
|
47
|
+
type: :numeric,
|
48
|
+
default: 1,
|
49
|
+
desc: 'Minimum operation duration'
|
50
|
+
option :'operation-duration-max',
|
51
|
+
type: :numeric,
|
52
|
+
default: 20,
|
53
|
+
desc: 'Maximum operation duration'
|
54
|
+
def generate(file)
|
55
|
+
machine_opts = {
|
56
|
+
machines_count: options[:maintenances],
|
57
|
+
maintenances: {
|
58
|
+
from: options[:'maintenance-duration-min'],
|
59
|
+
to: options[:'maintenance-duration-max'],
|
60
|
+
step: {
|
61
|
+
min: options[:'maintenance-step-min'],
|
62
|
+
max: options[:'maintenance-step-max']
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
task_opts = {
|
67
|
+
operations: options[:operations] || options[:machines],
|
68
|
+
min: options[:'operation-duration-min'],
|
69
|
+
max: options[:'operation-duration-max']
|
70
|
+
}
|
71
|
+
hash = {
|
72
|
+
machines: Nmg::Type::Machine.generate(options[:machines], machine_opts),
|
73
|
+
tasks: Nmg::Type::Process.generate(options[:tasks], task_opts)
|
74
|
+
}
|
75
|
+
|
76
|
+
File.open(file, 'w') do |f|
|
77
|
+
f.write Nmg::Sink::Json.new.serialize(hash)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
desc 'carbon', 'Show application promotor', hide: true
|
82
|
+
def carbon
|
83
|
+
require 'zlib'
|
84
|
+
require 'base64'
|
85
|
+
|
86
|
+
puts Zlib::Inflate.inflate(Base64.decode64(<<WAT
|
87
|
+
eJxtlDFu3EAMRXudgsAULIbgAchGbpMDpJ01ksqAbbgIkNvnkxxpR+v9gBZa
|
88
|
+
7NtPip8j1fFdFBcd37YLIpyyoE5kYegguEPrX7f7rTG7+2Q6z5IXxrsb5ECK
|
89
|
+
Unpk3GXKAmmtnfUmQ8ai0MAlagW1Wezw6QGEAkovMFLViiFhPZwPCAxfmCHP
|
90
|
+
mE4JJUOkKxKMc9uDGXfGq+PTByP45sNJ6EOtNlam3/tJCMPsxVAxlMwJjDIC
|
91
|
+
IzyWfkxyfNmK1bi5mfs4awWkgjS0gshcnF1sLP1QNNC7DNgo7qMlbIAsWWBA
|
92
|
+
CExQULJYFHXGzcUnO5H4nMmiGezKmkVOunoGEU9mgYyFyTTyuVGr4kibMZ74
|
93
|
+
jKqYNni6y/5gnDUc7q4ymWlz7lhsB+aGXTbNhX3GUFQB03A6JiMPDJKKqeWp
|
94
|
+
6Z4It/7AoJgEEHGZ5EHre0HLWc4+kJJlJQa+l9N63k2O1OMkIi0GJA/vBM8k
|
95
|
+
4OcRPovtUGvbff+GtzqrFkg83cIEpdYavtdbIRFX9T21ZQQcQMh7KRHtYVNM
|
96
|
+
309pvjagQLQlsm9yWKRGZgmXKK/zl22/SIenamAHs718fn59/P3zm17/0Y/b
|
97
|
+
O/1Sur3diH/evl4/3nn7D/kwU9k=
|
98
|
+
WAT
|
99
|
+
))
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Nmg::CLI.start(ARGV)
|
104
|
+
|
105
|
+
# vi: ft=ruby
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nmg
|
2
|
+
module Type
|
3
|
+
class Machine < Base
|
4
|
+
attribute :maintenances, Array[Maintenance]
|
5
|
+
|
6
|
+
def self.generate(count, options = {}, gen = Random.new)
|
7
|
+
options = {maintenances_count: 10}.merge(options)
|
8
|
+
|
9
|
+
maintenances_count = options[:maintenances_count]
|
10
|
+
|
11
|
+
count.times.map do
|
12
|
+
new(maintenances: Maintenance.generate(maintenances_count,
|
13
|
+
options[:maintenances] || {},
|
14
|
+
gen))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Nmg
|
2
|
+
module Type
|
3
|
+
class Maintenance < Base
|
4
|
+
attribute :start, Integer
|
5
|
+
attribute :duration, Integer
|
6
|
+
|
7
|
+
def stop
|
8
|
+
start + duration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate(count, options = {}, generator = Random.new)
|
12
|
+
options = {from: 1, to: 20, step: {min: 10, max: 50}}.merge(options)
|
13
|
+
|
14
|
+
arr = []
|
15
|
+
duration = (options[:from]..options[:to])
|
16
|
+
step = (options[:step][:min]..options[:step][:max])
|
17
|
+
|
18
|
+
arr << Maintenance.new(start: generator.rand(step),
|
19
|
+
duration: generator.rand(duration))
|
20
|
+
|
21
|
+
count.to_i.times do
|
22
|
+
last = arr.last
|
23
|
+
|
24
|
+
arr << Maintenance.new(start: last.stop + generator.rand(step),
|
25
|
+
duration: generator.rand(duration))
|
26
|
+
end
|
27
|
+
|
28
|
+
arr
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Nmg
|
2
|
+
module Type
|
3
|
+
# Define process with all it's attributes
|
4
|
+
class Process < Base
|
5
|
+
# @!macro [attach] virtus.attribute
|
6
|
+
# @!attribute $1
|
7
|
+
# @return [$2] the $1 $0
|
8
|
+
attribute :operations, Array[Integer]
|
9
|
+
|
10
|
+
def to_json(options = {})
|
11
|
+
operations.to_json(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.generate(count, options = {}, gen = Random.new)
|
15
|
+
options = {operations: 3, min: 1, max: 20}.merge(options)
|
16
|
+
|
17
|
+
operations = options[:operations]
|
18
|
+
range = (options[:min]..options[:max])
|
19
|
+
|
20
|
+
count.times.map do
|
21
|
+
new(operations: operations.times.map { gen.rand(range) })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/nmg/version.rb
ADDED
data/lib/nmg.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require 'nmg/version'
|
4
|
+
require 'nmg/type/base'
|
5
|
+
|
6
|
+
module Nmg
|
7
|
+
module Sink
|
8
|
+
autoload :Json, 'nmg/sink/json'
|
9
|
+
end
|
10
|
+
module Type
|
11
|
+
autoload :Process, 'nmg/type/process'
|
12
|
+
autoload :Machine, 'nmg/type/machine'
|
13
|
+
autoload :Maintenance, 'nmg/type/maintenance'
|
14
|
+
end
|
15
|
+
end
|
data/nmg.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nmg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nmg"
|
8
|
+
spec.version = Nmg::VERSION
|
9
|
+
spec.authors = ["Łukasz Niemier"]
|
10
|
+
spec.email = ["lukasz@niemier.pl"]
|
11
|
+
spec.description = %q{Easy machines and tasks generator for PUT lessons}
|
12
|
+
spec.summary = %q{Tool for generating machines and tasks for them.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
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"]
|
20
|
+
|
21
|
+
spec.add_dependency "thor", "~> 0.18.1"
|
22
|
+
spec.add_dependency "virtus", "~> 1.0.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rr"
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Nmg::Type::Process do
|
4
|
+
let(:operations) { rand(50..1000).times.map { rand(10..100) } }
|
5
|
+
|
6
|
+
subject { Nmg::Type::Process.new(operations: operations, preparation: 10) }
|
7
|
+
|
8
|
+
describe '#operations' do
|
9
|
+
it 'is an array' do
|
10
|
+
subject.operations.must_be_kind_of Array
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has exactly the same length as given to' do
|
14
|
+
subject.operations.length.must_be :==, operations.length
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nmg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Łukasz Niemier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Easy machines and tasks generator for PUT lessons
|
84
|
+
email:
|
85
|
+
- lukasz@niemier.pl
|
86
|
+
executables:
|
87
|
+
- nmg
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/nmg
|
97
|
+
- lib/nmg.rb
|
98
|
+
- lib/nmg/sink/json.rb
|
99
|
+
- lib/nmg/type/base.rb
|
100
|
+
- lib/nmg/type/machine.rb
|
101
|
+
- lib/nmg/type/maintenance.rb
|
102
|
+
- lib/nmg/type/process.rb
|
103
|
+
- lib/nmg/version.rb
|
104
|
+
- nmg.gemspec
|
105
|
+
- test/test_helper.rb
|
106
|
+
- test/type/process_test.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.0.3
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Tool for generating machines and tasks for them.
|
131
|
+
test_files:
|
132
|
+
- test/test_helper.rb
|
133
|
+
- test/type/process_test.rb
|