Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
geoserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
backend
geoserver
Commits
38672e0b
Commit
38672e0b
authored
Sep 20, 2019
by
gaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
距离更新
parent
1a8bcc2b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
16 deletions
+72
-16
settings.cpython-36.pyc
geoserver/__pycache__/settings.cpython-36.pyc
+0
-0
settings_local.cpython-36.pyc
geoserver/__pycache__/settings_local.cpython-36.pyc
+0
-0
views.cpython-36.pyc
home/__pycache__/views.cpython-36.pyc
+0
-0
unit.py
home/unit.py
+34
-0
views.py
home/views.py
+38
-16
No files found.
geoserver/__pycache__/settings.cpython-36.pyc
View file @
38672e0b
No preview for this file type
geoserver/__pycache__/settings_local.cpython-36.pyc
View file @
38672e0b
No preview for this file type
home/__pycache__/views.cpython-36.pyc
View file @
38672e0b
No preview for this file type
home/unit.py
0 → 100644
View file @
38672e0b
import
redis
import
logging
from
django.conf
import
settings
from
django.shortcuts
import
render
from
math
import
radians
,
cos
,
sin
,
asin
,
sqrt
from
django.http
import
HttpResponse
,
JsonResponse
import
random
import
requests
import
ipdb
from
gm_rpcd.all
import
bind
,
RPCDFaultException
r
=
redis
.
Redis
(
host
=
settings
.
REDIS_HOST
,
port
=
settings
.
REDIS_PORT
,
db
=
settings
.
REDIS_DB
,
password
=
settings
.
REDIS_PASSWORD
,
decode_responses
=
True
)
rpc_client
=
settings
.
RPC_INVOKER
def
refresh_cache_locations
():
'''刷新缓存中医院的数据'''
print
(
"地理位置信息过期---,重新拿取---"
)
locations
=
rpc_client
[
'api/hospital/location'
]()
.
unwrap
()
cache_key
=
"hospital_location"
cache_diuration
=
24
*
60
*
60
#将地理位置信息加入redis缓存
for
item
in
locations
:
lat
=
item
.
get
(
"baidu_loc_lat"
)
if
item
.
get
(
"baidu_loc_lat"
)
else
item
.
get
(
"google_loc_lat"
)
lng
=
item
.
get
(
"baidu_loc_lng"
)
if
item
.
get
(
"baidu_loc_lng"
)
else
item
.
get
(
"google_loc_lng"
)
try
:
r
.
geoadd
(
cache_key
,
float
(
lng
),
float
(
lat
),
item
.
get
(
"id"
))
except
Exception
as
e
:
print
(
e
)
pass
r
.
expire
(
cache_key
,
cache_diuration
)
\ No newline at end of file
home/views.py
View file @
38672e0b
...
...
@@ -6,8 +6,11 @@ from math import radians, cos, sin, asin, sqrt
from
django.http
import
HttpResponse
,
JsonResponse
import
random
import
requests
import
uuid
import
ipdb
from
gm_rpcd.all
import
bind
,
RPCDFaultException
from
.unit
import
refresh_cache_locations
#from rpc.decorators import bind_context, bind
r
=
redis
.
Redis
(
host
=
settings
.
REDIS_HOST
,
port
=
settings
.
REDIS_PORT
,
db
=
settings
.
REDIS_DB
,
password
=
settings
.
REDIS_PASSWORD
,
decode_responses
=
True
)
...
...
@@ -27,23 +30,9 @@ def nearly_hospitals(q_lat,q_lng,radis=500,unit="km",count=20):
#q_lat,q_lng=40.001930265172,116.4871890387796
#数据缓存时间,现在为24小时
cache_key
=
"hospital_location"
cache_diuration
=
24
*
60
*
60
#ipdb.set_trace()
if
not
r
.
exists
(
cache_key
):
print
(
"地理位置信息过期---,重新拿取---"
)
locations
=
rpc_client
[
'api/hospital/location'
]()
.
unwrap
()
#将地理位置信息加入redis缓存
for
item
in
locations
:
lat
=
item
.
get
(
"baidu_loc_lat"
)
if
item
.
get
(
"baidu_loc_lat"
)
else
item
.
get
(
"google_loc_lat"
)
lng
=
item
.
get
(
"baidu_loc_lng"
)
if
item
.
get
(
"baidu_loc_lng"
)
else
item
.
get
(
"google_loc_lng"
)
try
:
r
.
geoadd
(
cache_key
,
float
(
lng
),
float
(
lat
),
item
.
get
(
"id"
))
except
Exception
as
e
:
print
(
e
)
pass
r
.
expire
(
cache_key
,
cache_diuration
)
refresh_cache_locations
()
result
=
r
.
georadius
(
cache_key
,
q_lng
,
q_lat
,
radis
,
unit
,
withdist
=
True
,
count
=
20
)
...
...
@@ -54,6 +43,39 @@ def nearly_hospitals(q_lat,q_lng,radis=500,unit="km",count=20):
}
return
data
@bind
(
"geoserver/home/hospitals_distance"
)
def
specify_hospitals_distance
(
q_lng
,
q_lat
,
hospital_ids
):
'''
到指定医院距离排序
'''
cache_key
=
"hospital_location"
#锁定临时的key
result
=
[]
temp_key
=
"hospital_location_temp"
lock_key
=
"hospital_location_lock"
with
r
.
lock
(
lock_key
,
blocking_timeout
=
15
)
as
lock
:
r
.
geoadd
(
cache_key
,
float
(
q_lng
),
float
(
q_lat
),
temp_key
)
for
item
in
hospital_ids
:
distance
=
r
.
geodist
(
cache_key
,
temp_key
,
item
)
if
not
distance
:
distance
=
0
result
.
append
({
"id"
:
item
,
"distance"
:
distance
})
#排序
result
=
sorted
(
result
,
key
=
lambda
x
:
x
.
get
(
"distance"
))
data
=
{
"result"
:
True
,
"data"
:
result
,
"message"
:
""
}
return
data
def
get_location_by_address
(
request
,
address
):
"""由地址获获取经纬度坐标
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment