Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
df-aggregator
Overview
Overview
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
Oleksandr Barabash
df-aggregator
Commits
79a14e65
Commit
79a14e65
authored
Apr 14, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small fixes
parent
777fc1e2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
102 deletions
+52
-102
df-aggregator.py
df-aggregator.py
+4
-89
receiver.py
utils/ether_service/entities/receiver.py
+32
-10
ProcessService.py
utils/ether_service/utils/ProcessService.py
+8
-3
receivers_controller.py
utils/ether_service/utils/receivers_controller.py
+8
-0
No files found.
df-aggregator.py
View file @
79a14e65
...
...
@@ -774,12 +774,13 @@ def write_rx_czml():
"width"
:
48
,
}
receivers_doa
=
Context
.
receiver_controller
.
get_doa
()
for
index
,
(
station_id
,
doa_list
)
in
enumerate
(
receivers_doa
.
items
()):
for
doa
in
doa_list
:
for
main_index
,
(
station_id
,
doa_list
)
in
enumerate
(
receivers_doa
.
items
()):
for
slave_index
,
doa
in
enumerate
(
doa_list
):
index
=
main_index
*
10
+
slave_index
confidence
=
np
.
max
(
int
(
float
(
doa
.
confidence
)
*
100
))
power
=
np
.
maximum
(
-
100
,
float
(
doa
.
power
)
+
100
)
print
(
doa
.
degrees
)
# logging.info(f" {station_id}: {doa.degrees}º "
)
if
confidence
>
min_conf
and
power
>
min_power
:
lob_color
=
green
elif
confidence
<=
min_conf
and
power
>
min_power
:
...
...
@@ -856,92 +857,6 @@ def write_rx_czml():
doa
.
latitude
,
15
]})
)
# for index, x in enumerate(l_receivers):
# if x.isActive and ms.receiving:
# if x.confidence > min_conf and x.power > min_power:
# lob_color = green
# elif x.confidence <= min_conf and x.power > min_power:
# lob_color = orange
# else:
# lob_color = red
# lob_start_lat = x.latitude
# lob_start_lon = x.longitude
# lob_stop_lat, lob_stop_lon = v.direct(
# lob_start_lat, lob_start_lon, x.doa, x.lob_length()
# )
# lob_packets.append(
# Packet(
# id=f"LOB-{x.station_id}-{index}",
# polyline=Polyline(
# material=Material(
# polylineOutline=PolylineOutlineMaterial(
# color=Color(rgba=lob_color),
# outlineColor=Color(rgba=[0, 0, 0, 255]),
# outlineWidth=2
# )
# ),
# clampToGround=True,
# width=5,
# positions=Position(
# cartographicDegrees=[
# lob_start_lon,
# lob_start_lat,
# height,
# lob_stop_lon,
# lob_stop_lat,
# height
# ]
# )
# )
# )
# )
# heading_start_lat = x.latitude
# heading_start_lon = x.longitude
# heading_stop_lat, heading_stop_lon = v.direct(
# heading_start_lat, heading_start_lon, x.heading, heading_d)
# lob_packets.append(
# Packet(
# id=f"HEADING-{x.station_id}-{index}",
# polyline=Polyline(
# material=PolylineMaterial(
# polylineDash=PolylineDashMaterial(
# color=Color(rgba=gray),
# gapColor=Color(rgba=[0, 0, 0, 0])
# )
# ),
# clampToGround=True,
# width=2,
# positions=Position(
# cartographicDegrees=[
# heading_start_lon,
# heading_start_lat,
# height,
# heading_stop_lon,
# heading_stop_lat,
# height]
# )
# )
# )
# )
# else:
# lob_packets = []
#
# if x.isMobile is True:
# rx_icon = {"image": {"uri": "/static/flipped_car.svg"}}
# # if x.heading > 0 or x.heading < 180:
# # rx_icon = {"image":{"uri":"/static/flipped_car.svg"},
# # "rotation":math.radians(360 - x.heading + 90)}
# # elif x.heading < 0 or x.heading > 180:
# # rx_icon = {"image":{"uri":"/static/car.svg"},
# # "rotation":math.radians(360 - x.heading - 90)}
# else:
# rx_icon = {"image": {"uri": "/static/tower.svg"}}
# receiver_point_packets.append(
# Packet(id=f"{x.station_id}-{index}",
# billboard={**rx_properties, **rx_icon},
# position={"cartographicDegrees": [x.longitude,
# x.latitude, 15]})
# )
document_list
=
[
top
,
]
document_list
.
extend
(
receiver_point_packets
)
document_list
.
extend
(
lob_packets
)
...
...
utils/ether_service/entities/receiver.py
View file @
79a14e65
...
...
@@ -111,6 +111,7 @@ class Receiver(BasicDataclass):
def
clear_bearings
(
self
:
"Receiver"
)
->
None
:
""" Remove all bearings """
self
.
bearings
=
[]
nodes
=
self
.
tree
.
get_all
()
for
node
in
nodes
:
node
.
items
=
[]
...
...
@@ -147,15 +148,17 @@ class Receiver(BasicDataclass):
absolute_bearings
.
append
(
curr_bearing
)
i
+=
1
prev_bearing
=
absolute_bearings
.
pop
()
if
abs
(
prev_bearing
.
degrees
-
curr_bearing
.
degrees
)
<=
3
:
if
abs
(
prev_bearing
.
degrees
-
curr_bearing
.
degrees
)
<=
5
:
absolute_bearings
.
append
(
self
.
get_median_bearing
(
prev_bearing
,
curr_bearing
))
else
:
absolute_bearings
.
append
(
prev_bearing
)
absolute_bearings
.
append
(
curr_bearing
)
i
+=
1
for
a_bearing
in
absolute_bearings
:
a_bearing
.
power
=
a_bearing
.
power
/
a_bearing
.
num
a_bearing
.
confidence
=
a_bearing
.
confidence
/
a_bearing
.
num
a_bearing
.
power
=
a_bearing
.
num
a_bearing
.
confidence
/=
a_bearing
.
num
# This code is just copied from the old DF-AGG
if
self
.
inverted
:
...
...
@@ -163,7 +166,7 @@ class Receiver(BasicDataclass):
elif
self
.
flipped
:
a_bearing
.
degrees
=
self
.
heading
+
(
180
-
a_bearing
.
degrees
)
else
:
a_bearing
.
degrees
=
self
.
heading
+
a_bearing
.
degrees
a_bearing
.
degrees
+=
self
.
heading
if
a_bearing
.
degrees
<
0
:
a_bearing
.
degrees
+=
360
elif
a_bearing
.
degrees
>
359
:
...
...
@@ -171,13 +174,10 @@ class Receiver(BasicDataclass):
return
absolute_bearings
def
add_packet
(
self
:
"Receiver"
,
packet
:
KrPacket
)
->
None
:
"""
Add KrRpi packet to
the receiver """
def
refresh
(
self
)
->
None
:
"""
Refresh DOA of
the receiver """
now
=
int
(
time
.
time
()
*
1000
)
# insert packet
self
.
tree
.
insert_node
(
packet
.
radio_bearing
,
packet
)
bearings
=
[]
bearings_len
=
0
...
...
@@ -187,7 +187,7 @@ class Receiver(BasicDataclass):
bearing
=
Bearing
(
node
.
val
,
0
,
0
,
0
)
slice_id
=
None
for
idx
,
item
in
enumerate
(
node
.
items
):
if
now
-
item
.
t_stamp
>
20000
:
# 20
seconds old
if
now
-
item
.
t_stamp
>
5000
:
# 5
seconds old
slice_id
=
idx
else
:
bearing
.
num
+=
1
...
...
@@ -208,6 +208,28 @@ class Receiver(BasicDataclass):
self
.
tree
.
delete_node
(
node
.
val
)
self
.
bearings
=
self
.
create_absolute_bearings
(
bearings
,
bearings_len
)
logger
.
info
(
f
"{self.station_id}, "
f
"{[str(x.degrees) + 'º'for x in self.bearings]}"
)
def
add_packet
(
self
:
"Receiver"
,
packet
:
KrPacket
)
->
None
:
""" Add KrRpi packet to the receiver """
self
.
tree
.
insert_node
(
packet
.
radio_bearing
,
packet
)
# insert packet
# fake_packet = KrPacket(
# packet.t_stamp,
# packet.latitude,
# packet.longitude,
# packet.gps_bearing,
# 13,
# packet.conf,
# packet.power,
# packet.freq,
# packet.ant_type,
# packet.latency,
# packet.doa_array,
# packet.id)
# self.tree.insert_node(fake_packet.radio_bearing, fake_packet)
@staticmethod
def
lob_length
()
->
int
:
...
...
utils/ether_service/utils/ProcessService.py
View file @
79a14e65
...
...
@@ -2,7 +2,7 @@
import
logging
import
signal
from
multiprocessing
import
Process
,
Value
,
Queue
from
time
import
sleep
from
time
import
sleep
,
time
from
..utils.log
import
init_logging
...
...
@@ -46,13 +46,18 @@ class ProcessService(Process):
signal
.
signal
(
signal
.
SIGTERM
,
lambda
x
,
y
:
None
)
init_logging
(
level
=
self
.
loglevel
)
last_refresh
=
time
()
while
self
.
is_running
:
try
:
command
=
self
.
cmd_queue
.
get
()
command
=
self
.
cmd_queue
.
get
(
timeout
=
1
)
self
.
handle_command
(
*
command
)
except
Exception
as
ex
:
exc_info
=
type
(
ex
),
ex
,
ex
.
__traceback__
logger
.
error
(
"main loop execution error"
,
exc_info
=
exc_info
)
# logger.error("main loop execution error", exc_info=exc_info)
now
=
time
()
if
time
()
-
last_refresh
>=
1
:
last_refresh
=
now
self
.
cmd_queue
.
put_nowait
((
0
,))
sleep
(
0.001
)
# sleep for 1ms to prevent 100% CPU load
self
.
cmd_queue
.
close
()
logger
.
info
(
f
"{self.name} has been stopped"
)
...
...
utils/ether_service/utils/receivers_controller.py
View file @
79a14e65
""" ReceiverController implementation """
import
logging
import
sqlite3
import
time
from
multiprocessing
import
Queue
from
typing
import
Optional
,
Dict
,
List
...
...
@@ -18,6 +19,7 @@ logger = logging.getLogger()
class
ReceiverCommands
:
""" Receiver Controller commands """
REFRESH_RECEIVERS
=
0
HANDLE_DATA
=
200
REGISTER_RECEIVER
=
210
# Register new receiver
UNREGISTER_RECEIVER
=
220
# Unregister receiver
...
...
@@ -185,9 +187,11 @@ class ReceiverController(ProcessService):
(
data_bytes
,
)
=
params
data
=
json_loads
(
data_bytes
,
{})
kr_packet
=
KrPacket
.
load
(
data
,
unknown
=
EXCLUDE
)
kr_packet
.
t_stamp
=
int
(
time
.
time
()
*
1000
)
receiver
=
self
.
get_registered_receiver
(
kr_packet
.
id
)
if
receiver
and
receiver
.
active
:
# TODO(s1z): Add bearings to the queue
receiver
.
update_config
(
kr_packet
)
return
receiver
.
add_packet
(
kr_packet
)
# create receiver if does not exist
...
...
@@ -268,3 +272,7 @@ class ReceiverController(ProcessService):
receiver_doa
.
append
(
doa
)
doa_list
[
receiver
.
station_id
]
=
receiver_doa
self
.
doa_queue
.
put_nowait
(
doa_list
)
elif
command
==
ReceiverCommands
.
REFRESH_RECEIVERS
:
for
_
,
receiver
in
self
.
_registered_receivers
.
items
():
receiver
.
refresh
()
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