Brand new session stats log with saved counts for novel and notes seperately, and new parsing code
This commit is contained in:
@@ -53,6 +53,8 @@ class OptionState():
|
||||
"widthCol2",
|
||||
"sortCol",
|
||||
"sortOrder",
|
||||
"incNovel",
|
||||
"incNotes",
|
||||
"hideZeros",
|
||||
"hideNegative",
|
||||
"groupByDay",
|
||||
|
||||
+28
-10
@@ -93,6 +93,8 @@ class NWProject():
|
||||
self.lastViewed = None # The handle of the last file to be viewed
|
||||
self.lastWCount = 0 # The project word count from last session
|
||||
self.currWCount = 0 # The project word count in current session
|
||||
self.novelWCount = 0 # Total number of words in novel files
|
||||
self.notesWCount = 0 # Total number of words in note files
|
||||
self.doBackup = True # Run project backup on exit
|
||||
|
||||
# Set Defaults
|
||||
@@ -231,6 +233,8 @@ class NWProject():
|
||||
self.lastViewed = None
|
||||
self.lastWCount = 0
|
||||
self.currWCount = 0
|
||||
self.novelWCount = 0
|
||||
self.notesWCount = 0
|
||||
|
||||
return
|
||||
|
||||
@@ -435,6 +439,10 @@ class NWProject():
|
||||
self.lastViewed = checkString(xItem.text, None, True)
|
||||
elif xItem.tag == "lastWordCount":
|
||||
self.lastWCount = checkInt(xItem.text, 0, False)
|
||||
elif xItem.tag == "novelWordCount":
|
||||
self.novelWCount = checkInt(xItem.text, 0, False)
|
||||
elif xItem.tag == "notesWordCount":
|
||||
self.notesWCount = checkInt(xItem.text, 0, False)
|
||||
elif xItem.tag == "status":
|
||||
self.statusItems.unpackEntries(xItem)
|
||||
elif xItem.tag == "importance":
|
||||
@@ -501,6 +509,10 @@ class NWProject():
|
||||
})
|
||||
|
||||
editTime = int(self.editTime + saveTime - self.projOpened)
|
||||
wcNovel, wcNotes = self.projTree.sumWords()
|
||||
self.novelWCount = wcNovel
|
||||
self.notesWCount = wcNotes
|
||||
self.setProjectWordCount(wcNovel + wcNotes)
|
||||
|
||||
# Save Project Meta
|
||||
xProject = etree.SubElement(nwXML, "project")
|
||||
@@ -519,6 +531,8 @@ class NWProject():
|
||||
self._packProjectValue(xSettings, "lastEdited", self.lastEdited)
|
||||
self._packProjectValue(xSettings, "lastViewed", self.lastViewed)
|
||||
self._packProjectValue(xSettings, "lastWordCount", self.currWCount)
|
||||
self._packProjectValue(xSettings, "novelWordCount", wcNovel)
|
||||
self._packProjectValue(xSettings, "notesWordCount", wcNotes)
|
||||
|
||||
xAutoRep = etree.SubElement(xSettings, "autoReplace")
|
||||
for aKey, aValue in self.autoReplace.items():
|
||||
@@ -1101,18 +1115,22 @@ class NWProject():
|
||||
if not self.ensureFolderStructure():
|
||||
return False
|
||||
|
||||
sessionFile = path.join(self.projMeta, nwFiles.SESS_INFO)
|
||||
sessionFile = path.join(self.projMeta, nwFiles.SESS_STATS)
|
||||
isFile = path.isfile(sessionFile)
|
||||
|
||||
with open(sessionFile, mode="a+", encoding="utf8") as outFile:
|
||||
print((
|
||||
"Start: {opened:s} "
|
||||
"End: {closed:s} "
|
||||
"Words: {words:8d}"
|
||||
).format(
|
||||
opened = formatTimeStamp(self.projOpened),
|
||||
closed = formatTimeStamp(time()),
|
||||
words = self.getSessionWordCount(),
|
||||
), file=outFile)
|
||||
if not isFile:
|
||||
# It's a new file, so add a header
|
||||
outFile.write("# Initial: %d\n# %-17s %-19s %8s %8s\n" % (
|
||||
self.lastWCount, "Start Time", "End Time", "Novel", "Notes"
|
||||
))
|
||||
|
||||
outFile.write("%-19s %-19s %8d %8d\n" % (
|
||||
formatTimeStamp(self.projOpened),
|
||||
formatTimeStamp(time()),
|
||||
self.novelWCount,
|
||||
self.notesWCount,
|
||||
))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
+18
-1
@@ -36,7 +36,7 @@ from time import time
|
||||
|
||||
from nw.core.item import NWItem
|
||||
from nw.common import checkString
|
||||
from nw.constants import nwFiles, nwItemType, nwItemClass
|
||||
from nw.constants import nwFiles, nwItemType, nwItemClass, nwItemLayout
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -182,6 +182,23 @@ class NWTree():
|
||||
|
||||
return
|
||||
|
||||
def sumWords(self):
|
||||
"""Loops over all entries and adds up the word counts.
|
||||
"""
|
||||
noteWords = 0
|
||||
novelWords = 0
|
||||
for tHandle in self._treeOrder:
|
||||
tItem = self.__getitem__(tHandle)
|
||||
if tItem is None:
|
||||
continue
|
||||
if tItem.itemLayout == nwItemLayout.NO_LAYOUT:
|
||||
pass
|
||||
elif tItem.itemLayout == nwItemLayout.NOTE:
|
||||
noteWords += tItem.wordCount
|
||||
else:
|
||||
novelWords += tItem.wordCount
|
||||
return novelWords, noteWords
|
||||
|
||||
##
|
||||
# Tree Structure Methods
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user