Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
694cd1c8
Commit
694cd1c8
authored
2 years ago
by
Thorge Petersen
Committed by
Jesper Zedlitz
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor get_spatial_for_selection() to ensure unique values and prioritize municipality keys
parent
007c1ae8
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!48
Merge dev into master
,
!42
Refactor get_spatial_for_selection() to ensure unique values and prioritize municipality keys
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/helpers_tpsh.py
+28
-7
28 additions, 7 deletions
ckanext/odsh/helpers_tpsh.py
with
28 additions
and
7 deletions
ckanext/odsh/helpers_tpsh.py
+
28
−
7
View file @
694cd1c8
...
@@ -134,13 +134,34 @@ def get_spatial_for_selection():
...
@@ -134,13 +134,34 @@ def get_spatial_for_selection():
file_path
=
config
.
get
(
'
ckanext.odsh.spatial.mapping
'
,
extension_path
+
'
/resources/schleswig-holstein_geojson.csv
'
)
file_path
=
config
.
get
(
'
ckanext.odsh.spatial.mapping
'
,
extension_path
+
'
/resources/schleswig-holstein_geojson.csv
'
)
with
open
(
file_path
,
newline
=
''
)
as
mapping_file
:
with
open
(
file_path
,
newline
=
''
)
as
mapping_file
:
cr
=
csv
.
reader
(
mapping_file
,
delimiter
=
"
\t
"
)
cr
=
csv
.
reader
(
mapping_file
,
delimiter
=
"
\t
"
)
spatial_mapping
=
list
()
spatial_mapping
=
list
(
cr
)
for
row
in
cr
:
key
=
row
[
0
]
unique_mapping
=
[]
value
=
row
[
1
]
seen_values
=
set
()
spatial_mapping
.
append
({
'
key
'
:
key
,
'
value
'
:
value
})
for
key
,
value
,
_
in
spatial_mapping
:
spatial_mapping
.
append
({
'
key
'
:
''
,
'
value
'
:
''
})
if
value
in
seen_values
:
return
spatial_mapping
continue
# Skip if the value has already been seen
if
"
municipalityKey
"
in
key
:
unique_mapping
.
append
({
'
key
'
:
key
,
'
value
'
:
value
})
else
:
# Check if there is a municipality key entry for the value
municipality_entry
=
next
(
(
entry
for
entry
in
spatial_mapping
if
entry
[
1
]
==
value
and
"
municipalityKey
"
in
entry
[
0
]),
None
)
if
municipality_entry
:
# If a municipality key entry exists, use it instead of the current key
unique_mapping
.
append
({
'
key
'
:
municipality_entry
[
0
],
'
value
'
:
value
})
else
:
# Otherwise, use the current key
unique_mapping
.
append
({
'
key
'
:
key
,
'
value
'
:
value
})
seen_values
.
add
(
value
)
unique_mapping
.
append
({
'
key
'
:
''
,
'
value
'
:
''
})
return
unique_mapping
def
get_subject_for_selection
():
def
get_subject_for_selection
():
SUBJECT_MAPPING
=
load_subject_mapping
()
SUBJECT_MAPPING
=
load_subject_mapping
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment