Class: Octo::UserTimeline

Inherits:
Object
  • Object
show all
Includes:
Cequel::Record
Defined in:
lib/octocore-cassandra/models/user/user_timeline.rb

Constant Summary collapse

BROWSE_PRODUCT =
0
BROWSE_PAGE =
1
SEARCH =
2
SHARE =
3
ADD_TO_CART =
4
CHECKOUT =
5
APP_OPEN =
6
APP_CLOSE =
7
PAGE_RELOAD =
8
LOC_HOME =
11
LOC_OFFICE =
12
LOC_TRANSIT =
13
LOC_VACATION =
14
LOC_OOH =
15
LOC_OTHERS =
16

Constants included from Cequel::Record

Cequel::Record::DUMP_ATTRS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cequel::Record

#marshal_dump, #marshal_load, redis, update_cache_config

Class Method Details

.fakedata(user, n = rand(7..20)) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/octocore-cassandra/models/user/user_timeline.rb', line 37

def self.fakedata(user, n = rand(7..20))
  Array.new(3*n) do |i|
    i+1
  end.shuffle.sample(n).sort.reverse.collect do |i|
    args = {
      user: user,
      ts: i.minutes.ago,
      type: rand(0..8),
      title: 'Product Name',
      location_type: rand(11..16),
      insight: 'some valueable insight',
      details: 'other details here'
    }
    self.new(args).save!
  end
end

Instance Method Details

#human_readableObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/octocore-cassandra/models/user/user_timeline.rb', line 94

def human_readable
  args = {
    user: self.user,
    ts: self.ts,
    type: type_text(self.type),
    type_raw: self.type,
    title: self.title,
    location: location_text(self.location_type),
    location_raw: self.location_type,
    insight: self.insight,
    details: self.details
  }
  OpenStruct.new(args)
end

#location_text(location_type) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/octocore-cassandra/models/user/user_timeline.rb', line 54

def location_text(location_type)
  case location_type
  when LOC_HOME
    'Home'
  when LOC_OFFICE
    'Office'
  when LOC_TRANSIT
    'In Transit'
  when LOC_VACATION
    'While Vacation'
  when LOC_OOH
    'Out of Home City'
  when LOC_OTHERS
    'Other Location'
  end
end

#type_text(activity_type) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/octocore-cassandra/models/user/user_timeline.rb', line 71

def type_text(activity_type)
  case activity_type
  when BROWSE_PRODUCT
    'Browsed for Product'
  when BROWSE_PAGE
    'Browsed for Page'
  when SEARCH
    'Searched'
  when SHARE
    'Shared'
  when ADD_TO_CART
    'Added to Cart'
  when CHECKOUT
    'Performed Checkout'
  when APP_OPEN
    'Opened App'
  when APP_CLOSE
    'Closed App'
  when PAGE_RELOAD
    'Reloaded Page'
  end
end