Skip to content
Snippets Groups Projects
Commit 1df8d745 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

added benchmark.py

added LabelAttributeTableModel.shortcuts(QgsField)->list of auto-labels
parent 3fc7ba74
No related branches found
No related tags found
No related merge requests found
import numpy as np
import time
from timeseriesviewer.main import TimeSeriesViewer
from timeseriesviewer.utils import file_search
pathSrc = r''
files = file_search(pathSrc, recursive=True, '*BOA.bsq')
t_start = time.time()
EOTSV = TimeSeriesViewer()
EOTSV.show()
t_start = time.time() - t_start
print('Start & show EOTSV: {}'.format(t_start))
t_addImages = time.time()
EOTSV.addTimeSeriesImages()
t_addImages = time.time() - t_addImages()
print('Add {} images: {}'.format(len(files), t_start))
EOTSV.spatialTemporalVis.setMapSize(QSize(200,200))
t_load200px = time.time()
EOTSV.spatialTemporalVis.timedCanvasRefresh()
t_load200px = time.time() - t_load200px
......@@ -125,6 +125,11 @@ class testclassLabelingTest(unittest.TestCase):
dock.setFieldShortCut('class2l', LabelShortCutType.Off)
dock.setFieldShortCut('class2n', LabelShortCutType.Off)
for name in lyr.fields().names():
options = model.shortcuts(name)
self.assertIsInstance(options, list)
self.assertTrue(len(options) > 0)
m = dock.mLabelAttributeModel
self.assertIsInstance(m, LabelAttributeTableModel)
self.assertTrue(m.data(m.createIndex(3, 0), Qt.DisplayRole) == 'sensor')
......
......@@ -14,12 +14,12 @@ from timeseriesviewer.timeseries import TimeSeriesDatum
class LabelShortCutType(enum.Enum):
"""Enumeration for shortcuts to be derived from a TimeSeriesDatum instance"""
Off = 0
Date = 1
DOY = 2
DecimalYear = 3
Sensor = 4
ClassLabel = 5
Off = 'No label shortcut'
Date = 'Date-Time'
DOY = 'Day of Year (DOY)'
Year = 'Year'
DecimalYear = 'Decimal year'
Sensor = 'Sensor name'
......@@ -194,6 +194,43 @@ class LabelAttributeTableModel(QAbstractTableModel):
self.setData(self.createIndex(idx.row(), 2), attributeType, role=Qt.EditRole)
def shortcuts(self, field:QgsField):
"""
Returns the possible LabelShortCutTypes for a certain field
:param fieldName: str
:return: [list]
"""
if not self.hasVectorLayer():
return []
if isinstance(field, QModelIndex):
field = self.index2field(field)
if isinstance(field, str):
i = self.mVectorLayer.fields().lookupField(field)
field = self.mVectorLayer.fields().at(i)
assert isinstance(field, QgsField)
shortCutsString = [LabelShortCutType.Sensor, LabelShortCutType.Date]
shortCutsInt = [LabelShortCutType.Year, LabelShortCutType.DOY]
shortCutsFloat = [LabelShortCutType.DecimalYear]
options = [LabelShortCutType.Off]
t = field.typeName().lower()
if t == 'string':
options.extend(shortCutsString)
options.extend(shortCutsInt)
options.extend(shortCutsFloat)
elif t.startswith('integer'):
options.extend(shortCutsInt)
elif t.startswith('real'):
options.extend(shortCutsInt)
options.extend(shortCutsFloat)
else:
s = ""
return options
def data(self, index, role = Qt.DisplayRole):
if role is None or not index.isValid():
......@@ -299,8 +336,10 @@ class LabelAttributeTypeWidgetDelegate(QStyledItemDelegate):
if index.isValid() and isinstance(model, LabelAttributeTableModel):
if cname == model.cnLabel:
w = QComboBox(parent=parent)
for i in list(LabelShortCutType):
w.addItem(i.name, i)
for i, shortcutType in enumerate(model.shortcuts(index)):
assert isinstance(shortcutType, LabelShortCutType)
w.addItem(shortcutType.name, shortcutType)
w.setItemData(i, shortcutType.value, Qt.ToolTipRole)
return w
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment