-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The words count and min to read seems wrong [fix added] #5
Comments
It's 0:02 — 0 hours, 02 minutes. Format is H:MM. See issue #4 for details. |
Thanks. I got it. But I still think the calculation was wrong >_<. I checked the Then I found Unfortunately, I’ve never wrote js code, I write python and C/C++. But I guess I can possibly understand what the code will do. But the code with the red line in the picture above I can't understand it. I don't know how |
This is a little bit difficult, yes. But when i write this code (in past year ~in Sep.) i'm trying to isolate and separate all possible functions and exports with minimum comments. And when u see small comments at the right u can guess what it mean if u take a look at the begining of this function. But let's go in order: var getFormatTime = function(minutes) {
var fHours = Math.floor(minutes / 60);
var fMinutes = Math.floor(minutes - (fHours * 60));
if (fMinutes < 1) {
fMinutes = '01'; // 0:0 => 0:01
} else if (fMinutes < 10) {
fMinutes = '0' + fMinutes; // 0:9 => 0:09
}
return fHours + ':' + fMinutes;
}; This function give as result time in format as i say before: H:MM. Just from string in minutes. For example, if we get 127 minutes before this function, after the result we get 2:07. module.exports.symbolsCount = function(content) {
var symbolsResult = getSymbols(content);
return symbolsResult < 1024
? symbolsResult // < 999 => 100
: Math.round(((symbolsResult / 1000) * 10) / 10) + 'k'; // > 999 => 1.1k
}; This function count symbols of current post from it's body. And your question is about « / 1000) * 10) / 10»:
This mean we never get something like 5.68k as a result and always get only 5.7 to round with bigger digit (because 5687 is closer to 5.7 not to 5.6). If it will be 5617 — when will round to 5.6k. Try to remove module.exports.symbolsCountTotal = function(site) {
var symbolsResultTotal = getSymbolsTotal(site);
return symbolsResultTotal < 1024024
? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 100k
: Math.round(((symbolsResultTotal / 1000000 * 10)) / 10) + 'm'; // > 999k => 1.1m
}; And this function, as u can see, it's like previous, but there is can be on whole site more then 999k symbols (in one post it can't be). So, this is double filter and u have same description as above, but only for count with millions symbols. Hope i give answer on your question and always remember: in javascript all make sense. 😃 |
Wow! Thanks! Thanks for your patience! It's my first time to discuss with someone on github. So funny :) so Math.round(((5687 / 1000) * 10) / 10) and Math.round(5687 / 1000) is the same one, because Math.round((5687 / 1000) * 10) / 10 you just type redundant parenthesis around And the code can be simplified like this: Math.round(5687 / 100) / 10 In fact, I think the original code is okay too. And I guess may be in this function: var getSymbols = function(content) {
var util = require('hexo-util');
var stripHTML = util.stripHTML;
return stripHTML(content).length;
}; we have to do some calculation with Thank you again! And I think, Python is the best :) (just a joke😃) |
Yeah, u are right, something wrong here. I just run test and see what there is no 1.3k, just 1k: describe('Test symbolsCount > 1024', function() {
var symbols = helper.symbolsCount('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.');
it('assert - 1k', function() {
assert.equal(symbols, '1k');
});
}); I say what this code was written a long time ago and i don't remebmer why i made it exactly like that. All of i remember idea was in: If we get 567 symbols, then we return it as it — 567 And test not totally finished, so, need to finish this work.
parseInt(568700 / 1000) + (Math.round((5687 % 1000) / 100) / 10) + 'k' This code is a little bit slower i think, need to do with math simple as possible.
Yes! Here is bug. Thank u! 👍 - : Math.round(((symbolsResult / 1000) * 10) / 10) + 'k'; // > 999 => 1.1k
+ : Math.round((symbolsResult / 1000) * 10) / 10 + 'k'; // > 999 => 1.1k 7 passing (13ms)
1 failing
1) Hexo Symbols Count Time Test symbolsCount > 1024 assert - 1k:
AssertionError: expected '1.3k' to equal '1k'
at Context.<anonymous> (test/index.js:34:14)
Math.round(5687 / 100) / 10 And this is good, yeah! Minus 1 interation. I just cycled on >1024, so, i divide it on Pull requests are welcome! |
Ok, rounding fixed in eca327d > mocha test --reporter spec
Hexo Symbols Count Time
Test symbolsCount function & check should / expect / assert
✓ should - 22
✓ expect - 22
✓ assert - 22
Test symbolsCount < 1024
✓ Symbols: 569 => 569
Test symbolsCount > 1024
✓ Symbols: 1337 => 1.3k
Test symbolsCount > 10k
✓ Symbols: 10703 => 11k
Test symbolsCount & symbolsTime
✓ assert (symbolsCount - 90)
✓ assert (symbolsTime without parameters (awl = 5, wpm = 200) - 0:01)
✓ assert (symbolsTime [awl = 5, wpm = 5] - 0:04)
✓ assert (symbolsTime [awl = 1, wpm = 50] - 0:02)
10 passing (9ms) |
haha! seems I did a good job. May be I have to learn some js and font-end, so that I can make some pull request. |
Environment:
Problem description:
I‘ve install hexo-symbols-count-time and set it into NexT. It already worked. But the results seems to be wrong.
I'm chinese so I set
AWL = 25
andWPM = 275
. The result just like the following pictureI'm sure that I didn't wrote so many words, and the time format makes me confused. Is that means 2 sec?
The text was updated successfully, but these errors were encountered: