88 getSentenceCount ,
99 getPageCount ,
1010 getWordCount ,
11+ getCitationCount ,
12+ getFootnoteCount ,
1113} from "../utils/StatUtils" ;
1214
1315export default class StatsManager {
@@ -80,6 +82,8 @@ export default class StatsManager {
8082 const totalWords = await this . calcTotalWords ( ) ;
8183 const totalCharacters = await this . calcTotalCharacters ( ) ;
8284 const totalSentences = await this . calcTotalSentences ( ) ;
85+ const totalFootnotes = await this . calcTotalFootnotes ( ) ;
86+ const totalCitations = await this . calcTotalCitations ( ) ;
8387 const totalPages = await this . calcTotalPages ( ) ;
8488
8589 const newDay : Day = {
@@ -88,9 +92,13 @@ export default class StatsManager {
8892 sentences : 0 ,
8993 pages : 0 ,
9094 files : 0 ,
95+ footnotes : 0 ,
96+ citations : 0 ,
9197 totalWords : totalWords ,
9298 totalCharacters : totalCharacters ,
9399 totalSentences : totalSentences ,
100+ totalFootnotes : totalFootnotes ,
101+ totalCitations : totalCitations ,
94102 totalPages : totalPages ,
95103 } ;
96104
@@ -104,6 +112,8 @@ export default class StatsManager {
104112 const currentWords = getWordCount ( text ) ;
105113 const currentCharacters = getCharacterCount ( text ) ;
106114 const currentSentences = getSentenceCount ( text ) ;
115+ const currentCitations = getCitationCount ( text ) ;
116+ const currentFootnotes = getFootnoteCount ( text ) ;
107117 const currentPages = getPageCount ( text , this . plugin . settings . pageWords ) ;
108118
109119 if (
@@ -119,11 +129,18 @@ export default class StatsManager {
119129 currentCharacters - modFiles [ fileName ] . characters . current ;
120130 this . vaultStats . history [ this . today ] . totalSentences +=
121131 currentSentences - modFiles [ fileName ] . sentences . current ;
132+ this . vaultStats . history [ this . today ] . totalFootnotes +=
133+ currentSentences - modFiles [ fileName ] . footnotes . current ;
134+ this . vaultStats . history [ this . today ] . totalCitations +=
135+ currentSentences - modFiles [ fileName ] . citations . current ;
122136 this . vaultStats . history [ this . today ] . totalPages +=
123137 currentPages - modFiles [ fileName ] . pages . current ;
138+
124139 modFiles [ fileName ] . words . current = currentWords ;
125140 modFiles [ fileName ] . characters . current = currentCharacters ;
126141 modFiles [ fileName ] . sentences . current = currentSentences ;
142+ modFiles [ fileName ] . footnotes . current = currentFootnotes ;
143+ modFiles [ fileName ] . citations . current = currentCitations ;
127144 modFiles [ fileName ] . pages . current = currentPages ;
128145 } else {
129146 modFiles [ fileName ] = {
@@ -139,6 +156,14 @@ export default class StatsManager {
139156 initial : currentSentences ,
140157 current : currentSentences ,
141158 } ,
159+ footnotes : {
160+ initial : currentFootnotes ,
161+ current : currentFootnotes ,
162+ } ,
163+ citations : {
164+ initial : currentCitations ,
165+ current : currentCitations ,
166+ } ,
142167 pages : {
143168 initial : currentPages ,
144169 current : currentPages ,
@@ -161,6 +186,16 @@ export default class StatsManager {
161186 Math . max ( 0 , counts . sentences . current - counts . sentences . initial )
162187 )
163188 . reduce ( ( a , b ) => a + b , 0 ) ;
189+
190+ const footnotes = Object . values ( modFiles )
191+ . map ( ( counts ) =>
192+ Math . max ( 0 , counts . footnotes . current - counts . footnotes . initial )
193+ )
194+ . reduce ( ( a , b ) => a + b , 0 ) ;
195+ const citations = Object . values ( modFiles )
196+ . map ( ( counts ) =>
197+ Math . max ( 0 , counts . citations . current - counts . citations . initial )
198+ ) . reduce ( ( a , b ) => a + b , 0 ) ;
164199 const pages = Object . values ( modFiles )
165200 . map ( ( counts ) =>
166201 Math . max ( 0 , counts . pages . current - counts . pages . initial )
@@ -170,6 +205,8 @@ export default class StatsManager {
170205 this . vaultStats . history [ this . today ] . words = words ;
171206 this . vaultStats . history [ this . today ] . characters = characters ;
172207 this . vaultStats . history [ this . today ] . sentences = sentences ;
208+ this . vaultStats . history [ this . today ] . footnotes = footnotes ;
209+ this . vaultStats . history [ this . today ] . citations = citations ;
173210 this . vaultStats . history [ this . today ] . pages = pages ;
174211 this . vaultStats . history [ this . today ] . files = this . getTotalFiles ( ) ;
175212
@@ -189,6 +226,8 @@ export default class StatsManager {
189226 todayHist . totalWords = await this . calcTotalWords ( ) ;
190227 todayHist . totalCharacters = await this . calcTotalCharacters ( ) ;
191228 todayHist . totalSentences = await this . calcTotalSentences ( ) ;
229+ todayHist . totalFootnotes = await this . calcTotalFootnotes ( ) ;
230+ todayHist . totalCitations = await this . calcTotalCitations ( ) ;
192231 todayHist . totalPages = await this . calcTotalPages ( ) ;
193232 this . update ( ) ;
194233 } else {
@@ -231,7 +270,6 @@ export default class StatsManager {
231270 sentence += getSentenceCount ( await this . vault . cachedRead ( file ) ) ;
232271 }
233272 }
234-
235273 return sentence ;
236274 }
237275
@@ -249,6 +287,30 @@ export default class StatsManager {
249287 return pages ;
250288 }
251289
290+ private async calcTotalFootnotes ( ) : Promise < number > {
291+ let footnotes = 0 ;
292+ const files = this . vault . getFiles ( ) ;
293+ for ( const i in files ) {
294+ const file = files [ i ] ;
295+ if ( file . extension === "md" ) {
296+ footnotes += getFootnoteCount ( await this . vault . cachedRead ( file ) ) ;
297+ }
298+ }
299+ return footnotes ;
300+ }
301+
302+ private async calcTotalCitations ( ) : Promise < number > {
303+ let citations = 0 ;
304+ const files = this . vault . getFiles ( ) ;
305+ for ( const i in files ) {
306+ const file = files [ i ] ;
307+ if ( file . extension === "md" ) {
308+ citations += getCitationCount ( await this . vault . cachedRead ( file ) ) ;
309+ }
310+ }
311+ return citations ;
312+ }
313+
252314 public getDailyWords ( ) : number {
253315 return this . vaultStats . history [ this . today ] . words ;
254316 }
@@ -261,6 +323,14 @@ export default class StatsManager {
261323 return this . vaultStats . history [ this . today ] . sentences ;
262324 }
263325
326+
327+ public getDailyFootnotes ( ) : number {
328+ return this . vaultStats . history [ this . today ] . footnotes ;
329+ }
330+
331+ public getDailyCitations ( ) : number {
332+ return this . vaultStats . history [ this . today ] . citations ;
333+ }
264334 public getDailyPages ( ) : number {
265335 return this . vaultStats . history [ this . today ] . pages ;
266336 }
@@ -283,6 +353,16 @@ export default class StatsManager {
283353 if ( ! this . vaultStats ) return await this . calcTotalSentences ( ) ;
284354 return this . vaultStats . history [ this . today ] . totalSentences ;
285355 }
356+
357+ public async getTotalFootnotes ( ) : Promise < number > {
358+ if ( ! this . vaultStats ) return await this . calcTotalFootnotes ( ) ;
359+ return this . vaultStats . history [ this . today ] . totalFootnotes ;
360+ }
361+
362+ public async getTotalCitations ( ) : Promise < number > {
363+ if ( ! this . vaultStats ) return await this . calcTotalCitations ( ) ;
364+ return this . vaultStats . history [ this . today ] . totalCitations ;
365+ }
286366
287367 public async getTotalPages ( ) : Promise < number > {
288368 if ( ! this . vaultStats ) return await this . calcTotalPages ( ) ;
0 commit comments