Skip to content

How can I calculate the repository language number of bytes into percentage? #313

Open

Description

@amirVirtuenetz

According to this repository
i have testing the Language Breakdown
and i found the exact solution
here is response and code below
Future loadRepositories()async{

  var  github = createClient(AppConstantNames.personalAccessToken);
  // github.users.getCurrentUser().then((final CurrentUser user) {
  //   log(user.login!);
  // });
  Repository repo = await github.repositories.getRepository(RepositorySlug('amirVirtuenetz', 'App-Navigation-Flutter'));
  final abcrepo=RepositorySlug('amirVirtuenetz', 'App-Navigation-Flutter');
  breakdown=await github.repositories.listLanguages(abcrepo);
   print(breakdown.runtimeType);
 loadLanguage();
  print("heis is dfsdf");
}
void loadLanguage({int accuracy=4}){
var github=GitHub();

final md=generateMarkDown(accuracy);
github.misc.renderMarkdown(md).then((value){
  log("value $value");
});

}
int totalBytes(LanguageBreakdown breakdown) {
return breakdown.info.values.reduce((a, b) => a + b);
}
String generateMarkDown(int accuracy){
final total = totalBytes(breakdown);
final data = breakdown.toList();
var md = StringBuffer('''
|Name|Bytes|Percentage|
|-----|-----|-----|
''');
data.sort((a, b) => b[1].compareTo(a[1]));
for (final info in data) {
final String? name = info[0];
final int bytes = info[1];
final num percentage = (bytes / total) * 100;
md.writeln('|$name|$bytes|${percentage.toStringAsFixed(2)}|');
}
// log("List Language Data ${md}");
return md.toString();
}

and response is like excatly that in my github repository languages shwoing
output:

|Name|Bytes|Percentage|
|-----|-----|-----|
|Dart|178241|85.59|

|C++|16824|8.08| |CMake|7951|3.82| |HTML|3938|1.89| |C|734|0.35| |Swift|404|0.19| |Kotlin|130|0.06| |Objective-C|38|0.02|

my question is that , I am using the GitHub rest API of list of lanugage here is api: https://api.github.com/repos/OWNER/REPO/languages i have cover all the basics step to authenticate now i got the response from this api is {"Dart":178241,"C++":16824,"CMake":7951,"HTML":3938,"C":734,"Swift":404,"Kotlin":130,"Objective-C":38} how can i convert number of bytes of code into percentage? thank you!

Activity

  1. github-actions commented on Jun 22, 2022

    @github-actions

    👋 Thanks for reporting! @robrbecker will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions