1 | import {DateWrapper, isPresent, isBlank, Json} from 'angular2/src/facade/lang';
|
2 | import {PromiseWrapper} from 'angular2/src/facade/async';
|
3 |
|
4 | import {bind, provide, Provider, OpaqueToken} from 'angular2/src/core/di';
|
5 |
|
6 | import {Reporter} from '../reporter';
|
7 | import {SampleDescription} from '../sample_description';
|
8 | import {MeasureValues} from '../measure_values';
|
9 | import {Options} from '../common_options';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export class JsonFileReporter extends Reporter {
|
15 |
|
16 | static get PATH(): OpaqueToken { return _PATH; }
|
17 |
|
18 | static get BINDINGS(): Provider[] { return _PROVIDERS; }
|
19 |
|
20 | _writeFile: Function;
|
21 | _path: string;
|
22 | _description: SampleDescription;
|
23 | _now: Function;
|
24 |
|
25 | constructor(sampleDescription, path, writeFile, now) {
|
26 | super();
|
27 | this._description = sampleDescription;
|
28 | this._path = path;
|
29 | this._writeFile = writeFile;
|
30 | this._now = now;
|
31 | }
|
32 |
|
33 | reportMeasureValues(measureValues: MeasureValues): Promise<any> {
|
34 | return PromiseWrapper.resolve(null);
|
35 | }
|
36 |
|
37 | reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise<any> {
|
38 | var content = Json.stringify({
|
39 | 'description': this._description,
|
40 | 'completeSample': completeSample,
|
41 | 'validSample': validSample
|
42 | });
|
43 | var filePath =
|
44 | `${this._path}/${this._description.id}_${DateWrapper.toMillis(this._now())}.json`;
|
45 | return this._writeFile(filePath, content);
|
46 | }
|
47 | }
|
48 |
|
49 | var _PATH = new OpaqueToken('JsonFileReporter.path');
|
50 | var _PROVIDERS = [
|
51 | bind(JsonFileReporter)
|
52 | .toFactory((sampleDescription, path, writeFile, now) =>
|
53 | new JsonFileReporter(sampleDescription, path, writeFile, now),
|
54 | [SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
|
55 | provide(_PATH, {useValue: '.'})
|
56 | ];
|