Class: BlackStack::QABot::IntFlag

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.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/dbclasses.rb', line 328

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::IntFlag.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 decide to go green or red.
    o.value_threshold = h[:value_threshold]            
    # what is the value to show red (true or 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)


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/dbclasses.rb', line 266

def is_red?
    if self.trigger_red == BlackStack::QABot::LOWER_OR_EQUAL
        return self.value <= self.value_threshold
    elsif self.trigger_red == BlackStack::QABot::LOWER
        return self.value < self.value_threshold
    elsif self.trigger_red == BlackStack::QABot::EQUAL
        return self.value == self.value_threshold
    elsif self.trigger_red == BlackStack::QABot::GREATER
        return self.value > self.value_threshold
    elsif self.trigger_red == BlackStack::QABot::GREATER_OR_EQUAL
        return self.value >= self.value_threshold
    else
        return nil
    end
end

#last_update_descriptionObject

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



386
387
388
389
390
391
392
393
394
# File 'lib/dbclasses.rb', line 386

def last_update_description
    row = DB["
        select top 1 dbo.fnTimeAgoDescription(trace_time, getdate()) as timeago
        from qaintflagtrace with (nolock)
        where id_qaintflag = '#{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.



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/dbclasses.rb', line 283

def parse(h)
    self.value = h[:value].to_i
    self.value_threshold = h[:value_threshold].to_i
    self.trigger_red = h[:trigger_red].to_i
    q = "
        UPDATE qaintflag
        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].to_i.to_s},
            -- what is the value to decide to go green or red.
            value_threshold = #{h[:value_threshold].to_i.to_s},            
            -- what is the value to show red (true or false). Default value is `false`.
            trigger_red = #{h[:trigger_red].to_i.to_s},
            -- 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]}'
    "
    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.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/dbclasses.rb', line 226

def to_hash()
    {
        :id => self.id,
        :type => BlackStack::QABot::INT,
        :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 decide to go green or red.
        value_threshold => self.value_threshold,                 
        # 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::IntFlag.selfself.trace_frequency_period, -#BlackStack::QABot::IntFlag.selfself.trace_frequency_units, getdate())`

Returns:

  • (Boolean)


376
377
378
379
380
381
382
383
# File 'lib/dbclasses.rb', line 376

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