<commit_before>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * TODO:
 */
library stagehand.analytics_io;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:io';

import 'package:path/path.dart' as path;

import 'src/analytics_impl.dart';

export 'analytics.dart';

// TODO: send the OS? Or is it parsed from the dart:io user agent?

/**
 * TODO:
 */
class AnalyticsIO extends AnalyticsImpl {
  AnalyticsIO(String trackingId, String applicationName, String applicationVersion) :
    super(
      trackingId,
      new _PersistentProperties(applicationName),
      new _PostHandler(),
      applicationName: applicationName,
      applicationVersion: applicationVersion);
}

class _PostHandler extends PostHandler {
  String _userAgent;

  _PostHandler() {
    _userAgent = _createUserAgent();
  }

  Future sendPost(String url, Map<String, String> parameters) {
    String data = postEncode(parameters);

    HttpClient client = new HttpClient();
    client.userAgent = _userAgent;
    return client.postUrl(Uri.parse(url)).then((HttpClientRequest req) {
      req.write(data);
      return req.close();
    }).then((HttpClientResponse response) {
      response.drain();
    });
  }

  String _createUserAgent() {
    // Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en)
    String locale = Platform.environment['LANG'];
    return "Dart/${Platform.version} (${Platform.operatingSystem}; ${locale})";
  }<commit_msg>try and track OS<commit_after>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * TODO:
 */
library stagehand.analytics_io;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:io';

import 'package:path/path.dart' as path;

import 'src/analytics_impl.dart';

export 'analytics.dart';

/**
 * TODO:
 */
class AnalyticsIO extends AnalyticsImpl {
  AnalyticsIO(String trackingId, String applicationName, String applicationVersion) :
    super(
      trackingId,
      new _PersistentProperties(applicationName),
      new _PostHandler(),
      applicationName: applicationName,
      applicationVersion: applicationVersion);
}

class _PostHandler extends PostHandler {
  String _userAgent;

  _PostHandler() {
    _userAgent = _createUserAgent();
  }

  Future sendPost(String url, Map<String, String> parameters) {
    String data = postEncode(parameters);

    // TODO: Should we try and re-use this client?
    HttpClient client = new HttpClient();
    client.userAgent = _userAgent;
    return client.postUrl(Uri.parse(url)).then((HttpClientRequest req) {
      req.write(data);
      return req.close();
    }).then((HttpClientResponse response) {
      response.drain();
    });
  }

  String _createUserAgent() {
    // Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en)
    String os = Platform.operatingSystem;
    String locale = Platform.environment['LANG'];
    return "Dart/${Platform.version} (${os}; ${os}; ${os}; ${locale})";
  }
{'fraction_non_alphanumeric': 0.11781076066790352, 'fraction_numerical': 0.0055658627087198514, 'mean_word_length': 3.778434268833087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5808106', 'n_tokens_mistral': 974, 'n_tokens_neox': 947, 'n_words': 287}