MarkUs Blog

MarkUs Developers Blog About Their Project

Seeking for help on the Dashboard Task

with 2 comments

These days I am trying to do some coding on showing TA’s marking distribution. But I find that after reading through part of our codebase carefully I got more questions than ideas about the implementation. So I decide to post this blog listing all my thinkings so far and seeking for help from yours 😉

Following are the code files I read through in detail which I think is highly related to my topic:
* app/models/assignment.rb
* app/models/assignment_stat.rb
* app/models/flexible_criterion.rb
* app/models/rubric_criterion.rb
* app/models/criterion_ta_association.rb
* app/models/submission.rb
* app/model/result.rb
* app/model/mark.rb
* app/model/membership.rb
* app/model/group.rb
* app/model/grouping.rb
* app/controllers/results_controller.rb

The first thing that troubled me a lot is the various types of Active Record associations 🙁 Fortunately, by reading this page http://guides.rubyonrails.org/association_basics.html I’ve got some basic understandings about all these “belongs_to”, “has_one”, “has_many”, “has_many :through” and so on. Then by reading this graph https://github.com/MarkUsProject/Markus/wiki/database_20101001.png I got a general idea about how our database works but it’s still not very clear. I need some more help to understand the relationships between these models, especially:
* Assignment
* Submission
* Result
* Mark
* Grouping
* Group
Basically, on the topmost level I want to find some relationships between the *result of each submission of an assignment* and *the TA who gives this mark*. Although I know the meaning of these “belongs_to”, “has_one”, “has_many”, “has_many :through” and so on, I got stuck when I want to use these associations between Active Record models to get what I want. So, anybody help? 😉

Here I pick and list some lines out of our codebase:

* app/models/assignment.rb

has_many :rubric_criteria, :class_name => "RubricCriterion",:order => :position
has_many :flexible_criteria, :class_name => "FlexibleCriterion",:order => :position
...
has_many :criterion_ta_associations
...
has_many :groupings
has_many :ta_memberships, :class_name => "TaMembership", :through => :groupings
...
has_many :submissions, :through => :groupings
has_many :groups, :through => :groupings
...
has_one :assignment_stat

* app/model/result.rb

belongs_to :submission
has_many :marks
has_many :extra_marks
has_one :remarked_submission, :foreign_key => :remark_result_id

* app/models/submission.rb

belongs_to :grouping
has_one :result, :dependent => :destroy
...

* app/model/ta.rb

has_many :criterion_ta_associations, :dependent => :delete_all

* app/models/criterion_ta_association.rb

belongs_to :ta
belongs_to :criterion, :polymorphic => true
belongs_to :assignment

* app/models/flexible_criterion.rb

belongs_to :assignment, :counter_cache => true
has_many :marks, :as => :markable, :dependent => :destroy
has_many :criterion_ta_associations, :as => :criterion, :dependent => :destroy
has_many :tas, :through => :criterion_ta_associations

* app/models/rubric_criterion.rb

belongs_to :assignment, :counter_cache => true
has_many :marks, :as => :markable, :dependent => :destroy
has_many :criterion_ta_associations, :as => :criterion, :dependent => :destroy
has_many :tas, :through => :criterion_ta_associations

Above are all my thinkings about the associations between our models, and then I want to talk something about the results_controller.rb.

I think the edit method is where the TA gives a mark to a submission, also I’m not quite understand how these two methods work which are set_released_to_students and update_mark. I believe fully understand these three methods will help me a lot on my task, so can anyone help me here? 🙂

Moreover I see in the results_controller.rb the method current_user which is defined in app/helpers/main_helper.rb is called in many places. Basically, the major thing I want to do in the results_controller.rb is collect the data about which TA gives what mark to a submission of an assignment. I think results_controller.rb is the best place where I can get all these factors at the same time. The idea is I can get the user_id of the TA by calling current_user and get the submission and assignment in the similar way in the edit method (line 24 to 27 in results_controller.rb). Although I see the edit method (line 47) set the mark, I got a question about how I can get the mark of a submission?

I don’t know whether my thinkings above are exactly right. But assuming they are right and suppose I have got all these things I want in hand. The next thing I want to do is construct a data structure to store these information. For now the best way I can figure out is introduce a hash as a member variable for the assignment model which keep the submission_id as keys and ta_id with corresponding marks as values. I don’t know whether it’s a proper way to do this and I have no idea where should I construct this hash. Should I introduce a new model like assignment_stat or just do it in the assignment_stat model or define a new method in the results_controller.rb to collect these information in the hash? I’m looking forward for some comments on this and really appreciate for your helps 🙂

Written by Yansong

March 1st, 2011 at 4:49 pm

Posted in Uncategorized

2 Responses to 'Seeking for help on the Dashboard Task'

Subscribe to comments with RSS or TrackBack to 'Seeking for help on the Dashboard Task'.

  1. Hi,

    It is a very good start. You have all the basics to start correctly.

    The first piece of advice I would give to you is to draw a diagram of structures to help you seeing everything.
    You can have several diagrams, but I would advise you to have a database diagram (generated by Rails and based on your model files in app/models/) and a model diagram (the one exactly described in app/models). When you are manipulating Ruby objects, you are manipulating objects according to your model diagram. But having in mind the database diagram is helpful when requesting the database (with the Object.find(…) methods)

    For drawing diagrams, you have superdumper, which will give you one of the diagrams mentioned above (I don’t remember which one…)

    I guess railroady/railroads will help you having the other diagram. If you need help generating diagrams, just ask me.

    Moreover, one other tip you have to keep in mind is we should NEVER have twice the same information in the database. Because having twice the same information (even if it is in different ways) includes possibility to have inconsistent data. For example, a student has many marks, and can have a average mark. You should never store the average mark, obtained from the students mark. Because if you update the student’s marks, you will have to also update the average mark. Having a method calculating the average mark from the student’s marks is far better.

    I hope you understand my (too) long explanation… If not, just tell me 😉

    Benjamin

    Benjamin

    1 Mar 11 at 5:12 pm

  2. Hi Benjamin,

    I really appreciate your help today. After talk with you and NelleV on our IRC channel this afternoon, maybe night for you and NelleV 😉 I have a clearer idea about my task now. Unfortunately, you know there are several back and forth in our dialogue on IRC. After reading our codebase and the database graph a while, I find that I’m kind of losing myself 😉 there. Even by reading our IRC log, it’s hard for me to pick out the main final ideas of yours and NelleV’s. So can you simply list here the main points out of our dialogue on IRC yesterday?

    Sincerely,
    Yansong

    Yansong

    1 Mar 11 at 8:01 pm

Leave a Reply