公司网站建设说明书,济南百度竞价开户,自己怎么创建网站,做机械设备销售的那个网站好有没有人发觉Superset时间过滤组件非常高级#xff0c;#x1f61f;但又有点复杂#xff0c;没有选择时间区间的快捷方式。 Superset的时间过滤控件可以通过在代码中进行二次开发来进行定制。以下是一些可能有用的提示#xff1a; 查找源代码#xff1a;可以在Superset的源… 有没有人发觉Superset时间过滤组件非常高级但又有点复杂没有选择时间区间的快捷方式。 Superset的时间过滤控件可以通过在代码中进行二次开发来进行定制。以下是一些可能有用的提示 查找源代码可以在Superset的源代码中找到时间过滤器的相关代码在superset/assets/src/explore/components/controls目录下搜索时间控件的名称比如DateFilterControl.jsx。 深入理解时间控件了解时间控件是如何工作的非常重要可以通过阅读Superset的源代码和官方文档来学习。 编写自定义时间控件可以使用React等工具编写自定义时间控件然后将其与Superset集成。可以在前端开发人员手册中找到相关的信息。 集成自定义时间控件集成自定义时间控件的过程取决于它的实现方式和您的Superset部署环境。可以参考官方文档中的信息来集成您的自定义时间控件。 测试一旦自定义时间控件被集成需要对其进行测试以确保它正常工作。这包括测试常见的时间过滤器用例以及测试它在不同的浏览器和设备上是否正常显示。
过滤参数入参time_range 图表有两种接口
/superset/explore_json/?form_data
目录\superset-2.0\superset\views\core.py
apihas_access_apihandle_api_exceptionevent_logger.log_thisexpose(/explore_json/datasource_type/int:datasource_id/,methodsEXPLORE_JSON_METHODS,)expose(/explore_json/, methodsEXPLORE_JSON_METHODS)etag_cache()check_resource_permissions(check_datasource_perms)def explore_json(self, datasource_type: Optional[str] None, datasource_id: Optional[int] None) - FlaskResponse:Serves all request that GET or POST form_dataThis endpoint evolved to be the entry point of many differentrequests that GETs or POSTs a form_data.self.generate_json receives this input and returns differentpayloads based on the request args in the first blockTODO: break into one endpoint for each return shaperesponse_type ChartDataResultFormat.JSON.valueresponses: List[Union[ChartDataResultFormat, ChartDataResultType]] list(ChartDataResultFormat)responses.extend(list(ChartDataResultType))for response_option in responses:if request.args.get(response_option) true:response_type response_optionbreak# Verify user has permission to export CSV fileif (response_type ChartDataResultFormat.CSVand not security_manager.can_access(can_csv, Superset)):return json_error_response(_(You dont have the rights to ) _(download as csv),status403,)form_data get_form_data()[0]try:datasource_id, datasource_type get_datasource_info(datasource_id, datasource_type, form_data)force request.args.get(force) true# TODO: support CSV, SQL query and other non-JSON typesif (is_feature_enabled(GLOBAL_ASYNC_QUERIES)and response_type ChartDataResultFormat.JSON):# First, look for the chart query results in the cache.try:viz_obj get_viz(datasource_typecast(str, datasource_type),datasource_iddatasource_id,form_dataform_data,force_cachedTrue,forceforce,)payload viz_obj.get_payload()# If the chart query has already been cached, return it immediately.if payload is not None:return self.send_data_payload_response(viz_obj, payload)except CacheLoadError:pass# Otherwise, kick off a background job to run the chart query.# Clients will either poll or be notified of query completion,# at which point they will call the /explore_json/data/cache_key# endpoint to retrieve the results.try:async_channel_id async_query_manager.parse_jwt_from_request(request)[channel]job_metadata async_query_manager.init_job(async_channel_id, g.user.get_id())load_explore_json_into_cache.delay(job_metadata, form_data, response_type, force)except AsyncQueryTokenException:return json_error_response(Not authorized, 401)return json_success(json.dumps(job_metadata), status202)viz_obj get_viz(datasource_typecast(str, datasource_type),datasource_iddatasource_id,form_dataform_data,forceforce,)return self.generate_json(viz_obj, response_type)except SupersetException as ex:return json_error_response(utils.error_msg_from_exception(ex), 400) /api/v1/chart/data?form_data
目录\superset\charts\data\api.py
该接口还比较难找哈
class ChartDataRestApi(ChartRestApi):include_route_methods {get_data, data, data_from_cache}expose(/int:pk/data/, methods[GET])protect()statsd_metricsevent_logger.log_this_with_context(actionlambda self, *args, **kwargs: f{self.__class__.__name__}.data,log_to_statsdFalse,)def get_data(self, pk: int) - Response:chart self.datamodel.get(pk, self._base_filters)if not chart:return self.response_404()try:json_body json.loads(chart.query_context)except (TypeError, json.decoder.JSONDecodeError):json_body Noneif json_body is None:return self.response_400(message_(Chart has no query context saved. Please save the chart again.))# override saved query contextjson_body[result_format] request.args.get(format, ChartDataResultFormat.JSON)json_body[result_type] request.args.get(type, ChartDataResultType.FULL)
。。。。。
。。。。。
。。。。。# TODO: support CSV, SQL query and other non-JSON typesif (is_feature_enabled(GLOBAL_ASYNC_QUERIES)and query_context.result_format ChartDataResultFormat.JSONand query_context.result_type ChartDataResultType.FULL):return self._run_async(json_body, command)try:form_data json.loads(chart.params)except (TypeError, json.decoder.JSONDecodeError):form_data {}return self._get_data_response(commandcommand, form_dataform_data, datasourcequery_context.datasource) 时间过滤控件
计算时间范围
venv38\Lib\site-packages\marshmallow\schema.py 再往下计算日期地方
data processor(data, manymany, **kwargs) 再往下在superset\common\query_object_factory.py可以看到from_dttm和to_dttm processed_extras self._process_extras(extras)result_type kwargs.setdefault(result_type, parent_result_type)row_limit self._process_row_limit(row_limit, result_type)from_dttm, to_dttm self._get_dttms(time_range, time_shift, processed_extras)kwargs[from_dttm] from_dttmkwargs[to_dttm] to_dttmreturn QueryObject(datasourcedatasource_model_instance,extrasextras,row_limitrow_limit,time_rangetime_range,time_shifttime_shift,**kwargs,) 进行定制或二次开发
如果需要对Superset中的时间过滤控件进行定制或二次开发可以按照以下步骤进行 复制时间过滤控件的源代码
Superset中的时间过滤控件源代码位于superset/assets/src/explore/components/controls/DateFilterControl.jsx可以将该文件复制到本地进行修改。 修改时间过滤控件的样式或行为
可以根据需要修改时间过滤控件的样式或行为比如修改日期格式、修改默认时间段等。修改完成后可以运行npm run build命令进行编译。 将修改后的时间过滤控件发布到Superset中
将修改后的时间过滤控件发布到Superset中有两种方法
将修改后的代码替换掉原来的文件然后重新启动Superset将修改后的代码打包成一个插件然后通过Superset的插件机制进行安装和使用。
至此定制化或二次开发Superset的时间过滤控件就完成了。