wms 0.0.2 → 0.0.3
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 +8 -8
- data/lib/wms/input/filetype1.rb +172 -0
- data/lib/wms/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTI5MGJiMjYwMGNjNWNiODgwNDNjZWIyM2YwZWMyMTg5MTdjOWI5Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjVlNWI4ODA3MTNhM2YyNmQ3MjAxMDI0N2MwM2MwYmY1ZGJhMjg1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTg1ZjAxMTIxODUxOGY0NTExZDc5Y2FmZDdlZWJmYzMwMWM1MTUwZDNjODlh
|
10
|
+
ZTY0Y2U2NmE5ZTI2YjE0NTZkY2YyODEyN2ZlYmVjYjk1NDMwOTEzMTIyOTg3
|
11
|
+
MzNkYmVmMjY2MGQzZTU4NjVmZjMzZDQyODg1ZmQzODMxNDE2YmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWQzMjRmZTNmNjY5ODYyZWUxNmRmZGRiZDBiYTUxZjc3NzA1MTVjYjE4NjFl
|
14
|
+
YTQ5NzQ2MDBlNGY4NWFlY2Y1YTY1YThmNjE2MzU3YzUxMjQ3NDU4Mjg2ZDMw
|
15
|
+
YjAxZTAzMTcxODVkZGM4MmRjMGQ1MmYzZDU0YzM3MTgwMmZlMTU=
|
@@ -0,0 +1,172 @@
|
|
1
|
+
|
2
|
+
require 'wms/input/base'
|
3
|
+
require 'wms/config/mixin'
|
4
|
+
require 'csv'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
class Wms::Input::Filetype1 < Wms::Input::Base
|
8
|
+
|
9
|
+
attr_accessor :filepath
|
10
|
+
|
11
|
+
|
12
|
+
public
|
13
|
+
def register(options={})
|
14
|
+
raise "#{self.class.name}: filepath required in options" unless options[:filepath]
|
15
|
+
@filepath = options[:filepath]
|
16
|
+
@compressed = options[:compressed]
|
17
|
+
@file_ext = options[:file_ext]
|
18
|
+
@is_gz = options[:file_ext] == '.gz'
|
19
|
+
|
20
|
+
end # def register
|
21
|
+
|
22
|
+
# Read from csv file row by row. Callback function will be called when each
|
23
|
+
# row is done reading.
|
24
|
+
public
|
25
|
+
def run(&block)
|
26
|
+
# adding options to make data manipulation easy
|
27
|
+
total_lines = 0
|
28
|
+
str_arr = []
|
29
|
+
callback = block
|
30
|
+
if @is_gz
|
31
|
+
Zlib::GzipReader.open(@filepath) do |csv|
|
32
|
+
csv.read.each_line do |line|
|
33
|
+
splits = line.split(',')
|
34
|
+
type = splits[0]
|
35
|
+
timestr = splits[1]
|
36
|
+
timestamp = Time.at(splits[2].to_i / 1000.0, splits[2].to_i % 1000.0)
|
37
|
+
device_id = splits[3]
|
38
|
+
|
39
|
+
data = Hash.new
|
40
|
+
data[:type] = type
|
41
|
+
data[:timestamp] = timestamp
|
42
|
+
data[:device_id] = device_id
|
43
|
+
|
44
|
+
case type
|
45
|
+
when "wifi_accesspoint_info"
|
46
|
+
joined = splits[4..splits.size].join(',')
|
47
|
+
jsoned = JSON.parse(joined)
|
48
|
+
data[:list] = jsoned['list']
|
49
|
+
callback.call(data)
|
50
|
+
when "location"
|
51
|
+
(4..splits.size-1).step(2).each do |i|
|
52
|
+
data[splits[i]] = cascading_convert(splits[i+1])
|
53
|
+
callback.call data
|
54
|
+
end
|
55
|
+
when "battery"
|
56
|
+
(4..splits.size-1).step(2).each do |i|
|
57
|
+
data[splits[i]] = cascading_convert(splits[i+1])
|
58
|
+
callback.call data
|
59
|
+
end
|
60
|
+
when "application"
|
61
|
+
(4..splits.size-1).step(2).each do |i|
|
62
|
+
data[splits[i]] = cascading_convert(splits[i+1])
|
63
|
+
callback.call data
|
64
|
+
end
|
65
|
+
|
66
|
+
# when "wifiscan"
|
67
|
+
|
68
|
+
else
|
69
|
+
@logger.debug "Type #{type} is no supported!"
|
70
|
+
end
|
71
|
+
|
72
|
+
@logger.debug data
|
73
|
+
|
74
|
+
|
75
|
+
# str_arr = []
|
76
|
+
# str_arr << '['
|
77
|
+
# str_arr << line
|
78
|
+
# str_arr << ']'
|
79
|
+
|
80
|
+
# joined_str = str_arr.join("")
|
81
|
+
# @logger.debug " ==> #{joined_str}"
|
82
|
+
#
|
83
|
+
# json_obj = JSON.parse(joined_str)
|
84
|
+
|
85
|
+
# @logger.debug " --> #{json_obj}"
|
86
|
+
# norm_json = normlaize_json_obj(json_obj)
|
87
|
+
# callback = block
|
88
|
+
# callback.call(norm_json)
|
89
|
+
# @logger.debug ">>>>>>#{norm_json}"
|
90
|
+
|
91
|
+
total_lines += 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
@logger.debug "Total line: %d" % total_lines
|
96
|
+
else
|
97
|
+
File.open(@filepath, "r").each_line do |line|
|
98
|
+
str_arr = []
|
99
|
+
str_arr << '['
|
100
|
+
str_arr << line
|
101
|
+
str_arr << ']'
|
102
|
+
joined_str = str_arr.join("")
|
103
|
+
json_obj = JSON.parse(joined_str)
|
104
|
+
|
105
|
+
|
106
|
+
# norm_json = normlaize_json_obj(json_obj)
|
107
|
+
# callback = block
|
108
|
+
# callback.call(norm_json)
|
109
|
+
# @logger.debug ">>>>>>#{norm_json}"
|
110
|
+
|
111
|
+
total_lines += 1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end # end run(&block)
|
116
|
+
|
117
|
+
# Try to convert in order
|
118
|
+
# Int > Float > String
|
119
|
+
private
|
120
|
+
def cascading_convert(value)
|
121
|
+
result = nil
|
122
|
+
begin
|
123
|
+
result = Integer(value)
|
124
|
+
rescue
|
125
|
+
begin
|
126
|
+
result = Float(value)
|
127
|
+
rescue
|
128
|
+
result = value
|
129
|
+
end
|
130
|
+
end
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
private
|
136
|
+
def normlaize_json_obj(json_obj)
|
137
|
+
normlaized_json_obj = {}
|
138
|
+
if json_obj[0] == 'wifi_accesspoint_info'
|
139
|
+
normlaized_json_obj['type'] = 'wifi_accesspoint_info'
|
140
|
+
normlaized_json_obj['timestamp'] = Time.at(json_obj[2] / 1000.0, json_obj[2] % 1000.0)
|
141
|
+
normlaized_json_obj['device_id'] = json_obj[3]
|
142
|
+
normlaized_json_obj['wifi_list'] = json_obj[4]['list']
|
143
|
+
|
144
|
+
# Convert string values into floats
|
145
|
+
convert_level_freq(normlaized_json_obj['wifi_list'])
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
elsif json_obj[0] == 'location'
|
150
|
+
normlaized_json_obj['type'] = 'location'
|
151
|
+
normlaized_json_obj['timestamp'] = Time.at(json_obj[2] / 1000.0, json_obj[2] % 1000.0)
|
152
|
+
normlaized_json_obj['device_id'] = json_obj[3]
|
153
|
+
stop_at = json_obj.length - 1
|
154
|
+
range = (4..stop_at)
|
155
|
+
range.step(2).each do |i|
|
156
|
+
normlaized_json_obj[json_obj[i]] = json_obj[i+1]
|
157
|
+
end
|
158
|
+
# @logger.debug normlaized_json_obj
|
159
|
+
end
|
160
|
+
|
161
|
+
return normlaized_json_obj
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def convert_level_freq(wifi_list)
|
166
|
+
wifi_list.each do |wifi|
|
167
|
+
wifi['level'] = wifi['level'].to_i if wifi['level']
|
168
|
+
wifi['frequency'] = wifi['frequency'].to_i if wifi['frequency']
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
data/lib/wms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phoorichet Thepdusith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/wms/input/android_sensor.rb
|
73
73
|
- lib/wms/input/android_wifilocation.rb
|
74
74
|
- lib/wms/input/base.rb
|
75
|
+
- lib/wms/input/filetype1.rb
|
75
76
|
- lib/wms/plugin/plugin.rb
|
76
77
|
- lib/wms/version.rb
|
77
78
|
- lib/wms/widget/base.rb
|