Class: Octo::Ctr

Inherits:
Object
  • Object
show all
Includes:
Cequel::Record, Record
Defined in:
lib/octocore-cassandra/models/enterprise/ctr.rb

Constant Summary collapse

NEWSFEED =

Type of Ctr. Reserved for future use

0

Constants included from Cequel::Record

Cequel::Record::DUMP_ATTRS

Class Method Summary collapse

Methods included from Record

#unique_id

Methods included from Cequel::Record

#marshal_dump, #marshal_load, redis, update_cache_config

Class Method Details

.data(enterprise_id, ts = Time.now.floor) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octocore-cassandra/models/enterprise/ctr.rb', line 22

def data( enterprise_id, ts = Time.now.floor)
  args = {
    enterprise_id: enterprise_id,
    ts: ts
  }
  res = self.where(args)
  if res.count > 0
    res.first
  else
    args.merge!({ value: value_array(15)})
    self.new(args).save!
  end
end

.value_array(count) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/octocore-cassandra/models/enterprise/ctr.rb', line 36

def value_array(count)
  arr = []
  res = []
  sum = 0
  count.times do |x|
    temp = rand(10.00..100.00)
    arr.push(temp)
    sum = sum + temp
  end
  count.times do |x|
    res.push((arr[x]/sum)*100)
  end
  res
end