strategy.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. __author__ = 'Ulric Qin'
  16. from .bean import Bean
  17. class Strategy(Bean):
  18. _tbl = 'strategy'
  19. _cols = 'id,metric,tags,max_step,priority,func,op,right_value,note,run_begin,run_end,tpl_id'
  20. def __init__(self, _id, metric, tags, max_step, priority, func, op, right_value, note, run_begin, run_end, tpl_id):
  21. self.id = _id
  22. self.metric = metric
  23. self.tags = tags
  24. self.max_step = max_step
  25. self.priority = priority
  26. self.func = func
  27. self.op = op
  28. self.right_value = right_value
  29. self.note = note
  30. self.run_begin = run_begin
  31. self.run_end = run_end
  32. self.tpl_id = tpl_id
  33. def to_json(self):
  34. return {
  35. 'id': self.id,
  36. 'metric': self.metric,
  37. 'tags': self.tags,
  38. 'max_step': self.max_step,
  39. 'priority': self.priority,
  40. 'func': self.func,
  41. 'op': self.op,
  42. 'right_value': self.right_value,
  43. 'note': self.note,
  44. 'run_begin': self.run_begin,
  45. 'run_end': self.run_end,
  46. 'tpl_id': self.tpl_id
  47. }