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

Add a Language Statistics Bar to repo/view #2135

Closed
wants to merge 7 commits into from

Conversation

dayvonjersen
Copy link

EDIT: ackk, I didn't select develop branch first sorry >_<
EDIT 2: didn't post my thoughtfully worded explanation,
only commit message second time. need to sleep.

Hi,

Long-time user, first-time contributor here. Really love this project
it's so cool to have my own personal clone of github to privately host
stuff.

I don't know what possessed me over the past two days or so,
but I really, really wanted to have github's language statistics bar
in gogs.

So much so that I thought I saw it mentioned here: #1447

Even though it's not an important feature, per-se, it's one of
the things I love looking at the most on github for some
reason I cannot explain.

The changes made here are probably not ideal, hopefully they can
be adapted to better fit the project.

The really substantial part is accomplished by this library I hacked on:
https://github.com/generaltso/linguist

And its command-line companion that I haven't finished yet:
https://github.com/generaltso/l

Please see commit message for more/slightly different words

<3
~tso

With the usage of a port of github's linguist functionality to Go,
which I have made as a separate library and is hosted here:

https://github.com/generaltso/linguist

And a quick design I made, I have hacked a language statistics bar
into gogs

I wasn't sure where to put everything so it's sitting directly
on the view router and the CSS is inlined into a new template file

Based on the structure of this project I would fully expect this
feature to belong in its own sub-package

Also, even though determining language stats on-the-fly is pretty
fast, caching the results in the database for large codebases
would probably be a much better strategy, especially if the top
language were to be displayed in the "Explore" view like GitHub has

I also had difficulty trying to figure out how to do:

if len(something) == 1 ? '' : 's'

with go templates for plurals (1 Commit vs 2 Commits), and I kinda
gave up there...
@dayvonjersen
Copy link
Author

I should probably also include an example of what it looks like:

http://var.abl.cl/language-bar-example.htm

(home server, connection may be spotty...)

Here are screenshots:
https://u.teknik.io/zFdsty.png
https://u.teknik.io/tqKR6K.png

@thehowl
Copy link
Contributor

thehowl commented Dec 9, 2015

👍 👍 👍 👍 👍 👍 👍 👍 👍

@nanoant
Copy link
Contributor

nanoant commented Dec 9, 2015

While generally I am okay with the idea of showing language statistics, I don't think there's a reason to put that on very first page of the repo. It occupies really precious space, it uses extra CPU cycles to gather & render these stats, that may be irrelevant anyway to many projects.

I suggest such thing maybe should live in some separate tab, maybe called Statistics or Graphs like on GitHub.

There're also couple of things wrong with your PR:

  1. New templates rely on completely custom (possibly non-portable) CSS code, rather than Semantic UI used across the project.
  2. <style> injected into the page itself, where all CSS related stuff should be defined in .less files, and only if it is really necessary and cannot be done using pure Semantic UI constructs.

Didn't mention the that the templates are not following indention rules of the project.

@unknwon
Copy link
Member

unknwon commented Dec 9, 2015

The idea is awesome, but I need more time dig into your linguist lib and some other points @nanoant already made.

@unknwon unknwon added this to the 0.8.x milestone Dec 9, 2015
@unknwon
Copy link
Member

unknwon commented Dec 10, 2015

If we are really going to add this feature, should consider put github.com/generaltso/linguist under Gogs's organization account.

The way this package works certainly has many downsides such as require user to install Go...

@unknwon unknwon added the status: needs feedback Tell me more about it label Dec 10, 2015
@dayvonjersen
Copy link
Author

Hello again,

I should preface this with some disclaimers:

I am not really familiar with the code structure of this project, or its
conventions.

I just wanted to get the ball rolling with just simple a proof of concept
demo for a feature I really wanted to have. :)

While generally I am okay with the idea of showing language statistics, I don't think there's a reason to put that on very first page of the repo. It occupies really precious space, it uses extra CPU cycles to gather & render these stats, that may be irrelevant anyway to many projects.

Yes, I agree. Ideally, it would be an optional, toggle on-off feature where
the data is gathered in the background (probably on a post-receive hook) and
cached in the database somewhere.

I suggest such thing maybe should live in some separate tab, maybe called Statistics or Graphs like on GitHub.

Even better :)

(css stuff, indentation)

I can change this, I just wanted to create a self-contained widget with a
particular design I had in mind (namely the 3D block effect) without breaking
the rest of the CSS on the site.

And I can change the whitespace to be consistent with everything else

The idea is awesome, but I need more time dig into your linguist lib

Yes, please do have a look: https://github.com/generaltso/linguist

I've consolidated and reworked quite a few things now, and it's working
better. I wrote up some documentation and you can try out the l utility
which is a cli version of gathering stats using the library:

go get github.com/generaltso/linguist/cmd/l

I made breaking changes however so actually this pull request will not work
in any case any more :\ But I'm not sure about the conventions of these things
...Where do we go from here?

If you want to integrate this feature in your own way and just use the library
or help me make the library better
or write your own library

or whatever! Let me know what I can do to help make it happen :D

The way this package works certainly has many downsides such as require user to install Go...

Yes I was very disappointed by having to do this but I ran into problems with
trying to embed the serialized github.com/jbrukh/bayesian.Classifier directly

Previously I had this: dayvonjersen/linguist@33fd2ec#diff-599c352338d4002d410b66e78d0f1f7dL89

And this: dayvonjersen/linguist@33fd2ec#diff-0f2d1bb050d649324fb99a481841ab4bL14

But the data stream could not be decoded after the classifier reached a certain
arbitrary size (megabytes).

If you know of any good way to embed large, serialized data into go programs
and deserialize them directly without data corruption or having to use the
filesystem or third-party hosting I'm all ears :)

~ tso

@unknwon
Copy link
Member

unknwon commented Dec 10, 2015

@generaltso thanks for following up!

The way I prefer would be put linguist package under Gogs organization, so we can either:

  1. Transfer your current repository and add you to the organization
  2. Create a new repository based on your current work

Before you decide, note that in both cases, the code of package will possibly be modified a lot in order to better fit into Gogs main repository.

@dayvonjersen
Copy link
Author

@unknwon OK you have my blessing to do what you need

Do you need me to initiate the transfer? Do I transfer to you or @gogits?

Or is it easier to create a new project?

~tso

@nanoant
Copy link
Contributor

nanoant commented Dec 10, 2015

(css stuff, indentation)

I can change this, I just wanted to create a self-contained widget with a
particular design I had in mind (namely the 3D block effect) without breaking
the rest of the CSS on the site.

@generaltso That's why you should use existing Semantic UI class rather than introducing custom CSS to keep the L&F consistent and keep the code (including templates) abstract & as small as possible. Have a look at Semantic UI's Menu which is basically all you need there. NOTE: This menu class is used in many places across Gogs, so just look for "ui menu" class for example.

@unknwon
Copy link
Member

unknwon commented Dec 10, 2015

@generaltso

Or is it easier to create a new project?

This is basically my second suggestion :D

If you're Ok with this way, the project should works nicer with Gogs, and I'll start doing so.

@dayvonjersen
Copy link
Author

@unknwon make it so

@nanoant ok well you can throw it out and start over again it was just a quick mockup
The framework provides things like like the 1px border and rounded corners on menus
and stuff, yes I should have done more research into using existing classes for that but
the heavily stylized stuff like the circle ::before pseudo element and using css to display
the percentages and colors dynamically, both for that circle and the graph display
underneath... I didn't really want to over-complicate what was, again, just a mockup

EDIT: also the 3d box effect. I did this all for the 3d box effect D:

The design of gogs has greatly improved with the recent switch to Semantic UI so I don't
want to make it seem like it isn't great but I just made the simplest thing that would work
please have mercy :x

~tso

@unknwon unknwon removed the status: needs feedback Tell me more about it label Dec 11, 2015
 - Limit amount of data sent to linguist.LanguageByContents to 512 bytes
   (performance concern, though it is still slow...)

 - Limit amount of results to 8, sum remainder and display as "Other"
   (the widget looks cluttered with a lot of results)

 - Better error handling.
@dayvonjersen
Copy link
Author

Hello again,

I've continued work on my go linguist library over the past week.

That project has advanced significantly since I first made this PR, and
I would direct your attention to that repo for the details.

I've updated this branch to reflect any API changes I've made since
then, as well as some other tidying up and making the templates and
less/css more consistent with the existing ui (hopefully!)

I would stress again that this is just a proof-of-concept, offered as a
starting point, something born from my irrational, burning desire to have
language statistics for my projects, which I'm happy to report is a now
a reality on my personal install of gogs.

I hope you find these updated changes more useful than the last in some
way, shape or form. I know @unknwon mentioned creating a new module/repo
for this functionality but I haven't seen any movement on that front yet
and I didn't want abandon my linguist project in an unfinished state...

...and this PR was still open so now I'm leaving this message ok bye <3
~tso

@unknwon
Copy link
Member

unknwon commented Dec 17, 2015

I didn't want abandon my linguist project in an unfinished state...

Yes this is a good thing to do.

Many other works are ahead of this. So need wait for more time.

@carbontwelve
Copy link
Contributor

I really like the idea of adding this.

@tonivj5
Copy link
Contributor

tonivj5 commented Feb 25, 2016

+1

@unknwon unknwon added the status: review later The pull request is not confident to be review at the moment label Mar 25, 2016
@bkcsoft bkcsoft mentioned this pull request May 25, 2016
@unknwon unknwon closed this Oct 25, 2019
@github-actions GitHub Actions bot locked as resolved and limited conversation to collaborators Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: review later The pull request is not confident to be review at the moment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants