Store & use ConvDev percentages returned by Version app

This commit is contained in:
Jarka Kadlecova 2017-08-01 08:46:43 +02:00
parent 28299de189
commit 0f9bde41fc
11 changed files with 159 additions and 16 deletions

View file

@ -13,9 +13,7 @@ module ConversationalDevelopmentIndex
end
def percentage_score(feature)
return 100 if leader_score(feature).zero?
100 * instance_score(feature) / leader_score(feature)
self["percentage_#{feature}"]
end
end
end

View file

@ -1,6 +1,16 @@
class SubmitUsagePingService
URL = 'https://version.gitlab.com/usage_data'.freeze
METRICS = %w[leader_issues instance_issues percentage_issues leader_notes instance_notes
percentage_notes leader_milestones instance_milestones percentage_milestones
leader_boards instance_boards percentage_boards leader_merge_requests
instance_merge_requests percentage_merge_requests leader_ci_pipelines
instance_ci_pipelines percentage_ci_pipelines leader_environments instance_environments
percentage_environments leader_deployments instance_deployments percentage_deployments
leader_projects_prometheus_active instance_projects_prometheus_active
percentage_projects_prometheus_active leader_service_desk_issues instance_service_desk_issues
percentage_service_desk_issues].freeze
include Gitlab::CurrentSettings
def execute
@ -27,15 +37,7 @@ class SubmitUsagePingService
return unless response['conv_index'].present?
ConversationalDevelopmentIndex::Metric.create!(
response['conv_index'].slice(
'leader_issues', 'instance_issues', 'leader_notes', 'instance_notes',
'leader_milestones', 'instance_milestones', 'leader_boards', 'instance_boards',
'leader_merge_requests', 'instance_merge_requests', 'leader_ci_pipelines',
'instance_ci_pipelines', 'leader_environments', 'instance_environments',
'leader_deployments', 'instance_deployments', 'leader_projects_prometheus_active',
'instance_projects_prometheus_active', 'leader_service_desk_issues',
'instance_service_desk_issues'
)
response['conv_index'].slice(*METRICS)
)
end
end

View file

@ -0,0 +1,4 @@
---
title: Store & use ConvDev percentages returned by the Version app
merge_request:
author:

View file

@ -0,0 +1,32 @@
class AddPercentagesToConvDev < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_column_with_default :conversational_development_index_metrics, :percentage_boards, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_ci_pipelines, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_deployments, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_environments, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_issues, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_merge_requests, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_milestones, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_notes, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_projects_prometheus_active, :float, allow_null: false, default: 0
add_column_with_default :conversational_development_index_metrics, :percentage_service_desk_issues, :float, allow_null: false, default: 0
end
def down
remove_column :conversational_development_index_metrics, :percentage_boards
remove_column :conversational_development_index_metrics, :percentage_ci_pipelines
remove_column :conversational_development_index_metrics, :percentage_deployments
remove_column :conversational_development_index_metrics, :percentage_environments
remove_column :conversational_development_index_metrics, :percentage_issues
remove_column :conversational_development_index_metrics, :percentage_merge_requests
remove_column :conversational_development_index_metrics, :percentage_milestones
remove_column :conversational_development_index_metrics, :percentage_notes
remove_column :conversational_development_index_metrics, :percentage_projects_prometheus_active
remove_column :conversational_development_index_metrics, :percentage_service_desk_issues
end
end

View file

@ -0,0 +1,30 @@
class CalculateConvDevIndexPercentages < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
class ConversationalDevelopmentIndexMetric < ActiveRecord::Base
self.table_name = 'conversational_development_index_metrics'
METRICS = %w[boards ci_pipelines deployments environments issues merge_requests milestones notes
projects_prometheus_active service_desk_issues]
end
def up
ConversationalDevelopmentIndexMetric.find_each do |conv_dev_index|
update = []
ConversationalDevelopmentIndexMetric::METRICS.each do |metric|
instance_score = conv_dev_index["instance_#{metric}"].to_f
leader_score = conv_dev_index["leader_#{metric}"].to_f
percentage = leader_score.zero? ? 0.0 : (instance_score / leader_score) * 100
update << "percentage_#{metric} = '#{percentage}'"
end
execute("UPDATE conversational_development_index_metrics SET #{update.join(',')} WHERE id = #{conv_dev_index.id}")
end
end
def down
end
end

View file

@ -451,6 +451,16 @@ ActiveRecord::Schema.define(version: 20170803130232) do
t.float "instance_service_desk_issues", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "percentage_boards", default: 0.0, null: false
t.float "percentage_ci_pipelines", default: 0.0, null: false
t.float "percentage_deployments", default: 0.0, null: false
t.float "percentage_environments", default: 0.0, null: false
t.float "percentage_issues", default: 0.0, null: false
t.float "percentage_merge_requests", default: 0.0, null: false
t.float "percentage_milestones", default: 0.0, null: false
t.float "percentage_notes", default: 0.0, null: false
t.float "percentage_projects_prometheus_active", default: 0.0, null: false
t.float "percentage_service_desk_issues", default: 0.0, null: false
end
create_table "deploy_keys_projects", force: :cascade do |t|

View file

@ -2,32 +2,42 @@ FactoryGirl.define do
factory :conversational_development_index_metric, class: ConversationalDevelopmentIndex::Metric do
leader_issues 9.256
instance_issues 1.234
percentage_issues 13.331
leader_notes 30.33333
instance_notes 28.123
percentage_notes 92.713
leader_milestones 16.2456
instance_milestones 1.234
percentage_milestones 7.595
leader_boards 5.2123
instance_boards 3.254
percentage_boards 62.429
leader_merge_requests 1.2
instance_merge_requests 0.6
percentage_merge_requests 50.0
leader_ci_pipelines 12.1234
instance_ci_pipelines 2.344
percentage_ci_pipelines 19.334
leader_environments 3.3333
instance_environments 2.2222
percentage_environments 66.672
leader_deployments 1.200
instance_deployments 0.771
percentage_deployments 64.25
leader_projects_prometheus_active 0.111
instance_projects_prometheus_active 0.109
percentage_projects_prometheus_active 98.198
leader_service_desk_issues 15.891
instance_service_desk_issues 13.345
percentage_service_desk_issues 83.978
end
end

View file

@ -0,0 +1,41 @@
# encoding: utf-8
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170803090603_calculate_conv_dev_index_percentages.rb')
describe CalculateConvDevIndexPercentages, truncate: true do
let(:migration) { described_class.new }
let!(:conv_dev_index) do
create(:conversational_development_index_metric,
leader_notes: 0,
instance_milestones: 0,
percentage_issues: 0,
percentage_notes: 0,
percentage_milestones: 0,
percentage_boards: 0,
percentage_merge_requests: 0,
percentage_ci_pipelines: 0,
percentage_environments: 0,
percentage_deployments: 0,
percentage_projects_prometheus_active: 0,
percentage_service_desk_issues: 0)
end
describe '#up' do
it 'calculates percentages correctly' do
migration.up
conv_dev_index.reload
expect(conv_dev_index.percentage_issues).to be_within(0.1).of(13.3)
expect(conv_dev_index.percentage_notes).to be_zero # leader 0
expect(conv_dev_index.percentage_milestones).to be_zero # instance 0
expect(conv_dev_index.percentage_boards).to be_within(0.1).of(62.4)
expect(conv_dev_index.percentage_merge_requests).to eq(50.0)
expect(conv_dev_index.percentage_ci_pipelines).to be_within(0.1).of(19.3)
expect(conv_dev_index.percentage_environments).to be_within(0.1).of(66.7)
expect(conv_dev_index.percentage_deployments).to be_within(0.1).of(64.2)
expect(conv_dev_index.percentage_projects_prometheus_active).to be_within(0.1).of(98.2)
expect(conv_dev_index.percentage_service_desk_issues).to be_within(0.1).of(84.0)
end
end
end

View file

@ -0,0 +1,11 @@
require 'rails_helper'
describe ConversationalDevelopmentIndex::Metric do
let(:conv_dev_index) { create(:conversational_development_index_metric) }
describe '#percentage_score' do
it 'returns stored percentage score' do
expect(conv_dev_index.percentage_score('issues')).to eq(13.331)
end
end
end

View file

@ -8,9 +8,9 @@ describe ConversationalDevelopmentIndex::MetricPresenter do
it 'includes instance score, leader score and percentage score' do
issues_card = subject.cards.first
expect(issues_card.instance_score).to eq 1.234
expect(issues_card.leader_score).to eq 9.256
expect(issues_card.percentage_score).to be_within(0.1).of(13.3)
expect(issues_card.instance_score).to eq(1.234)
expect(issues_card.leader_score).to eq(9.256)
expect(issues_card.percentage_score).to eq(13.331)
end
end

View file

@ -46,6 +46,8 @@ describe SubmitUsagePingService do
.by(1)
expect(ConversationalDevelopmentIndex::Metric.last.leader_issues).to eq 10.2
expect(ConversationalDevelopmentIndex::Metric.last.instance_issues).to eq 3.2
expect(ConversationalDevelopmentIndex::Metric.last.percentage_issues).to eq 31.37
end
end
@ -60,6 +62,7 @@ describe SubmitUsagePingService do
conv_index: {
leader_issues: 10.2,
instance_issues: 3.2,
percentage_issues: 31.37,
leader_notes: 25.3,
instance_notes: 23.2,
@ -86,7 +89,9 @@ describe SubmitUsagePingService do
instance_projects_prometheus_active: 0.30,
leader_service_desk_issues: 15.8,
instance_service_desk_issues: 15.1
instance_service_desk_issues: 15.1,
non_existing_column: 'value'
}
}
end