Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Recommendation Engine
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
URBANITE
Open
Recommendation Engine
Commits
667fda50
Commit
667fda50
authored
2 years ago
by
Campos Cordobes, Sergio
Browse files
Options
Downloads
Patches
Plain Diff
Update src/load_data.py
Deleted src/load_data - copia.py
parent
7db6fa8f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/load_data - copia.py
+0
-123
0 additions, 123 deletions
src/load_data - copia.py
src/load_data.py
+2
-0
2 additions, 0 deletions
src/load_data.py
with
2 additions
and
123 deletions
src/load_data - copia.py
deleted
100644 → 0
+
0
−
123
View file @
7db6fa8f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on: 16/01/2023
@author: Andoni Aranguren Ubierna
"""
import
os
import
sys
import
numpy
as
np
import
pandas
as
pd
import
requests
from
mysql
import
connector
from
utm.conversion
import
to_latlon
as
utm_to_latlon
import
sys
print
(
sys
.
path
)
from
src
import
constants
def
to_latlon
(
df
,
x_str
,
y_str
):
x
,
y
=
[],
[]
for
index
,
row
in
df
.
iterrows
():
coords_portal
=
utm_to_latlon
(
row
[
x_str
],
row
[
y_str
],
zone_number
=
30
,
zone_letter
=
"
T
"
)
x
+=
[
coords_portal
[
0
]]
y
+=
[
coords_portal
[
1
]]
df
[
"
lon
"
]
=
np
.
round
(
x
,
8
)
df
[
"
lat
"
]
=
np
.
round
(
y
,
8
)
return
df
def
generate_POIs
(
cnx
):
cursor
=
cnx
.
cursor
(
buffered
=
True
)
path
=
constants
.
PATH_POIS
file
=
path
+
"
/POIS_LugaresTuristicos_Bilbao.csv
"
if
os
.
path
.
isfile
(
file
):
df
=
pd
.
read_csv
(
file
,
encoding
=
"
utf-8
"
,
sep
=
"
;
"
,
decimal
=
"
.
"
,
encoding_errors
=
'
replace
'
)
df
=
to_latlon
(
df
,
"
COORDENADA_UTM_X
"
,
"
COORDENADA_UTM_Y
"
)
df
.
drop_duplicates
(
subset
=
[
"
lon
"
,
"
lat
"
,
"
NOMBRE_LUGAR_CAS
"
],
inplace
=
True
)
valores_preferencias
=
set
([
i
for
x
in
df
[
"
TAGS
"
].
unique
().
tolist
()
for
i
in
x
.
split
(
"
,
"
)])
df_sql
=
df
[[
"
ID
"
,
"
lon
"
,
"
lat
"
,
"
NOMBRE_LUGAR_CAS
"
]]
cursor
.
executemany
(
constants
.
sql_insert_poi
,
df_sql
.
values
.
tolist
())
cnx
.
commit
()
for
tag
in
valores_preferencias
:
cursor
.
execute
(
constants
.
sql_insert_tag
,
[
tag
])
cnx
.
commit
()
names_dict
=
{}
for
tag
in
valores_preferencias
:
names_dict
[
tag
]
=
""
cursor
.
execute
(
constants
.
sql_get_tag_ids
.
format
(
names
=
"'
,
'"
.
join
(
names_dict
.
keys
())),
)
cnx
.
commit
()
ret
=
cursor
.
fetchall
()
for
row
in
ret
:
names_dict
[
row
[
0
]]
=
row
[
1
]
for
index
,
row
in
df
.
iterrows
():
for
tag
in
row
[
"
TAGS
"
].
split
(
"
,
"
):
cursor
.
execute
(
constants
.
sql_insert_poi_tag
.
format
(
tag
=
names_dict
[
tag
]),
row
[[
"
lon
"
,
"
lat
"
,
"
NOMBRE_LUGAR_CAS
"
]].
values
.
tolist
())
cnx
.
commit
()
def
generate_routes
(
cnx
):
cursor
=
cnx
.
cursor
(
buffered
=
True
)
a
,
b
=
'
áéíóúüÁÉÍÓÚÜ
'
,
'
%%%%%%%%%%%%
'
trans
=
str
.
maketrans
(
a
,
b
)
path
=
constants
.
PATH_ROUTES
for
filename
in
os
.
listdir
(
path
):
f
=
os
.
path
.
join
(
path
,
filename
)
if
os
.
path
.
isfile
(
f
):
df
=
pd
.
read_csv
(
f
,
sep
=
"
\t
"
)
json_itinerary
=
None
for
index
,
row
in
df
.
iterrows
():
names
=
row
[
"
poi_names
"
].
replace
(
"
;
"
,
"'
,
'"
)
dict_id
=
{}
for
name
in
row
[
"
poi_names
"
].
split
(
"
;
"
):
cursor
.
execute
(
constants
.
sql_get_chosen_poi_ids
,[
name
.
translate
(
trans
)])
cnx
.
commit
()
ret
=
cursor
.
fetchall
()
try
:
dict_id
[
ret
[
0
][
0
]]
=
str
(
ret
[
0
][
1
])
except
:
pass
poi_id
=
"
,
"
.
join
(
list
(
dict_id
.
values
()))
url_route
=
'
http://localhost:5000/planner/route?
'
parameters
=
"
&
"
.
join
([
"
fromPlace=
"
+
row
[
"
from_place
"
],
"
toPlace=
"
+
row
[
"
to_place
"
],
"
timeSlot=
"
+
str
(
int
(
row
[
"
time_slot
"
])),
"
sports=
"
+
str
(
row
[
"
sports
"
]),
"
culture=
"
+
str
(
row
[
"
culture
"
]),
"
sightseeing=
"
+
str
(
row
[
"
sightseeing
"
]),
"
gastronomy=
"
+
str
(
row
[
"
gastronomy
"
])])
if
poi_id
!=
''
:
parameters
+=
"
&intermediateNodesIds=
"
+
poi_id
if
json_itinerary
is
None
:
json_itinerary
=
requests
.
get
(
url_route
+
parameters
).
json
()
else
:
time_slot
=
str
(
int
(
row
[
"
time_slot
"
]))
json_itinerary
[
"
routes
"
][
time_slot
]
=
requests
.
get
(
url_route
+
parameters
).
json
()[
"
routes
"
][
time_slot
]
url_save_it
=
'
http://localhost:5000/database/save/itinerary
'
requests
.
post
(
url_save_it
,
json
=
json_itinerary
)
def
main
(
ddbb_config
:
dict
):
cnx
=
connector
.
connect
(
**
ddbb_config
)
generate_POIs
(
cnx
)
generate_routes
(
cnx
)
cnx
.
close
()
if
__name__
==
'
__main__
'
:
ddbb_config
=
constants
.
DDBB_CONFIG
main
(
ddbb_config
)
This diff is collapsed.
Click to expand it.
src/load_data.py
+
2
−
0
View file @
667fda50
...
...
@@ -3,6 +3,8 @@
"""
Created on: 16/01/2023
@author: Andoni Aranguren Ubierna
-- Adaptations: 02/2023 @author: Sergio Campos
"""
import
os
...
...
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