Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Temperaturverteilung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s39174
Temperaturverteilung
Commits
1ad33abf
Commit
1ad33abf
authored
3 years ago
by
Clemens Berteld
Browse files
Options
Downloads
Patches
Plain Diff
Weighted interpolation fully working now (lat and long were mixed up)
parent
f97e69ce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dataacquisition/ExportToDatabase.py
+1
-3
1 addition, 3 deletions
dataacquisition/ExportToDatabase.py
dataacquisition/GetAverageData.py
+1
-1
1 addition, 1 deletion
dataacquisition/GetAverageData.py
dataacquisition/sandbox.py
+36
-5
36 additions, 5 deletions
dataacquisition/sandbox.py
with
38 additions
and
9 deletions
dataacquisition/ExportToDatabase.py
+
1
−
3
View file @
1ad33abf
...
...
@@ -91,7 +91,7 @@ def create_table(station_list, db_name):
def
insert_empty_matrix_into_db
():
with
psycopg2
.
connect
(
database
=
param_postgres
[
'
dbName
'
],
user
=
param_postgres
[
"
user
"
],
password
=
param_postgres
[
"
password
"
],
host
=
param_postgres
[
"
host
"
],
port
=
param_postgres
[
"
port
"
])
as
connection
:
with
connection
.
cursor
()
as
cursor
:
with
open
(
'
clipped_matrix_
10x10
.csv
'
,
'
r
'
)
as
matrix
:
with
open
(
'
clipped_matrix_
25x25
.csv
'
,
'
r
'
)
as
matrix
:
matrix_data
=
matrix
.
readlines
()
for
line
in
matrix_data
[
1
:]:
values
=
''
# Used in second parameter of cursor.execute() (Avoids SQL injection)
...
...
@@ -121,13 +121,11 @@ def create_matrix_data():
id
=
point
[
0
]
lon
=
point
[
1
]
lat
=
point
[
2
]
print
(
lat
,
lon
)
interpolation_data
=
get_interpolation_data_for_point
(
lat
,
lon
,
sql
.
SQL
(
'
*
'
))
for
year
,
value
in
interpolation_data
.
items
():
update_data
.
append
({
'
year
'
:
year
,
'
value
'
:
value
,
'
id
'
:
id
})
print
(
update_data
)
query
=
sql
.
SQL
(
"""
UPDATE stations SET
"
%(year)s
"
= %(value)s WHERE id = %(id)s;
"""
)
psycopg2
.
extras
.
execute_batch
(
cursor
,
query
,
update_data
)
# 2 times faster than using execute() in a for loop, ~20 mins instead of 40
...
...
This diff is collapsed.
Click to expand it.
dataacquisition/GetAverageData.py
+
1
−
1
View file @
1ad33abf
...
...
@@ -31,7 +31,7 @@ def get_neighbours(cursor, lat, lon, columns):
query
=
sql
.
SQL
(
"""
SELECT array_to_json(array_agg(row_to_json(t))) from (
SELECT {columns}, ST_Distance(ST_MakePoint(l
on
, l
at
), ST_MakePoint({lon}, {lat})) AS distance
SELECT {columns}, ST_Distance(ST_MakePoint(l
at
, l
on
), ST_MakePoint({lon}, {lat})) AS distance
FROM stations
WHERE file IS NOT NULL
ORDER BY distance
...
...
This diff is collapsed.
Click to expand it.
dataacquisition/sandbox.py
+
36
−
5
View file @
1ad33abf
# import psycopg2
# from psycopg2 import sql
import
configparser
import
psycopg2
from
psycopg2
import
sql
cfg
=
configparser
.
ConfigParser
()
cfg
.
read
(
'
config.ini
'
)
assert
"
POSTGRES
"
in
cfg
,
"
missing POSTGRES in config.ini
"
param_postgres
=
cfg
[
"
POSTGRES
"
]
param_interpol
=
cfg
[
"
INTERPOLATION
"
]
#
# query = sql.SQL("select {0} from {1} where {2} LIKE {3} {4}").format(sql.SQL(', ').join([sql.Identifier('foo'), sql.Identifier('bar')]), sql.Identifier('table'), sql.Identifier('coulumn'), sql.Placeholder(),
# sql.SQL('AND 1 = 1'))
...
...
@@ -20,8 +29,30 @@
# list_b = [x * 2 for x in list_a if x % 2 == 0]
# print(list_b)
# list_a = [1,2,3,4,5,6,7,8,9,10]
# new_list = list_a[0::2]
# print(new_list)
def
get_neighbours
(
lat
,
lon
,
columns
):
values
=
''
# Used in second parameter of cursor.execute() (Avoids SQL injection)
for
n
in
[
lat
,
lon
]:
values
=
(
*
values
,
n
)
# adding n to existing tuple
with
psycopg2
.
connect
(
database
=
param_postgres
[
"
dbName
"
],
user
=
param_postgres
[
"
user
"
],
password
=
param_postgres
[
"
password
"
],
host
=
param_postgres
[
"
host
"
],
port
=
param_postgres
[
"
port
"
])
as
connection
:
with
connection
.
cursor
()
as
cursor
:
query
=
sql
.
SQL
(
"""
SELECT array_to_json(array_agg(row_to_json(t))) from (
SELECT {columns}, ST_Distance(ST_MakePoint(lat, lon), ST_MakePoint({lon}, {lat})) AS distance
FROM stations
WHERE file IS NOT NULL
ORDER BY distance
LIMIT {amount_neighbours}
) t;
"""
).
format
(
columns
=
columns
,
lon
=
sql
.
Placeholder
(),
lat
=
sql
.
Placeholder
(),
amount_neighbours
=
sql
.
SQL
(
param_interpol
[
"
amount_neighbours
"
]))
cursor
.
execute
(
query
,
values
)
neighbours
=
cursor
.
fetchall
()[
0
][
0
]
print
(
neighbours
)
# return neighbours
list_a
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
new_list
=
list_a
[
0
::
2
]
print
(
new_list
)
\ No newline at end of file
get_neighbours
(
53.42
,
9.24
,
sql
.
SQL
(
'"
2015
"
,
"
2014
"
,
"
2010
"'
))
\ No newline at end of file
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