javascript
pmp 成本估算准确高_如何更准确地估算JavaScript中文章的阅读时间
pmp 成本估算準(zhǔn)確高
by Pritish Vaidya
通過(guò)Pritish Vaidya
準(zhǔn)確估算JavaScript中篇文章的閱讀時(shí)間 (Accurate estimation of read time for Medium articles in JavaScript)
介紹 (Introduction)
Read Time Estimate is the estimation of the time taken by the reader to read an article. It has been a part of Medium’s core features since it launched in 2013.
閱讀時(shí)間估算是讀者閱讀文章所花費(fèi)時(shí)間的估算。 自2013年推出以來(lái),它一直是Medium核心功能的一部分。
As explained in the New Yorker:
如《紐約客》中所述 :
The more we know about something — including precisely how much time it will consume — the greater the chance we will commit to it.我們對(duì)某事了解得越多-確切地包括它將消耗多少時(shí)間-我們致力于該事的機(jī)會(huì)就越大。Knowing in advance how long an article will take to read helps with better time management by allowing us to plan further ahead.
提前知道一篇文章將花費(fèi)多長(zhǎng)時(shí)間,可以使我們提前計(jì)劃,從而有助于更好地管理時(shí)間。
為什么要使用新腳本? (Why should I use a new script?)
Yes, there are many open source libraries available on npm but they contain several flaws.
是的, npm上有很多開(kāi)源庫(kù) 但它們包含一些缺陷。
Before that, let’s take a look at these two articles on Medium.
在此之前,讓我們看一下有關(guān)Medium的這兩篇文章。
Read Time — Medium Support
讀取時(shí)間-中度支持
Read Time and You
閱讀時(shí)間和你
The above two articles have the following key features
上面的兩篇文章具有以下主要功能
- Average Read Time (English) — 265 Words per min 平均閱讀時(shí)間(英語(yǔ))—每分鐘265個(gè)單詞
- Average Read Time (Chinese, Japanese and Korean) — 500 Characters/min 平均閱讀時(shí)間(中文,日文和韓文)-500個(gè)字符/分鐘
- Image Read Time — 12 seconds for the first image, 11 for the second, and minus an additional second for each subsequent image. Other images counted at 3 seconds. 圖像讀取時(shí)間-第一張圖像12秒鐘,第二張圖像11秒鐘,每個(gè)后續(xù)圖像再減去一秒鐘。 其他圖像計(jì)數(shù)為3秒。
Most of the libraries don’t account for the above features completely. They use HTML strings as is without omitting its tag names which increases the deviation of estimation from the original value.
大多數(shù)庫(kù)并未完全說(shuō)明上述功能。 他們按原樣使用HTML字符串,而不會(huì)省略其標(biāo)簽名 ,這會(huì)增加估計(jì)值與原始值的偏差。
碼 (Code)
The code can be split into three parts:
該代碼可以分為三部分:
- Constants 常數(shù)
- Utility 效用
- Main 主要
常數(shù) (Constants)
The constants can be used as defaults to the main function. The image tag has its own use which will be defined later.
常量可以用作主函數(shù)的默認(rèn)值。 image標(biāo)簽有其自己的用途,稍后將進(jìn)行定義。
實(shí)用功能 (Utility Functions)
Strip WhiteSpace
帶空格
It is a simple utility function to remove all leading and trailing whitespace from the string provided.
這是一個(gè)簡(jiǎn)單的實(shí)用程序函數(shù),可從提供的字符串中刪除所有前導(dǎo)和尾隨空格。
2. Image Read Time
2.圖像讀取時(shí)間
It parses the string, looks for any HTML image tags based on the defaults provided in the constants and returns the count.
它解析該字符串,根據(jù)常量中提供的默認(rèn)值查找任何HTML圖像標(biāo)簽,然后返回計(jì)數(shù)。
If the image count is greater than 10, we calculate the image read time of the first 10 images in decreasing arithmetic progression starting from 12 sec / customReadTime provided by the user using the simple formula n * (a+b) / 2 and 3 sec for the remaining images.
如果圖像數(shù)量大于10,我們將使用簡(jiǎn)單的公式n * (a+b) / 2和3秒,從12秒/用戶提供的customReadTime開(kāi)始,以遞減的算術(shù)級(jí)數(shù)計(jì)算前10張圖像的圖像讀取時(shí)間。剩下的圖像。
3. Strip Tags
3.剝離標(biāo)簽
Next, we check for any HTML tags (both) in the string and remove it to extract only the words from it.
接下來(lái),我們檢查字符串中是否有HTML標(biāo)記(均為HTML標(biāo)記),并將其刪除以僅提取其中的單詞。
4. Words Read Time
4.單詞閱讀時(shí)間
This utility function calculates the words count and Chinese / Korean and Japanese characters using the different Unicode character range.
該實(shí)用程序功能使用不同的Unicode字符范圍來(lái)計(jì)算單詞數(shù)以及中文/韓文和日文字符。
The time is calculated by dividing it with the constants defined above.
通過(guò)將時(shí)間除以上面定義的常數(shù)來(lái)計(jì)算時(shí)間。
5. Humanize Time
5.人性化的時(shí)間
Based on the distance of time in words, we can calculate and return the humanized duration of the time taken to read.
根據(jù)時(shí)間(以字為單位)的距離 ,我們可以計(jì)算并返回讀取時(shí)間的人性化持續(xù)時(shí)間。
主要 (Main)
The main function only consolidates all the utility methods in the correct order.
main函數(shù)僅以正確的順序合并所有實(shí)用程序方法。
這個(gè)腳本的準(zhǔn)確性如何? (How accurate is this script?)
Taking the tests on the HTML string (from the Chrome inspector) before this article section.
在本文開(kāi)始之前 ,請(qǐng)對(duì)HTML字符串(來(lái)自Chrome檢查器) 進(jìn)行測(cè)試。
The tests and the Pages clearly give the correct estimate about the total words from the parsed HTML and the number of images.
測(cè)試和頁(yè)面清楚地給出了來(lái)自解析HTML的單詞總數(shù)和圖像數(shù)量的正確估計(jì)。
鏈接 (Links)
I’ve consolidated the complete code on GitHub. It is also available as an npm package read-time-estimate.
我已經(jīng)在GitHub上整合了完整的代碼。 它也可以作為npm包read-time-estimate提供 。
More of the cool stuff can be found on my StackOverflow and GitHub profiles.
在我的StackOverflow和GitHub個(gè)人資料中可以找到更多有趣的東西。
Follow me on LinkedIn, Medium, Twitter for further update new articles.
在LinkedIn , Medium和Twitter上關(guān)注我,以獲取更多更新的新文章。
One clap, two claps, three claps, forty?
一拍,兩拍,三拍,四十?
Originally published at blog.pritishvaidya.com on January 30, 2019.
最初于2019年1月30日發(fā)布在blog.pritishvaidya.com上。
翻譯自: https://www.freecodecamp.org/news/how-to-more-accurately-estimate-read-time-for-medium-articles-in-javascript-fb563ff0282a/
pmp 成本估算準(zhǔn)確高
總結(jié)
以上是生活随笔為你收集整理的pmp 成本估算准确高_如何更准确地估算JavaScript中文章的阅读时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到关不上门什么意思
- 下一篇: 孕妇梦到大石头是什么意思