Fossil SCM

Also show the projection number of events for the by-week activity report.

drh 2023-05-26 00:43 trunk
Commit 09ca77f76a48353a31bca56475c8b21daa3d400ad61fda92cb1e6d9ccff61998
1 file changed +38 -7
+38 -7
--- src/statrep.c
+++ src/statrep.c
@@ -639,10 +639,13 @@
639639
int nMaxEvents = 1; /* max number of events for
640640
all rows. */
641641
int iterations = 0; /* # of active time periods. */
642642
int rowCount = 0;
643643
int total = 0;
644
+ char *zCurrentWeek; /* Current week number */
645
+ double rNowFraction = 0.0; /* Fraction of current week that has
646
+ ** passed */
644647
645648
stats_report_init_view();
646649
style_submenu_sql("y", "Year:",
647650
"WITH RECURSIVE a(b) AS ("
648651
" SELECT substr(date('now'),1,4) UNION ALL"
@@ -665,11 +668,18 @@
665668
@ for the calendar weeks of %h(zYear)
666669
if( zUserName ){
667670
@ for user %h(zUserName)
668671
}
669672
@ </h1>
670
- style_table_sorter();
673
+ zCurrentWeek = db_text(0,
674
+ "SELECT strftime('%%W','now') WHERE date() LIKE '%q%%'",
675
+ zYear);
676
+ if( zCurrentWeek ){
677
+ rNowFraction = db_double(0.5,
678
+ "SELECT (unixepoch()-unixepoch('now','weekday 0','-7 days'))/604800.0;");
679
+ }
680
+ style_table_sorter();
671681
cgi_printf("<table class='statistics-report-table-events sortable' "
672682
"border='0' cellpadding='2' width='100%%' "
673683
"cellspacing='0' data-column-types='tnx' data-init-sort='0'>\n");
674684
cgi_printf("<thead><tr>"
675685
"<th>Week</th>"
@@ -676,21 +686,27 @@
676686
"<th>Events</th>"
677687
"<th width='90%%'><!-- relative commits graph --></th>"
678688
"</tr></thead>\n"
679689
"<tbody>\n");
680690
while( SQLITE_ROW == db_step(&q) ){
681
- const int nCount = db_column_int(&q, 1);
691
+ int nCount = db_column_int(&q, 1);
692
+ if( zCurrentWeek!=0
693
+ && strcmp(db_column_text(&q,0),zCurrentWeek)==0
694
+ && rNowFraction>0.05
695
+ ){
696
+ nCount = (int)(((double)nCount)/rNowFraction);
697
+ }
682698
if(nCount>nMaxEvents){
683699
nMaxEvents = nCount;
684700
}
685701
++iterations;
686702
}
687703
db_reset(&q);
688704
while( SQLITE_ROW == db_step(&q) ){
689705
const char *zWeek = db_column_text(&q,0);
690706
const int nCount = db_column_int(&q,1);
691
- int nSize = nCount
707
+ int nSize = (nCount>0 && nMaxEvents>0)
692708
? (int)(100 * nCount / nMaxEvents)
693709
: 0;
694710
if(!nSize) nSize = 1;
695711
total += nCount;
696712
cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
@@ -702,14 +718,29 @@
702718
}
703719
cgi_printf("'>%s</a></td>",zWeek);
704720
705721
cgi_printf("<td>%d</td>",nCount);
706722
cgi_printf("<td>");
707
- if(nCount){
708
- cgi_printf("<div class='statistics-report-graph-line'"
709
- "style='width:%d%%;'>&nbsp;</div>",
710
- nSize);
723
+ if( nCount ){
724
+ if( zCurrentWeek!=0
725
+ && strcmp(zWeek, zCurrentWeek)==0
726
+ && rNowFraction>0.05
727
+ && nMaxEvents>0
728
+ ){
729
+ /* If the covered covered by this row contains "now", then project
730
+ ** the number of changes until the completion of the week and
731
+ ** show a dashed box of that projection. */
732
+ int nExtra = (int)(((double)nCount)/rNowFraction) - nCount;
733
+ int nXSize = (100 * nExtra)/nMaxEvents;
734
+ @ <span class='statistics-report-graph-line' \
735
+ @ style='display:inline-block;min-width:%d(nSize)%%;'>&nbsp;</span>\
736
+ @ <span class='statistics-report-graph-extra' \
737
+ @ style='display:inline-block;min-width:%d(nXSize)%%;'>&nbsp;</span>\
738
+ }else{
739
+ @ <div class='statistics-report-graph-line' \
740
+ @ style='width:%d(nSize)%%;'>&nbsp;</div> \
741
+ }
711742
}
712743
cgi_printf("</td></tr>\n");
713744
}
714745
db_finalize(&q);
715746
cgi_printf("</tbody></table>");
716747
--- src/statrep.c
+++ src/statrep.c
@@ -639,10 +639,13 @@
639 int nMaxEvents = 1; /* max number of events for
640 all rows. */
641 int iterations = 0; /* # of active time periods. */
642 int rowCount = 0;
643 int total = 0;
 
 
 
644
645 stats_report_init_view();
646 style_submenu_sql("y", "Year:",
647 "WITH RECURSIVE a(b) AS ("
648 " SELECT substr(date('now'),1,4) UNION ALL"
@@ -665,11 +668,18 @@
665 @ for the calendar weeks of %h(zYear)
666 if( zUserName ){
667 @ for user %h(zUserName)
668 }
669 @ </h1>
670 style_table_sorter();
 
 
 
 
 
 
 
671 cgi_printf("<table class='statistics-report-table-events sortable' "
672 "border='0' cellpadding='2' width='100%%' "
673 "cellspacing='0' data-column-types='tnx' data-init-sort='0'>\n");
674 cgi_printf("<thead><tr>"
675 "<th>Week</th>"
@@ -676,21 +686,27 @@
676 "<th>Events</th>"
677 "<th width='90%%'><!-- relative commits graph --></th>"
678 "</tr></thead>\n"
679 "<tbody>\n");
680 while( SQLITE_ROW == db_step(&q) ){
681 const int nCount = db_column_int(&q, 1);
 
 
 
 
 
 
682 if(nCount>nMaxEvents){
683 nMaxEvents = nCount;
684 }
685 ++iterations;
686 }
687 db_reset(&q);
688 while( SQLITE_ROW == db_step(&q) ){
689 const char *zWeek = db_column_text(&q,0);
690 const int nCount = db_column_int(&q,1);
691 int nSize = nCount
692 ? (int)(100 * nCount / nMaxEvents)
693 : 0;
694 if(!nSize) nSize = 1;
695 total += nCount;
696 cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
@@ -702,14 +718,29 @@
702 }
703 cgi_printf("'>%s</a></td>",zWeek);
704
705 cgi_printf("<td>%d</td>",nCount);
706 cgi_printf("<td>");
707 if(nCount){
708 cgi_printf("<div class='statistics-report-graph-line'"
709 "style='width:%d%%;'>&nbsp;</div>",
710 nSize);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711 }
712 cgi_printf("</td></tr>\n");
713 }
714 db_finalize(&q);
715 cgi_printf("</tbody></table>");
716
--- src/statrep.c
+++ src/statrep.c
@@ -639,10 +639,13 @@
639 int nMaxEvents = 1; /* max number of events for
640 all rows. */
641 int iterations = 0; /* # of active time periods. */
642 int rowCount = 0;
643 int total = 0;
644 char *zCurrentWeek; /* Current week number */
645 double rNowFraction = 0.0; /* Fraction of current week that has
646 ** passed */
647
648 stats_report_init_view();
649 style_submenu_sql("y", "Year:",
650 "WITH RECURSIVE a(b) AS ("
651 " SELECT substr(date('now'),1,4) UNION ALL"
@@ -665,11 +668,18 @@
668 @ for the calendar weeks of %h(zYear)
669 if( zUserName ){
670 @ for user %h(zUserName)
671 }
672 @ </h1>
673 zCurrentWeek = db_text(0,
674 "SELECT strftime('%%W','now') WHERE date() LIKE '%q%%'",
675 zYear);
676 if( zCurrentWeek ){
677 rNowFraction = db_double(0.5,
678 "SELECT (unixepoch()-unixepoch('now','weekday 0','-7 days'))/604800.0;");
679 }
680 style_table_sorter();
681 cgi_printf("<table class='statistics-report-table-events sortable' "
682 "border='0' cellpadding='2' width='100%%' "
683 "cellspacing='0' data-column-types='tnx' data-init-sort='0'>\n");
684 cgi_printf("<thead><tr>"
685 "<th>Week</th>"
@@ -676,21 +686,27 @@
686 "<th>Events</th>"
687 "<th width='90%%'><!-- relative commits graph --></th>"
688 "</tr></thead>\n"
689 "<tbody>\n");
690 while( SQLITE_ROW == db_step(&q) ){
691 int nCount = db_column_int(&q, 1);
692 if( zCurrentWeek!=0
693 && strcmp(db_column_text(&q,0),zCurrentWeek)==0
694 && rNowFraction>0.05
695 ){
696 nCount = (int)(((double)nCount)/rNowFraction);
697 }
698 if(nCount>nMaxEvents){
699 nMaxEvents = nCount;
700 }
701 ++iterations;
702 }
703 db_reset(&q);
704 while( SQLITE_ROW == db_step(&q) ){
705 const char *zWeek = db_column_text(&q,0);
706 const int nCount = db_column_int(&q,1);
707 int nSize = (nCount>0 && nMaxEvents>0)
708 ? (int)(100 * nCount / nMaxEvents)
709 : 0;
710 if(!nSize) nSize = 1;
711 total += nCount;
712 cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
@@ -702,14 +718,29 @@
718 }
719 cgi_printf("'>%s</a></td>",zWeek);
720
721 cgi_printf("<td>%d</td>",nCount);
722 cgi_printf("<td>");
723 if( nCount ){
724 if( zCurrentWeek!=0
725 && strcmp(zWeek, zCurrentWeek)==0
726 && rNowFraction>0.05
727 && nMaxEvents>0
728 ){
729 /* If the covered covered by this row contains "now", then project
730 ** the number of changes until the completion of the week and
731 ** show a dashed box of that projection. */
732 int nExtra = (int)(((double)nCount)/rNowFraction) - nCount;
733 int nXSize = (100 * nExtra)/nMaxEvents;
734 @ <span class='statistics-report-graph-line' \
735 @ style='display:inline-block;min-width:%d(nSize)%%;'>&nbsp;</span>\
736 @ <span class='statistics-report-graph-extra' \
737 @ style='display:inline-block;min-width:%d(nXSize)%%;'>&nbsp;</span>\
738 }else{
739 @ <div class='statistics-report-graph-line' \
740 @ style='width:%d(nSize)%%;'>&nbsp;</div> \
741 }
742 }
743 cgi_printf("</td></tr>\n");
744 }
745 db_finalize(&q);
746 cgi_printf("</tbody></table>");
747

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button