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
48f52161
Commit
48f52161
authored
Nov 26, 2020
by
Corey Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Saves receivers in DB. Removes requirement for receivers file
parent
a4e3ec8d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
328 additions
and
260 deletions
+328
-260
README.md
README.md
+5
-4
df-aggregator.py
df-aggregator.py
+100
-34
receiver_configurator.js
static/receiver_configurator.js
+223
-222
No files found.
README.md
View file @
48f52161
...
@@ -13,15 +13,12 @@
...
@@ -13,15 +13,12 @@
-
Create a single line file named
```accesstoken.txt```
-
Create a single line file named
```accesstoken.txt```
-
[
Extended XML KerberosSDR Software
](
https://github.com/ckoval7/kerberossdr
)
-
[
Extended XML KerberosSDR Software
](
https://github.com/ckoval7/kerberossdr
)
-
This is available for both Qt4 (original version) and Qt5 (Ubuntu 20.04+). Just check out the appropriate branch.
-
This is available for both Qt4 (original version) and Qt5 (Ubuntu 20.04+). Just check out the appropriate branch.


## Usage: df-aggregator.py [options]
## Usage: df-aggregator.py [options]
### Required inputs:
### Required inputs:
-
-r FILE, --receivers=FILE
-
List of receiver URLs
-
Do not include quotes. Each receiver should be on a new line.
-
-d FILE, --database=FILE
-
-d FILE, --database=FILE
-
Name of new or existing database to store intersect information.
-
Name of new or existing database to store intersect information.
...
@@ -29,6 +26,10 @@
...
@@ -29,6 +26,10 @@
-
Post processing math is done against the entire database.
-
Post processing math is done against the entire database.
### Optional Inputs:
### Optional Inputs:
-
-r FILE, --receivers=FILE
-
List of receiver URLs
-
Do not include quotes. Each receiver should be on a new line.
-
-g FILE, --geofile=FILE
-
-g FILE, --geofile=FILE
-
GeoJSON Output File
-
GeoJSON Output File
-
Conventional file extension: .geojson
-
Conventional file extension: .geojson
...
...
df-aggregator.py
View file @
48f52161
...
@@ -7,6 +7,7 @@ import time
...
@@ -7,6 +7,7 @@ import time
import
sqlite3
import
sqlite3
import
threading
import
threading
import
signal
import
signal
import
hashlib
from
colorsys
import
hsv_to_rgb
from
colorsys
import
hsv_to_rgb
from
optparse
import
OptionParser
from
optparse
import
OptionParser
from
os
import
system
,
name
,
kill
,
getpid
from
os
import
system
,
name
,
kill
,
getpid
...
@@ -20,6 +21,7 @@ import json
...
@@ -20,6 +21,7 @@ import json
from
bottle
import
route
,
run
,
request
,
get
,
post
,
put
,
response
,
redirect
,
template
,
static_file
from
bottle
import
route
,
run
,
request
,
get
,
post
,
put
,
response
,
redirect
,
template
,
static_file
d
=
40000
#meters
d
=
40000
#meters
receivers
=
[]
class
math_settings
:
class
math_settings
:
def
__init__
(
self
,
eps
,
min_samp
,
conf
,
power
):
def
__init__
(
self
,
eps
,
min_samp
,
conf
,
power
):
...
@@ -34,6 +36,8 @@ class receiver:
...
@@ -34,6 +36,8 @@ class receiver:
def
__init__
(
self
,
station_url
):
def
__init__
(
self
,
station_url
):
self
.
station_url
=
station_url
self
.
station_url
=
station_url
self
.
isAuto
=
True
self
.
isAuto
=
True
# hashed_url = hashlib.md5(station_url.encode('utf-8')).hexdigest()
# self.uid = hashed_url[:5] + hashed_url[-5:]
try
:
try
:
self
.
update
()
self
.
update
()
except
:
except
:
...
@@ -153,15 +157,15 @@ def process_data(database_name, outfile):
...
@@ -153,15 +157,15 @@ def process_data(database_name, outfile):
intersect_list
=
[]
intersect_list
=
[]
try
:
try
:
c
.
execute
(
"SELECT COUNT(*) FROM intersects"
)
#
c.execute("SELECT COUNT(*) FROM intersects")
n_intersects
=
int
(
c
.
fetchone
()[
0
])
#
n_intersects = int(c.fetchone()[0])
c
.
execute
(
"SELECT longitude, latitude, time FROM intersects"
)
c
.
execute
(
"SELECT longitude, latitude, time FROM intersects"
)
intersect_array
=
np
.
array
(
c
.
fetchall
())
intersect_array
=
np
.
array
(
c
.
fetchall
())
except
sqlite3
.
OperationalError
:
except
sqlite3
.
OperationalError
:
n_intersects
=
0
n_intersects
=
0
intersect_array
=
np
.
array
([])
intersect_array
=
np
.
array
([])
likely_location
=
[]
likely_location
=
[]
weighted_location
=
[]
#
weighted_location = []
ellipsedata
=
[]
ellipsedata
=
[]
n_std
=
3.0
n_std
=
3.0
...
@@ -264,11 +268,6 @@ def write_czml(best_point, all_the_points, ellipsedata):
...
@@ -264,11 +268,6 @@ def write_czml(best_point, all_the_points, ellipsedata):
}
}
}
}
rx_properties
=
{
rx_properties
=
{
# "image":
# {
# "uri": "/static/tower.svg"
# },
# "rotation": "Cesium.Math.PI_OVER_FOUR",
"verticalOrigin"
:
"BOTTOM"
,
"verticalOrigin"
:
"BOTTOM"
,
"scale"
:
0.75
,
"scale"
:
0.75
,
"heightReference"
:
"RELATIVE_TO_GROUND"
,
"heightReference"
:
"RELATIVE_TO_GROUND"
,
...
@@ -358,6 +357,7 @@ def finish():
...
@@ -358,6 +357,7 @@ def finish():
clear
(
debugging
)
clear
(
debugging
)
print
(
"Processing, please wait."
)
print
(
"Processing, please wait."
)
ms
.
receiving
=
False
ms
.
receiving
=
False
update_rx_table
()
if
geofile
!=
None
:
if
geofile
!=
None
:
write_geojson
(
*
process_data
(
database_name
,
geofile
)[:
2
])
write_geojson
(
*
process_data
(
database_name
,
geofile
)[:
2
])
kill
(
getpid
(),
signal
.
SIGTERM
)
kill
(
getpid
(),
signal
.
SIGTERM
)
...
@@ -375,9 +375,6 @@ def clear(debugging):
...
@@ -375,9 +375,6 @@ def clear(debugging):
else
:
else
:
_
=
system
(
'clear'
)
_
=
system
(
'clear'
)
with
open
(
'accesstoken.txt'
,
"r"
)
as
tokenfile
:
access_token
=
tokenfile
.
read
()
.
replace
(
'
\n
'
,
''
)
@route
(
'/static/<filepath:path>'
,
name
=
'static'
)
@route
(
'/static/<filepath:path>'
,
name
=
'static'
)
def
server_static
(
filepath
):
def
server_static
(
filepath
):
return
static_file
(
filepath
,
root
=
'./static'
)
return
static_file
(
filepath
,
root
=
'./static'
)
...
@@ -386,6 +383,8 @@ def server_static(filepath):
...
@@ -386,6 +383,8 @@ def server_static(filepath):
@get
(
'/index'
)
@get
(
'/index'
)
@get
(
'/cesium'
)
@get
(
'/cesium'
)
def
cesium
():
def
cesium
():
with
open
(
'accesstoken.txt'
,
"r"
)
as
tokenfile
:
access_token
=
tokenfile
.
read
()
.
replace
(
'
\n
'
,
''
)
write_czml
(
*
process_data
(
database_name
,
geofile
))
write_czml
(
*
process_data
(
database_name
,
geofile
))
return
template
(
'cesium.tpl'
,
return
template
(
'cesium.tpl'
,
{
'access_token'
:
access_token
,
{
'access_token'
:
access_token
,
...
@@ -429,20 +428,23 @@ def rx_params():
...
@@ -429,20 +428,23 @@ def rx_params():
response
.
headers
[
'Content-Type'
]
=
'application/json'
response
.
headers
[
'Content-Type'
]
=
'application/json'
return
json
.
dumps
(
all_rx
)
return
json
.
dumps
(
all_rx
)
@put
(
'/rx_params/<
uid
>'
)
@put
(
'/rx_params/<
action
>'
)
def
update_rx
(
uid
):
def
update_rx
(
action
):
data
=
json
.
load
(
request
.
body
)
data
=
json
.
load
(
request
.
body
)
if
uid
==
"new"
:
if
action
==
"new"
:
receivers
.
append
(
receiver
(
data
[
'station_url'
]
.
replace
(
'
\n
'
,
''
)))
receiver_url
=
data
[
'station_url'
]
.
replace
(
'
\n
'
,
''
)
print
(
"Created new DF Station at "
+
data
[
'station_url'
])
add_receiver
(
receiver_url
)
elif
uid
==
"del"
:
elif
action
==
"del"
:
del
receivers
[
int
(
data
[
'uid'
])]
index
=
int
(
data
[
'uid'
])
del_receiver
(
receivers
[
index
]
.
station_id
)
del
receivers
[
index
]
else
:
else
:
uid
=
int
(
uid
)
action
=
int
(
action
)
try
:
try
:
receivers
[
uid
]
.
isMobile
=
data
[
'mobile'
]
receivers
[
action
]
.
isMobile
=
data
[
'mobile'
]
receivers
[
uid
]
.
station_url
=
data
[
'station_url'
]
receivers
[
action
]
.
station_url
=
data
[
'station_url'
]
receivers
[
uid
]
.
update
()
receivers
[
action
]
.
update
()
update_rx_table
()
except
IndexError
:
except
IndexError
:
print
(
"I got some bad data. Doing nothing out of spite."
)
print
(
"I got some bad data. Doing nothing out of spite."
)
return
redirect
(
'/rx_params'
)
return
redirect
(
'/rx_params'
)
...
@@ -458,6 +460,7 @@ def run_receiver(receivers):
...
@@ -458,6 +460,7 @@ def run_receiver(receivers):
c
=
conn
.
cursor
()
c
=
conn
.
cursor
()
c
.
execute
(
"CREATE TABLE IF NOT EXISTS intersects (time INTEGER, latitude REAL, longitude REAL, num_parents INTEGER)"
)
c
.
execute
(
"CREATE TABLE IF NOT EXISTS intersects (time INTEGER, latitude REAL, longitude REAL, num_parents INTEGER)"
)
while
ms
.
receiving
:
while
ms
.
receiving
:
if
not
debugging
:
if
not
debugging
:
print
(
"Receiving"
+
dots
*
'.'
)
print
(
"Receiving"
+
dots
*
'.'
)
...
@@ -508,11 +511,75 @@ def run_receiver(receivers):
...
@@ -508,11 +511,75 @@ def run_receiver(receivers):
conn
.
close
()
conn
.
close
()
def
add_receiver
(
receiver_url
):
conn
=
sqlite3
.
connect
(
database_name
)
c
=
conn
.
cursor
()
c
.
execute
(
'''CREATE TABLE IF NOT EXISTS receivers (
station_id TEXT UNIQUE,
station_url TEXT,
isAuto INTEGER,
isMobile INTEGER,
latitude REAL,
longitude REAL)
'''
)
try
:
if
any
(
x
.
station_url
==
receiver_url
for
x
in
receivers
):
print
(
"Duplicate receiver, ignoring."
)
else
:
receivers
.
append
(
receiver
(
receiver_url
))
new_rx
=
receivers
[
-
1
]
.
receiver_dict
()
to_table
=
[
new_rx
[
'station_id'
],
new_rx
[
'station_url'
],
new_rx
[
'auto'
],
new_rx
[
'mobile'
],
new_rx
[
'latitude'
],
new_rx
[
'longitude'
]]
c
.
execute
(
"INSERT OR IGNORE INTO receivers VALUES (?,?,?,?,?,?)"
,
to_table
)
conn
.
commit
()
mobile
=
c
.
execute
(
"SELECT isMobile FROM receivers WHERE station_id = ?"
,
[
new_rx
[
'station_id'
]])
.
fetchone
()[
0
]
receivers
[
-
1
]
.
isMobile
=
bool
(
mobile
)
print
(
"Created new DF Station at "
+
receiver_url
)
except
IOError
:
ms
.
receiving
=
False
conn
.
close
()
def
read_rx_table
():
conn
=
sqlite3
.
connect
(
database_name
)
c
=
conn
.
cursor
()
try
:
c
.
execute
(
"SELECT station_url FROM receivers"
)
rx_list
=
c
.
fetchall
()
for
x
in
rx_list
:
receiver_url
=
x
[
0
]
.
replace
(
'
\n
'
,
''
)
add_receiver
(
receiver_url
)
except
sqlite3
.
OperationalError
:
rx_list
=
[]
conn
.
close
()
def
update_rx_table
():
conn
=
sqlite3
.
connect
(
database_name
)
c
=
conn
.
cursor
()
for
item
in
receivers
:
rx
=
item
.
receiver_dict
()
to_table
=
[
rx
[
'auto'
],
rx
[
'mobile'
],
rx
[
'latitude'
],
rx
[
'longitude'
],
rx
[
'station_id'
]]
c
.
execute
(
'''UPDATE receivers SET
isAuto=?,
isMobile=?,
latitude=?,
longitude=?
WHERE station_id = ?'''
,
to_table
)
conn
.
commit
()
conn
.
close
()
def
del_receiver
(
del_rx
):
conn
=
sqlite3
.
connect
(
database_name
)
c
=
conn
.
cursor
()
c
.
execute
(
"DELETE FROM receivers WHERE station_id=?"
,
[
del_rx
])
conn
.
commit
()
conn
.
close
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
usage
=
"usage:
%
prog -
r FILE -
d FILE [options]"
usage
=
"usage:
%
prog -d FILE [options]"
parser
=
OptionParser
(
usage
=
usage
)
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
"-r"
,
"--receivers"
,
dest
=
"rx_file"
,
help
=
"REQUIRED List of receiver URLs"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-d"
,
"--database"
,
dest
=
"database_name"
,
help
=
"REQUIRED Database File"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-d"
,
"--database"
,
dest
=
"database_name"
,
help
=
"REQUIRED Database File"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-r"
,
"--receivers"
,
dest
=
"rx_file"
,
help
=
"List of receiver URLs"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-g"
,
"--geofile"
,
dest
=
"geofile"
,
help
=
"GeoJSON Output File"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-g"
,
"--geofile"
,
dest
=
"geofile"
,
help
=
"GeoJSON Output File"
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-e"
,
"--epsilon"
,
dest
=
"eps"
,
help
=
"Max Clustering Distance, Default 0.2. 0 to disable clustering."
,
parser
.
add_option
(
"-e"
,
"--epsilon"
,
dest
=
"eps"
,
help
=
"Max Clustering Distance, Default 0.2. 0 to disable clustering."
,
metavar
=
"NUMBER"
,
type
=
"float"
,
default
=
0.2
)
metavar
=
"NUMBER"
,
type
=
"float"
,
default
=
0.2
)
...
@@ -534,7 +601,7 @@ if __name__ == '__main__':
...
@@ -534,7 +601,7 @@ if __name__ == '__main__':
action
=
"store_true"
)
action
=
"store_true"
)
(
options
,
args
)
=
parser
.
parse_args
()
(
options
,
args
)
=
parser
.
parse_args
()
mandatories
=
[
'
rx_file'
,
'
database_name'
]
mandatories
=
[
'database_name'
]
for
m
in
mandatories
:
for
m
in
mandatories
:
if
options
.
__dict__
[
m
]
is
None
:
if
options
.
__dict__
[
m
]
is
None
:
print
(
"You forgot an arguement"
)
print
(
"You forgot an arguement"
)
...
@@ -557,15 +624,14 @@ if __name__ == '__main__':
...
@@ -557,15 +624,14 @@ if __name__ == '__main__':
web
.
start
()
web
.
start
()
try
:
try
:
read_rx_table
()
receivers
=
[]
if
rx_file
:
with
open
(
rx_file
,
"r"
)
as
file2
:
print
(
"I got a file!"
)
receiver_list
=
file2
.
readlines
()
with
open
(
rx_file
,
"r"
)
as
file2
:
for
x
in
receiver_list
:
receiver_list
=
file2
.
readlines
()
try
:
for
x
in
receiver_list
:
receivers
.
append
(
receiver
(
x
.
replace
(
'
\n
'
,
''
)))
receiver_url
=
x
.
replace
(
'
\n
'
,
''
)
except
IOError
:
add_receiver
(
receiver_url
)
ms
.
receiving
=
False
while
True
:
while
True
:
if
ms
.
receiving
:
if
ms
.
receiving
:
...
...
static/receiver_configurator.js
View file @
48f52161
...
@@ -2,196 +2,196 @@
...
@@ -2,196 +2,196 @@
// * Gets Rx data from backend
// * Gets Rx data from backend
// *************************************************
// *************************************************
function
updateRx
(
callBack
,
id
)
{
function
updateRx
(
callBack
,
id
)
{
fetch
(
"/rx_params"
)
fetch
(
"/rx_params"
)
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
res
=>
{
callBack
(
res
,
id
)
})
.
then
(
res
=>
{
callBack
(
res
,
id
)
})
}
}
// ******************************************************
// ******************************************************
// * Makes Changes to Receiver, Saves, & Refreshes Cards
// * Makes Changes to Receiver, Saves, & Refreshes Cards
// ******************************************************
// ******************************************************
function
editReceivers
(
rx_json
,
id
)
{
function
editReceivers
(
rx_json
,
id
)
{
const
receivers
=
rx_json
[
'receivers'
];
const
receivers
=
rx_json
[
'receivers'
];
var
stationUrlHtml
=
var
stationUrlHtml
=
"<input type=
\"
hidden
\"
id=
\"
url_"
+
id
+
"
\"
/>"
;
"<input type=
\"
hidden
\"
id=
\"
url_"
+
id
+
"
\"
/>"
;
var
stationIDhtml
=
var
stationIDhtml
=
"Station ID: <a href=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
target=
\"
_blank
\"
>"
+
receivers
[
id
].
station_id
+
"</a>"
;
"Station ID: <a href=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
target=
\"
_blank
\"
>"
+
receivers
[
id
].
station_id
+
"</a>"
;
var
manualInfo
=
var
manualInfo
=
"<input type=
\"
hidden
\"
id=
\"
manual_toggle_"
+
receivers
[
id
].
uid
+
"
\"
/>"
;
"<input type=
\"
hidden
\"
id=
\"
manual_toggle_"
+
receivers
[
id
].
uid
+
"
\"
/>"
;
var
locationHtml
=
var
locationHtml
=
"Location: "
+
receivers
[
id
].
latitude
+
"°, "
+
receivers
[
id
].
longitude
+
"°"
;
"Location: "
+
receivers
[
id
].
latitude
+
"°, "
+
receivers
[
id
].
longitude
+
"°"
;
var
heading
=
var
heading
=
"Heading: "
+
receivers
[
id
].
heading
+
"°"
;
"Heading: "
+
receivers
[
id
].
heading
+
"°"
;
var
freqHtml
=
var
freqHtml
=
"Tuned to "
+
receivers
[
id
].
frequency
+
" MHz"
;
"Tuned to "
+
receivers
[
id
].
frequency
+
" MHz"
;
var
edit_stationUrlHtml
=
var
edit_stationUrlHtml
=
"Station URL:<input style=
\"
width: 300px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
name=
\"
station_url_"
+
id
+
"
\"
/>"
;
"Station URL:<input style=
\"
width: 300px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
name=
\"
station_url_"
+
id
+
"
\"
/>"
;
var
edit_stationIDhtml
=
var
edit_stationIDhtml
=
"Station ID:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
station_id
+
"
\"
name=
\"
station_id_"
+
id
+
"
\"
/>"
;
"Station ID:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
station_id
+
"
\"
name=
\"
station_id_"
+
id
+
"
\"
/>"
;
var
edit_manualInfo
=
var
edit_manualInfo
=
"Manually input receiver info: <input id=
\"
manual_toggle_"
+
id
+
"
\"
type=
\"
checkbox
\"
/>"
;
"Manually input receiver info: <input id=
\"
manual_toggle_"
+
id
+
"
\"
type=
\"
checkbox
\"
/>"
;
var
edit_locationHtml
=
var
edit_locationHtml
=
"Latitude:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
latitude
+
"
\"
name=
\"
station_lat_"
+
id
+
"
\"
/>"
"Latitude:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
latitude
+
"
\"
name=
\"
station_lat_"
+
id
+
"
\"
/>"
+
+
" Longitude:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
longitude
+
"
\"
name=
\"
station_lon_"
+
id
+
"
\"
/>"
;
" Longitude:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
longitude
+
"
\"
name=
\"
station_lon_"
+
id
+
"
\"
/>"
;
var
edit_heading
=
var
edit_heading
=
"Heading:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
heading
+
"
\"
name=
\"
station_heading_"
+
id
+
"
\"
/>"
;
"Heading:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
heading
+
"
\"
name=
\"
station_heading_"
+
id
+
"
\"
/>"
;
var
edit_freqHtml
=
var
edit_freqHtml
=
"Frequency:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
frequency
+
"
\"
name=
\"
frequency_"
+
id
+
"
\"
/>"
;
"Frequency:<input style=
\"
width: 105px;
\"
type=
\"
text
\"
value=
\"
"
+
receivers
[
id
].
frequency
+
"
\"
name=
\"
frequency_"
+
id
+
"
\"
/>"
;
var
mobile
=
id
+
"-mobile"
;
var
mobile
=
id
+
"-mobile"
;
var
editButton
=
document
.
getElementById
(
id
+
"-edit"
);
var
editButton
=
document
.
getElementById
(
id
+
"-edit"
);
var
isMobileCheck
=
document
.
getElementById
(
"mobilerx_toggle_"
+
id
);
var
isMobileCheck
=
document
.
getElementById
(
"mobilerx_toggle_"
+
id
);
if
(
editButton
.
checked
)
{
if
(
editButton
.
checked
)
{
let
isMobile
=
""
;
let
isMobile
=
""
;
if
(
receivers
[
id
].
mobile
)
isMobile
=
"checked"
;
if
(
receivers
[
id
].
mobile
)
isMobile
=
"checked"
;
document
.
getElementById
(
id
+
"-editicon"
).
innerHTML
=
"save"
;
document
.
getElementById
(
id
+
"-editicon"
).
innerHTML
=
"save"
;
document
.
getElementById
(
mobile
).
innerHTML
=
document
.
getElementById
(
mobile
).
innerHTML
=
"Mobile Receiver: <input "
+
isMobile
+
" id=
\"
mobilerx_toggle_"
+
id
+
"
\"
type=
\"
checkbox
\"
/>"
;
"Mobile Receiver: <input "
+
isMobile
+
" id=
\"
mobilerx_toggle_"
+
id
+
"
\"
type=
\"
checkbox
\"
/>"
;
document
.
getElementById
(
id
+
"-manual"
).
innerHTML
=
edit_manualInfo
;
document
.
getElementById
(
id
+
"-manual"
).
innerHTML
=
edit_manualInfo
;
document
.
getElementById
(
id
+
"-url"
).
innerHTML
=
edit_stationUrlHtml
;
document
.
getElementById
(
id
+
"-url"
).
innerHTML
=
edit_stationUrlHtml
;
document
.
getElementById
(
"manual_toggle_"
+
id
).
onchange
=
function
()
{
document
.
getElementById
(
"manual_toggle_"
+
id
).
onchange
=
function
()
{
if
(
document
.
getElementById
(
"manual_toggle_"
+
id
).
checked
)
{
if
(
document
.
getElementById
(
"manual_toggle_"
+
id
).
checked
)
{
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
edit_stationIDhtml
;
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
edit_stationIDhtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
edit_locationHtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
edit_locationHtml
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
edit_heading
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
edit_heading
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
edit_freqHtml
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
edit_freqHtml
;
}
else
{
}
else
{
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
stationIDhtml
;
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
stationIDhtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
locationHtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
locationHtml
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
heading
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
heading
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
freqHtml
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
freqHtml
;
}
}
}
}
}
else
{
isMobileCheck
=
document
.
getElementById
(
"mobilerx_toggle_"
+
id
);
if
(
isMobileCheck
.
checked
)
{
receivers
[
id
].
mobile
=
true
;
}
else
{
}
else
{
receivers
[
id
].
mobile
=
false
;
isMobileCheck
=
document
.
getElementById
(
"mobilerx_toggle_"
+
id
);
if
(
isMobileCheck
.
checked
)
{
receivers
[
id
].
mobile
=
true
;
}
else
{
receivers
[
id
].
mobile
=
false
;
}
const
otherParams
=
{
headers
:
{
"content-type"
:
"application/json"
},
body
:
JSON
.
stringify
(
receivers
[
id
]),
method
:
"PUT"
};
clearOld
();
fetch
(
"/rx_params/"
+
id
,
otherParams
)
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
res
=>
{
updateRx
(
showReceivers
,
id
)
})
.
then
(
res
=>
{
loadCzml
()
})
//.catch(error=>{console.log(error)})
// updateRx(showReceivers, id);
// loadCzml();
}
}
const
otherParams
=
{
headers
:{
"content-type"
:
"application/json"
},
body
:
JSON
.
stringify
(
receivers
[
id
]),
method
:
"PUT"
};
clearOld
();
fetch
(
"/rx_params/"
+
id
,
otherParams
)
.
then
(
data
=>
{
return
data
.
json
()})
.
then
(
res
=>
{
updateRx
(
showReceivers
,
id
)})
.
then
(
res
=>
{
loadCzml
()})
//.catch(error=>{console.log(error)})
// updateRx(showReceivers, id);
// loadCzml();
}
}
}
// ****************************************************
// ****************************************************
// * Sends Rx station URL to backend and refreshes map
// * Sends Rx station URL to backend and refreshes map
// ****************************************************
// ****************************************************
function
makeNewRx
(
url
)
{
function
makeNewRx
(
url
)
{
const
new_rx
=
{
"station_url"
:
url
};
const
new_rx
=
{
"station_url"
:
url
};
// console.log(new_rx);
// console.log(new_rx);
const
otherParams
=
{
const
otherParams
=
{
headers
:
{
headers
:
{
"content-type"
:
"application/json"
"content-type"
:
"application/json"
},
},
body
:
JSON
.
stringify
(
new_rx
),
body
:
JSON
.
stringify
(
new_rx
),
method
:
"PUT"
method
:
"PUT"
};
};
clearOld
();
clearOld
();
fetch
(
"/rx_params/new"
,
otherParams
)
fetch
(
"/rx_params/new"
,
otherParams
)
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
res
=>
{
updateRx
(
createReceivers
,
true
)
})
.
then
(
res
=>
{
updateRx
(
createReceivers
,
true
)
})
.
then
(
res
=>
{
loadCzml
()
})
.
then
(
res
=>
{
loadCzml
()
})
//.catch(error=>{console.log(error)})
//.catch(error=>{console.log(error)})
//.then(updateRx(createReceivers, true));
//.then(updateRx(createReceivers, true));
// loadCzml();
// loadCzml();
}
}
// *****************************************
// *****************************************
// * Removes the Rx UI Card
// * Removes the Rx UI Card
// *****************************************
// *****************************************
function
removerx
(
uid
)
{
function
removerx
(
uid
)
{
const
rxcard
=
document
.
getElementById
(
"rx-"
+
uid
);
const
rxcard
=
document
.
getElementById
(
"rx-"
+
uid
);
rxcard
.
remove
();
rxcard
.
remove
();
}
}
// *******************************************
// *******************************************
// * Removes Rx from Backend and Reloads Map
// * Removes Rx from Backend and Reloads Map
// *******************************************
// *******************************************
function
deleteReceiver
(
uid
)
{
function
deleteReceiver
(
uid
)
{
const
del_rx
=
{
"uid"
:
uid
};
const
del_rx
=
{
"uid"
:
uid
};
// console.log(new_rx);
// console.log(new_rx);
const
otherParams
=
{
const
otherParams
=
{
headers
:
{
headers
:
{
"content-type"
:
"application/json"
"content-type"
:
"application/json"
},
},
body
:
JSON
.
stringify
(
del_rx
),
body
:
JSON
.
stringify
(
del_rx
),
method
:
"PUT"
method
:
"PUT"
};
};
clearOld
();
clearOld
();
fetch
(
"/rx_params/del"
,
otherParams
)
fetch
(
"/rx_params/del"
,
otherParams
)
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
data
=>
{
return
data
.
json
()
})
.
then
(
res
=>
{
removerx
(
uid
)
})
.
then
(
res
=>
{
removerx
(
uid
)
})
.
then
(
res
=>
{
loadCzml
()
})
.
then
(
res
=>
{
loadCzml
()
})
//.catch(error=>{console.log(error)})
//.catch(error=>{console.log(error)})
//.then(updateRx(createReceivers, true));
//.then(updateRx(createReceivers, true));
// loadCzml();
// loadCzml();
}
}
// *******************************************
// *******************************************
// * Fills in Rx UI cards with Rx info
// * Fills in Rx UI cards with Rx info
// *******************************************
// *******************************************
function
showReceivers
(
rx_json
,
id
)
{
function
showReceivers
(
rx_json
,
id
)
{
const
receivers
=
rx_json
[
'receivers'
];
const
receivers
=
rx_json
[
'receivers'
];
var
stationUrlHtml
=
var
stationUrlHtml
=
"<input type=
\"
hidden
\"
id=
\"
url_"
+
id
+
"
\"
/>"
;
"<input type=
\"
hidden
\"
id=
\"
url_"
+
id
+
"
\"
/>"
;
var
stationIDhtml
=
var
stationIDhtml
=
"Station ID: <a href=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
target=
\"
_blank
\"
>"
+
receivers
[
id
].
station_id
+
"</a>"
;
"Station ID: <a href=
\"
"
+
receivers
[
id
].
station_url
+
"
\"
target=
\"
_blank
\"
>"
+
receivers
[
id
].
station_id
+
"</a>"
;
var
manualInfo
=
var
manualInfo
=
"<input type=
\"
hidden
\"
id=
\"
manual_toggle_"
+
receivers
[
id
].
uid
+
"
\"
/>"
;
"<input type=
\"
hidden
\"
id=
\"
manual_toggle_"
+
receivers
[
id
].
uid
+
"
\"
/>"
;
var
locationHtml
=
var
locationHtml
=
"Location: "
+
receivers
[
id
].
latitude
+
"°, "
+
receivers
[
id
].
longitude
+
"°"
;
"Location: "
+
receivers
[
id
].
latitude
+
"°, "
+
receivers
[
id
].
longitude
+
"°"
;
var
heading
=
var
heading
=
"Heading: "
+
receivers
[
id
].
heading
+
"°"
;
"Heading: "
+
receivers
[
id
].
heading
+
"°"
;
var
freqHtml
=
var
freqHtml
=
"Tuned to "
+
receivers
[
id
].
frequency
+
" MHz"
;
"Tuned to "
+
receivers
[
id
].
frequency
+
" MHz"
;
const
urlspan
=
document
.
getElementById
(
id
+
"-url"
);
const
urlspan
=
document
.
getElementById
(
id
+
"-url"
);
const
mobilespan
=
document
.
getElementById
(
id
+
"-mobile"
);
const
mobilespan
=
document
.
getElementById
(
id
+
"-mobile"
);
const
manualspan
=
document
.
getElementById
(
id
+
"-manual"
);
const
manualspan
=
document
.
getElementById
(
id
+
"-manual"
);
const
idspan
=
document
.
getElementById
(
id
+
"-id"
);
const
idspan
=
document
.
getElementById
(
id
+
"-id"
);
const
locationspan
=
document
.
getElementById
(
id
+
"-location"
);
const
locationspan
=
document
.
getElementById
(
id
+
"-location"
);
const
headingspan
=
document
.
getElementById
(
id
+
"-heading"
);
const
headingspan
=
document
.
getElementById
(
id
+
"-heading"
);
const
freqspan
=
document
.
getElementById
(
id
+
"-freq"
);
const
freqspan
=
document
.
getElementById
(
id
+
"-freq"
);
document
.
getElementById
(
id
+
"-mobile"
).
innerHTML
=
""
;
document
.
getElementById
(
id
+
"-mobile"
).
innerHTML
=
""
;
document
.
getElementById
(
id
+
"-editicon"
).
innerHTML
=
"edit"
;
document
.
getElementById
(
id
+
"-editicon"
).
innerHTML
=
"edit"
;
document
.
getElementById
(
id
+
"-manual"
).
innerHTML
=
manualInfo
;
document
.
getElementById
(
id
+
"-manual"
).
innerHTML
=
manualInfo
;
document
.
getElementById
(
id
+
"-url"
).
innerHTML
=
stationUrlHtml
;
document
.
getElementById
(
id
+
"-url"
).
innerHTML
=
stationUrlHtml
;
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
stationIDhtml
;
document
.
getElementById
(
id
+
"-id"
).
innerHTML
=
stationIDhtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
locationHtml
;
document
.
getElementById
(
id
+
"-location"
).
innerHTML
=
locationHtml
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
heading
;
document
.
getElementById
(
id
+
"-heading"
).
innerHTML
=
heading
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
freqHtml
;
document
.
getElementById
(
id
+
"-freq"
).
innerHTML
=
freqHtml
;
}
}
...
@@ -200,87 +200,87 @@ function showReceivers(rx_json, id) {
...
@@ -200,87 +200,87 @@ function showReceivers(rx_json, id) {
// * Iterates through Rx objects on page load/Rx add.
// * Iterates through Rx objects on page load/Rx add.
// ****************************************************
// ****************************************************
function
createReceivers
(
rx_json
,
id
)
{
function
createReceivers
(
rx_json
,
id
)
{
var
receivers
var
receivers
if
(
id
==
true
)
{
if
(
id
==
true
)
{
receivers
=
[
rx_json
[
'receivers'
][
Object
.
keys
(
rx_json
[
'receivers'
]).
length
-
1
]];
receivers
=
[
rx_json
[
'receivers'
][
Object
.
keys
(
rx_json
[
'receivers'
]).
length
-
1
]];
}
else
{
}
else
{
receivers
=
rx_json
[
'receivers'
];
receivers
=
rx_json
[
'receivers'
];
}
}
console
.
log
(
receivers
);
console
.
log
(
receivers
);
for
(
let
i
=
0
;
i
<
Object
.
keys
(
receivers
).
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
Object
.
keys
(
receivers
).
length
;
i
++
)
{
const
rxcard
=
document
.
createElement
(
'div'
);
const
rxcard
=
document
.
createElement
(
'div'
);
rxcard
.
className
=
"receiver"
;
rxcard
.
className
=
"receiver"
;
rxcard
.
id
=
"rx-"
+
receivers
[
i
].
uid
;
rxcard
.
id
=
"rx-"
+
receivers
[
i
].
uid
;
const
urlspan
=
document
.
createElement
(
'span'
);
const
urlspan
=
document
.
createElement
(
'span'
);
const
mobilespan
=
document
.
createElement
(
'span'
);
const
mobilespan
=
document
.
createElement
(
'span'
);
const
manualspan
=
document
.
createElement
(
'span'
);
const
manualspan
=
document
.
createElement
(
'span'
);
const
idspan
=
document
.
createElement
(
'span'
);
const
idspan
=
document
.
createElement
(
'span'
);
const
locationspan
=
document
.
createElement
(
'span'
);
const
locationspan
=
document
.
createElement
(
'span'
);
const
headingspan
=
document
.
createElement
(
'span'
);
const
headingspan
=
document
.
createElement
(
'span'
);
const
freqspan
=
document
.
createElement
(
'span'
);
const
freqspan
=
document
.
createElement
(
'span'
);
const
editiconspan
=
document
.
createElement
(
'span'
);
const
editiconspan
=
document
.
createElement
(
'span'
);
editiconspan
.
classList
.
add
(
"material-icons"
,
"edit-icon"
,
"no-select"
);
editiconspan
.
classList
.
add
(
"material-icons"
,
"edit-icon"
,
"no-select"
);
editiconspan
.
innerHTML
=
"edit"
;
editiconspan
.
innerHTML
=
"edit"
;
const
editcheck
=
document
.
createElement
(
'input'
);
const
editcheck
=
document
.
createElement
(
'input'
);
editcheck
.
classList
.
add
(
"edit-checkbox"
,
"edit-icon"
);
editcheck
.
classList
.
add
(
"edit-checkbox"
,
"edit-icon"
);
editcheck
.
type
=
'checkbox'
;
editcheck
.
type
=
'checkbox'
;
editcheck
.
id
=
receivers
[
i
].
uid
+
"-edit"
;
editcheck
.
id
=
receivers
[
i
].
uid
+
"-edit"
;
editcheck
.
setAttribute
(
'onclick'
,
"updateRx(editReceivers, "
+
receivers
[
i
].
uid
+
")"
);
editcheck
.
setAttribute
(
'onclick'
,
"updateRx(editReceivers, "
+
receivers
[
i
].
uid
+
")"
);
const
deleteiconspan
=
document
.
createElement
(
'span'
);
const
deleteiconspan
=
document
.
createElement
(
'span'
);
deleteiconspan
.
classList
.
add
(
"material-icons"
,
"delete-icon"
,
"no-select"
);
deleteiconspan
.
classList
.
add
(
"material-icons"
,
"delete-icon"
,
"no-select"
);
deleteiconspan
.
innerHTML
=
"delete"
;
deleteiconspan
.
innerHTML
=
"delete"
;
const
deletecheck
=
document
.
createElement
(
'input'
);
const
deletecheck
=
document
.
createElement
(
'input'
);
deletecheck
.
classList
.
add
(
"edit-checkbox"
,
"delete-icon"
);
deletecheck
.
classList
.
add
(
"edit-checkbox"
,
"delete-icon"
);
deletecheck
.
type
=
'checkbox'
;
deletecheck
.
type
=
'checkbox'
;
deletecheck
.
id
=
receivers
[
i
].
uid
+
"-delete"
;
deletecheck
.
id
=
receivers
[
i
].
uid
+
"-delete"
;
deletecheck
.
setAttribute
(
'onclick'
,
"deleteReceiver("
+
receivers
[
i
].
uid
+
")"
);
deletecheck
.
setAttribute
(
'onclick'
,
"deleteReceiver("
+
receivers
[
i
].
uid
+
")"
);
urlspan
.
id
=
receivers
[
i
].
uid
+
"-url"
;
urlspan
.
id
=
receivers
[
i
].
uid
+
"-url"
;
mobilespan
.
id
=
receivers
[
i
].
uid
+
"-mobile"
;
mobilespan
.
id
=
receivers
[
i
].
uid
+
"-mobile"
;
manualspan
.
id
=
receivers
[
i
].
uid
+
"-manual"
;
manualspan
.
id
=
receivers
[
i
].
uid
+
"-manual"
;
idspan
.
id
=
receivers
[
i
].
uid
+
"-id"
;
idspan
.
id
=
receivers
[
i
].
uid
+
"-id"
;
locationspan
.
id
=
receivers
[
i
].
uid
+
"-location"
;
locationspan
.
id
=
receivers
[
i
].
uid
+
"-location"
;
headingspan
.
id
=
receivers
[
i
].
uid
+
"-heading"
;
headingspan
.
id
=
receivers
[
i
].
uid
+
"-heading"
;
freqspan
.
id
=
receivers
[
i
].
uid
+
"-freq"
;
freqspan
.
id
=
receivers
[
i
].
uid
+
"-freq"
;
editiconspan
.
id
=
receivers
[
i
].
uid
+
"-editicon"
;
editiconspan
.
id
=
receivers
[
i
].
uid
+
"-editicon"
;
document
.
getElementById
(
"menu"
).
insertBefore
(
rxcard
,
document
.
getElementById
(
"add_station"
));
document
.
getElementById
(
"menu"
).
insertBefore
(
rxcard
,
document
.
getElementById
(
"add_station"
));
rxcard
.
appendChild
(
urlspan
);
rxcard
.
appendChild
(
urlspan
);
rxcard
.
appendChild
(
mobilespan
);
rxcard
.
appendChild
(
mobilespan
);
rxcard
.
appendChild
(
manualspan
);
rxcard
.
appendChild
(
manualspan
);
rxcard
.
appendChild
(
idspan
);
rxcard
.
appendChild
(
idspan
);
rxcard
.
appendChild
(
locationspan
);
rxcard
.
appendChild
(
locationspan
);
rxcard
.
appendChild
(
headingspan
);
rxcard
.
appendChild
(
headingspan
);
rxcard
.
appendChild
(
freqspan
);
rxcard
.
appendChild
(
freqspan
);
rxcard
.
appendChild
(
editiconspan
);
rxcard
.
appendChild
(
editiconspan
);
rxcard
.
appendChild
(
deleteiconspan
);
rxcard
.
appendChild
(
deleteiconspan
);
rxcard
.
appendChild
(
editcheck
);
rxcard
.
appendChild
(
editcheck
);
rxcard
.
appendChild
(
deletecheck
);
rxcard
.
appendChild
(
deletecheck
);
showReceivers
(
rx_json
,
receivers
[
i
].
uid
);
showReceivers
(
rx_json
,
i
);
}
}
}
}
// ****************************************************
// ****************************************************
// * Refreshes info on Rx UI Cards (Refresh button)
// * Refreshes info on Rx UI Cards (Refresh button)
// ****************************************************
// ****************************************************
function
refreshRx
(
rx_json
,
id
)
{
function
refreshRx
(
rx_json
,
id
)
{
const
receivers
=
rx_json
[
'receivers'
];
const
receivers
=
rx_json
[
'receivers'
];
for
(
let
i
=
0
;
i
<
Object
.
keys
(
receivers
).
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
Object
.
keys
(
receivers
).
length
;
i
++
)
{
showReceivers
(
rx_json
,
receivers
[
i
].
uid
);
showReceivers
(
rx_json
,
receivers
[
i
].
uid
);
}
}
}
}
// ****************************************************
// ****************************************************
// * Main function - Loads all Receivers
// * Main function - Loads all Receivers
// ****************************************************
// ****************************************************
function
loadRx
(
action
)
{
function
loadRx
(
action
)
{
updateRx
(
action
,
null
);
updateRx
(
action
,
null
);
}
}
\ No newline at end of file
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