def draw_by_login_dimensions(): url = 'https://www.growingio.com/v2/projects/1P6j1bVP/charts/nRbXvYlo.json' headers = GrowingIO.get_headers() params = GrowingIO.get_params() response = requests.get(url, headers=headers, params=params) print('response is ' + response.text) chart = response.json()
def draw_by_leave(): url = 'https://www.growingio.com/v2/projects/1P6j1bVP/charts/j9yAxnm9.json' headers = GrowingIO.get_headers() params = GrowingIO.get_params() response = requests.get(url, headers=headers, params=params) print('response is ' + response.text) chart = response.json() draw(chart)
def run(self): response = GrowingIO.get_dashboard(self.project, self.dashboard) if response is None: raise RuntimeError('response is None') if 'charts' not in response.keys(): raise RuntimeError('not find charts') charts = response['charts'] for chart in charts: self.create_chart(chart) time.sleep(2)
def create_chart(self, chart: dict): if 'id' not in chart.keys(): raise RuntimeError('not found id') if 'name' not in chart.keys(): raise RuntimeError('not found name') chart_id = chart['id'] chart_name = chart['name'] # if chart_name != '广告监测': # return if chart_name not in self.chart_configs.keys(): return days = 7 interval = 86400000 config: dict = self.chart_configs[chart_name] if config is not None: if '(天)' in config.keys(): days = config['(天)'] if days == 1: interval = 3600000 if '(单位)' in config.keys(): if config['(单位)'] == '(天)': interval = 86400000 elif config['(单位)'] == '(小时)': interval = 3600000 response = GrowingIO.get_chart(self.project, chart_id, days, interval) # 这里判断是图表还是表格 if 'meta' not in response.keys(): raise RuntimeError('not found meta') if 'data' not in response.keys(): raise RuntimeError('not found data') metas: dict = response['meta'] datas: list = response['data'] if chart_id == 'nRbX0Lzo': GioOutputer_nRbX0Lzo.output(chart_name, metas, datas, self) elif chart_id == 'EoZLXeqR': GioOutputer_EoZLXeqR.output(chart_name, metas, datas, self) elif chart_id == 'lPQqm4vP': GioOutputer_lPQqm4vP.output(chart_name, metas, datas, self) elif chart_id == '39lYy4dR': GioOutputer_39lYy4dR.output(chart_name, metas, datas, self) elif chart_id == 'bR7NDvY9': GioOutputer_bR7NDvY9.output(chart_name, metas, datas, self) elif chart_id == '4PKzOGyR': GioOutputer_4PKzOGyR.output(chart_name, metas, datas, self) elif chart_id == 'lPQzDeno': GioOutputer_lPQzDeno.output(chart_name, metas, datas, self) elif chart_id == 'qPkNbYlR': GioOutputer_qPkNbYlR.output(chart_name, metas, datas, self) else: dimensions = [] metrics = [] for meta in metas: if 'name' not in meta.keys(): raise RuntimeError('not found meta') name = meta['name'] if 'dimension' in meta.keys(): dimensions.append(name) elif 'metric' in meta.keys(): metrics.append(name) else: raise RuntimeError('not found dimension or metric') # 如果维度=(目标用户+其他),则为单趋势图 # 如果维度=(目标用户+其他+其他)且有两个变量,则为双趋势图,两个变量分两个图表 # 如果维度=(目标用户+其他+其他...),则为表格 if len(dimensions) < 2: raise RuntimeError('dimensions count error') if len(metrics) < 1: raise RuntimeError('metrics count error') if len(dimensions) == 2: if dimensions[0] == '目标用户': # pass self.single_chart(chart_name, datas, dimensions, metrics) else: pass # raise RuntimeError('dimensions error') elif len(dimensions) == 3 and len(metrics) == 2: if dimensions[0] == '目标用户': # pass self.double_chart(chart_name, datas, dimensions, metrics) else: self.table(chart_name, datas, dimensions, metrics) else: self.table(chart_name, datas, dimensions, metrics)