Closed iomadh closed 10 years ago
I think the problem is line 108
if (MODE == 1) {
/* ASSERT: Split into fiction/nonficiton */
var ficWords = getWordsWritten(almanac_day, "Writing", "fiction");
var nfWords = getWordsWritten(almanac_day, "Writing", "nonfiction");
var totalFicNonFicWords = ficWords + nfWords;
var fictionPercent = (ficWords/totalFicNonFicWords)*100;
var nonFictionPercent = 100 - fictionPercent;
} else {
/* ASSERT: Don't split, just give the totals */
var ficWords = getWordsWritten(almanac_day, "Writing", "fiction");
var totalFicNonFicWords = ficWords;
}
getWordsWritten is called with "fiction" when MODE is not 1 but the fiction column is empty
I believe I have fixed this. The problem wasn't entirelyin the 108 section above because you'll note that in the else clause, varTotalFicNonFicWord is to ficWords. The problem was in getWordsWritten, which wasn't looking in the proper column for total words when Word Count Mode = 0. In order to fix it, I've changed code in 2 place, first, up by 108:
if (MODE == 1) {
/* ASSERT: Split into fiction/nonficiton */
var ficWords = getWordsWritten(almanac_day, "Writing", "fiction");
var nfWords = getWordsWritten(almanac_day, "Writing", "nonfiction");
var totalFicNonFicWords = ficWords + nfWords;
var fictionPercent = (ficWords/totalFicNonFicWords)*100;
var nonFictionPercent = 100 - fictionPercent;
} else {
/* ASSERT: Don't split, just give the totals */
var ficWords = getWordsWritten(almanac_day, "Writing", "total");
var totalFicNonFicWords = ficWords;
}
Note that in the else clause, it now passes almanac_day, "writing" and "total". That latter will kick in below:
function getWordsWritten(date, type, wordType) {
var qs_doc = SpreadsheetApp.openById(WRITING_DATA);
var sheet = qs_doc.getSheetByName(type);
var words = 0;
var range = sheet.getRange("A2:A" + sheet.getLastRow());
var match = findDate(date, range);
Logger.log(match);
if (wordType == "fiction") {
/* ASSERT: capture fiction writing */
try {
words = sheet.getRange(COL_FICTION + match.getRow()).getValue();
} catch (e) {
words = 0;
}
} else if (wordType == "nonfiction") {
/* ASSERT: capture nonfiction writing */
try {
words = sheet.getRange(COL_NONFICTION + match.getRow()).getValue();
} catch (e) {
words = 0;
}
} else if (wordType == "Blogging") {
/* ASSERT: capture blog writing */
try {
words = sheet.getRange(COL_BLOGGING_TOTAL + match.getRow()).getValue();
} catch (e) {
words = 0;
}
} else if (wordType == "total") {
/* ASSERT: capture total writing when Word Count Mode = 0 */
try {
words = sheet.getRange(COL_WRITING_TOTAL + match.getRow()).getValue();
} catch (e) {
words = 0;
}
}
return words;
}
total will get trapped in the last else clause. You can see that this is using appropriate setting variables for which column to pull the word counts from, and all together reads a little more cleanly.
I tested it with both Word Count Mode = 1 and Word Count Mode = 0 and it worked correctly in both cases. But I'd ask that you update the code and then test it yourself to see if you are getting the same results I am now.
Tested and confirmed fixed - great stuff - looking forward to this running properly overnight
When Word Count Mode was set to 0, I was not getting the words reported in the almanac,
Looking at the code, specifically the calls to getWordsWritten the logic seemed odd in that it is only ever called with "fiction", "nonfiction" or "blogging" never "total"
I copied the data from column D (Total) to column B(Fiction) and got the correct output