Skip to content

Instantly share code, notes, and snippets.

@malibayram
Created July 11, 2023 09:44
Show Gist options
  • Save malibayram/20d00afcd33a5f277dd5938dadcd8338 to your computer and use it in GitHub Desktop.
Save malibayram/20d00afcd33a5f277dd5938dadcd8338 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async {
final data = await getData();
// get the record list of any keys, 'Score' as an example
final recordList = (data['Information'] as List)
.firstWhere((t) => (t as Map).keys.first == 'Score')['Score']
['RecordList'];
print(recordList);
// get the average of the records
final average = recordList
.map((record) => double.tryParse("${record['Value']}") ?? 0)
.reduce((a, b) => a + b) /
recordList.length;
print(average);
}
Future<Map> getData() async {
final res = await http.get(Uri.parse(
"https://hkbu-api.hibluesky.co:8443/Iaq/Information/1100/2023-07-02T16:00:00.000Z/2023-07-03T07:00:00.00Z/3600000"));
return jsonDecode(res.body) as Map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment