Пример #1
0
def format_message():
    if ('KEEN_PROJECT_ID' not in globals()
            or 'KEEN_READ_KEY' not in globals()):
        raise NameError('Keen settings not set.')
    keen.project_id = KEEN_PROJECT_ID
    keen.read_key = KEEN_READ_KEY
    usageSum = keen.sum("flow", "volume", "previous_7_days", None, "daily",
                        [{
                            'property_name': 'volume',
                            "operator": "gt",
                            "property_value": "0"
                        }])
    totalUsage = 0
    for usage in usageSum:
        totalUsage += usage['value']

    output = ''
    for usage in usageSum:
        repeat = int(ceil(10 * (float(usage['value']) / totalUsage)))
        start = dateutil.parser.parse(usage['timeframe']['start'])
        usage_value = str(usage['value'])
        usage_bar = ('=' * repeat).ljust(10)
        output += '\n{}: {} {}'.format(start.strftime('%A'), usage_bar,
                                       usage['value'])
    return output
Пример #2
0
def format_message():
  if ('KEEN_PROJECT_ID' not in globals() or 'KEEN_READ_KEY' not in globals()):
    raise NameError('Keen settings not set.')
  keen.project_id = KEEN_PROJECT_ID
  keen.read_key = KEEN_READ_KEY
  usageSum = keen.sum("flow", "volume", "previous_7_days", None, "daily", [{'property_name':'volume', "operator":"gt", "property_value":"0"}])
  totalUsage = 0;
  for usage in usageSum:
    totalUsage += usage['value']

  output = ''
  for usage in usageSum:
    repeat = int(ceil(10 * (float(usage['value']) / totalUsage)))
    start = dateutil.parser.parse(usage['timeframe']['start'])
    usage_value = str(usage['value'])
    usage_bar = ('=' * repeat).ljust(10)
    output += '\n{}: {} {}'.format(start.strftime('%A'), usage_bar, usage['value'])
  return output;
 def test_sum(self):
     resp = keen.sum("query test", target_property="number", timeframe="today")
     self.assertEqual(type(resp), int)
Пример #4
0
 def test_sum(self, get):
     get.return_value = self.INT_RESPONSE
     resp = keen.sum("query test",
                     target_property="number",
                     timeframe="today")
     self.assertEqual(type(resp), int)
 def test_sum(self):
     resp = keen.sum("query test", target_property="number", timeframe="today")
     assert type(resp) is int
Пример #6
0
 def test_sum(self, get):
     get.return_value = self.INT_RESPONSE
     resp = keen.sum("query test", target_property="number", timeframe="today")
     self.assertEqual(type(resp), int)
Пример #7
0
 def test_sum(self):
     resp = keen.sum("query test",
                     target_property="number",
                     timeframe="today")
     assert type(resp) is int