icharger-log 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 710ba3674a6d6d8dba185b5f85d3cde8ddbe9319
4
+ data.tar.gz: ebb0ab93cf3733156f458b19fd1c452b2bd4531a
5
+ SHA512:
6
+ metadata.gz: a97f570ac7a02989338185aa0645f8f6e1781bd7270e7fd5d88d9a65bf4d6ea87caf33b36c446fb9b913f902ff1ac65026dd50cb65704fdee8f8bd5c854bef7e
7
+ data.tar.gz: 70db24d915ce59325372f8ab331ed39a45bd47ae6f2791266f71d9a22c24d91b28ed256f9e894fa3597c1b56490b10d0add569cf93607cc90161a8aea7dd3d42
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+
5
+ notifications:
6
+ disabled: true
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in icharger-log.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nick Veys
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ICharger::Log [![Build Status](https://travis-ci.org/code-lever/icharger-log.png)](https://travis-ci.org/code-lever/icharger-log) [![Dependency Status](https://gemnasium.com/code-lever/icharger-log.png)](https://gemnasium.com/code-lever/icharger-log) [![Code Climate](https://codeclimate.com/github/code-lever/icharger-log.png)](https://codeclimate.com/github/code-lever/icharger-log)
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'icharger-log'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install icharger-log
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'icharger/log/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "icharger-log"
8
+ spec.version = ICharger::Log::VERSION
9
+ spec.authors = ["Nick Veys"]
10
+ spec.email = ["nick@codelever.com"]
11
+ spec.description = %q{Read and interpret iCharger log files.}
12
+ spec.summary = %q{iCharger log file reader}
13
+ spec.homepage = "http://github.com/code-lever/icharger-log"
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_development_dependency 'awesome_print'
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'ci_reporter', '= 1.8.4'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 2.13'
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'simplecov-gem-adapter'
28
+ spec.add_development_dependency 'simplecov-rcov'
29
+ end
@@ -0,0 +1,38 @@
1
+ require 'open-uri'
2
+
3
+ module ICharger
4
+ module Log
5
+
6
+ class File
7
+
8
+ attr_reader :rows
9
+
10
+ # Determines if the file at the given URI is an iCharger log file.
11
+ #
12
+ # @param uri URI to file to read
13
+ # @return [ICharger::Log::File] loaded file if the file is an iCharger log file, nil otherwise
14
+ def self.icharger?(uri)
15
+ File.new(uri) rescue nil
16
+ end
17
+
18
+ def initialize(uri)
19
+ open(uri, 'r') do |file|
20
+ @rows = file.readlines.map { |row| ICharger::Log::Row.new(row) }
21
+ end
22
+ raise ArgumentError, "No records found in file" if @rows.empty?
23
+ rescue => e
24
+ raise ArgumentError, "File does not appear to be an iCharger log (#{e})"
25
+ end
26
+
27
+ def channel
28
+ @rows.first.channel
29
+ end
30
+
31
+ def duration
32
+ @rows.last.time / 10000.0
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,82 @@
1
+ module ICharger
2
+ module Log
3
+
4
+ class Row
5
+
6
+ def initialize(raw_line)
7
+ @fields = raw_line.strip.split(';')
8
+ throw ArgumentError, "Unexpected field count (#{@fields.length})" unless @fields.length == 22
9
+ end
10
+
11
+ def channel
12
+ /(?<ch>\d)/.match(@fields[0])[:ch].to_i
13
+ end
14
+
15
+ # XXX state of some kind?
16
+ def field1
17
+ @fields[1]
18
+ end
19
+
20
+ # XXX figure out time unit
21
+ def time
22
+ @fields[2].to_i
23
+ end
24
+
25
+ # XXX always seems to be 1
26
+ def field3
27
+ @fields[3]
28
+ end
29
+
30
+ # XXX always seems to be 0
31
+ def field4
32
+ @fields[4]
33
+ end
34
+
35
+ # XXX VERIFY
36
+ def current
37
+ @fields[5].to_i / 100.0
38
+ end
39
+
40
+ # XXX voltage input?
41
+ def field6
42
+ @fields[6].to_i / 1000.0
43
+ end
44
+
45
+ # XXX voltage measured?
46
+ def field7
47
+ @fields[7].to_i / 1000.0
48
+ end
49
+
50
+ # XXX mAh charged?
51
+ def field8
52
+ @fields[8]
53
+ end
54
+
55
+ # XXX internal temperature / 10.0?
56
+ def field9
57
+ @fields[9]
58
+ end
59
+
60
+ # XXX always seems to be 0, external temp. sensor?
61
+ def field10
62
+ @fields[10]
63
+ end
64
+
65
+ def cell(index)
66
+ @fields[11 + index].to_i / 1000.0
67
+ end
68
+
69
+ def cell_count
70
+ @fields[11..20].reject{ |v| v.to_i == 0 }.length
71
+ end
72
+
73
+ def field21
74
+ @fields[21].to_i
75
+ end
76
+
77
+ private
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ module ICharger
2
+ module Log
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "icharger/log/file"
2
+ require "icharger/log/row"
3
+ require "icharger/log/version"