Add idle time to session log and writing stats dialog
This commit is contained in:
@@ -47,6 +47,7 @@ class OptionState():
|
|||||||
"widthCol0",
|
"widthCol0",
|
||||||
"widthCol1",
|
"widthCol1",
|
||||||
"widthCol2",
|
"widthCol2",
|
||||||
|
"widthCol3",
|
||||||
"sortCol",
|
"sortCol",
|
||||||
"sortOrder",
|
"sortOrder",
|
||||||
"incNovel",
|
"incNovel",
|
||||||
|
|||||||
+7
-6
@@ -726,12 +726,12 @@ class NWProject():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def closeProject(self):
|
def closeProject(self, idleTime=0):
|
||||||
"""Close the current project and clear all meta data.
|
"""Close the current project and clear all meta data.
|
||||||
"""
|
"""
|
||||||
self.optState.saveSettings()
|
self.optState.saveSettings()
|
||||||
self.projTree.writeToCFile()
|
self.projTree.writeToCFile()
|
||||||
self._appendSessionStats()
|
self._appendSessionStats(idleTime)
|
||||||
self._clearLockFile()
|
self._clearLockFile()
|
||||||
self.clearProject()
|
self.clearProject()
|
||||||
self.lockedBy = None
|
self.lockedBy = None
|
||||||
@@ -1389,7 +1389,7 @@ class NWProject():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _appendSessionStats(self):
|
def _appendSessionStats(self, idleTime):
|
||||||
"""Append session statistics to the sessions log file.
|
"""Append session statistics to the sessions log file.
|
||||||
"""
|
"""
|
||||||
if not self.ensureFolderStructure():
|
if not self.ensureFolderStructure():
|
||||||
@@ -1404,15 +1404,16 @@ class NWProject():
|
|||||||
# It's a new file, so add a header
|
# It's a new file, so add a header
|
||||||
if self.lastWCount > 0:
|
if self.lastWCount > 0:
|
||||||
outFile.write("# Offset %d\n" % self.lastWCount)
|
outFile.write("# Offset %d\n" % self.lastWCount)
|
||||||
outFile.write("# %-17s %-19s %8s %8s\n" % (
|
outFile.write("# %-17s %-19s %8s %8s %8s\n" % (
|
||||||
"Start Time", "End Time", "Novel", "Notes"
|
"Start Time", "End Time", "Novel", "Notes", "Idle"
|
||||||
))
|
))
|
||||||
|
|
||||||
outFile.write("%-19s %-19s %8d %8d\n" % (
|
outFile.write("%-19s %-19s %8d %8d %8d\n" % (
|
||||||
formatTimeStamp(self.projOpened),
|
formatTimeStamp(self.projOpened),
|
||||||
formatTimeStamp(time()),
|
formatTimeStamp(time()),
|
||||||
self.novelWCount,
|
self.novelWCount,
|
||||||
self.notesWCount,
|
self.notesWCount,
|
||||||
|
int(idleTime),
|
||||||
))
|
))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
+54
-25
@@ -48,8 +48,9 @@ class GuiWritingStats(QDialog):
|
|||||||
|
|
||||||
C_TIME = 0
|
C_TIME = 0
|
||||||
C_LENGTH = 1
|
C_LENGTH = 1
|
||||||
C_COUNT = 2
|
C_IDLE = 2
|
||||||
C_BAR = 3
|
C_COUNT = 3
|
||||||
|
C_BAR = 4
|
||||||
|
|
||||||
FMT_JSON = 0
|
FMT_JSON = 0
|
||||||
FMT_CSV = 1
|
FMT_CSV = 1
|
||||||
@@ -89,16 +90,21 @@ class GuiWritingStats(QDialog):
|
|||||||
wCol2 = self.mainConf.pxInt(
|
wCol2 = self.mainConf.pxInt(
|
||||||
self.optState.getInt("GuiWritingStats", "widthCol2", 80)
|
self.optState.getInt("GuiWritingStats", "widthCol2", 80)
|
||||||
)
|
)
|
||||||
|
wCol3 = self.mainConf.pxInt(
|
||||||
|
self.optState.getInt("GuiWritingStats", "widthCol3", 80)
|
||||||
|
)
|
||||||
|
|
||||||
self.listBox = QTreeWidget()
|
self.listBox = QTreeWidget()
|
||||||
self.listBox.setHeaderLabels(["Session Start", "Length", "Words", "Histogram"])
|
self.listBox.setHeaderLabels(["Session Start", "Length", "Idle", "Words", "Histogram"])
|
||||||
self.listBox.setIndentation(0)
|
self.listBox.setIndentation(0)
|
||||||
self.listBox.setColumnWidth(self.C_TIME, wCol0)
|
self.listBox.setColumnWidth(self.C_TIME, wCol0)
|
||||||
self.listBox.setColumnWidth(self.C_LENGTH, wCol1)
|
self.listBox.setColumnWidth(self.C_LENGTH, wCol1)
|
||||||
self.listBox.setColumnWidth(self.C_COUNT, wCol2)
|
self.listBox.setColumnWidth(self.C_IDLE, wCol2)
|
||||||
|
self.listBox.setColumnWidth(self.C_COUNT, wCol3)
|
||||||
|
|
||||||
hHeader = self.listBox.headerItem()
|
hHeader = self.listBox.headerItem()
|
||||||
hHeader.setTextAlignment(self.C_LENGTH, Qt.AlignRight)
|
hHeader.setTextAlignment(self.C_LENGTH, Qt.AlignRight)
|
||||||
|
hHeader.setTextAlignment(self.C_IDLE, Qt.AlignRight)
|
||||||
hHeader.setTextAlignment(self.C_COUNT, Qt.AlignRight)
|
hHeader.setTextAlignment(self.C_COUNT, Qt.AlignRight)
|
||||||
|
|
||||||
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
|
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
|
||||||
@@ -127,6 +133,10 @@ class GuiWritingStats(QDialog):
|
|||||||
self.labelTotal.setFont(self.theTheme.guiFontFixed)
|
self.labelTotal.setFont(self.theTheme.guiFontFixed)
|
||||||
self.labelTotal.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
self.labelTotal.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
||||||
|
|
||||||
|
self.labelIdleT = QLabel(formatTime(0))
|
||||||
|
self.labelIdleT.setFont(self.theTheme.guiFontFixed)
|
||||||
|
self.labelIdleT.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
||||||
|
|
||||||
self.labelFilter = QLabel(formatTime(0))
|
self.labelFilter = QLabel(formatTime(0))
|
||||||
self.labelFilter.setFont(self.theTheme.guiFontFixed)
|
self.labelFilter.setFont(self.theTheme.guiFontFixed)
|
||||||
self.labelFilter.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
self.labelFilter.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
||||||
@@ -144,16 +154,18 @@ class GuiWritingStats(QDialog):
|
|||||||
self.totalWords.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
self.totalWords.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
|
||||||
|
|
||||||
self.infoForm.addWidget(QLabel("Total Time:"), 0, 0)
|
self.infoForm.addWidget(QLabel("Total Time:"), 0, 0)
|
||||||
self.infoForm.addWidget(QLabel("Filtered Time:"), 1, 0)
|
self.infoForm.addWidget(QLabel("Idle Time:"), 1, 0)
|
||||||
self.infoForm.addWidget(QLabel("Novel Word Count:"), 2, 0)
|
self.infoForm.addWidget(QLabel("Filtered Time:"), 2, 0)
|
||||||
self.infoForm.addWidget(QLabel("Notes Word Count:"), 3, 0)
|
self.infoForm.addWidget(QLabel("Novel Word Count:"), 3, 0)
|
||||||
self.infoForm.addWidget(QLabel("Total Word Count:"), 4, 0)
|
self.infoForm.addWidget(QLabel("Notes Word Count:"), 4, 0)
|
||||||
|
self.infoForm.addWidget(QLabel("Total Word Count:"), 5, 0)
|
||||||
self.infoForm.addWidget(self.labelTotal, 0, 1)
|
self.infoForm.addWidget(self.labelTotal, 0, 1)
|
||||||
self.infoForm.addWidget(self.labelFilter, 1, 1)
|
self.infoForm.addWidget(self.labelIdleT, 1, 1)
|
||||||
self.infoForm.addWidget(self.novelWords, 2, 1)
|
self.infoForm.addWidget(self.labelFilter, 2, 1)
|
||||||
self.infoForm.addWidget(self.notesWords, 3, 1)
|
self.infoForm.addWidget(self.novelWords, 3, 1)
|
||||||
self.infoForm.addWidget(self.totalWords, 4, 1)
|
self.infoForm.addWidget(self.notesWords, 4, 1)
|
||||||
self.infoForm.setRowStretch(5, 1)
|
self.infoForm.addWidget(self.totalWords, 5, 1)
|
||||||
|
self.infoForm.setRowStretch(6, 1)
|
||||||
|
|
||||||
# Filter Options
|
# Filter Options
|
||||||
sPx = self.theTheme.baseIconSize
|
sPx = self.theTheme.baseIconSize
|
||||||
@@ -278,6 +290,7 @@ class GuiWritingStats(QDialog):
|
|||||||
widthCol0 = self.mainConf.rpxInt(self.listBox.columnWidth(0))
|
widthCol0 = self.mainConf.rpxInt(self.listBox.columnWidth(0))
|
||||||
widthCol1 = self.mainConf.rpxInt(self.listBox.columnWidth(1))
|
widthCol1 = self.mainConf.rpxInt(self.listBox.columnWidth(1))
|
||||||
widthCol2 = self.mainConf.rpxInt(self.listBox.columnWidth(2))
|
widthCol2 = self.mainConf.rpxInt(self.listBox.columnWidth(2))
|
||||||
|
widthCol3 = self.mainConf.rpxInt(self.listBox.columnWidth(3))
|
||||||
sortCol = self.listBox.sortColumn()
|
sortCol = self.listBox.sortColumn()
|
||||||
sortOrder = self.listBox.header().sortIndicatorOrder()
|
sortOrder = self.listBox.header().sortIndicatorOrder()
|
||||||
incNovel = self.incNovel.isChecked()
|
incNovel = self.incNovel.isChecked()
|
||||||
@@ -292,6 +305,7 @@ class GuiWritingStats(QDialog):
|
|||||||
self.optState.setValue("GuiWritingStats", "widthCol0", widthCol0)
|
self.optState.setValue("GuiWritingStats", "widthCol0", widthCol0)
|
||||||
self.optState.setValue("GuiWritingStats", "widthCol1", widthCol1)
|
self.optState.setValue("GuiWritingStats", "widthCol1", widthCol1)
|
||||||
self.optState.setValue("GuiWritingStats", "widthCol2", widthCol2)
|
self.optState.setValue("GuiWritingStats", "widthCol2", widthCol2)
|
||||||
|
self.optState.setValue("GuiWritingStats", "widthCol3", widthCol3)
|
||||||
self.optState.setValue("GuiWritingStats", "sortCol", sortCol)
|
self.optState.setValue("GuiWritingStats", "sortCol", sortCol)
|
||||||
self.optState.setValue("GuiWritingStats", "sortOrder", sortOrder)
|
self.optState.setValue("GuiWritingStats", "sortOrder", sortOrder)
|
||||||
self.optState.setValue("GuiWritingStats", "incNovel", incNovel)
|
self.optState.setValue("GuiWritingStats", "incNovel", incNovel)
|
||||||
@@ -347,23 +361,25 @@ class GuiWritingStats(QDialog):
|
|||||||
with open(savePath, mode="w", encoding="utf8") as outFile:
|
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||||
if dataFmt == self.FMT_JSON:
|
if dataFmt == self.FMT_JSON:
|
||||||
jsonData = []
|
jsonData = []
|
||||||
for _, sD, tT, wD, wA, wB in self.filterData:
|
for _, sD, tT, wD, wA, wB, tI in self.filterData:
|
||||||
jsonData.append({
|
jsonData.append({
|
||||||
"date": sD,
|
"date": sD,
|
||||||
"length": tT,
|
"length": tT,
|
||||||
"newWords": wD,
|
"newWords": wD,
|
||||||
"novelWords": wA,
|
"novelWords": wA,
|
||||||
"noteWords": wB,
|
"noteWords": wB,
|
||||||
|
"idleTime": tI,
|
||||||
})
|
})
|
||||||
json.dump(jsonData, outFile, indent=2)
|
json.dump(jsonData, outFile, indent=2)
|
||||||
wSuccess = True
|
wSuccess = True
|
||||||
|
|
||||||
if dataFmt == self.FMT_CSV:
|
if dataFmt == self.FMT_CSV:
|
||||||
outFile.write(
|
outFile.write(
|
||||||
'"Date","Length (sec)","Words Changed","Novel Words","Note Words"\n'
|
'"Date","Length (sec)","Words Changed",'
|
||||||
|
'"Novel Words","Note Words","Idle Time (sec)"\n'
|
||||||
)
|
)
|
||||||
for _, sD, tT, wD, wA, wB in self.filterData:
|
for _, sD, tT, wD, wA, wB, tI in self.filterData:
|
||||||
outFile.write(f'"{sD}",{tT:.0f},{wD},{wA},{wB}\n')
|
outFile.write(f'"{sD}",{tT:.0f},{wD},{wA},{wB},{tI}\n')
|
||||||
wSuccess = True
|
wSuccess = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -401,6 +417,7 @@ class GuiWritingStats(QDialog):
|
|||||||
ttNovel = 0
|
ttNovel = 0
|
||||||
ttNotes = 0
|
ttNotes = 0
|
||||||
ttTime = 0
|
ttTime = 0
|
||||||
|
ttIdle = 0
|
||||||
|
|
||||||
logFile = os.path.join(self.theProject.projMeta, nwFiles.SESS_STATS)
|
logFile = os.path.join(self.theProject.projMeta, nwFiles.SESS_STATS)
|
||||||
if not os.path.isfile(logFile):
|
if not os.path.isfile(logFile):
|
||||||
@@ -419,7 +436,7 @@ class GuiWritingStats(QDialog):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
inData = inLine.split()
|
inData = inLine.split()
|
||||||
if len(inData) != 6:
|
if len(inData) < 6:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dStart = datetime.strptime(
|
dStart = datetime.strptime(
|
||||||
@@ -429,16 +446,21 @@ class GuiWritingStats(QDialog):
|
|||||||
"%s %s" % (inData[2], inData[3]), nwConst.FMT_TSTAMP
|
"%s %s" % (inData[2], inData[3]), nwConst.FMT_TSTAMP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sIdle = 0
|
||||||
|
if len(inData) > 6:
|
||||||
|
sIdle = checkInt(inData[6], 0)
|
||||||
|
|
||||||
tDiff = dEnd - dStart
|
tDiff = dEnd - dStart
|
||||||
sDiff = tDiff.total_seconds()
|
sDiff = tDiff.total_seconds()
|
||||||
ttTime += sDiff
|
ttTime += sDiff
|
||||||
|
ttIdle += sIdle
|
||||||
|
|
||||||
wcNovel = int(inData[4])
|
wcNovel = int(inData[4])
|
||||||
wcNotes = int(inData[5])
|
wcNotes = int(inData[5])
|
||||||
ttNovel = wcNovel
|
ttNovel = wcNovel
|
||||||
ttNotes = wcNotes
|
ttNotes = wcNotes
|
||||||
|
|
||||||
self.logData.append((dStart, sDiff, wcNovel, wcNotes))
|
self.logData.append((dStart, sDiff, wcNovel, wcNotes, sIdle))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.theParent.makeAlert(
|
self.theParent.makeAlert(
|
||||||
@@ -448,6 +470,7 @@ class GuiWritingStats(QDialog):
|
|||||||
|
|
||||||
ttWords = ttNovel + ttNotes
|
ttWords = ttNovel + ttNotes
|
||||||
self.labelTotal.setText(formatTime(round(ttTime)))
|
self.labelTotal.setText(formatTime(round(ttTime)))
|
||||||
|
self.labelIdleT.setText(formatTime(round(ttIdle)))
|
||||||
self.novelWords.setText(f"{ttNovel:n}")
|
self.novelWords.setText(f"{ttNovel:n}")
|
||||||
self.notesWords.setText(f"{ttNotes:n}")
|
self.notesWords.setText(f"{ttNotes:n}")
|
||||||
self.totalWords.setText(f"{ttWords:n}")
|
self.totalWords.setText(f"{ttWords:n}")
|
||||||
@@ -474,25 +497,28 @@ class GuiWritingStats(QDialog):
|
|||||||
tempData = []
|
tempData = []
|
||||||
sessDate = None
|
sessDate = None
|
||||||
sessTime = 0
|
sessTime = 0
|
||||||
|
sIdle = 0
|
||||||
lstNovel = 0
|
lstNovel = 0
|
||||||
lstNotes = 0
|
lstNotes = 0
|
||||||
|
|
||||||
for n, (dStart, sDiff, wcNovel, wcNotes) in enumerate(self.logData):
|
for n, (dStart, sDiff, wcNovel, wcNotes, sIdle) in enumerate(self.logData):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
sessDate = dStart.date()
|
sessDate = dStart.date()
|
||||||
if sessDate != dStart.date():
|
if sessDate != dStart.date():
|
||||||
tempData.append((sessDate, sessTime, lstNovel, lstNotes))
|
tempData.append((sessDate, sessTime, lstNovel, lstNotes, sIdle))
|
||||||
sessDate = dStart.date()
|
sessDate = dStart.date()
|
||||||
sessTime = sDiff
|
sessTime = sDiff
|
||||||
|
sIdle = sIdle
|
||||||
lstNovel = wcNovel
|
lstNovel = wcNovel
|
||||||
lstNotes = wcNotes
|
lstNotes = wcNotes
|
||||||
else:
|
else:
|
||||||
sessTime += sDiff
|
sessTime += sDiff
|
||||||
|
sIdle += sIdle
|
||||||
lstNovel = wcNovel
|
lstNovel = wcNovel
|
||||||
lstNotes = wcNotes
|
lstNotes = wcNotes
|
||||||
|
|
||||||
if sessDate is not None:
|
if sessDate is not None:
|
||||||
tempData.append((sessDate, sessTime, lstNovel, lstNotes))
|
tempData.append((sessDate, sessTime, lstNovel, lstNotes, sIdle))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
tempData = self.logData
|
tempData = self.logData
|
||||||
@@ -502,7 +528,7 @@ class GuiWritingStats(QDialog):
|
|||||||
pcTotal = 0
|
pcTotal = 0
|
||||||
listMax = 0
|
listMax = 0
|
||||||
isFirst = True
|
isFirst = True
|
||||||
for dStart, sDiff, wcNovel, wcNotes in tempData:
|
for dStart, sDiff, wcNovel, wcNotes, sIdle in tempData:
|
||||||
|
|
||||||
wcTotal = 0
|
wcTotal = 0
|
||||||
if incNovel:
|
if incNovel:
|
||||||
@@ -527,16 +553,17 @@ class GuiWritingStats(QDialog):
|
|||||||
else:
|
else:
|
||||||
sStart = dStart.strftime(nwConst.FMT_TSTAMP)
|
sStart = dStart.strftime(nwConst.FMT_TSTAMP)
|
||||||
|
|
||||||
self.filterData.append((dStart, sStart, sDiff, dwTotal, wcNovel, wcNotes))
|
self.filterData.append((dStart, sStart, sDiff, dwTotal, wcNovel, wcNotes, sIdle))
|
||||||
listMax = min(max(listMax, dwTotal), histMax)
|
listMax = min(max(listMax, dwTotal), histMax)
|
||||||
pcTotal = wcTotal
|
pcTotal = wcTotal
|
||||||
|
|
||||||
# Populate the list
|
# Populate the list
|
||||||
for _, sStart, sDiff, nWords, _, _ in self.filterData:
|
for _, sStart, sDiff, nWords, _, _, sIdle in self.filterData:
|
||||||
|
|
||||||
newItem = QTreeWidgetItem()
|
newItem = QTreeWidgetItem()
|
||||||
newItem.setText(self.C_TIME, sStart)
|
newItem.setText(self.C_TIME, sStart)
|
||||||
newItem.setText(self.C_LENGTH, formatTime(round(sDiff)))
|
newItem.setText(self.C_LENGTH, formatTime(round(sDiff)))
|
||||||
|
newItem.setText(self.C_IDLE, formatTime(sIdle))
|
||||||
newItem.setText(self.C_COUNT, f"{nWords:n}")
|
newItem.setText(self.C_COUNT, f"{nWords:n}")
|
||||||
|
|
||||||
if nWords > 0 and listMax > 0:
|
if nWords > 0 and listMax > 0:
|
||||||
@@ -549,11 +576,13 @@ class GuiWritingStats(QDialog):
|
|||||||
newItem.setData(self.C_BAR, Qt.DecorationRole, theBar)
|
newItem.setData(self.C_BAR, Qt.DecorationRole, theBar)
|
||||||
|
|
||||||
newItem.setTextAlignment(self.C_LENGTH, Qt.AlignRight)
|
newItem.setTextAlignment(self.C_LENGTH, Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.C_IDLE, Qt.AlignRight)
|
||||||
newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight)
|
newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight)
|
||||||
newItem.setTextAlignment(self.C_BAR, Qt.AlignLeft | Qt.AlignVCenter)
|
newItem.setTextAlignment(self.C_BAR, Qt.AlignLeft | Qt.AlignVCenter)
|
||||||
|
|
||||||
newItem.setFont(self.C_TIME, self.theTheme.guiFontFixed)
|
newItem.setFont(self.C_TIME, self.theTheme.guiFontFixed)
|
||||||
newItem.setFont(self.C_LENGTH, self.theTheme.guiFontFixed)
|
newItem.setFont(self.C_LENGTH, self.theTheme.guiFontFixed)
|
||||||
|
newItem.setFont(self.C_IDLE, self.theTheme.guiFontFixed)
|
||||||
newItem.setFont(self.C_COUNT, self.theTheme.guiFontFixed)
|
newItem.setFont(self.C_COUNT, self.theTheme.guiFontFixed)
|
||||||
|
|
||||||
self.listBox.addTopLevelItem(newItem)
|
self.listBox.addTopLevelItem(newItem)
|
||||||
|
|||||||
+1
-1
@@ -420,7 +420,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.closeDocument()
|
self.closeDocument()
|
||||||
self.docViewer.clearNavHistory()
|
self.docViewer.clearNavHistory()
|
||||||
self.projView.closeOutline()
|
self.projView.closeOutline()
|
||||||
self.theProject.closeProject()
|
self.theProject.closeProject(self.idleTime)
|
||||||
self.theIndex.clearIndex()
|
self.theIndex.clearIndex()
|
||||||
self.clearGUI()
|
self.clearGUI()
|
||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
|
|||||||
Reference in New Issue
Block a user