feature: fancy statistics (without extra dependencies)#394
feature: fancy statistics (without extra dependencies)#394Jocho-Smith wants to merge 10 commits intoredimp:mainfrom
Conversation
This reverts commit 9057f8e.
add admin_dashboard() that 1. builds Mermaid pie chart 2. renders the markdown to html add item *dashboard* to settings side bar add dashboard.html NOTE: Mermaid did not render by itself outside of .md files, so I hat 2 choices: either in dashboard.html or in wiki.html. Doing it in dashboard.html is ugly, but that way I ensured I understand its implications to the rest of otterwiki. adding it to wiki.html would conceptually fit better, but I doubt other system pages (user management, about, ...) will benefit from global Mermaid rendering
|
An ideas I just had: I noticed that after ~12 users/entries the pie chart starts to look a bit messy. I could modify the function to only show the top 10 users and concatenate the remainder users into on entry. |
redimp
left a comment
There was a problem hiding this comment.
Hey @Jocho-Smith, thank you for this PR. An Otter Wiki lacks anything even roughly in the direction of fancy statistics. This PR might lead to a nice enhancement.
The current state of the PR is more a draft. Please read the review carefully and implement the required changes.
I'm thinking about what else might be nice to see when looking at statistics/graphs of a wiki:
- a code frequency graph with additions and deletions
- an activity heat map, showing when changes happened
I was thinking about dynamically loading the graphs, but since all of these could be computed from the same log query this can be done quickly enough.
|
|
||
| {% block title %} | ||
| <title>Contribution Dashboard</title> | ||
| <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script> |
There was a problem hiding this comment.
General Note: We want to keep An Otter Wiki free of external dependencies. It should always be possible to run it in an air-gapped environment, so using any external source is not possible.
Mermaid (11.6.0) is distributed with An Otter Wiki, there is no need to load it from a cdn.
| {% block title %} | ||
| <title>Contribution Dashboard</title> | ||
| <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script> | ||
| <script> |
There was a problem hiding this comment.
Please do not place scripts in the {% block title %} there is a {% block js %}.
An example how to load mermaid can be found in otterwiki/templates/syntax.html:
otterwiki/otterwiki/templates/syntax.html
Lines 12 to 17 in e951fed
There was a problem hiding this comment.
Not sure how I overlooked this.. This way it also behaves properly with dark and light mode <3
otterwiki/templates/settings.html
Outdated
| <span class="sidebar-icon" style="min-width: 3rem;"> | ||
| <i class="fas fa-chart-pie"></i> | ||
| </span> | ||
| Dashboard |
There was a problem hiding this comment.
This feature seems to mostly target statistics, please rename the sidebar entry to 'Statistics'.
otterwiki/views.py
Outdated
|
|
||
| def mermaid_commit_block(title: str, git_args: list) -> str: | ||
| """Run git log, count commits per author, return a Mermaid pie chart as markdown.""" | ||
| result = subprocess.run( |
There was a problem hiding this comment.
Please use the otterwiki.gitstorage module for fetching the log file. No need to reinvent the wheel.
otterwiki/views.py
Outdated
| return otterwiki.preferences.handle_mail_preferences(request.form) | ||
|
|
||
|
|
||
| @app.route("/-/admin/dashboard") |
There was a problem hiding this comment.
We want to prevent to have any complex logic in the otterwiki.views Module. Please move the logic into e.g. otterwiki.statistics.
otterwiki/views.py
Outdated
| markdown_content = "\n\n".join([all_commits_block, last_3_months_block]) | ||
|
|
||
| # Render Markdown | ||
| htmlcontent, _, library_requirements = render.markdown(markdown_content) |
There was a problem hiding this comment.
I'm torn here ... It is a nice idea to use the renderer for displaying internal statistics module. On the other hand, just adding the mermaid plain to the template skips the need for using the renderer here.
There was a problem hiding this comment.
I removed the renderer now.
|
Thank you for this extensive feedback! I'll put in some time to implement the required changes.
I don't understand what exactly you mean by that. Can you share a picture of it?
Actually I implemented this some time ago, however I don't see how to do that with Mermaid. What package would you be fine to distribute it within otterwiki for this Statistics feature? I've seen Flask+Plotly some times. |
|
So what do you think how should we continue from here? Do you want to take this simple mermaid statistics feature as it is - maybe as an "experimental feature" (as in 'Repository Management') - or should we dive into more sophisticated packages (like Plotly)? |
|
This looks much better thanks for the effort. Are Pie Charts the best option?I checked how these charts look like for different projects and came to the conclusion that Pie Charts are not the best way for displaying this. In most projects the number of commits is very unbalanced a lot of people only have a small number of commits. I think a bar chart would be better suited, like github does it, see https://github.com/redimp/otterwiki/pulse:
I gave it a try and this looks readable to me:
Code: ```mermaid
---
config:
xyChart:
showDataLabel: true
width: 500
height: 400
themeVariables:
plotColorPalette: '#1890ff'
---
xychart
title "February 21, 2026 – February 28, 2026"
y-axis "Commits"
x-axis ["redimp", "deseven", "ryanwhowe", "Prodeguerriero","gokomer"]
bar [9,3,2,2,1]
```Note: I updated mermaid to 11.12.3 to make this work. What do you think? Other options for diagramsFor now I don't want to add more dependencies if not really necessary. Adding e.g. More diagrams to display:Heapmap: Yes what you created with seaborn is exactly what I had in mind. This needs no library, you can build this with a html table ;) LayoutAnother thing to optimize is the layout of the diagrams, the two diagrams shouuld be displayed side by side if the screen size allows it (so everything wider than mobile screens). |
|
Hey @redimp
I love it! This was actually my initial plan, I just accepted the current mermaid version and went with what is available. Obviously one can just update mermaid xD
Cool idea, I'll work on that.
This could probably also be done with just html/css - I think flexbox does the job. I'll try that out. plan for this PRSo what would you suggest is the objective of this PR? xychart + html heatmap + flexbox = merge? Or should we discus this more? Sorry btw. for crashing in with a PR, without opening an Issue for discussion first. |
In general I merge PRs when I have nothing to ask for anymore ;) I'm way more picky for completely new features: In this case, when this statistics page looks nice and I think users of An Otter Wiki can get something useful from it, I will merge it. |
|
Ok. Then I guess we will see where this goes. For now I'll work on the things you suggested ✌️ |




The Idea is to have a dashboard in the settings to review the number of commits made by users.
Here is how it looks like now:
On my machine, it passes all the tests.
Note:
Happy to hear any feedback :)