Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Richer display of scorers #556

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ angular.module('QuepidApp')

scorerControllerActionsSvc.figureOutScaleChoice(ctrl);



ctrl.scorerOptions = {
showName: true
};

ctrl.ok = function () {
$uibModalInstance.close(ctrl.scorer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ angular.module('QuepidApp')

scorerControllerActionsSvc.figureOutScaleChoice(ctrl);

ctrl.scorerOptions = {
showName: true
};

ctrl.ok = function () {
$uibModalInstance.close(ctrl.scorer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ angular.module('QuepidApp')
ctrl.scaleChoice = 'binaryScale';
ctrl.scorer = defaultScorer;

ctrl.scorerOptions = {
showName: true
};

ctrl.ok = function () {
$uibModalInstance.close(ctrl.scorer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ angular.module('QuepidApp')
ctrl.diffScore = '?';
ctrl.diffStyle = {};
ctrl.score = '?';
ctrl.scoreType = ctrl.scoreType || 'normal';
ctrl.scoreType = ctrl.scoreType; // either header or query
ctrl.style = { 'background-color': qscoreSvc.scoreToColor(ctrl.score, ctrl.maxScore) };

$scope.$watch('ctrl.scorable.currentScore', function() {
Expand Down
18 changes: 16 additions & 2 deletions app/assets/javascripts/components/scorer_form/scorer_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-group" ng-show='ctrl.scorerOptions.showName'>
<div class="form-group">
<label>Name</label>
<input id="scorer-name" type="text" class="form-control" ng-required="true" ng-model="ctrl.scorer.name" placeholder="Give your scorer a name" autoFocus>
</div>
Expand All @@ -17,8 +17,22 @@
ng-model="ctrl.scorer.code"></div>
</div>

<div class="form-group">
<label>Tooltip</label>
<input id="scorer-tooltip" type="text" class="form-control" ng-required="true" ng-model="ctrl.scorer.tooltip" placeholder="Short tool tip descripton" autoFocus>
</div>
<div class="form-group">
<label>Description</label>
<input id="scorer-description" type="text" class="form-control" ng-required="true" ng-model="ctrl.scorer.description" placeholder="The gory details of how your Scorer works." autoFocus>
</div>

<div class="form-group">
<label>Rollup Method (TEMP FOR NOW SHOULD BE ENUM)</label>
<input id="scorer-rollup-method" type="text" class="form-control" ng-required="true" ng-model="ctrl.scorer.rollupMethod" autoFocus>
</div>

<div class='form-group scorer max-score'>
<label>Max Score:</label></br />
<label>Max Score:</label><br/>
<label>
<input id="manual-max-score" type="radio" ng-model="ctrl.scorer.manualMaxScore" ng-value="false">
Automatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="item-box row">
<div class="col-xs-1">
{{ ctrl.scorer.name }}
<br/>
<small class="text-muted">{{ ctrl.scorer.tooltip }}</small>

<span class="item-actions">
<span ng-if="!ctrl.scorer.communal">
Expand Down
59 changes: 58 additions & 1 deletion app/assets/javascripts/controllers/queriesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ angular.module('QuepidApp')

$scope.getScorer = getScorer;

$scope.pickScorable = pickScorable;

$scope.reverse = $location.search().reverse;
$scope.sortBy($location.search().sort || 'default', !$scope.reverse);

Expand Down Expand Up @@ -167,11 +169,49 @@ angular.module('QuepidApp')
}
};

// a simulated "query" that the results view uses for display
var lastVersion = -1;

// a simulated "query" that the results view uses for display
// This method is used by scorers whose rollupMethod is averaging
var avgQuery = {
lastScore: -1,
calcScore: function() {
console.log("In avgQuery calcScore");
// rescore only if
// - there are no unscored queries
// - we seem to have a new version of the query service
if (!queriesSvc.hasUnscoredQueries() &&
(lastVersion !== queriesSvc.version())) {

runScore(this);
saveScoring();
}
},
score: () => {
console.log("In avgQuery score");
var deferred = $q.defer();
deferred.resolve($scope.queries.avgQuery.diff.currentScore);
return deferred.promise;
},
diff: {
score: function() {
console.log("In avgQuery diff score");
return queriesSvc.scoreAllDiffs().then( (scoreInfo) => {
$scope.queries.avgQuery.diff.currentScore = scoreInfo;
return scoreInfo;
});
}
}
//var diff: null, // TODO fill out
};

// a simulated "query" that the results view uses for display
// This method is used by scorers whose rollupMethod is sum
// note: this hasn't actually been converted to a SUM!
var sumQuery = {
lastScore: -1,
calcScore: function() {
console.log("In sumQuery calcScore");
// rescore only if
// - there are no unscored queries
// - we seem to have a new version of the query service
Expand All @@ -183,12 +223,14 @@ angular.module('QuepidApp')
}
},
score: () => {
console.log("In sumQuery score");
var deferred = $q.defer();
deferred.resolve($scope.queries.avgQuery.diff.currentScore);
return deferred.promise;
},
diff: {
score: function() {
console.log("In sumQuery diff score");
return queriesSvc.scoreAllDiffs().then( (scoreInfo) => {
$scope.queries.avgQuery.diff.currentScore = scoreInfo;
return scoreInfo;
Expand Down Expand Up @@ -268,7 +310,9 @@ angular.module('QuepidApp')
}
}

// Do we need to define them here, or can, based on the type of scorer, we define it later???
$scope.queries.avgQuery = avgQuery;
$scope.queries.sumQuery = sumQuery;

// get all the queries for this case for the query service
$scope.queriesList = [];
Expand Down Expand Up @@ -316,6 +360,19 @@ angular.module('QuepidApp')
return scorerSvc.defaultScorer;
}

function pickScorable() {
var scorable;
switch (getScorer().rollupMethod) {
case 'sum_of_scores':
scorable = $scope.queries.sumQuery;
break;
case 'average_of_scores':
scorable = $scope.queries.avgQuery;
break;
}
return scorable;
}

/*jslint latedef:false*/
function pickCaseScorer() {
var modalInstance = $uibModal.open({
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/factories/ScorerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
self.manualMaxScore = data.manualMaxScore || false;
self.manualMaxScoreValue = data.manualMaxScoreValue || 100;
self.name = data.name;
self.tooltip = data.tooltip;
self.description = data.description;
self.owned = data.owned;
self.ownerId = data.owner_id;
self.ownerName = data.owner_name;
Expand All @@ -36,6 +38,7 @@
self.scaleWithLabels = data.scaleWithLabels;
self.scorerId = data.scorerId;
self.communal = data.communal;
self.rollupMethod = data.rollup_method;
self.showScaleLabels = data.showScaleLabels || false;
self.teams = data.teams || [];

Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/services/scorerSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@
'name': scorer.name,
'code': scorer.code,
'scale': scale,
'rollup_method': scorer.rollupMethod,
'manual_max_score': scorer.manualMaxScore,
'manual_max_score_value': scorer.manualMaxScoreValue,
'show_scale_labels': scorer.showScaleLabels,
'scale_with_labels': scorer.scaleWithLabels,
'tooltip': scorer.tooltip,
'description': scorer.description,
};


Expand Down Expand Up @@ -112,10 +115,13 @@
'name': scorer.name,
'code': scorer.code,
'scale': scale,
'rollup_method': scorer.rollupMethod,
'manual_max_score': scorer.manualMaxScore,
'manual_max_score_value': scorer.manualMaxScoreValue,
'show_scale_labels': scorer.showScaleLabels,
'scale_with_labels': scorer.scaleWithLabels,
'tooltip': scorer.tooltip,
'description': scorer.description,
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/views/pick_scorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h4>Select from defaults:</h4>
ng-repeat="scorer in communalScorers track by scorer.scorerId"
ng-class="{ active: scorer.scorerId === activeScorer.scorerId }"
ng-click="selectScorer(scorer)">
{{scorer.name}}
{{scorer.name}} <small class="text-muted">{{ scorer.tooltip }}</small>
</li>
</ul>

Expand Down
5 changes: 3 additions & 2 deletions app/assets/templates/views/queriesLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<div id="case-header" class="row">
<div class="col-sm-12">
<div style="display: inline-block">
{{ getScorer().rollupMethod }}
<qscore
class="case-score"
diff-label="queries.selectedDiffName()"
full-diff-name="queries.fullDiffName()"
max-score="maxScore || 1";
scorable="queries.avgQuery"
scorable="pickScorable()"
score-label="getScorer().name"
score-type="'header'"
scores="scores"
Expand Down Expand Up @@ -54,7 +55,7 @@ <h1 class="">

<small class="text-muted">
&mdash;
{{ getScorer().name }}
<span aria-hidden="true" popover-trigger="'mouseenter'" popover-placement="right" uib-popover="{{ getScorer().tooltip }}">{{ getScorer().name }}</span>
</small>
</h1>
</div>
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/admin/communal_scorers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ def scorer_params
params.require(:scorer).permit(
:code,
:name,
:communal,
:manual_max_score,
:manual_max_score_value,
:show_scale_labels,
:rollup_method,
:scale_list, # alternate approach to the scale:[] array used in admin only
:tooltip,
:description,
:state,
scale: [],
scale_with_labels: {}

)
end

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/v1/scorers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ def scorer_params
:manual_max_score,
:manual_max_score_value,
:show_scale_labels,
:rollup_method,
:communal,
:tooltip,
:description,
scale: [],
scale_with_labels: {}
)
Expand Down
4 changes: 3 additions & 1 deletion app/models/scorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# manual_max_score :boolean default(FALSE)
# manual_max_score_value :integer default(100)
# name :string(255)
# rollup_method :integer default(0)
# rollup_method :integer default("average_of_scores")
# scale :string(255)
# scale_with_labels :text(65535)
# show_scale_labels :boolean default(FALSE)
Expand Down Expand Up @@ -59,6 +59,8 @@ class Scorer < ApplicationRecord

scope :communal, -> { where(communal: true) }

enum rollup_method: [:average_of_scores, :sum_of_scores]

# the default scorer for users who don't have one specified.
def self.system_default_scorer
find_by(name: Rails.application.config.quepid_default_scorer)
Expand Down
13 changes: 13 additions & 0 deletions app/views/admin/communal_scorers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
</div>
</div>

<div class="mb-3">
<%= f.label :tooltip, class: 'form-label' %>
<%= f.text_field :tooltip, class: 'form-control' %>
<div class="form-text">A short "tooltip" style description.</div>
</div>

<div class="mb-3">
<%= f.label :description, class: 'form-label' %>
<div class="form-text">The gory details about this Scorer!</div>
<%= f.text_area :description, cols: 60, rows: 6 %>
</div>


<%= f.submit class: 'btn btn-primary' %>

<% end %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/communal_scorers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<tr>
<th>ID</th>
<th>Name</th>
<th>Tooltip</th>
<th>Code</th>
<th>Scale</th>
<th>Manual Max Score?</th>
<th>Manual Max Score Value</th>
<th>Show Scale Labels?</th>
<th>Scale with Labels</th>
<th>Description</th>
<th>Updated At</th>
<th colspan="2"></th>
</tr>
Expand All @@ -23,6 +25,7 @@
<tr class='scorer'>
<td><%= scorer.id %></td>
<td><%= scorer.name %></td>
<td><%= scorer.tooltip %></td>
<td class='code'>
<div
id="code-<%= scorer.id %>"
Expand All @@ -35,6 +38,7 @@
<td><%= scorer.manual_max_score_value %></td>
<td><%= scorer.show_scale_labels? %></td>
<td><%= scorer.scale_with_labels %></td>
<td><%= scorer.description %></td>
<td>
<%= scorer.updated_at %>
<% if scorer.updated_at %>
Expand Down
Loading