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

Implement Event Ratings #1204

Closed
wants to merge 8 commits into from

Conversation

shlok007
Copy link
Member

@shlok007 shlok007 commented Sep 22, 2016

Refers to issue #1158 .

Rfc: https://docs.google.com/document/d/1sWImuP14RFeTWrs3nqdRZt8xfD0-xr0hBj10B2_KCQQ/edit?usp=sharing

To-Do:

  • Introduce VotableFields and admin views to manage votable fields.
  • Enable votes for events ( proposals ) by users if the event has ended.
  • Add tests for votable fields introduced.
  • Introduce new voting on admin side as well.
  • Drop the whole current voting system on admin side.
  • Rake task to migrate current voting of past conferences to new 'overall' in VotableField.

@shlok007
Copy link
Member Author

The code generated is by ratyrate gem . Can somebody please help with the failing test here?
hakiri

@@ -84,6 +85,10 @@ def registration_possible?
registrations.count < max_attendees
end

def ended?
Time.now.to_i > event_schedules.find_by(schedule_id: program.selected_schedule_id).end_time.to_i
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is the right way to compute if an event has ended .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use the timezone of the conference this event belongs to. And you can compare times directly without converting them to string.

timezone = program.conference.timezone
Time.find_zone(timezone).now > event_schedules.find_by(schedule: program.selected_schedule).end_time

@@ -84,6 +85,10 @@ def registration_possible?
registrations.count < max_attendees
end

def ended?
Time.now.to_i > event_schedules.find_by(schedule_id: program.selected_schedule_id).end_time.to_i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use the timezone of the conference this event belongs to. And you can compare times directly without converting them to string.

timezone = program.conference.timezone
Time.find_zone(timezone).now > event_schedules.find_by(schedule: program.selected_schedule).end_time

@differentreality
Copy link
Contributor

@shlok007 did you review other gems for this as well?

@differentreality
Copy link
Contributor

@shlok007 ?

@shlok007
Copy link
Member Author

Sorry for the late response. Yes, i stumbled upon letsrate gem as well. There is always a possibility to write our own rating system to rate proposals.

@differentreality
Copy link
Contributor

Nah we don't have to do that, if there is something well maintained with updates that suits our needs. But I would like to know what other gems you evaluated and what the one you chose offers us. So can you provide some more details about your choice of gem? What advantages/disadvantages it has in comparison with other alternatives? Things like that which will help us make a conscious decision.

We will use voting extensively, so we should choose the gem wisely and then use it for all the places we have/will have voting.

@shlok007
Copy link
Member Author

I stumbled upon letsrate and its fork ratyrate. Seems like ratyrate is still maintained after letsrate. Also, ratyrate has a lot of options and well documented guide that we could use. There is also jquery-raty-rails which I avoided as people seem to be having issues with rails 4 https://github.com/bmc/jquery-raty-rails/issues/7 .

This poster lists the additional features that ratyrate has over letsrate.

At the end of the day, all the rating gems wraps the JQuery Raty library so if none works for us we have an option to manually add and use the library ourself.

@shlok007
Copy link
Member Author

shlok007 commented Feb 18, 2017

Do let me know what should be appropriate here. I'll proceed with this PR and try fixing the Hakiri test failures as well if we decide to use ratyrate gem . 🙂

@differentreality
Copy link
Contributor

Please rebase!

@@ -0,0 +1,760 @@
/*!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file here?

@@ -1,5 +1,6 @@
class Event < ActiveRecord::Base
include ActiveRecord::Transitions
ratyrate_rateable 'speaker_quality', 'competence', 'slides'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this custom? Meaning an organizer chooses the qualities to rate on.

@differentreality
Copy link
Contributor

What about making this available on the admin side as well? Let's first decide on how to implement it, in a way that does not disrupt too much conferences using the current way of voting (and only want 1 point of voting, overall voting - not voting on multiple qualities).

@shlok007
Copy link
Member Author

shlok007 commented Mar 8, 2017

This is what I propose:

  • The votable fields can be decided by organizers in a separate view admin/votes#index and admin/votes#new .

Screenshot of admin/votes#index :
vote

  • Rake task to migrate the current votes from the admin side into a new field overall rating overall .

  • The new fields added could have an option to be global ( like questions ) for all conferences and hence could be enabled or disabled for each conference .

  • VotableFields would have a has_and_belongs_to_many has_many belongs_to association with conference .

All we need to do is specify the dimensions on which the proposals have to be rated upon. Ratyrate should take care of everything else.

@@ -0,0 +1,62 @@
$.fn.raty.defaults.half = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this file if we have the gem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gem seems to have included it by itself. I am wondering the same. Although, I'll give it a check if the gem still works the same when I get rid of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to work without it.

belongs_to :rater, class_name: 'User'
belongs_to :rateable, polymorphic: true

# attr_accessible :rate, :dimension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this comment here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we do. This is automatically generated code. I'll look up more for comments/things like these that can be safely removed. Although, I shouldn't change much except comments as I won't know reason things were introduced.

@differentreality
Copy link
Contributor

Do we truly need to introduce all those new models?

@shlok007 shlok007 changed the title Implement Event Ratings [WIP] Implement Event Ratings Mar 20, 2017
validates :title, :votable_type, presence: true

# ratyrate does not allow criterias to have spaces in them
validate :no_spaces_in_title
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution could be to replace spaces with another character like underscore ( _ ) and convert them back to spaces while rendering them in proposals#show . But this could be a problem if the user actually defines a field that has a underscore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ask for proper names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By proper names you mean names without spaces, the way it is currently done, right? 🙂

Copy link
Contributor

@differentreality differentreality Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You commented on the code that ratyrate does not allow votable_fields to have spaces, so that's what's proper. No spaces. This is very similar to the validation we do for conference.short_title

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if I use regexp instead of this to check for no spaces ?

end

def correct_votable_type
errors.add(:votable_type, "should be one of the following: 'Event'") unless ['Event'].include? votable_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

available votable_types should be in a variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed .. 😅

config/routes.rb Outdated
@@ -1,5 +1,6 @@
Osem::Application.routes.draw do

post '/rate' => 'rater#create', :as => 'rate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as: 'rate'

@hennevogel hennevogel temporarily deployed to osem-demo-pr-1204 March 24, 2017 13:27 Inactive
@differentreality
Copy link
Contributor

So I guess the remaining things to take into account here are:

  • Enable the gem for the admin voting on events
  • Show results of current implemented voting in admin

@shlok007
Copy link
Member Author

It seems like ratyrate does not allow using same names ( dimension as they call it ) to vote for the same model. Therefore, it won't be possible to have the same field name for admin and non admin side.

Ticket in ratyrate to address the same: wazery/ratyrate#143 .
Official Documentation for ratyrate: https://www.sitepoint.com/ratyrate-add-rating-rails-app/

@shlok007
Copy link
Member Author

The two drawbacks of using this gem are:

  • Title for the votable fields cannot have spaces so fields like speaker's familiarity with subject which cannot be represented by a single word might cause a problem

    Possible Solution
    Replace spaces with _ or some other character in https://github.com/openSUSE/osem/pull/1204/files#diff-6ecd61439b970b0e5ae49be738861446R4 ( with this approach speaker competance and speaker_competance will be treated the same, we might have to take care of that as well )

  • We cannot have same field name to rate a model in admin and non admin side. ( eg: if the attendees have an option to rate on 'overall' then the admins can't have an 'overall' field, if they do the ratings of both will be combined together )

    Possible Solution
    Prepend admin_ to the votable fields that are created for the admin side voting by the admin.

In both the cases we have an option to just go with the default behaviour although, it might reduce the usability.

@hennevogel hennevogel temporarily deployed to osem-demo-pr-1204 March 27, 2017 05:09 Inactive
@@ -23,6 +23,9 @@ gem 'mysql2'
# for observing records
gem 'rails-observers'

# for rating
gem 'ratyrate', github: 'wazery/ratyrate', branch: 'master'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I am really unsure about. The released version of ratyrate contains a bug in the rating_for_user method that shows a particular user's rating. This method is required for blind voting. However, the master is quite stable and does not contain the bug. This could be a temporary change until we get a response regarding wazery/ratyrate#125 ( issue asking for a new version release )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using the gem from the master branch instead of the released version something we can agree upon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the gem from master:
ratyrate_gem

Using the released version:
rayrate

The function to show current_user's vote renders only a single star in the released version which has been fixed in master but a new version hasn't been released yet.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this master branch version you guys are talking about? I'm trying the master, but keep comes the alpha, is there another file to download?

I'm having a lot of issues with this gem for helper rating_for_user. I can't record at overrall_averages and average_cache tables, as long record the rater_id at rate table.
The method on this file is also comment:
https://github.com/wazery/ratyrate/blob/master/lib/ratyrate/model.rb

tks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the master branch is as simple as using this line above in the Gemfile. It would be great if we can discuss this more on the issue itself rather than here. 🙂

@shlok007
Copy link
Member Author

Except tests, the work on this PR should be complete. Can it be please temporarily deployed to heroku at this stage for everyone else to review ?

@hennevogel hennevogel temporarily deployed to osem-demo-pr-1204 April 13, 2017 10:36 Inactive
@differentreality
Copy link
Contributor

@shlok007 it would be useful if you added the necessary records in the review app.

@differentreality
Copy link
Contributor

Please rebase, and feel free to squash those commits to make rebasing easier (you can leave a couple of commits, if you think that's useful).

@shlok007 shlok007 changed the title [WIP] Implement Event Ratings Implement Event Ratings Apr 27, 2017
@shlok007
Copy link
Member Author

width: 24px;
height: 24px;
display: inline-block;
img.raty-cancel {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cancel button doesn't cancel the rating but instead clicking on cancel changes the rating to '0' stars. This property is to prevent the cancel button from being displayed.


private

def remove_rates
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To delete the existing rating for a votable field so when a new field of same title is created, it does not have any previous rating present already.

@differentreality
Copy link
Contributor

I am thinking that if we manually have to introduce the custom votable fields we want, then we might as well not use the gem, and just extend the capabilities of the existing voting options we have, and refactor where needed.

end

it 'is not valid without a votable field' do
should validate_presence_of(:votable_type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(".disabled-rate .star").each(function(){
$(this).raty('readOnly', true);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line

@@ -22,7 +22,7 @@ class Conference < ActiveRecord::Base
has_many :supporters, through: :ticket_purchases, source: :user
has_many :tickets, dependent: :destroy
has_many :resources, dependent: :destroy

has_many :votable_fields, dependent: :destroy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be in Program?

Copy link
Member Author

@shlok007 shlok007 May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then probably we should move VotableField to be a program option instead of conference in all places including views and routes of the app as well. I should do that also. :)

@@ -1,5 +1,8 @@
class Event < ActiveRecord::Base
include ActiveRecord::Transitions

scope :vote, ->(votable_fields) { votable_fields.each { |field| ratyrate_rateable field.title } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can name this better, as vote does not really convey the meaning of what we are doing here. votable_on ?

end

##

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

@@ -1,14 +1,2 @@
class Vote < ActiveRecord::Base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we keeping this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a rake task to migrate old votes into new. The Vote model class is required for that task. If this class is removed we might have to write raw SQL inside the task to access the old votes data table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= f.input :title
= f.input :votable_type, collection: options_for_select(['Event'])
= f.input :stars, label: 'Add the total number of stars for the field'
= f.input :for_admin, label: 'Add this field for voting in admin side only'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we have 2 boolean options, one for admin namespace, one for attendees? That way we can have votable fields available only for admin, or only for attendees, or for both.

= f.input :blind_voting, hint: 'Enable this feature if you do not want to show voting results and voters prior to user submitting a vote. For the feature to work you need to set the voting dates below as well'
= f.input :voting_start_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?) }
= f.input :voting_end_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?) }
= f.input :rating_enabled, label: 'Enable voting', hint: 'To enable voting you need to set voting dates as well'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a new section to separate the voting options from the rest.

@bear454
Copy link
Contributor

bear454 commented Dec 15, 2017

I would like to close this PR:

  • The discussion looks like we could better solve the problem with enhancements to Surveys #1100 .
  • There have been no changes in over half a year, and it's now very conflicted with master.

@differentreality
Copy link
Contributor

What I had in mind was to keep the stars rating, but maybe we should indeed look into integrating something specifically for this reason into surveys.

Indeed it's been a while since we worked on this. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants