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


Python KeenClient.extraction方法代码示例

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


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

示例1: main

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import extraction [as 别名]
def main():
    print "[INFO] Getting raw spire data..."
    date = (datetime.today() - timedelta(days=DAYS_AGO)).strftime("%Y-%m-%d")

    # Breath
    breath_client = KeenClient(
        project_id=keen["breath"]["project_id"],
        read_key=keen["breath"]["read_key"],
        write_key=keen["breath"]["write_key"],
    )

    if len(breath_client.extraction("sessions", timeframe="this_" + str(DAYS_AGO) + "_days")) > 0:
        print "[INFO] Already uploaded breath data for " + date + "."
    else:
        breaths = get_spire(spire["breath"], date)

        if len(breaths["data"]) > 0:
            print "[INFO] Uploading breath data..."

            keen_breaths = {}
            keen_breaths["breaths"] = [{"timestamp": b["timestamp"], "value": b["value"]} for b in breaths["data"]]
            keen_breaths["metadata"] = breaths["metadata"]

            keen_breaths["metadata"]["min"] = min([b["value"] for b in breaths["data"]])
            keen_breaths["metadata"]["max"] = max([b["value"] for b in breaths["data"]])
            keen_breaths["id"] = USER + date
            breath_client.add_event("sessions", keen_breaths)
            print "[INFO] Uploaded breath data for " + date + "."
        else:
            print "[INFO] No breath data found for " + date + "."

    # Steps
    steps_client = KeenClient(
        project_id=keen["steps"]["project_id"], read_key=keen["steps"]["read_key"], write_key=keen["steps"]["write_key"]
    )

    if len(steps_client.extraction("sessions", timeframe="this_" + str(DAYS_AGO) + "_days")) > 0:
        print "[INFO] Already uploaded steps data for " + date + "."
    else:
        steps = get_spire(spire["step"], date)

        if len(steps["data"]) > 0:
            print "[INFO] Uploading steps data..."

            keen_steps = {}
            keen_steps["steps"] = [{"timestamp": s["timestamp"], "value": s["value"]} for s in steps["data"]]
            keen_steps["metadata"] = steps["metadata"]
            keen_steps["id"] = USER + date
            steps_client.add_event("sessions", keen_steps)
            print "[INFO] Uploaded steps data for " + date + "."
        else:
            print "[INFO] No steps data found for " + date + "."
开发者ID:tonyin,项目名称:spire,代码行数:54,代码来源:daily_load.py

示例2: main

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import extraction [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

示例3: get_keen_sonar

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import extraction [as 别名]
def get_keen_sonar(collection, timeframe, filters = [], timezone="US/Pacific"):
    client = KeenClient(
        project_id=conf['keen_project_id'], read_key=conf['keen_read_key'])

    return client.extraction(
        collection, timeframe=timeframe, filters=filters, timezone=timezone)
开发者ID:MrMaksimize,项目名称:docker-airflow,代码行数:8,代码来源:sonar_jobs.py

示例4: __init__

# 需要导入模块: from keen.client import KeenClient [as 别名]
# 或者: from keen.client.KeenClient import extraction [as 别名]
class HireKeen:

    def __init__(self):
        self.keenWriter = KeenClient(
            project_id=config.KEEN_PROJECTID,
            write_key=config.KEEN_WRITEKEY,
            read_key=config.KEEN_READKEY
        )        

    def record_keen(self, index, event):
        self.keenWriter.add_event(index, event)

    def extract_keen(self, index, timeframe, filters):
        return self.keenWriter.extraction(index, timeframe, filters=filters)

    def pred_identify(self, user_id):
        self.identified = True
        self.predclient.identify(user_id)

    def pred_ranked(self, engine, data):
        return self.predclient.get_itemrank_ranked(engine, data)

    def pred_top_rec(self, engine, number):
        return self.predclient.get_itemrec_topn(engine, number)

    def pred_create(self, user, userType):
        self.predclient.create_user(user, {'userType': userType})

    def event_record_register(self, loggedin_id):
        user_details = self.db_user.find_one({'linkedin_id': loggedin_id})
        if user_details:
            event_data = {
                "action": "registration",
                "userId": user_details['linkedin_id'],
                "userCompanyId": user_details['linkedin_company_id']
            }
            recordEvent.delay('siteActions', event_data)

    def event_record_activate(self, loggedin_id):
        user_details = self.db_user.find_one({'linkedin_id': loggedin_id})
        if user_details:
            event_data = {
                "action": "activation",
                "userId": user_details['linkedin_id'],
                "userCompanyId": user_details['linkedin_company_id']
            }
            recordEvent.delay('siteActions', event_data)

    def event_record_create_project(self, project_slug, user_id):
        project_details = self.db_project.find_one({'slug': project_slug, 'loggedin_id': user_id})
        if project_details:
            try:
                user_details = self.db_user.find_one({'linkedin_id': project_details['loggedin_id']})
                company_details = self.db_linkedincompany.find_one({'id': user_details['linkedin_company_id']})
                event_data = {
                    "action": "project creation",
                    "userId": project_details['loggedin_id'],
                    "userCompanyId": user_details['linkedin_company_id'],
                    "slug": project_slug,
                    "skills": [],
                    "addlSkills": [],
                    "userCompany": company_details['name'],
                    "forCompanyId": project_details['companyId'],
                    "forCompanyName": project_details['company'],
                    "name": project_details['name']
                }
                for skill in project_details['skills']:
                    if skill['skill'] not in event_data['skills']:
                        event_data['skills'].append(skill['skill'])
                for addlskill in project_details['addlSkills']:
                    if addlskill not in event_data['addlSkills']:
                        event_data['addlSkills'].append(addlskill)
                recordEvent.delay('siteActions', event_data)
            except:
                rollbar.report_exc_info()

    def event_record_create_position(self, project_slug, position_slug, user_id):
        position_details = self.db_position.find_one({'project': project_slug, 'slug': position_slug, 'loggedin_id': user_id})
        if position_details:
            try:
                user_details = self.db_user.find_one({'linkedin_id': position_details['loggedin_id']})
                company_details = self.db_linkedincompany.find_one({'id': user_details['linkedin_company_id']})
                project_details = self.db_project.find_one({'slug': project_slug})
                event_data = {
                    "action": "position creation",
                    "userId": user_details['linkedin_id'],
                    "companyId": user_details['linkedin_company_id'],
                    "slug": position_details['slug'],
                    "projectslug": position_details['project'],
                    "skills": [],
                    "addlSkills": [],
                    "userCompany": company_details['name'],
                    "forCompanyId": project_details['companyId'],
                    "forCompanyName": project_details['company'],
                    "title": position_details['title'],
                    "projectName": project_details['name']
                }
                for skill in position_details['skills']:
                    if skill['skill'] not in event_data['skills']:
                        event_data['skills'].append(skill['skill'])
#.........这里部分代码省略.........
开发者ID:sreenathp20,项目名称:analytics,代码行数:103,代码来源:hire_keen.py


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