goodmap 0.4.3__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: goodmap
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Map engine to serve all the people :)
5
5
  Author: Krzysztof Kolodzinski
6
6
  Author-email: krzysztof.kolodzinski@problematy.pl
@@ -0,0 +1,46 @@
1
+ from typing import Any, Dict, List
2
+
3
+ # TODO move filtering to db site
4
+
5
+
6
+ def does_fulfill_requirement(entry, requirements):
7
+ matches = []
8
+ for category, values in requirements:
9
+ if not values:
10
+ continue
11
+ matches.append(all(entry_value in entry[category] for entry_value in values))
12
+ return all(matches)
13
+
14
+
15
+ def sort_by_distance(data: List[Dict[str, Any]], query_params: Dict[str, List[str]]):
16
+ try:
17
+ if "lat" in query_params and "lon" in query_params:
18
+ lat = float(query_params["lat"][0])
19
+ lon = float(query_params["lon"][0])
20
+ data.sort(key=lambda x: (x["position"][0] - lat) ** 2 + (x["position"][1] - lon) ** 2)
21
+ return data
22
+ return data
23
+ except (ValueError, KeyError, IndexError):
24
+ return data
25
+
26
+
27
+ def limit(data, query_params):
28
+ try:
29
+ if "limit" in query_params:
30
+ limit = int(query_params["limit"][0])
31
+ data = data[:limit]
32
+ return data
33
+ return data
34
+ except (ValueError, KeyError, IndexError):
35
+ return data
36
+
37
+
38
+ def get_queried_data(all_data, categories, query_params):
39
+ requirements = []
40
+ for key in categories.keys():
41
+ requirements.append((key, query_params.get(key)))
42
+
43
+ filtered_data = [x for x in all_data if does_fulfill_requirement(x, requirements)]
44
+ final_data = sort_by_distance(filtered_data, query_params)
45
+ final_data = limit(final_data, query_params)
46
+ return final_data
@@ -116,6 +116,7 @@ window.PRIMARY_COLOR = "{{ primary_color }}";
116
116
  window.SHOW_SUGGEST_NEW_POINT_BUTTON = {{ feature_flags.SHOW_SUGGEST_NEW_POINT_BUTTON | default(false) | tojson }};
117
117
  window.SHOW_SEARCH_BAR = {{ feature_flags.SHOW_SEARCH_BAR | default(false) | tojson }};
118
118
  window.USE_LAZY_LOADING = {{ feature_flags.USE_LAZY_LOADING | default(false) | tojson }};
119
+ window.SHOW_ACCESSIBILITY_TABLE = {{ feature_flags.SHOW_ACCESSIBILITY_TABLE | default(false) | tojson }};
119
120
  </script>
120
121
  <script src="/static/map.js"></script>
121
122
  {% endblock %}
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "goodmap"
3
- version = "0.4.3"
3
+ version = "0.4.4"
4
4
  description = "Map engine to serve all the people :)"
5
5
  authors = ["Krzysztof Kolodzinski <krzysztof.kolodzinski@problematy.pl>"]
6
6
  readme = "README.md"
@@ -1,19 +0,0 @@
1
- # TODO move filtering to db site
2
-
3
-
4
- def does_fulfill_requirement(entry, requirements):
5
- matches = []
6
- for category, values in requirements:
7
- if not values:
8
- continue
9
- matches.append(all(entry_value in entry[category] for entry_value in values))
10
- return all(matches)
11
-
12
-
13
- def get_queried_data(all_data, categories, query_params):
14
- requirements = []
15
- for key in categories.keys():
16
- requirements.append((key, query_params.get(key)))
17
-
18
- filtered_data = [x for x in all_data if does_fulfill_requirement(x, requirements)]
19
- return filtered_data
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes