Class: BlackStack::QABot::FloatFlag

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.



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/dbclasses.rb', line 510

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::FloatFlag.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)


448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/dbclasses.rb', line 448

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



568
569
570
571
572
573
574
575
576
# File 'lib/dbclasses.rb', line 568

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



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/dbclasses.rb', line 465

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



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/dbclasses.rb', line 408

def to_hash()
    {
        :id => self.id,
        :type => BlackStack::QABot::FLOAT,
        :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::FloatFlag.selfself.trace_frequency_period, -#BlackStack::QABot::FloatFlag.selfself.trace_frequency_units, getdate())`

Returns:

  • (Boolean)


558
559
560
561
562
563
564
565
# File 'lib/dbclasses.rb', line 558

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