Skip to content
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

Contribution system: History heatmap for user #6

Closed
joubertredrat opened this issue Nov 2, 2016 · 35 comments · Fixed by #5131
Closed

Contribution system: History heatmap for user #6

joubertredrat opened this issue Nov 2, 2016 · 35 comments · Fixed by #5131
Labels
topic/ui Change the appearance of the Gitea UI type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Milestone

Comments

@joubertredrat
Copy link
Contributor

joubertredrat commented Nov 2, 2016

Hi guys,

I think that is a possible feature, a history heatmap similar to github or gitlab.
Actually exists a plugin called Calendar HeatMap. I used this on mine project to heat application log and worked fine here.
Then, is only a idea, what you think? :)

http:https://cal-heatmap.com/
https://github.com/wa0x6e/cal-heatmap

Reference: gogs/gogs#1640

@bkcsoft
Copy link
Member

bkcsoft commented Nov 2, 2016

I would prefer a solution that is in the backend, unless it's required to have it update without reloading. Unfortunately I can't seem to find anything that does that 😒

Also this would require caching, since it will fetch huge amounts of data from disk...

@joubertredrat
Copy link
Contributor Author

Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this.

In my case I use ajax to get data, but build on frontend anyway

@tboerger tboerger changed the title [Feature suggestion] History heatmap for user History heatmap for user Nov 3, 2016
@tboerger tboerger added the type/enhancement An improvement of existing functionality label Nov 3, 2016
@tboerger tboerger added this to the 1.x.x milestone Nov 3, 2016
@xinity
Copy link
Contributor

xinity commented Nov 3, 2016

following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
something like in the latest 15days could be enough don't you think ?

@tboerger tboerger added type/feature Completely new functionality. Can only be merged if feature freeze is not active. topic/ui Change the appearance of the Gitea UI and removed type/enhancement An improvement of existing functionality labels Nov 3, 2016
@bkcsoft
Copy link
Member

bkcsoft commented Nov 4, 2016

@xinity a simple LRU-cache should suffice in my opinion. Might be useful to be able to set the size of that cache though.
For my own projects I use hashicorp/golang-lru which works just fine and has a configurable size 🙂

@charlesreid1
Copy link
Contributor

d3-calendar illustrates this really nicely and simply with javascript: https://bl.ocks.org/mbostock/4063318

git log is really flexible, so you can use it to output directly to JSON format, filter on users or dates, customize output format, etc (even has its own set of shortcodes). After an aggregation step, that data can be loaded into D3 calendar (basically just json objects with a key of the date and a value of the number of commits).

Here is a single-user activity graph that illustrates embedding the Javascript visualization in the home template file: git.charlesreid1.com and modified home template.

@lunny
Copy link
Member

lunny commented Feb 22, 2018

@charlesreid1 could you send a PR to gitea with your heatmap?

@charlesreid1
Copy link
Contributor

charlesreid1 commented Feb 22, 2018

I'm happy to put together a visualization in an PR, but a couple of things need to be worked out first:

  1. Placement. My example heatmap is commit data scraped for a single user, displayed on the home page for the (single-user) gitea server - which doesn't make sense for multi-user gitea servers. If we wanted to have a per-user heatmap, it could go a couple of places:
  • Behind the "Public Activity" tab on the user's profile (most appropriate place, but not very visible)
  • Just on top of the three tabs "Repositories"/"Public Activity"/"Starred repositories" on the user's profile (most visible, on user profile so useful for others to see your activity graph)
  • On the top of the user's dashboard (less useful since others cannot see your activity graph)
  1. Data. The model I'm using for data would need to be changed a bit as well (my visualization points to a JSON file not dynamically generated by gitea). We could modify gitea to cache per-user commit data (updated with a post-commit hook or a daily maintenance task) and provide an endpoint route, where you provide it a username and it returns commit data in a JSON form convenient for visualization.

Thoughts? Potential roadblocks?

@lunny
Copy link
Member

lunny commented Feb 22, 2018

I would like put it under the Public Activity tab and top of all the activities on user's profile. Like the below example image:
heatmap

@joubertredrat
Copy link
Contributor Author

@lunny I liked this approach, if possible to change color to green can be best.... or not, github is green too.

@charlesreid1
Copy link
Contributor

charlesreid1 commented Feb 22, 2018

Thanks @lunny for the suggestion, looks like a great spot for it.

@joubertredrat I'll do something plain and let the hipsters decide what color scheme to use. 🤓

@lafriks
Copy link
Member

lafriks commented Feb 22, 2018

Green would be more consistent with gitea theme

@charlesreid1
Copy link
Contributor

I will use ColorBrewer's YlGn theme, which looks like the same one Github uses and is nicely consistent with Gitea green.

YlGn scheme

@charlesreid1
Copy link
Contributor

It looks like gitea/models/graph.go may already implement a model for commit counts. Is that correct?

@charlesreid1
Copy link
Contributor

Maybe not... But it looks like graph.go might be useful for implementing commit counts. There are a couple of files referring to a commit graph. Is this related to the heatmap/calendar idea, or is this referring to the timeline that shows up on a user's/organization's page?

@lunny
Copy link
Member

lunny commented Feb 26, 2018

I think we need a new table to store the statistics information.

type UserHeatMap struct {
      ID int64
      UserID int64 `xorm:"index"`
      Day string `xorm:"char(10)"` // 2018-02-26
      Count int
}

And all needed data could read from table action.

@thehowl
Copy link
Contributor

thehowl commented Feb 26, 2018

Could we not use a SQL DATE instead of a char(10)?

@lafriks
Copy link
Member

lafriks commented Feb 26, 2018

Also if this is just activity from action table than probably no new table is needed just select user_id, date, count(1) with group by user_id, date?

@lunny
Copy link
Member

lunny commented Feb 26, 2018

@lafriks that maybe
select date, count(1) from action where user_id = ? and date >= ? and date < ? order by date group by date

@lafriks
Copy link
Member

lafriks commented Feb 26, 2018

@lunny yes that what I meant but I don't know if xorm supports such queries

@lunny
Copy link
Member

lunny commented Feb 27, 2018

type Stat struct {
      Date string
      Count int
}
var stats = make([]Stat,0, 366)
x.SQL(`select date, count(1) as count from action where user_id = ? and date >= ? and date < ? order by date group by date`, 
userID, startDate, endDate).Find(&stats)

@thehowl
Copy link
Contributor

thehowl commented Feb 27, 2018

would that work in all dialects?

@lafriks
Copy link
Member

lafriks commented Feb 27, 2018

If we have date column (do we?) than it should work

@lunny
Copy link
Member

lunny commented Feb 28, 2018

@lafriks we can use created and remove the time parts.

@lafriks
Copy link
Member

lafriks commented Feb 28, 2018

@lunny don't think removing time part will be that easy so that it would perform good enaugh for such select

@charlesreid1
Copy link
Contributor

This effort was over my head, as there many decisions where I didn't have a clear sense of how to proceed, so I didn't get very far.

@lunny lunny changed the title History heatmap for user Contribution system: History heatmap for user Aug 17, 2018
@kolaente
Copy link
Member

Any updates on this?

@lunny
Copy link
Member

lunny commented Oct 18, 2018

@kolaente no people are working on this.

@kolaente
Copy link
Member

Someone created a nice article on how to implement this externally: https://medium.com/@markuman/gitea-contribution-heatmap-af4be1d7a0d5

@kolaente
Copy link
Member

I'll try to implement this.

@lafriks
Copy link
Member

lafriks commented Oct 20, 2018

Problem is with this part:

group by DATE_FORMAT(FROM_UNIXTIME(created_unix), '%Y%m%d')

At least I did not find a way to implement it for sqlite

@kolaente
Copy link
Member

kolaente commented Oct 20, 2018

@lafriks I did find one:

SELECT created_unix as timestamp, count(user_id) as contributions
FROM `action`
WHERE (user_id = 1)
  AND (created_unix > 1508503562)
GROUP BY strftime('%Y-%m-%d', created_unix, 'unixepoch')
ORDER BY created_unix

I think I'll do it with a hard switch to provide another query if we are dealing with an sqlite db.

@lafriks
Copy link
Member

lafriks commented Oct 20, 2018

I think you will need different for mssql and Postgres also

@kolaente
Copy link
Member

PR is up: #5131

@naiba
Copy link
Contributor

naiba commented Oct 21, 2018

Awesome, can't wait for release this.

@lafriks lafriks modified the milestones: 1.x.x, 1.7.0 Oct 21, 2018
lunny referenced this issue in lunny/gitea Feb 7, 2019
Fix to allow tags with '/' to be returned correctly
lunny referenced this issue in lunny/gitea Feb 7, 2019
lunny referenced this issue in lunny/gitea Feb 7, 2019
6543 added a commit to 6543-forks/gitea that referenced this issue Apr 21, 2020
* some fixes
clectecd from conflict resolve and so on

* Fix Frontend LINT errors
silverwind pushed a commit to silverwind/gitea that referenced this issue Oct 27, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/ui Change the appearance of the Gitea UI type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging a pull request may close this issue.