"dynamic_fields": None,
  "query_timezone": "America/Los_Angeles",
  "has_table_calculations": False,
  "model": "i__looker"
}

if args.resume:
    with open(args.filename) as json_schedules:
        data = json.load(json_schedules)
        print("Resumed from " + args.filename)
        for schedule in data:
            # resume all schedules, or a specific schedule if a id is passed as a command-line argument
            if (args.resume != -1 and int(schedule['scheduled_plan.id']) == int(args.resume)) or args.resume == -1:
                looker.update_schedule(schedule['scheduled_plan.id'], body={"crontab":schedule['scheduled_plan.cron_schedule']})
elif args.pause:
    scheduler_data = looker.run_inline_query(body=query_body)
    for schedule in scheduler_data:
        # Don't overwrite already-paused schedules
        if schedule['scheduled_plan.cron_schedule'] == "0 5 31 2 *":
          paused_id = schedule['scheduled_plan.id']

          try:
            with open(args.filename) as json_schedules:
                paused_data = json.load(json_schedules)
                for paused_schedule in paused_data:
                  # If a schedule has already been paused, preserve the existing paused value
                  if int(paused_id) == paused_schedule['scheduled_plan.id']:
                    schedule['scheduled_plan.cron_schedule'] = paused_schedule['scheduled_plan.cron_schedule']
          except:
            pass
def index():
    looker = LookerApi(client_id, client_secret, api_endpoint)

    markets = request.form.getlist('market')
    channels = request.form.getlist('channel')
    subtypes = request.form.getlist('subtype')
    start_date = request.form.getlist('start_date')
    end_date = request.form.getlist('end_date')

    r = looker.get_look_query(500)
    i = looker.get_look_query(532)

    r = r['query']
    i = i['query']

    # Format the date query the way Looker expects it
    if start_date[0] != '' and end_date[0] != '':
        date_query = dt.datetime.strptime(start_date[0], '%Y-%m-%d').strftime('%Y/%m/%d') + ' to '\
                     + dt.datetime.strptime(end_date[0], '%Y-%m-%d').strftime('%Y/%m/%d')
    else:
        date_query = r['filters']['visit_dimensions.local_visit_date']

    print(date_query)

    # Get only necessary fields to run an inline query
    t = {
        k: r[k]
        for k in ('model', 'view', 'fields', 'limit', 'dynamic_fields',
                  'filters')
    }
    m = {
        n: i[n]
        for n in ('model', 'view', 'fields', 'limit', 'dynamic_fields',
                  'filters')
    }
    # Replace existing filters with new filters
    t['filters']['market_dimensions.market_name'] = ','.join(markets)
    t['filters']['channel_dimensions.organization'] = ','.join(channels)
    t['filters']['channel_dimensions.sub_type'] = ','.join(subtypes)
    t['filters']['visit_dimensions.local_visit_date'] = date_query
    r2 = looker.run_inline_query(t)

    m['filters']['market_dimensions.market_name'] = ','.join(markets)
    m['filters']['channel_dimensions.organization'] = ','.join(channels)
    m['filters']['channel_dimensions.sub_type'] = ','.join(subtypes)
    m['filters']['visit_dimensions.local_visit_date'] = date_query
    m2 = looker.run_inline_query(m)

    #code.interact(local=dict(globals(), **locals()))

    r2 = r2[0]

    try:
        on_route_time = int(round(r2['avg_on_route_time'], 0))
        on_scene_time = int(round(r2['avg_on_scene_time'], 0))
        bb_rate = int(round(r2['bb_rate'] * 100, 0))
        ed_escalation = int(round(r2['ed_escalation_rate'] * 100, 0))
        nps = int(round(r2['nps'], 0))
        num_requests = "{:,}".format(r2['visit_facts.visits'])
        cost_svg = "{:,}".format(int(round(r2['cost_savings'], 0)))
        avg_age = int(round(r2['patient_dimensions.average_age'], 0))
        pct_female = int(round(r2['pct_female'], 0))
        pct_male = int(round(r2['pct_male'], 0))
        pct_web = int(round(r2['pct_web'] * 100, 0))
        pct_mobile = int(round(r2['pct_mobile'] * 100, 0))
        pct_phone = int(round(r2['pct_phone'] * 100, 0))
    except Exception as e:
        on_route_time = 0
        on_scene_time = 0
        bb_rate = 0
        ed_escalation = 0
        nps = 0
        num_requests = "{:,}".format(r2['visit_facts.visits'])
        cost_svg = 0
        avg_age = 0
        pct_female = 0
        pct_male = 0
        pct_web = 0
        pct_mobile = 0
        pct_phone = 0

    icds = m2[0:5]
    icd_codes = [i['icd_code_dimensions.diagnosis_group'] for i in icds]
    icd_pcts = [int(round(p['pct_of_total'] * 100, 0)) for p in icds]
    """Render the client overview report."""
    return render_template('client_overview_report.html', on_route_time=on_route_time,cost_svg=cost_svg,\
    on_scene_time=on_scene_time, bb_rate=bb_rate, ed_escalation=ed_escalation, nps=nps, num_requests=num_requests,\
    avg_age=avg_age, pct_female=pct_female, pct_male=pct_male, pct_web=pct_web, pct_mobile=pct_mobile,\
    pct_phone=pct_phone, icd_codes=icd_codes, icd_pcts=icd_pcts, markets=markets, channels=channels,\
    subtypes=subtypes, start_date=start_date, end_date=end_date)
for model in models:
	model_name = model['name']

	## -- Get single model --
	model_def = looker.get_model(model_name)
	# pp(model_def)

	## -- Get single explore --
	for explore_def in model_def['explores']:
		# print(model_name + " " + explore_def['name'])
		explore_name = model_name+','+explore_def['name']
		lis[explore_name]=0

body = {
  "model":"i__looker",
  "view":"history",
  "fields":["query.view","query.model","history.query_run_count"],
  "filters":{"history.most_recent_run_at_date":"90 days"},
  # "sorts":["products.count desc 0"],
  "limit":"500",
  "query_timezone":"America/Los_Angeles"
}

res = looker.run_inline_query(body)
for exp in res:
	explore_name =  exp['query.model']+','+exp['query.view']
	lis[explore_name]=exp['history.query_run_count']

for i in list(lis.keys()):
	write_fields(i, lis[i])
Esempio n. 4
0
        full_query = element['query']
    else:
        full_query = element['look']['query']
    # keep the query params we care about
    query = {param: full_query[param] for param in query_params}
    dashboard_element['query'] = query
    dashboard_element['filter_listeners'] = [
        filterable['listen']
        for filterable in element['result_maker']['filterables']
    ][0]
    dashboard_elements.append(dashboard_element)

# # add default_value to listener array
for element in dashboard_elements:
    for filter_listener in element['filter_listeners']:
        default_value = list(
            filter(
                lambda dashboard_filter: dashboard_filter[
                    'title'] == filter_listener['dashboard_filter_name'],
                dashboard_filters))[0]['default_value']
        filter_listener['default_value'] = default_value

    # apply dashboard filters to queries with default values
    if element['query']['filters'] is None:
        element['query']['filters'] = {}
    for filter_listener in element['filter_listeners']:
        field = filter_listener['field']
        value = filter_listener['default_value']
        element['query']['filters'][field] = value
    looker.run_inline_query(element['query'])