当前位置: 首页>>代码示例>>Python>>正文


Python KeenClient.add_events方法代码示例

本文整理汇总了Python中keen.client.KeenClient.add_events方法的典型用法代码示例。如果您正苦于以下问题:Python KeenClient.add_events方法的具体用法?Python KeenClient.add_events怎么用?Python KeenClient.add_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keen.client.KeenClient的用法示例。


在下文中一共展示了KeenClient.add_events方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_post_timeout_batch

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
 def test_post_timeout_batch(self):
     keen.project_id = "5004ded1163d66114f000000"
     api_key = "2e79c6ec1d0145be8891bf668599c79a"
     keen.write_key = scoped_keys.encrypt(api_key, {"allowed_operations": ["write"]})
     client = KeenClient(keen.project_id, write_key=keen.write_key, read_key=None,
                         post_timeout=0.0001)
     client.add_events({"python_test": [{"hello": "goodbye"}]})
开发者ID:ChrisNolan1992,项目名称:KeenClient-Python,代码行数:9,代码来源:client_tests.py

示例2: run

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
    def run(self):
        keen_client = KeenClient(
            project_id=self.project_id,
            write_key=self.write_key,
        )

        timezone = pytz.timezone(self.data['user']['timezone'])

        self.events = []
        with click.progressbar(self.data['days'],
                            label='Preparing keen.io events',
                            fill_char=click.style('#', fg='blue')) as days:

            for day in days:
                dt = self._parse_date(day['date'], timezone)

                self.append_event(dt, 'total', {
                    'seconds': day['grand_total']['total_seconds'],
                })

                categories = [
                    'editor',
                    'language',
                    'operating_system',
                    'project',
                ]
                for category in categories:
                    for item in day.get(category + 's', []):
                        self.append_event(dt, category, {
                            'seconds': item['total_seconds'],
                            'name': item['name'],
                        })

                files = {}
                for project in day.get('projects', []):
                    for f in project.get('dump', {}).get('files', []):
                        if f['name'] not in files:
                            files[f['name']] = 0
                        files[f['name']] += f['total_seconds']

                for name, seconds in files.items():
                    self.append_event(dt, 'file', {
                        'seconds': seconds,
                        'name': name,
                    })

        if len(self.events) == 0:
            click.echo('No events available for exporting to keen.io')
            return

        click.echo('Uploading events to keen.io...')
        start = datetime.utcfromtimestamp(self.data['range']['start'])
        end = datetime.utcfromtimestamp(self.data['range']['end'])
        collection = 'WakaTime Data Dump from {start} until {end}'.format(
            start=start.strftime('%Y-%m-%d'),
            end=end.strftime('%Y-%m-%d'),
        )
        keen_client.add_events({
            collection: self.events,
        })
开发者ID:zerin108,项目名称:wakadump,代码行数:62,代码来源:keenio.py

示例3: main

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
def main():

    call(['./get_sleep.sh'])

    with open('data_json.txt') as raw:
        print '[Info] Loading raw sleep data...'
        raw_sessions = json.load(raw)
        timestamp = (datetime.today() - timedelta(days=TIME_DELTA)).isoformat()
        chk_sessions = [s for s in raw_sessions if s['start'] > timestamp]
        
        if len(chk_sessions) > 0:
            print '[Info] Found {0} sleep sessions to check...'.format(len(chk_sessions))

            client = KeenClient(
                project_id = KEEN_PROJECT_ID,
                write_key = KEEN_WRITE_KEY,
                read_key = KEEN_READ_KEY
                )
            old_sessions = client.extraction('sessions', timeframe=TIME_FRAME)
            new_sessions = [s for s in chk_sessions if 'tyin' + s['start'] not in [s2['id'] for s2 in old_sessions]]

            if len(new_sessions) > 0:
                print '[Info] Found {0} sleep sessions to add...'.format(len(new_sessions))
                sessions = []
                events = []
                sessions, events = transform(new_sessions, 'tyin')

                client.add_events({'sessions': sessions, 'events': events})
                print '[Info] Added {0} sleep sessions.'.format(len(new_sessions))

    print '[Info] Done.'
开发者ID:tonyin,项目名称:sleep-track,代码行数:33,代码来源:daily_load_sleep.py

示例4: send_events

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
 def send_events(self, events):
     keen_project = keen_settings['private']['project_id']
     write_key = keen_settings['private']['write_key']
     if keen_project and write_key:
         client = KeenClient(
             project_id=keen_project,
             write_key=write_key,
         )
         logger.info('Adding {} events to the {} collection'.format(len(events), self.collection_name))
         client.add_events({self.collection_name: events})
     else:
         logger.info('Keen not enabled - would otherwise be adding the following {} events to the {} collection'.format(len(events), self.collection_name))
         print(events)
开发者ID:icereval,项目名称:osf.io,代码行数:15,代码来源:base.py

示例5: send_events

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
    def send_events(self, events):
        keen_project = keen_settings["private"]["project_id"]
        write_key = keen_settings["private"]["write_key"]
        if keen_project and write_key:
            client = KeenClient(project_id=keen_project, write_key=write_key)
            logger.info("Adding {} events to the {} collection".format(len(events), self.collection_name))

            for chunk in self.yield_chunked_events(events):
                client.add_events({self.collection_name: chunk})
                time.sleep(1)

        else:
            logger.info(
                "Keen not enabled - would otherwise be adding the following {} events to the {} collection".format(
                    len(events), self.collection_name
                )
            )
            print(events)
开发者ID:cslzchen,项目名称:osf.io,代码行数:20,代码来源:base.py

示例6: test_direct_persistence_strategy

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
 def test_direct_persistence_strategy(self):
     project_id = "5004ded1163d66114f000000"
     api_key = "2e79c6ec1d0145be8891bf668599c79a"
     write_key = scoped_keys.encrypt(api_key, {"allowed_operations": ["write"]})
     read_key = scoped_keys.encrypt(api_key, {"allowed_operations": ["read"]})
     client = KeenClient(project_id, write_key=write_key, read_key=read_key)
     client.add_event("python_test", {"hello": "goodbye"})
     client.add_event("python_test", {"hello": "goodbye"})
     client.add_events(
         {
             "sign_ups": [{
                 "username": "timmy",
                 "referred_by": "steve",
                 "son_of": "my_mom"
             }],
             "purchases": [
                 {"price": 5},
                 {"price": 6},
                 {"price": 7}
             ]}
     )
开发者ID:ChrisNolan1992,项目名称:KeenClient-Python,代码行数:23,代码来源:client_tests.py

示例7: is_exist_girl

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import add_events [as 别名]
        self.keen.add_events({
            collection : data_array})
        return True

    def is_exist_girl(self, collection, name, timestamp, **kwargs):
        return self.keen.count(collection, filters=[{"property_name" : "keen.timestamp", "operator" : 'eq', "property_value" : timestamp}, {"property_name" : "캐릭터", "operator" : 'eq', "property_value" : name}]) != 0

    def test_function(self, **kwargs):
        self.keen.add_events({
            "test_cases" : [
                {"user_name" : "nameuser4",
                    "keen" : {
                        "timestamp" : "2015-09-14T02:09:10.141Z"
                        },
                    "count" : 7
                    },
                {"user_name" : "nameuser5",
                    "keen" : {
                        "timestamp" : "2015-09-14T02:09:10.141Z"
                        },

                    "count" : 4}]
                })
        return self.keen.count("test_cases", timeframe="this_14_days")

if __name__ == '__main__':
    keen_client.add_events({
        'test_cases' : [
            {"user_name" : u"시부야 린",
                "count" : 4}]})
开发者ID:widian,项目名称:deremasu-ranking,代码行数:32,代码来源:keen_support.py


注:本文中的keen.client.KeenClient.add_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。