<commit_before>=== Creating a small project in one page of code
by <NAME>

==== Problem
You would like to create the whole project from code for whatever reason.

==== Prerequisites
- Project token

==== Solution
What we will do is to create a simple project with 4 datasets. Load couple of line of data create a simple report and invite 2 other people to it. All this will fit on one page of code. Let's get to it.

[source,ruby]
----
require 'gooddata'

GoodData.with_connection do |c|
  blueprint = GoodData::Model::ProjectBlueprint.build("Acme project") do |p|
    p.add_date_dimension('committed_on')

    p.add_dataset('devs') do |d|
      d.add_anchor('dev_id')
      d.add_label('email', :reference => 'dev_id')
    end

    p.add_dataset('commits') do |d|
      d.add_fact('lines_changed')
      d.add_date('committed_on', :dataset => "committed_on")
      d.add_reference('dev_id', :dataset => 'devs')
    end
  end

  project = GoodData::Project.create_from_blueprint(blueprint, :auth_token => '')
  GoodData::with_project(project) do |p|
    # Load data
    commits_data = [
      ["lines_changed","committed_on","dev_id","repo_id"],
      [1,"01/01/2014",1,1],
      [3,"01/02/2014",2,2],
      [5,"05/02/2014",3,1]]
    GoodData::Model.upload_data(commits_data, blueprint, 'commits')

    devs_data = [
      ["dev_id", "email"],
      [1, "<EMAIL>"],
      [2, "<EMAIL>"],
      [3, "<EMAIL>"]]
    GoodData::Model.upload_data(devs_data, blueprint, 'devs')

    # create a metric
    metric = p.fact('fact.commits.lines_changed').create_metric
    metric.save

    report = p.create_report(title: 'Awesome_report', top: [metric], left: ['label.devs.dev_id.email'])
    report.save

    ['<EMAIL>', '<EMAIL>'].each do |email|
      p.invite(email, 'admin', "Guys checkout this report #{report.browser_uri}")
    end
  end
end
----

==== Discussion








<commit_msg>Added a PID output to snippet<commit_after>=== Creating a small project in one page of code
by <NAME>

==== Problem
You would like to create the whole project from code for whatever reason.

==== Prerequisites
- Project token

==== Solution
What we will do is to create a simple project with 4 datasets. Load couple of line of data create a simple report and invite 2 other people to it. All this will fit on one page of code. Let's get to it.

[source,ruby]
----
require 'gooddata'

GoodData.with_connection do |c|
  blueprint = GoodData::Model::ProjectBlueprint.build("Acme project") do |p|
    p.add_date_dimension('committed_on')

    p.add_dataset('devs') do |d|
      d.add_anchor('dev_id')
      d.add_label('email', :reference => 'dev_id')
    end

    p.add_dataset('commits') do |d|
      d.add_fact('lines_changed')
      d.add_date('committed_on', :dataset => "committed_on")
      d.add_reference('dev_id', :dataset => 'devs')
    end
  end

  project = GoodData::Project.create_from_blueprint(blueprint, :auth_token => '')
  puts "Created project #{project.pid}"

  GoodData::with_project(project) do |p|
    # Load data
    commits_data = [
      ["lines_changed","committed_on","dev_id","repo_id"],
      [1,"01/01/2014",1,1],
      [3,"01/02/2014",2,2],
      [5,"05/02/2014",3,1]]
    GoodData::Model.upload_data(commits_data, blueprint, 'commits')

    devs_data = [
      ["dev_id", "email"],
      [1, "<EMAIL>"],
      [2, "<EMAIL>"],
      [3, "<EMAIL>"]]
    GoodData::Model.upload_data(devs_data, blueprint, 'devs')

    # create a metric
    metric = p.fact('fact.commits.lines_changed').create_metric
    metric.save

    report = p.create_report(title: 'Awesome_report', top: [metric], left: ['label.devs.dev_id.email'])
    report.save

    ['<EMAIL>', '<EMAIL>'].each do |email|
      p.invite(email, 'admin', "Guys checkout this report #{report.browser_uri}")
    end
  end
end
----

==== Discussion









{'fraction_non_alphanumeric': 0.15702695629416383, 'fraction_numerical': 0.019890081130594085, 'mean_word_length': 3.55, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '375699', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1294, 'n_words': 333}