multi_line.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. import json
  18. from superset import db
  19. from superset.models.slice import Slice
  20. from .birth_names import load_birth_names
  21. from .helpers import merge_slice, misc_dash_slices
  22. from .world_bank import load_world_bank_health_n_pop
  23. def load_multi_line(only_metadata=False):
  24. load_world_bank_health_n_pop(only_metadata)
  25. load_birth_names(only_metadata)
  26. ids = [
  27. row.id
  28. for row in db.session.query(Slice).filter(
  29. Slice.slice_name.in_(["Growth Rate", "Trends"])
  30. )
  31. ]
  32. slc = Slice(
  33. datasource_type="table", # not true, but needed
  34. datasource_id=1, # cannot be empty
  35. slice_name="Multi Line",
  36. viz_type="line_multi",
  37. params=json.dumps(
  38. {
  39. "slice_name": "Multi Line",
  40. "viz_type": "line_multi",
  41. "line_charts": [ids[0]],
  42. "line_charts_2": [ids[1]],
  43. "since": "1970",
  44. "until": "1995",
  45. "prefix_metric_with_slice_name": True,
  46. "show_legend": False,
  47. "x_axis_format": "%Y",
  48. }
  49. ),
  50. )
  51. misc_dash_slices.add(slc.slice_name)
  52. merge_slice(slc)