Add modulation filters algorithm

This commit is contained in:
alessandro90
2018-11-11 19:01:06 +01:00
parent 89f3d39511
commit 3a30c5e3c2
4 changed files with 83 additions and 46 deletions

View File

@@ -10,7 +10,7 @@ class DoubleTextButton(QPushButton):
self.__text_a = text_a self.__text_a = text_a
self.__text_b = text_b self.__text_b = text_b
def set_slave_filters(self, simple_ones, def set_slave_filters(self, simple_ones = None,
radio_1 = None, radio_1 = None,
ruled_by_radio_1 = None, ruled_by_radio_1 = None,
radio_2 = None, radio_2 = None,

62
main.py
View File

@@ -13,7 +13,7 @@ from PyQt5.QtWidgets import (QMainWindow,
QListWidgetItem, QListWidgetItem,
QTreeView, QTreeView,
QTreeWidgetItem) QTreeWidgetItem)
from PyQt5.QtGui import QPixmap, QStandardItemModel, QStandardItem from PyQt5.QtGui import QPixmap
from PyQt5 import uic from PyQt5 import uic
from PyQt5.QtCore import (QFileInfo, from PyQt5.QtCore import (QFileInfo,
QSize, QSize,
@@ -108,7 +108,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.upper_freq_confidence) self.upper_freq_confidence)
) )
self.apply_remove_freq_filter_btn.set_texts("Apply", "Remove") self.apply_remove_freq_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE)
self.apply_remove_freq_filter_btn.set_slave_filters( self.apply_remove_freq_filter_btn.set_slave_filters(
[ [
*self.frequency_filters_btns, *self.frequency_filters_btns,
@@ -184,7 +184,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.upper_band_confidence) self.upper_band_confidence)
) )
self.apply_remove_band_filter_btn.set_texts("Apply", "Remove") self.apply_remove_band_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE)
self.apply_remove_band_filter_btn.set_slave_filters( self.apply_remove_band_filter_btn.set_slave_filters(
[ [
self.include_undef_bands, self.include_undef_bands,
@@ -228,7 +228,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.number_stations_btn, self.number_stations_btn,
self.time_signal_btn,] self.time_signal_btn,]
self.apply_remove_cat_filter_btn.set_texts('Apply', 'Remove') self.apply_remove_cat_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE)
self.apply_remove_cat_filter_btn.set_slave_filters([*self.cat_filter_btns, self.apply_remove_cat_filter_btn.set_slave_filters([*self.cat_filter_btns,
self.cat_at_least_one, self.cat_at_least_one,
self.cat_all]) self.cat_all])
@@ -274,7 +274,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.set_mode_tree_widget() self.set_mode_tree_widget()
self.mode_tree_widget.itemSelectionChanged.connect(self.manage_mode_selections) self.mode_tree_widget.itemSelectionChanged.connect(self.manage_mode_selections)
self.reset_mode_filters_btn.clicked.connect(self.reset_mode_filters) self.reset_mode_filters_btn.clicked.connect(self.reset_mode_filters)
self.apply_remove_mode_filter_btn.set_texts("Apply", "Remove") self.apply_remove_mode_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE)
self.apply_remove_mode_filter_btn.set_slave_filters([self.mode_tree_widget, self.apply_remove_mode_filter_btn.set_slave_filters([self.mode_tree_widget,
self.include_unknown_modes_btn]) self.include_unknown_modes_btn])
self.apply_remove_mode_filter_btn.clicked.connect(self.display_signals) self.apply_remove_mode_filter_btn.clicked.connect(self.display_signals)
@@ -283,10 +283,17 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.modulation_list.addItems(Constants.MODULATIONS) self.modulation_list.addItems(Constants.MODULATIONS)
self.search_bar_modulation.textEdited.connect(self.show_matching_modulations) self.search_bar_modulation.textEdited.connect(self.show_matching_modulations)
self.apply_remove_modulation_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE)
self.apply_remove_modulation_filter_btn.set_slave_filters([self.search_bar_modulation,
self.modulation_list])
self.apply_remove_modulation_filter_btn.clicked.connect(self.display_signals)
self.reset_modulation_filters_btn.clicked.connect(self.reset_modulation_filters)
# ########################################################################################## # ##########################################################################################
self.load_db() self.load_db()
# Left list widget and search bar.
self.search_bar.textChanged.connect(self.display_signals) self.search_bar.textChanged.connect(self.display_signals)
self.result_list.addItems(self.signal_names) self.result_list.addItems(self.signal_names)
self.result_list.currentItemChanged.connect(self.display_specs) self.result_list.currentItemChanged.connect(self.display_specs)
@@ -319,8 +326,12 @@ class MyApp(QMainWindow, Ui_MainWindow):
@pyqtSlot(str) @pyqtSlot(str)
def show_matching_modulations(self, text): def show_matching_modulations(self, text):
pass for index in range(self.modulation_list.count()):
# for modulation in item = self.modulation_list.item(index)
if self.search_bar_modulation.text().upper() in item.text() or item.isSelected():
item.setHidden(False)
else:
item.setHidden(True)
def set_mode_tree_widget(self): def set_mode_tree_widget(self):
for parent, children in Constants.MODES.items(): for parent, children in Constants.MODES.items():
@@ -434,7 +445,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
else: else:
self.signal_names = self.db.index self.signal_names = self.db.index
self.total_signals = len(self.signal_names) self.total_signals = len(self.signal_names)
self.db.fillna("N/A", inplace = True) self.db.fillna(Constants.UNKNOWN, inplace = True)
self.db["url_clicked"] = False self.db["url_clicked"] = False
self.update_status_tip(self.total_signals) self.update_status_tip(self.total_signals)
@@ -536,11 +547,12 @@ class MyApp(QMainWindow, Ui_MainWindow):
text = self.search_bar.text() text = self.search_bar.text()
available_signals = 0 available_signals = 0
for index, signal in enumerate(self.signal_names): for index, signal in enumerate(self.signal_names):
if text.lower() in signal.lower() and \ if all([text.lower() in signal.lower() ,
self.frequency_filters_ok(signal) and \ self.frequency_filters_ok(signal) ,
self.band_filters_ok(signal) and \ self.band_filters_ok(signal) ,
self.category_filters_ok(signal) and \ self.category_filters_ok(signal) ,
self.mode_filters_ok(signal): self.mode_filters_ok(signal) ,
self.modulation_filters_ok(signal)]):
self.result_list.item(index).setHidden(False) self.result_list.item(index).setHidden(False)
available_signals += 1 available_signals += 1
self.update_status_tip(available_signals) self.update_status_tip(available_signals)
@@ -599,6 +611,14 @@ class MyApp(QMainWindow, Ui_MainWindow):
if self.include_unknown_modes_btn.isChecked(): if self.include_unknown_modes_btn.isChecked():
self.include_unknown_modes_btn.setChecked(False) self.include_unknown_modes_btn.setChecked(False)
@pyqtSlot()
def reset_modulation_filters(self):
reset_apply_remove_btn(self.apply_remove_modulation_filter_btn)
self.search_bar_modulation.setText('')
for i in range(self.modulation_list.count()):
if self.modulation_list.item(i).isSelected():
self.modulation_list.item(i).setSelected(False)
def frequency_filters_ok(self, signal_name): def frequency_filters_ok(self, signal_name):
if not self.apply_remove_freq_filter_btn.isChecked(): if not self.apply_remove_freq_filter_btn.isChecked():
return True return True
@@ -700,6 +720,15 @@ class MyApp(QMainWindow, Ui_MainWindow):
ok.append(item.text(0) == signal_mode) ok.append(item.text(0) == signal_mode)
return any(ok) return any(ok)
def modulation_filters_ok(self, signal_name):
if not self.apply_remove_modulation_filter_btn.isChecked():
return True
signal_modulation = self.db.at[signal_name, "modulation"]
for item in self.modulation_list.selectedItems():
if item.text() == signal_modulation:
return True
return False
@staticmethod @staticmethod
def filters_ok(spinbox, filter_unit, confidence, sign = 1): def filters_ok(spinbox, filter_unit, confidence, sign = 1):
band_filter = spinbox.value() * Constants.CONVERSION_FACTORS[filter_unit.currentText()] band_filter = spinbox.value() * Constants.CONVERSION_FACTORS[filter_unit.currentText()]
@@ -755,7 +784,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.name_lab.setText("No signal") self.name_lab.setText("No signal")
self.name_lab.setAlignment(Qt.AlignHCenter) self.name_lab.setAlignment(Qt.AlignHCenter)
for lab in self.property_labels: for lab in self.property_labels:
lab.setText("N/A") lab.setText(Constants.UNKNOWN)
for lab in self.category_labels: for lab in self.category_labels:
lab.setStyleSheet(f"color: {Constants.INACTIVE_COLOR};") lab.setStyleSheet(f"color: {Constants.INACTIVE_COLOR};")
self.set_band_range() self.set_band_range()
@@ -765,13 +794,13 @@ class MyApp(QMainWindow, Ui_MainWindow):
def is_undef_freq(current_signal): def is_undef_freq(current_signal):
lower_freq = current_signal.at["inf_freq"] lower_freq = current_signal.at["inf_freq"]
upper_freq = current_signal.at["sup_freq"] upper_freq = current_signal.at["sup_freq"]
return lower_freq == 'N/A' or upper_freq == 'N/A' return lower_freq == Constants.UNKNOWN or upper_freq == Constants.UNKNOWN
@staticmethod @staticmethod
def is_undef_band(current_signal): def is_undef_band(current_signal):
lower_band = current_signal.at["inf_band"] lower_band = current_signal.at["inf_band"]
upper_band = current_signal.at["sup_band"] upper_band = current_signal.at["sup_band"]
return lower_band == 'N/A' or upper_band == 'N/A' return lower_band == Constants.UNKNOWN or upper_band == Constants.UNKNOWN
@classmethod @classmethod
def format_numbers(cls, lower, upper): def format_numbers(cls, lower, upper):
@@ -848,6 +877,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.reset_band_filters_btn.clicked.emit() self.reset_band_filters_btn.clicked.emit()
self.reset_cat_filters_btn.clicked.emit() self.reset_cat_filters_btn.clicked.emit()
self.reset_mode_filters_btn.clicked.emit() self.reset_mode_filters_btn.clicked.emit()
self.reset_modulation_filters_btn.clicked.emit()
@pyqtSlot() @pyqtSlot()
def go_to_web_page_signal(self): def go_to_web_page_signal(self):

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1206</width> <width>1206</width>
<height>638</height> <height>634</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@@ -3938,7 +3938,10 @@ QWidget#xFM_container, QWidget#xSK_container, QWidget#xSB_container{
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QPushButton" name="apply_remove_modulation_filter_btn"> <widget class="DoubleTextButton" name="apply_remove_modulation_filter_btn">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font"> <property name="font">
<font> <font>
<pointsize>12</pointsize> <pointsize>12</pointsize>
@@ -3949,6 +3952,9 @@ QWidget#xFM_container, QWidget#xSK_container, QWidget#xSB_container{
<property name="text"> <property name="text">
<string>Apply</string> <string>Apply</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View File

@@ -46,32 +46,34 @@ class Constants(object):
"RAW": [], "RAW": [],
"SC-FDMA": [],} "SC-FDMA": [],}
) )
UNKNOWN = "Unknown" APPLY = _ReadOnlyProperty("Apply")
MODULATIONS = ["8VSB", REMOVE = _ReadOnlyProperty("Remove")
"AFSK", UNKNOWN = _ReadOnlyProperty("N/A")
"AM", MODULATIONS = _ReadOnlyProperty(["8VSB",
"BFSK", "AFSK",
"C4FM", "AM",
"CDMA", "BFSK",
"COFDM", "C4FM",
"CW", "CDMA",
"FFSK", "COFDM",
"FM", "CW",
"FMCW", "FFSK",
"FMOP", "FM",
"FSK", "FMCW",
"GFSK", "FMOP",
"GMSK", "FSK",
"IFK", "GFSK",
"MFSK", "GMSK",
"MSK", "IFK",
"OFDM", "MFSK",
"OOK", "MSK",
"PAM", "OFDM",
"PPM", "OOK",
"PSK", "PAM",
"QAM", "PPM",
"TDMA",] "PSK",
"QAM",
"TDMA",])
def reset_apply_remove_btn(button): def reset_apply_remove_btn(button):
@@ -79,7 +81,6 @@ def reset_apply_remove_btn(button):
button.setChecked(False) button.setChecked(False)
button.clicked.emit() button.clicked.emit()
def checksum_ok(data, what): def checksum_ok(data, what):
code = hashlib.sha256() code = hashlib.sha256()
code.update(data) code.update(data)