Giter VIP home page Giter VIP logo

polylinguist's Introduction

Polylinguist

More exact language usage stats from Github profile.

Features:

  • No limits like only "top 10 languages"
  • Both public & private repos via access token
  • Aliasing similar languages to same stats. For example, combine C & C++ to C/C++
  • Ignoring languages. For example, drop markup like SCSS, HTML, Twig etc.
  • Ignoring repositories. For example, drop a repository that contains megabytes of generated code, skewing statistics.

Install

go get github.com/stscoundrel/polylinguist

Usage

Polylinguist exposes a functions for getting Github language stats by username & access token.

With default settings:

package main

import (
    "fmt"

	"github.com/stscoundrel/polylinguist"
)

accessToken := "YOUR_ACCESS_TOKEN"

// Fetches all languages from all repos.
stats, err := polylinguist.GetTopLanguages("YOUR_USERNAME", accessToken)

if err != nil {
    // However you want to deal with your errors.
    // Most likely cause: failed network, failed auth.
}

for index, language := range stats {
    fmt.Printf("%d. %s - %f - %s \n", index+1, language.Name, language.Percentage, language.Color)
}

With custom settings:

package main

import (
    "fmt"

	"github.com/stscoundrel/polylinguist"
	"github.com/stscoundrel/polylinguist/stats"
)

accessToken := "YOUR_ACCESS_TOKEN"

// Setup custom settings to skip certain languages & repos
// Also set custom aliases to combine some languages into single statistic.
settings := stats.Settings{
    IgnoredLanguages: []string{"SCSS", "CSS", "ASL", "HTML"},
    IgnoredRepos: []string{
        "old-norwegian-dictionary",
        "old-norwegian-dictionary-rs",
        "old-norwegian-dictionary-go",
    },
    AliasedLanguages: []stats.LanguageAlias{
        {
            Language: "C",
            Alias:    "C/C++",
        },
        {
            Language: "C++",
            Alias:    "C/C++",
        },
    },
}

stats, err := polylinguist.GetTopLanguagesWithSettings("YOUR_USERNAME", accessToken, settings)

if err != nil {
    // However you want to deal with your errors.
}

for index, language := range stats {
    fmt.Printf("%d. %s - %f - %s \n", index+1, language.Name, language.Percentage, language.Color)
}

Output will be something to the effect of:

1. TypeScript - 37.237267 - #3178c6 
2. JavaScript - 28.081825 - #f1e05a 
3. Go - 9.608068 - #00ADD8 
4. Rust - 5.951985 - #dea584 
5. C# - 5.426030 - #178600 
6. PHP - 4.735421 - #4F5D95 
7. Python - 3.653692 - #3572A5 
8. Java - 2.354974 - #b07219 
9. Nim - 1.370613 - #ffc200 
10. Scala - 0.892341 - #c22d40 
11. C/C++ - 0.359692 - #555555 
12. Kotlin - 0.223640 - #A97BFF 
13. F# - 0.076285 - #b845fc 
14. Dockerfile - 0.027167 - #384d54 
15. Shell - 0.001000 - #89e051

Up to you what kind of graphic or chart you want to produce with the data. The data includes Github language colors for visual portions.

As Vercel Cloud Function

For a template on usage as a cloud function on Vercel, see this repo

polylinguist's People

Contributors

dependabot[bot] avatar stscoundrel avatar

Watchers

 avatar  avatar

polylinguist's Issues

Return language sums in addition to percentages

Percentages are always relative to other languages. Therefore, comparing given languages percentage over time does not really tell if its usage has changed or not.

Return also the sum of each languages usage in addition to the percentage. Makes it easier to follow changes in language and/or total lines of code.

Ignored languages & repos

Allow languages & repos to be ignored.

Use case: skip "languages" like CSS/SCSS or singular repos that contain huge amount of generated code.

Allow combining of languages to one

Some languages may make more sense to be listed together. Allow that via custom mapping.

For example:

  • Combine C & C++ to C/C++
  • Combine Java, Kotlin and Scala to JVM
  • Combine SCSS, LESS and CSS to CSS
  • Combine JavaScript & TypeScript to JS/TS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.