<commit_before># Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import webapp2

from dashboard.pinpoint.models import change
from dashboard.pinpoint.models import job as job_module


class New(webapp2.RequestHandler):
  """Handler that cooks up a fresh Pinpoint job."""

  def post(self):
    # TODO(dtu): Read the parameters from the request object.
    # Not doing it for now because it's easier to run tests this way.
    configuration = 'Mac Pro 10.11 Perf'
    test_suite = 'speedometer'
    test = None
    metric = None
    deps = (change.Dep('src', '2c1f8ed028edcb44c954cb2a0625a8f278933481'),
            change.Dep('src', '858ceafc7cf4f11a6549b8c1ace839a45d943d68'),)

    # Validate parameters.
    if metric and not test_suite:
      raise ValueError("Specified a metric but there's no test_suite to run.")

    # Validate commit hashes.
    for dep in deps:
      dep.Validate()

    # Convert parameters to canonical internal representation.

    # Create job.
    job = job_module.Job.New(
        configuration=configuration,
        test_suite=test_suite,
        test=test,
        metric=metric,
        auto_explore=True)

    # Add changes.
    for dep in deps:
      job.AddChange(change.Change(dep))

    # Put job into datastore.
    job_id = job.put().urlsafe()

    # Start job.
    job.Start()
    job.put()

    # Show status page.
    # TODO: Should return a JSON result instead. Use Cloud Endpoints.
    self.redirect('/job/' + job_id)<commit_msg>[pinpoint] Use Change.FromDict() in the /new handler.<commit_after># Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import webapp2

from dashboard.pinpoint.models import change
from dashboard.pinpoint.models import job as job_module


class New(webapp2.RequestHandler):
  """Handler that cooks up a fresh Pinpoint job."""

  def post(self):
    """Start a new Pinpoint job."""

    # TODO(dtu): Read the parameters from the request object.
    # Not doing it for now because it's easier to run tests this way.
    configuration = 'Mac Pro 10.11 Perf'
    test_suite = 'speedometer'
    test = None
    metric = None
    auto_explore = True

    change_1 = {
        'base_commit': {
            'repository': 'src',
            'git_hash': '2c1f8ed028edcb44c954cb2a0625a8f278933481',
        }
    }
    change_2 = {
        'base_commit': {
            'repository': 'src',
            'git_hash': '858ceafc7cf4f11a6549b8c1ace839a45d943d68',
        }
    }

    # Validate parameters.
    try:
      if metric and not test_suite:
        raise ValueError("Specified a metric but there's no test_suite to run.")
      changes = (change.Change.FromDict(change_1),
                 change.Change.FromDict(change_2))
    except (KeyError, ValueError) as e:
      self.response.set_status(400)
      self.response.write(e)
      return

    # Convert parameters to canonical internal representation.

    # Create job.
    job = job_module.Job.New(
        configuration=configuration,
        test_suite=test_suite,
        test=test,
        metric=metric,
        auto_explore=auto_explore)

    # Add changes.
    for c in changes:
      job.AddChange(c)

    # Put job into datastore.
    job_id = job.put().urlsafe()

    # Start job.
    job.Start()
    job.put()

    self.response.write(job_id)
{'fraction_non_alphanumeric': 0.09072753209700428, 'fraction_numerical': 0.03566333808844508, 'mean_word_length': 2.71005291005291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5097778', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1071, 'n_words': 331}