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

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

Open
amirVirtuenetz opened this issue Jun 22, 2022 · 1 comment

Comments

@amirVirtuenetz
Copy link

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!
@github-actions
Copy link

👋 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
Projects
None yet
Development

No branches or pull requests

1 participant