Skip to content

Instantly share code, notes, and snippets.

@Zambrella
Last active September 23, 2019 20:05
Show Gist options
  • Save Zambrella/6966deed558a4024a13b448e227ccc11 to your computer and use it in GitHub Desktop.
Save Zambrella/6966deed558a4024a13b448e227ccc11 to your computer and use it in GitHub Desktop.
Class to get the user bucket and total number of people
import 'constants.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Brain {
Future<dynamic> getCumulativeCount({int userMMR}) async {
http.Response response = await http.get('$kURL?apikey=$kAPIKey');
if (response.statusCode == 200) {
String responseData = response.body;
int mmrResponse =
jsonDecode(responseData)['mmr']['rows'][userMMR]['cumulative_sum'];
print(mmrResponse);
int mmrTotal = jsonDecode(responseData)['mmr']['sum']['count'];
print(mmrTotal);
double percentage = (mmrResponse / mmrTotal) * 100;
print(percentage.toStringAsPrecision(4));
} else {
print(response.statusCode);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment