Visitar URL original
[imitatioin_game] Made the imitation_game start reporting its results… · creatorpiyush/packages@d7423fb · GitHub
Skip to content

Commit d7423fb

Browse files
authored
[imitatioin_game] Made the imitation_game start reporting its results in the README.md. (flutter#193)
1 parent d19d220 commit d7423fb

93 files changed

Lines changed: 256 additions & 73 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 0 deletions

‎packages/imitation_game/LICENSE‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2019 The Chromium Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

‎packages/imitation_game/README.md‎

Lines changed: 11 additions & 1 deletion

packages/imitation_game/imitation_game.dart renamed to packages/imitation_game/bin/imitation_game.dart

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
4+
import 'package:mustache/mustache.dart';
5+
import 'package:imitation_game/README_template.dart';
46

57
const int _port = 4040;
68

@@ -33,6 +35,14 @@ Future<List<FileSystemEntity>> findFiles(Directory dir, {FileFilter where}) {
3335
return completer.future;
3436
}
3537

38+
String _makeMarkdownOutput(Map<String, dynamic> results) {
39+
final Template template = Template(readmeTemplate, name: 'README.md');
40+
final Map<String, dynamic> values = Map<String, dynamic>.from(results);
41+
values['date'] = DateTime.now().toUtc();
42+
final String output = template.renderString(values);
43+
return output;
44+
}
45+
3646
class _Script {
3747
_Script({this.path});
3848
String path;
@@ -75,6 +85,33 @@ class _ScriptRunner {
7585
}
7686
}
7787

88+
/// Recursively converts a map of maps to a map of lists of maps.
89+
///
90+
/// For example:
91+
/// _map2List({'a': {'b': 123}}, ['foo', 'bar']) ->
92+
/// {
93+
/// 'foo':[
94+
/// {
95+
/// 'name': 'a',
96+
/// 'bar': [{'name': 'b', 'value': 123}]
97+
/// }
98+
/// ]
99+
/// }
100+
Map<String, dynamic> _map2List(Map<String, dynamic> map, List<String> names) {
101+
final List<Map<String, dynamic>> returnList = <Map<String, dynamic>>[];
102+
final List<String> tail = names.sublist(1);
103+
map.forEach((String key, dynamic value) {
104+
final Map<String, dynamic> testResult = <String, dynamic>{'name': key};
105+
if (tail.isEmpty) {
106+
testResult['value'] = value;
107+
} else {
108+
testResult[tail.first] = _map2List(value, tail)[tail.first];
109+
}
110+
returnList.add(testResult);
111+
});
112+
return <String, dynamic>{names.first: returnList};
113+
}
114+
78115
class _ImitationGame {
79116
final Map<String, dynamic> results = <String, dynamic>{};
80117
_ScriptRunner _scriptRunner;
@@ -95,6 +132,7 @@ class _ImitationGame {
95132
results[test][platform] = <String, dynamic>{};
96133
}
97134
data['results'].forEach((String k, dynamic v) {
135+
// ignore: avoid_as
98136
results[test][platform][k] = v as double;
99137
});
100138
return _runNext();
@@ -148,6 +186,7 @@ Future<void> main() async {
148186
if (request.method == 'POST') {
149187
final String content = await utf8.decoder.bind(request).join();
150188
final Map<String, dynamic> data =
189+
// ignore: avoid_as
151190
jsonDecode(content) as Map<String, dynamic>;
152191
print('$data');
153192
keepRunning = await game.handleResult(data);
@@ -163,8 +202,9 @@ Future<void> main() async {
163202
keepRunning = await game.handleTimeout();
164203
}
165204
}
166-
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
167-
final String jsonResults = encoder.convert(game.results);
168-
print('$jsonResults');
205+
206+
final Map<String, dynamic> markdownValues =
207+
_map2List(game.results, <String>['tests', 'platforms', 'measurements']);
208+
File('README.md').writeAsStringSync(_makeMarkdownOutput(markdownValues));
169209
await server.close(force: true);
170210
}

packages/imitation_game/tests/smiley/flutter/run_ios.sh renamed to packages/imitation_game/imitation_tests/smiley/flutter/run_ios.sh

File renamed without changes.

packages/imitation_game/tests/smiley/flutter/smiley/.gitignore renamed to packages/imitation_game/imitation_tests/smiley/flutter/smiley/.gitignore

File renamed without changes.

packages/imitation_game/tests/smiley/flutter/smiley/.metadata renamed to packages/imitation_game/imitation_tests/smiley/flutter/smiley/.metadata

File renamed without changes.

packages/imitation_game/tests/smiley/flutter/smiley/README.md renamed to packages/imitation_game/imitation_tests/smiley/flutter/smiley/README.md

packages/imitation_game/tests/smiley/flutter/smiley/android/.gitignore renamed to packages/imitation_game/imitation_tests/smiley/flutter/smiley/android/.gitignore

File renamed without changes.

0 commit comments

Comments
 (0)