jobs.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import logging
  2. from taipy.gui import Gui, navigate
  3. import taipy.gui.builder as tgb
  4. import pandas as pd
  5. logging.basicConfig(level=logging.INFO)
  6. df = pd.read_csv("data/aggregate/aggregate.csv")
  7. filtered_df = df
  8. selected_locations = list(df["location"].unique())
  9. selected_queries = [
  10. "python developer",
  11. "data analyst",
  12. "machine learning engineer",
  13. "software engineer",
  14. "backend developer",
  15. "devops engineer",
  16. "automation engineer",
  17. "network engineer",
  18. "vuejs developer",
  19. "react developer",
  20. "nodejs developer",
  21. "frontend developer",
  22. "full stack developer",
  23. "ui developer",
  24. "web application developer",
  25. "javascript engineer",
  26. "mobile app developer",
  27. "other",
  28. ]
  29. selected_sources = ["indeed", "yc"]
  30. links = {}
  31. chunk_index = 0
  32. def get_chunks(df, chunk_size=20):
  33. n_chunks = len(df) // chunk_size + 1
  34. for i in range(n_chunks):
  35. yield df.iloc[i * chunk_size : (i + 1) * chunk_size]
  36. chunks = list(get_chunks(filtered_df))
  37. def filter_data(state):
  38. print(state.selected_locations, state.selected_sources, state.selected_queries)
  39. state.filtered_df = state.filtered_df[
  40. state.filtered_df["location"].isin([state.selected_locations])
  41. & state.filtered_df["source"].isin([state.selected_sources])
  42. & state.filtered_df["query"].isin([state.selected_queries])
  43. ]
  44. state.chunk_index=0
  45. if state.filtered_df.empty:
  46. logging.warning("No filtered rows available")
  47. simulate_adding_more_links(state)
  48. def navigate_to_link(state, link_url, payload=None):
  49. navigate(state, to=link_url, force=True)
  50. # todo : On interacting with selector, it refreshes chunk without actually filtering, fix this
  51. def simulate_adding_more_links(state):
  52. state.selected_sources = 'indeed'
  53. state.selected_queries = 'python developer'
  54. state.selected_locations = 'remote'
  55. state.chunks = list(get_chunks(state.filtered_df))
  56. if state.chunk_index < len(state.chunks):
  57. chunk = state.chunks[state.chunk_index]
  58. if not chunk.empty:
  59. logging.info(f"processing chunk {state.chunk_index}")
  60. logging.info(chunk.index[0])
  61. chunk.reset_index(drop=True, inplace=True)
  62. state.links = {"link_" + str(i): row for i, row in chunk.iterrows()}
  63. state.chunk_index += 1
  64. with tgb.Page() as link_part:
  65. tgb.text('Find Jobs', class_name='h2')
  66. tgb.html('br')
  67. with tgb.layout("4 1 1"):
  68. tgb.selector(
  69. value="{selected_queries}",
  70. lov=selected_queries,
  71. on_change=filter_data,
  72. dropdown=True,
  73. multiple=False,
  74. class_name="fullwidth",
  75. )
  76. tgb.selector(
  77. value="{selected_locations}",
  78. lov=selected_locations,
  79. on_change=filter_data,
  80. dropdown=True,
  81. multiple=False,
  82. class_name="fullwidth",
  83. )
  84. tgb.selector(
  85. value="{selected_sources}",
  86. lov=selected_sources,
  87. on_change=filter_data,
  88. dropdown=True,
  89. multiple=False,
  90. class_name="fullwidth",
  91. )
  92. with tgb.layout("1 1 1 1"):
  93. for i in range(20):
  94. with tgb.part("card"):
  95. tgb.text("{links['link_" + str(i) + "']['title']}", class_name="h3")
  96. tgb.html("br")
  97. with tgb.layout("1 1"):
  98. tgb.text(
  99. "{links['link_" + str(i) + "']['company']}", class_name="h5"
  100. )
  101. tgb.text(
  102. "{links['link_" + str(i) + "']['location']}", class_name="h5"
  103. )
  104. tgb.button(
  105. "Apply",
  106. on_action=navigate_to_link,
  107. id="{links['link_" + str(i) + "']['link']}",
  108. class_name="plain",
  109. )
  110. tgb.button("See more jobs", on_action=simulate_adding_more_links)
  111. def on_init(state):
  112. simulate_adding_more_links(state)
  113. # * do not use the following line if running the multi page app, it is only for debugging
  114. Gui(link_part).run(debug=True, use_reloader=True)