haystack_ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/haystack_ruby/object.rb +11 -11
- data/lib/haystack_ruby/point.rb +15 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c6b9cdc1447c63ec9e4389027df52d9895c659
|
4
|
+
data.tar.gz: 5f49ee6b99c204c65b3b8553c1e71b802e61fc32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b476a3f16801e3b26f1db1f88694edafe3c53d5e4674523500031f621e3235f6b73033db3d6f79888cec58696cc0809d54c4b7701d2c29bf826c97a19784907
|
7
|
+
data.tar.gz: 43faa8a880a29efc9ef66f526668c58cc9bbff9351a73abbee82e5adfcd2ff0218da6a75853997963faf4eb5ad85af8f4c0d61294d3c293c150a790e99c5d93f
|
data/lib/haystack_ruby/object.rb
CHANGED
@@ -35,27 +35,27 @@ module HaystackRuby
|
|
35
35
|
# Map to Haystack type per http://project-haystack.org/doc/Json
|
36
36
|
case val
|
37
37
|
when /\Am:.*/
|
38
|
-
|
38
|
+
extend HaystackRuby::Types::Marker
|
39
39
|
when /\Az:.*/
|
40
|
-
|
40
|
+
extend HaystackRuby::Types::NA
|
41
41
|
when /\An:.*/
|
42
42
|
extend HaystackRuby::Types::Number
|
43
43
|
when /\Ar:.*/
|
44
|
-
|
44
|
+
extend HaystackRuby::Types::Ref
|
45
45
|
when /\As:.*/
|
46
|
-
|
46
|
+
extend HaystackRuby::Types::Str
|
47
47
|
when /\Ad:.*/
|
48
|
-
|
48
|
+
extend HaystackRuby::Types::Date
|
49
49
|
when /\Ah:.*/
|
50
|
-
|
50
|
+
extend HaystackRuby::Types::Time
|
51
51
|
when /\At:.*/
|
52
|
-
|
52
|
+
extend HaystackRuby::Types::DateTime
|
53
53
|
when /\Au:.*/
|
54
|
-
|
54
|
+
extend HaystackRuby::Types::Uri
|
55
55
|
when /\Ab:.*/
|
56
|
-
|
56
|
+
extend HaystackRuby::Types::Bin
|
57
57
|
when /\Ac:.*/
|
58
|
-
|
58
|
+
extend HaystackRuby::Types::Coord
|
59
59
|
when /\Ax:.*/
|
60
60
|
raise HaystackRuby::Error, "parsing of XStr type is not supported for string val #{val}"
|
61
61
|
else
|
@@ -67,4 +67,4 @@ module HaystackRuby
|
|
67
67
|
set_fields val
|
68
68
|
end
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
data/lib/haystack_ruby/point.rb
CHANGED
@@ -2,8 +2,8 @@ require 'date'
|
|
2
2
|
# require 'active_support'
|
3
3
|
module HaystackRuby
|
4
4
|
module Point
|
5
|
-
|
6
|
-
# is this Point valid for purposees of Project Haystack Integration?
|
5
|
+
|
6
|
+
# is this Point valid for purposees of Project Haystack Integration?
|
7
7
|
def haystack_valid?
|
8
8
|
return self.haystack_project_name.present? && self.haystack_point_id.present? && self.haystack_time_zone.present?
|
9
9
|
end
|
@@ -33,7 +33,7 @@ module HaystackRuby
|
|
33
33
|
|
34
34
|
# data is ascending array of hashes with format: {time: epochtime, value: myvalue}
|
35
35
|
def his_write(data)
|
36
|
-
query =
|
36
|
+
query =
|
37
37
|
["ver:\"#{haystack_project.haystack_version}\" id:@#{self.haystack_point_id}",'ts,val'] + data.map{ |d| "#{d[:time]},#{d[:value]}"}
|
38
38
|
|
39
39
|
res = connection.post('hisWrite') do |req|
|
@@ -44,7 +44,7 @@ module HaystackRuby
|
|
44
44
|
JSON.parse(res.body)['meta']['ok'].present?
|
45
45
|
end
|
46
46
|
|
47
|
-
def data(start, finish = nil, as_datetime = false) # as_datetime currently ignored
|
47
|
+
def data(start, finish = nil, as_datetime = false, include_unit = false) # as_datetime currently ignored
|
48
48
|
return unless haystack_valid? #may choose to throw exception instead
|
49
49
|
|
50
50
|
range = [start]
|
@@ -52,15 +52,16 @@ module HaystackRuby
|
|
52
52
|
# clean up the range argument before passing through to hisRead
|
53
53
|
# ----------------
|
54
54
|
r = HaystackRuby::Range.new(range, self.haystack_time_zone)
|
55
|
-
|
55
|
+
|
56
56
|
res = his_read r.to_s
|
57
|
-
|
57
|
+
# puts "res in data : #{res}"
|
58
|
+
reformat_timeseries(res['rows'], as_datetime, include_unit)
|
58
59
|
end
|
59
60
|
|
60
61
|
def write_data(data)
|
61
62
|
# format data for his_write
|
62
|
-
data = data.map do |d|
|
63
|
-
{
|
63
|
+
data = data.map do |d|
|
64
|
+
{
|
64
65
|
time: HaystackRuby::Timestamp.convert_to_string(d[:time], self.haystack_time_zone),
|
65
66
|
value: d[:value]
|
66
67
|
}
|
@@ -68,13 +69,15 @@ module HaystackRuby
|
|
68
69
|
his_write data
|
69
70
|
end
|
70
71
|
|
71
|
-
# map from
|
72
|
-
def reformat_timeseries data, as_datetime
|
72
|
+
# map from
|
73
|
+
def reformat_timeseries data, as_datetime = false, include_unit = false
|
73
74
|
data.map do |d|
|
74
75
|
time = (as_datetime) ? DateTime.parse(d['ts']) : DateTime.parse(d['ts']).to_i
|
75
76
|
val = HaystackRuby::Object.new(d['val'])
|
76
|
-
{:time => time, :value => val.value}
|
77
|
+
r = {:time => time, :value => val.value}
|
78
|
+
r[:unit] = val.unit if include_unit
|
79
|
+
r
|
77
80
|
end
|
78
81
|
end
|
79
82
|
end
|
80
|
-
end
|
83
|
+
end
|