Class: BlackStack::QABot::BoolFlag

Inherits:
Object
  • Object
show all
Includes:
Flag
Defined in:
lib/dbclasses.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Flag

#alert, push, #should_alert?

Class Method Details

.create(client, h) ⇒ Object

create a new object. map the attributes of the hash ‘h` to this object. return such an object.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/dbclasses.rb', line 147

def self.create(client, h)
    u = client.users.first # TODO: the email of the user should be included in the hash descriptor, and validate the user exists and is belonging this client.
    g = client.categories.select { |g| g.name == h[:category] }.first
    if g.nil?
        g = BlackStack::QABot::Category.new
        g.id = guid()
        g.create_time = now()
        g.id_user = u.id
        g.name = h[:category]
        g.save
    end # g.nil?

    o = BlackStack::QABot::BoolFlag.new
    o.id = guid()
    o.id_qacategory = g.id
    o.id_user = u.id
    o.create_time = now()
    o.name = h[:name]
    o.html_description = h[:html_description]
    # how often run this qa check - what is the frequency to show the timeline -- ss, mi, hh, mm, dd, qq, yy
    o.trace_frequency_period = h[:trace_frequency_period]
    o.trace_frequency_units = h[:trace_frequency_units]
    # show this flag public in the web
    o.public = h[:public]
    # what is the latest value reported
    o.value = h[:value]
    # what is the value to show red (true or false). Default value is `false`.
    o.trigger_red = h[:trigger_red]
    # each time the value is changed, you can show a comment about the last status.
    o.alert_comments = h[:alert_comments]
    # if it is currently red
    o.stat_red = o.is_red?
    # order to show it inside the category, in the dashboard
    o.order = h[:order]
    # sharing this with other people, so other people can add my alert on their dashboards.
    o.share = h[:share]
    # activate this flag to show in the flags column of the dashboard
    o.show_as_flag = h[:show_as_flag]
    # activate tis flag to show in the timelines column of the dashboard
    o.show_as_timeline = h[:show_as_timeline]
    # save
    o.save
    #
    o
end

Instance Method Details

#is_red?Boolean

it is red if the ‘value` is the same than the value assigned to `trigger_red`

Returns:

  • (Boolean)


95
96
97
# File 'lib/dbclasses.rb', line 95

def is_red?
    self.value == self.trigger_red
end

#last_update_descriptionObject

return a label to describe when this flag has been updated the last time



204
205
206
207
208
209
210
211
212
# File 'lib/dbclasses.rb', line 204

def last_update_description
    row = DB["
        select top 1 dbo.fnTimeAgoDescription(trace_time, getdate()) as timeago
        from qaboolflagtrace with (nolock)
        where id_qaboolflag = '#{self.id}'
        order by trace_time desc
    "].first
    return !row.nil? ? row[:timeago] : 'never'
end

#parse(h) ⇒ Object

map the attributes of the hash ‘h` to this object.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/dbclasses.rb', line 100

def parse(h)
    self.value = h[:value] == true
    self.trigger_red = h[:trigger_red] == true
    q = "
        UPDATE qaboolflag
        SET
            id_qacategory = '#{h[:id_qacategory]}',
            --create_time = '#{h[:create_time]}',
            --delete_time = '#{h[:delete_time]}',
            id_user = '#{h[:id_user]}',
            name = '#{h[:name].to_s.to_sql}',
            html_description = '#{h[:html_description].to_s.to_sql}',
            -- how often run this qa check - what is the frequency to show the timeline -- ss, mi, hh, mm, dd, qq, yy
            trace_frequency_period = '#{h[:trace_frequency_period]}',
            trace_frequency_units = #{h[:trace_frequency_units]},
            -- show this flag public in the web
            [public] = #{h[:public] == true ? 1 : 0},
            -- what is the latest value reported
            [value] = #{h[:value] == true ? 1 : 0},
            -- what is the value to show red (true or false). Default value is `false`.
            trigger_red = #{h[:trigger_red] == true ? 1 : 0},
            -- each time the value is changed, you can show a comment about the last status.
            alert_comments = '#{h[:alert_comments].to_s.to_sql}',
            -- if it is currently red
            stat_red = #{self.is_red? ? 1 : 0},
            -- order to show it inside the category, in the dashboard
            [order] = #{h[:order].to_i},
            -- sharing this with other people, so other people can add my alert on their dashboards.
            share = #{h[:share] == true ? 1 : 0},
            -- activate this flag to show in the flags column of the dashboard
            show_as_flag = #{h[:show_as_flag] == true ? 1 : 0},
            -- activate tis flag to show in the timelines column of the dashboard
            show_as_timeline = #{h[:show_as_timeline] == true ? 1 : 0}
        WHERE
            id = '#{h[:id]}'
    "
#puts
#puts
#puts q
#puts
#puts
    DB.execute(q)
end

#to_hashObject

map the attributes of this object to a hash. add custom elements to the hash: ‘:up_to_date`, `:last_update_description` return such a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dbclasses.rb', line 57

def to_hash()
    {
        :id => self.id,
        :type => BlackStack::QABot::BOOL,
        :id_qacategory => self.id_qacategory,
        :create_time => self.create_time,
        :delete_time => self.delete_time,
        :id_user => self.id_user,
        :name => self.name,
        :html_description => self.html_description,
        # how often run this qa check - what is the frequency to show the timeline -- ss, mi, hh, mm, dd, qq, yy
        :trace_frequency_period => self.trace_frequency_period,
        :trace_frequency_units => self.trace_frequency_units,
        # show this flag public in the web
        :public => self.public,
        # what is the latest value reported
        :value => self.value,
        # what is the value to show red (true or false).
        :trigger_red => self.trigger_red,
        # each time the value is changed, you can show a comment about the last status.
        :alert_comments => self.alert_comments,
        # if it is currently red
        :stat_red => self.stat_red,
        # order to show it inside the category, in the dashboard
        :order => self.order,
        # sharing this with other people, so other people can add my alert on their dashboards.
        :share => self.share,
        # activate this flag to show in the flags column of the dashboard
        :show_as_flag => self.show_as_flag,
        # activate tis flag to show in the timelines column of the dashboard
        :show_as_timeline => self.show_as_timeline,
        # custom elements
        :up_to_date => self.up_to_date?,
        :last_update_description => self.last_update_description,
    }
end

#up_to_date?Boolean

return true if the flag has been updated after ‘dateadd(#BlackStack::QABot::BoolFlag.selfself.trace_frequency_period, -#BlackStack::QABot::BoolFlag.selfself.trace_frequency_units, getdate())`

Returns:

  • (Boolean)


194
195
196
197
198
199
200
201
# File 'lib/dbclasses.rb', line 194

def up_to_date?
    !DB["
        select top 1 id
        from qaboolflagtrace with (nolock)
        where trace_time > dateadd(#{self.trace_frequency_period}, -#{self.trace_frequency_units}, getdate())
        and id_qaboolflag = '#{self.id}'
    "].first.nil?
end