Skip to content

Commit

Permalink
Add score column by calculating freq*length.
Browse files Browse the repository at this point in the history
Signed-off-by: Slendi <[email protected]>
  • Loading branch information
xslendix committed Aug 21, 2023
1 parent c71960e commit cf35859
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/nexus/Freqlog/Definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, word: str, frequency: int, last_used: datetime, average_speed
self.frequency = frequency
self.last_used = last_used
self.average_speed = average_speed
self.score = len(word) * frequency

def __or__(self, other: Any) -> Self:
"""Merge two WordMetadata objects"""
Expand All @@ -62,7 +63,7 @@ def __or__(self, other: Any) -> Self:

def __str__(self) -> str:
return f"Word: {self.word} | Frequency: {self.frequency} | Last used: {self.last_used} | " \
f"Average speed: {self.average_speed}"
f"Average speed: {self.average_speed} | Score: {self.score}"


class WordMetadataAttr(Enum):
Expand All @@ -71,6 +72,7 @@ class WordMetadataAttr(Enum):
frequency = "frequency"
last_used = "lastused"
average_speed = "avgspeed"
score = "score"


class ChordMetadata:
Expand Down
4 changes: 2 additions & 2 deletions src/nexus/Freqlog/Freqlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def list_words(self, limit: int = -1, sort_by: WordMetadataAttr = WordMetadataAt
"""
List words in the store
:param limit: Maximum number of words to return
:param sort_by: Attribute to sort by: word, frequency, last_used, average_speed
:param sort_by: Attribute to sort by: word, frequency, last_used, average_speed, score
:param reverse: Reverse sort order
:param case: Case sensitivity
"""
Expand All @@ -282,7 +282,7 @@ def export_words_to_csv(self, export_path: str, limit: int = -1,
Export words in the store
:param export_path: Path to csv file to export to
:param limit: Maximum number of words to return
:param sort_by: Attribute to sort by: word, frequency, last_used, average_speed
:param sort_by: Attribute to sort by: word, frequency, last_used, average_speed, score
:param reverse: Reverse sort order
:param case: Case sensitivity
:return: Number of words exported
Expand Down
3 changes: 3 additions & 0 deletions src/nexus/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def refresh(self):
item = QTableWidgetItem()
item.setData(Qt.ItemDataRole.DisplayRole, str(word.average_speed)[2:-3])
self.chentry_table.setItem(i, 3, item)
item = QTableWidgetItem()
item.setData(Qt.ItemDataRole.DisplayRole, word.score)
self.chentry_table.setItem(i, 4, item)

self.chentry_table.setRowCount(len(words))
self.chentry_table.resizeColumnsToContents()
Expand Down
24 changes: 14 additions & 10 deletions translations/i18n_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,56 +83,55 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/nexus/GUI.py" line="108"/>
<location filename="../src/nexus/GUI.py" line="140"/>
<location filename="../src/nexus/GUI.py" line="142"/>
<source>GUI</source>
<comment>Start logging</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="110"/>
<location filename="../src/nexus/GUI.py" line="111"/>
<source>GUI</source>
<comment>Starting...</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="121"/>
<location filename="../src/nexus/GUI.py" line="122"/>
<source>GUI</source>
<comment>Stop logging</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="125"/>
<location filename="../src/nexus/GUI.py" line="127"/>
<source>GUI</source>
<comment>Logging started</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="144"/>
<location filename="../src/nexus/GUI.py" line="147"/>
<source>GUI</source>
<comment>Logging stopped</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="177"/>
<location filename="../src/nexus/GUI.py" line="183"/>
<source>GUI</source>
<comment>Loaded {} freqlogged words</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="240"/>
<location filename="../src/nexus/GUI.py" line="246"/>
<source>GUI</source>
<comment>Unban {} words</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="242"/>
<location filename="../src/nexus/GUI.py" line="248"/>
<source>GUI</source>
<comment>Unban one word</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="259"/>
<location filename="../src/nexus/GUI.py" line="265"/>
<source>GUI</source>
<comment>Exported {} words to {}</comment>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -206,5 +205,10 @@
<source>Avg speed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/main.ui" line="194"/>
<source>Score</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
7 changes: 6 additions & 1 deletion ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<bool>false</bool>
</property>
<property name="columnCount">
<number>4</number>
<number>5</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
Expand Down Expand Up @@ -189,6 +189,11 @@
<string>Avg speed</string>
</property>
</column>
<column>
<property name="text">
<string>Score</string>
</property>
</column>
</widget>
</item>
</layout>
Expand Down

0 comments on commit cf35859

Please sign in to comment.