<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mdong3</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mdong3"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Mdong3"/>
	<updated>2026-06-08T06:24:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96718</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96718"/>
		<updated>2015-04-22T03:53:38Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* support more schedule tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks into &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store each task's assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form. In this file, we use a &amp;lt;code&amp;gt;@scheduled_jobs = DelayedJob.all &amp;lt;/code&amp;gt; to read all datas from the &amp;quot;delayed_jobs&amp;quot; table. &amp;lt;br&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures shows our UI works. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we created a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:scheduledtasklog.png|frame|center|four scheduled tasks are added in log]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
There are two tables in the database to store the information about the reviews: &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;response_maps &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; is used to store all the submitted reviews while &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; stores all the requested reviews, which means if one review has began it will not stored in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; table. Thus, we just need to find the review data in &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; while not in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; for one assignment and delete them in database.&amp;lt;br&amp;gt;&lt;br /&gt;
We add a method in  &amp;lt;code&amp;gt;/models/scheduled_task.rb&amp;lt;/code&amp;gt; named &amp;lt;code&amp;gt;drop_outstanding_reviews&amp;lt;/code&amp;gt; to drop those reviews.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_outstanding_reviews&lt;br /&gt;
    reviews = ResponseMap.where(reviewed_object_id: self.assignment_id)&lt;br /&gt;
    for review in reviews&lt;br /&gt;
      review_has_began = Response.where(map_id: review.id)&lt;br /&gt;
      if review_has_began.size.zero?&lt;br /&gt;
        review_to_drop = ResponseMap.where(id: review.id)&lt;br /&gt;
        review_to_drop.first.destroy&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then, add the following code in &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method of the same file to drop one specified assignment's outstanding reviews at the due time.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if(self.deadline_type == &amp;quot;drop_one_member_topics&amp;quot;)&lt;br /&gt;
    assignment = Assignment.find(self.assignment_id)&lt;br /&gt;
    if(assignment.team_assignment?)&lt;br /&gt;
      drop_one_member_topics&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96717</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96717"/>
		<updated>2015-04-22T03:52:53Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* support more schedule tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks into &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store each task's assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form. In this file, we use a &amp;lt;code&amp;gt;@scheduled_jobs = DelayedJob.all &amp;lt;/code&amp;gt; to read all datas from the &amp;quot;delayed_jobs&amp;quot; table. &amp;lt;br&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures shows our UI works. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we created a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:scheduledtasklog.png|frame|center|four scheduled tasks are added in log]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
There are two table in the database to store the information about the reviews: &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;response_maps &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; is used to store all the submitted reviews while &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; stores all the requested reviews, which means if one review has began it will not stored in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; table. Thus, we just need to find the review data in &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; while not in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; for one assignment and delete them in database.&amp;lt;br&amp;gt;&lt;br /&gt;
We add a method in  &amp;lt;code&amp;gt;/models/scheduled_task.rb&amp;lt;/code&amp;gt; named &amp;lt;code&amp;gt;drop_outstanding_reviews&amp;lt;/code&amp;gt; to drop those reviews.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_outstanding_reviews&lt;br /&gt;
    reviews = ResponseMap.where(reviewed_object_id: self.assignment_id)&lt;br /&gt;
    for review in reviews&lt;br /&gt;
      review_has_began = Response.where(map_id: review.id)&lt;br /&gt;
      if review_has_began.size.zero?&lt;br /&gt;
        review_to_drop = ResponseMap.where(id: review.id)&lt;br /&gt;
        review_to_drop.first.destroy&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then, add the following code in &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method of the same file to drop one specified assignment's outstanding reviews at the due time.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if(self.deadline_type == &amp;quot;drop_one_member_topics&amp;quot;)&lt;br /&gt;
    assignment = Assignment.find(self.assignment_id)&lt;br /&gt;
    if(assignment.team_assignment?)&lt;br /&gt;
      drop_one_member_topics&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96716</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96716"/>
		<updated>2015-04-22T03:48:49Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* support more schedule tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks into &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store each task's assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form. In this file, we use a &amp;lt;code&amp;gt;@scheduled_jobs = DelayedJob.all &amp;lt;/code&amp;gt; to read all datas from the &amp;quot;delayed_jobs&amp;quot; table. &amp;lt;br&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures shows our UI works. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we created a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:scheduledtasklog.png|frame|center|four scheduled tasks are added in log]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
There are two table in the database to store the information about the reviews: &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; is used to store all the submitted reviews while &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; stores all the requested reviews, which means if one review has began it will not stored in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; table. Thus, we just need to find the review data in &amp;lt;code&amp;gt;response_maps&amp;lt;/code&amp;gt; while not in &amp;lt;code&amp;gt;responses&amp;lt;/code&amp;gt; for one assignment and delete them in database.&amp;lt;br&amp;gt;&lt;br /&gt;
We add a method in  &amp;lt;code&amp;gt;/models/scheduled_task.rb&amp;lt;/code&amp;gt; named &amp;lt;code&amp;gt;drop_outstanding_reviews&amp;lt;/code&amp;gt; to drop those reviews.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_outstanding_reviews&lt;br /&gt;
    reviews = ResponseMap.where(reviewed_object_id: self.assignment_id)&lt;br /&gt;
    for review in reviews&lt;br /&gt;
      review_has_began = Response.where(map_id: review.id)&lt;br /&gt;
      if review_has_began.size.zero?&lt;br /&gt;
        review_to_drop = ResponseMap.where(id: review.id)&lt;br /&gt;
        review_to_drop.first.destroy&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then, in add following code in &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method of the same file to drop one kind assignment's outstanding reviews at the due time.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if(self.deadline_type == &amp;quot;drop_one_member_topics&amp;quot;)&lt;br /&gt;
    assignment = Assignment.find(self.assignment_id)&lt;br /&gt;
    if(assignment.team_assignment?)&lt;br /&gt;
      drop_one_member_topics&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96713</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96713"/>
		<updated>2015-04-22T03:25:55Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Keep log of the scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we created a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:scheduledtasklog.png|frame|center|four scheduled tasks are added in log]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Scheduledtasklog.png&amp;diff=96712</id>
		<title>File:Scheduledtasklog.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Scheduledtasklog.png&amp;diff=96712"/>
		<updated>2015-04-22T03:24:44Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96711</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96711"/>
		<updated>2015-04-22T03:23:35Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Keep log of the scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we create a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:scheduledtasklog.png|frame|center|four scheduled tasks are added in log]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96710</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96710"/>
		<updated>2015-04-22T03:21:14Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Keep log of the scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
According to the project E1478&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt;, there is a &amp;lt;code&amp;gt;paper_trail&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza/pull/462&amp;lt;/ref&amp;gt; gem can keep log of the models' data. What we need to do is let it also keep track of our scheduled task data.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Since the gem need to work with &amp;lt;code&amp;gt;ActiveRecord 3+&amp;lt;/code&amp;gt;, while &amp;lt;code&amp;gt;assignment_form&amp;lt;/code&amp;gt; doesn't. So we create a new file named &amp;lt;code&amp;gt;delayed_job.rb&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;models&amp;lt;/code&amp;gt; folder, add &amp;lt;code&amp;gt;has_paper_trail&amp;lt;/code&amp;gt; in it. Then it is like: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DelayedJob &amp;lt; Delayed::Job&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After that, every time when the &amp;lt;code&amp;gt;delayed_jobs&amp;lt;/code&amp;gt; table has added or deleted or updated data, the log can keep track of them. The following picture shows what the log is after creating scheduled tasks.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
&lt;br /&gt;
For each scheduled task, we have done the followings:&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_outstanding_reviews&amp;quot;. When we set the review’s due date, add an item into  “delayed job”  queue at the same time. When the review is due, it will automatically call a method to find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
&lt;br /&gt;
*Use a previously existed deadline type called &amp;quot;team_formation&amp;quot;  and enable to set a team_formation's due date and a reminder. Then add an item into “delayed job” at the same time.  When “delayed job” is triggered, it will automatically call a method to find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
&lt;br /&gt;
*Create a new deadline type called &amp;quot;drop_one_member_topics&amp;quot;. When time is due, the system will call a method to find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96706</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96706"/>
		<updated>2015-04-22T02:56:25Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96705</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96705"/>
		<updated>2015-04-22T02:55:18Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
We create a file &amp;lt;code&amp;gt;scheduled_tasks.erb&amp;lt;/code&amp;gt; in the path: &amp;lt;code&amp;gt;/views/assignments&amp;lt;/code&amp;gt; to show the form.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% @assignment = Assignment.find(params[:id]) %&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Scheduled tasks for &amp;lt;%= @assignment.name %&amp;gt; assignment&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;% if flash[:notice] %&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;flash_note&amp;quot;&amp;gt;&amp;lt;%= flash_message :notice %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% @scheduled_jobs = DelayedJob.all %&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;general&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Deadline type #&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Run time&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25%&amp;quot;&amp;gt;Due date&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;th width=&amp;quot;25 %&amp;quot;&amp;gt;Delete&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;% i=1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% for delayed_job in @scheduled_jobs %&amp;gt;&lt;br /&gt;
      &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;% if delayed_job.handler.include? &amp;quot;assignment_id: #{@assignment.id}&amp;quot;%&amp;gt;&lt;br /&gt;
            &amp;lt;% handler = delayed_job.handler.split()%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[5] %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= delayed_job.run_at %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= handler[7][1..-1] + &amp;quot;:&amp;quot; + handler[8][0..-2]%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;submission&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;review&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;metareview&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot; &amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;team_formation&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;send email to ask students to form teams&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_outstanding_reviews&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop outstanding reviews and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;% if handler[5] == &amp;quot;drop_one_member_topics&amp;quot; %&amp;gt;&lt;br /&gt;
                &amp;lt;td&amp;gt;&amp;lt;%= &amp;quot;drop one member team topics and send emails to those students&amp;quot;%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&amp;lt;%= link_to image_tag('delete_icon.png', :title =&amp;gt; 'Delete'),&lt;br /&gt;
                            {:controller =&amp;gt; 'assignments', :action =&amp;gt; 'delete_scheduled_task',&lt;br /&gt;
                             :id =&amp;gt; @assignment.id, :delayed_job_id =&amp;gt; delayed_job.id}%&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;% end %&amp;gt;&lt;br /&gt;
      &amp;lt;/tr&amp;gt;&lt;br /&gt;
      &amp;lt;% i=i+1 %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% session[:return_to] = request.url %&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;javascript:history.back()&amp;quot;&amp;gt;Back&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96704</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96704"/>
		<updated>2015-04-22T02:48:20Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table in database, so the system will read from that table to show all the tasks information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
The following two pictures are our UI work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayedjobs.png&amp;diff=96703</id>
		<title>File:Delayedjobs.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayedjobs.png&amp;diff=96703"/>
		<updated>2015-04-22T02:45:28Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96702</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96702"/>
		<updated>2015-04-22T02:45:11Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
In &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt;, we modified &amp;lt;code&amp;gt;curr_time=DateTime.now.to_s(:db)&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;curr_time=DateTime.now.in_time_zone(zone='UTC').to_s(:db)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;find_min_from_now&amp;lt;/code&amp;gt; method, to make sure when calculating the minutes from now, the time zone is right.&amp;lt;br&amp;gt;&lt;br /&gt;
Also, to make sure the right display of time, when log in as a administrator, go to Profile and choose the Preferred Time Zone to be &amp;quot;(GMT-05:00) Eastern Time (US&amp;amp;Canada)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category. This bug has been fixed by TA.&lt;br /&gt;
&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the delay_jobs table in database, so the system will read from that table to show all the needed information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
The code in &amp;lt;code&amp;gt;app/models/assignment_form.rb&amp;lt;/code&amp;gt; add the scheduled tasks in &amp;lt;code&amp;gt;delay_jobs&amp;lt;/code&amp;gt; table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if diff&amp;gt;0&lt;br /&gt;
    dj=DelayedJob.enqueue(ScheduledTask.new(@assignment.id, deadline_type, due_date.due_at.to_s(:db)),&lt;br /&gt;
                            1, diff.minutes.from_now)&lt;br /&gt;
    change_item_type(dj.id)&lt;br /&gt;
    due_date.update_attribute(:delayed_job_id, dj.id)&lt;br /&gt;
&lt;br /&gt;
    # If the deadline type is review, add a delayed job to drop outstanding review&lt;br /&gt;
    if deadline_type == &amp;quot;review&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_outstanding_reviews&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                              1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
    # If the deadline type is team_formation, add a delayed job to drop one member team&lt;br /&gt;
    if deadline_type == &amp;quot;team_formation&amp;quot;&lt;br /&gt;
      dj = DelayedJob.enqueue(ScheduledTask.new(@assignment.id, &amp;quot;drop_one_member_topics&amp;quot;, due_date.due_at.to_s(:db)),&lt;br /&gt;
                           1, diff.minutes.from_now)&lt;br /&gt;
      change_item_type(dj.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After adding to the delayed_jobs, the database will store all the assignment's id, deadline type, due date, task run time etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:delayedjobs.png |frame|center|the delayed jobs table in database]]&amp;lt;br&amp;gt;&lt;br /&gt;
The following two pictures are our work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96698</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96698"/>
		<updated>2015-04-22T02:27:25Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the delay_jobs table in database, so the system will read from that table to show all the needed information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in &amp;lt;code&amp;gt; assignment-&amp;gt;edit &amp;lt;/code&amp;gt;.&lt;br /&gt;
The following two pictures are our work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96697</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96697"/>
		<updated>2015-04-22T02:26:50Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Add UI to visualize for scheduled tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
All the scheduled tasks are in the delay_jobs table in database, so the system will read from that table to show all the needed information. A new page is created to show all of those scheduled tasks and there is also a delete button for instructor to delete any task. Instructor can view this page via a &amp;lt;code&amp;gt;view delayed jobs&amp;lt;/code&amp;gt; button in assignment-&amp;gt;edit.&lt;br /&gt;
The following two pictures are our work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96696</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96696"/>
		<updated>2015-04-22T02:21:07Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* UI issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
To view the tasks in delayed job queue,&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96695</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96695"/>
		<updated>2015-04-22T02:20:27Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* UI issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
The following two pictures are our work &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:showscheduledtask.png|frame|center|The UI to show all the scheduled tasks]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
To view the tasks in delayed job queue,&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Showscheduledtask.png&amp;diff=96694</id>
		<title>File:Showscheduledtask.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Showscheduledtask.png&amp;diff=96694"/>
		<updated>2015-04-22T02:19:10Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96693</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96693"/>
		<updated>2015-04-22T02:18:48Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* UI issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
The following two pictures are our work&lt;br /&gt;
[[File:viewdelayedjobs.png |frame|center|add a button to display all scheduled tasks]]]&lt;br /&gt;
[[File:showscheduledtask.png]]&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
To view the tasks in delayed job queue,&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Viewdelayedjobs.png&amp;diff=96692</id>
		<title>File:Viewdelayedjobs.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Viewdelayedjobs.png&amp;diff=96692"/>
		<updated>2015-04-22T02:17:16Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96690</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96690"/>
		<updated>2015-04-22T02:16:05Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* UI issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
==Email notification feature to scheduled tasks==&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our team aims to extend this project. This wiki page documents the problem analysis and provides a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
==Project Scope==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
Extending this project, the new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
*create tests to make sure the test coverage increases.&lt;br /&gt;
==Files Involved==&lt;br /&gt;
Mailers:&lt;br /&gt;
*delayed_mailer.rb&lt;br /&gt;
&lt;br /&gt;
Models:&lt;br /&gt;
*assignment_form.rb&lt;br /&gt;
*due_date.rb&lt;br /&gt;
*delayed_job.rb(new created)&lt;br /&gt;
*scheduled_task.rb(new created)&lt;br /&gt;
&lt;br /&gt;
Views:&lt;br /&gt;
*_due_dates.html.erb&lt;br /&gt;
*_assignments_actions.html.erb&lt;br /&gt;
*  scheduled_tasks.erb(new created)&lt;br /&gt;
&lt;br /&gt;
Controllers:&lt;br /&gt;
*assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
==Gems Related==&lt;br /&gt;
*gem 'delayed_job_active_record' &lt;br /&gt;
&lt;br /&gt;
[https://github.com/collectiveidea/delayed_job Delayed:Job] encapsulates the common pattern of asynchronously executing longer tasks in the background&amp;lt;ref&amp;gt; [https://github.com/collectiveidea/delayed_job Delayed_job Gem]&amp;lt;/ref&amp;gt;. It allows to support multiple backends for storing the job queue.  By using 'delayed_job_active_record'  gem, we can use delayed_job with Active Record. This Active Record backend requires a job table. &lt;br /&gt;
&lt;br /&gt;
After running rails generate delayed_job:active_record and rake db:migrate, a &amp;quot;delayed_jobs&amp;quot; table is created in our database. This gem integrates well with many [http://en.wikipedia.org/wiki/Relational_database_management_system RDBMS] backend such as MySQL. Using this gem, we can store all scheduled tasks queue into the &amp;quot;delayed_jobs&amp;quot; table.&lt;br /&gt;
&lt;br /&gt;
*gem 'paper_trail'&lt;br /&gt;
PaperTrail allows to track changes of models' data, which is good for versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed&amp;lt;ref&amp;gt;[https://github.com/airblade/paper_trail paper trail]&amp;lt;/ref&amp;gt;. Using this gem, we can keep log of the scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=Problem Analysis=&lt;br /&gt;
&lt;br /&gt;
== Time Issues==&lt;br /&gt;
&lt;br /&gt;
Initially,  when we want to verify the email function, we found many time issues in this system. That blocks our work about email notification. Some related problems are explained and analyzed in this section. &lt;br /&gt;
&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
Firstly, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎ |frame|center|Set due time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time 2.png |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. After we analyze, we found the problem may lay in the line of 68 of &amp;lt;code&amp;gt;views/assignment/edit/_due_dates.html.erb&amp;lt;/code&amp;gt; file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;due_at = new Date(due_at.substr(0, 16)).format('yyyy/mm/dd HH:MM');&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When we declare a Data object, this Data() function will perform a time zone conversion automatically. Yet Rails’ default timezone stored in database is UTC. So the displayed time(local time, which is EDT) and time in database is different.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Delayassign.png |frame|center|Delay a time]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delaydatabase.png |frame|center|Time Stored in Database]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The reason why there is a four-hour time difference is generated from the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;, method &amp;lt;code&amp;gt; find_min_from_now(due_at)&amp;lt;/code&amp;gt;, and line 142 &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT. The two time zones have four-hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
As a result, we conclude that only one due_time record associated with different period exists in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
==UI issues==&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view or delete their delayed tasks related to an assignment. We are going to add a button under Assignment-&amp;gt;edit, and add a view to display all delayed jobs derived from the delayed_jobs table in our database.&lt;br /&gt;
The following two pictures are our work&lt;br /&gt;
[[File:viewdelayedjobs.png]]&lt;br /&gt;
[[File:showscheduledtask.png]]&lt;br /&gt;
&lt;br /&gt;
=System Design=&lt;br /&gt;
==Fix Time Issues==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
==Add UI to visualize for scheduled tasks==&lt;br /&gt;
To view the tasks in delayed job queue,&lt;br /&gt;
&lt;br /&gt;
==Keep log of the scheduled tasks==&lt;br /&gt;
==support more schedule tasks==&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews (reviews which have not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
The design we want to highlight here is that these additional scheduled tasks can be achieved in same way as email notification used.  The difference is that each task refers to a different related due time(either a previously existing one or a new created one).  Then they all set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, corresponding actions could be taken. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Support more scheduled tasks.png|frame|center|Support more scheduled tasks]]&lt;br /&gt;
 &lt;br /&gt;
Diagram description:  In our system, we would have four scheduled time: submission, review, metareview and team_up. When due time comes, the system takes corresponding actions described as above. These scheduled actions are called scheduled tasks. And the design to achieve these functions are explained above. This diagram just displays the text description above in &amp;quot;Support more scheduled tasks &amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
===1===&lt;br /&gt;
===2===&lt;br /&gt;
===3===&lt;br /&gt;
&lt;br /&gt;
=Tests=&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96225</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96225"/>
		<updated>2015-04-01T01:33:20Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
The reason why there is also exist four hours time difference is generate from the code &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt; in the file &amp;lt;code&amp;gt; application_form.rb &amp;lt;/code&amp;gt;'s method&amp;lt;code&amp;gt; find_min_from_now(due_at)        &amp;lt;/code&amp;gt;.  &amp;lt;code&amp;gt; due_at &amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt; curr_time &amp;lt;/code&amp;gt; is the local time which is EDT, the two time zone time have four hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
[[File:delayagain.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
We found only one due_time record associated with different period in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96223</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96223"/>
		<updated>2015-04-01T01:31:58Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* New deadline replace the old one */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
[[File:delayagain.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
We found only one due_time record associated with different period in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96221</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96221"/>
		<updated>2015-04-01T01:31:05Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* New deadline replace the old one */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
[[File:delayagain.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
The reason why there is also exist four hours time difference is generate from the code &amp;lt;code&amp;gt;time_in_min=((due_at - curr_time).to_i/60)&amp;lt;/code&amp;gt; in the file &amp;lt;code&amp;gt;application_form.rb&amp;lt;/code&amp;gt;'s method&amp;lt;code&amp;gt;find_min_from_now(due_at)&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;due_at&amp;lt;/code&amp;gt; is the system time for Rails (UTC), while &amp;lt;code&amp;gt;curr_time&amp;lt;/code&amp;gt; is the local time which is EDT, the two time zone time have four hour time difference.&amp;lt;br&amp;gt;&lt;br /&gt;
We found only one due_time record associated with different period in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96209</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96209"/>
		<updated>2015-04-01T01:02:32Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* New deadline replace the old one */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
[[File:delayagain.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
However, the delayed_jobs database form is still the same, which means in one assignment there is only one reminder can work.&amp;lt;br&amp;gt;&lt;br /&gt;
We found only one due_time record associated with different period in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of deadline type id.&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayagain.png&amp;diff=96205</id>
		<title>File:Delayagain.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayagain.png&amp;diff=96205"/>
		<updated>2015-04-01T00:57:02Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96204</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96204"/>
		<updated>2015-04-01T00:56:41Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* New deadline replace the old one */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
&lt;br /&gt;
In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
We found only one due_time record associated with different period in the database:&lt;br /&gt;
*In Expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period separately.&lt;br /&gt;
*In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
*In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
*After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
This time, we add a new delay in Review section, we delay the deadline from 2015/03/22 21:00 to 2015/03/30 21:00, and set the remind hr to 8 hours.&lt;br /&gt;
[[File:delayagain.png]]&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
*When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
*Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
*When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96190</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96190"/>
		<updated>2015-04-01T00:42:32Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96185</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96185"/>
		<updated>2015-04-01T00:39:19Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delaydatabase.png&amp;diff=96184</id>
		<title>File:Delaydatabase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delaydatabase.png&amp;diff=96184"/>
		<updated>2015-04-01T00:38:50Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96182</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96182"/>
		<updated>2015-04-01T00:38:32Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 16 hours.&lt;br /&gt;
[[File:Delayassign.png]]&lt;br /&gt;
After click &amp;quot;save&amp;quot;, the run time showed database is about 8:00 am. Since 20-16=4, the correct run time is 4:00 am&lt;br /&gt;
[[File:delaydatabase.png]]&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96180</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96180"/>
		<updated>2015-04-01T00:34:23Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 8 hours.&lt;br /&gt;
[[File:Delayassign.png]]&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96179</id>
		<title>File:Delayassign.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96179"/>
		<updated>2015-04-01T00:33:52Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: uploaded a new version of &amp;amp;quot;File:Delayassign.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96178</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96178"/>
		<updated>2015-04-01T00:33:01Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 8 hours.&lt;br /&gt;
[[File:Delayassign.jpg]]&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96176</id>
		<title>File:Delayassign.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96176"/>
		<updated>2015-04-01T00:32:22Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: uploaded a new version of &amp;amp;quot;File:Delayassign.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96167</id>
		<title>File:Delayassign.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Delayassign.png&amp;diff=96167"/>
		<updated>2015-04-01T00:20:42Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96166</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96166"/>
		<updated>2015-04-01T00:20:10Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Different time zone */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
[[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
**After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
When we delay a deadline of an assignment, for example, we set the deadline of metareview from2015/03/28 16:00 to 2015/04/04 20:00 and set the reminder hr to 8 hours.&lt;br /&gt;
[[File:delayassign.jpg]]&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96150</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96150"/>
		<updated>2015-03-31T23:53:04Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the time we save. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96149</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96149"/>
		<updated>2015-03-31T23:32:24Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
After several tries, we found that every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time. However, the time in the database is alway correct as the we set originally. Then the problem may lay in the assignment edit view file.&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96143</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96143"/>
		<updated>2015-03-31T23:26:56Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved. What's more, every time when we click &amp;quot;save&amp;quot;, the saved time is 4 hours earlier then the last saved time&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96141</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96141"/>
		<updated>2015-03-31T23:20:00Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
[[File:database_deadline.png |frame|center|The deadline time is stored correct in the database]]&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96140</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96140"/>
		<updated>2015-03-31T23:18:53Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
And we can see that the date is stored correct in the database&lt;br /&gt;
[[File:database_deadline.png]]&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. ?????&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96136</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96136"/>
		<updated>2015-03-31T23:18:03Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. &lt;br /&gt;
And we can see that the date is stored correct in the database&lt;br /&gt;
[[File:database_deadline.png]]&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Database_deadline.png&amp;diff=96135</id>
		<title>File:Database deadline.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Database_deadline.png&amp;diff=96135"/>
		<updated>2015-03-31T23:17:07Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96134</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96134"/>
		<updated>2015-03-31T23:16:26Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. &lt;br /&gt;
And we can see that the date is stored correct in the database&lt;br /&gt;
[[File:database_deadline.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96130</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96130"/>
		<updated>2015-03-31T22:14:38Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. However,,,,,,,,,,,,,,,,,,,,,&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96128</id>
		<title>CSC/ECE 517 Spring 2015 E1529 GLDS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1529_GLDS&amp;diff=96128"/>
		<updated>2015-03-31T22:13:51Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Wrong displayed time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1529. Extend the Email notification feature to scheduled tasks &amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Overview'''==&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza. Github]&amp;lt;/ref&amp;gt;. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc). It is also a powerful tool for professor to manage courses and assignments and so on. The latest &amp;quot;Rails 4&amp;quot; branch of Expertiza, although combined with various enhancements from the past two years, is seriously broken, from data migration to key feature implementation. Part of the reason has been the design strategy and code changes by various teams.&lt;br /&gt;
&lt;br /&gt;
===Email notification feature to scheduled tasks===&lt;br /&gt;
This is a feature that has already been partially implemented in Expertiza [https://github.com/expertiza/expertiza/pull/445 E1451] implemented both sychronous and asychoronous mailers. Sychronous Emails refer to the Emails sent immediatly after an event (e.g. when student receive a peer-review). Asychoronous Email we implemented by the Gem &amp;quot;delayed job” and when a task (asychronous Email) is added to the delayed queue, a count-down number of minutes needs to be specified.&amp;lt;br&amp;gt;&lt;br /&gt;
Our team aim to extend this project. This wiki page documents the changes our team has made and provided a guideline for future development and enhancement.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
E1451. ​Create Mailers for All Email Messages [https://github.com/expertiza/expertiza/pull/445 github] [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1451_las wiki] [http://expertiza.ncsu.edu/submitted_content/download/28122?current_folder%5Bname%5D=%2Flocal%2Frails%2Fexpertiza%2Freleases%2F20140702225848%2Fpg_data%2Fefg%2Fcsc517%2Ff14%2F%2F18&amp;amp;download=E1451_Report.pdf report] (Merged in [https://docs.google.com/a/ncsu.edu/document/d/1aypHb5UOe-3nPfruNeh2HZjeT-wfv6f-ZsZg2jDMNkQ/edit E1483])&lt;br /&gt;
&lt;br /&gt;
==Scope==&lt;br /&gt;
The new system should be capable of&lt;br /&gt;
*If one task is added to the delayed job queue, the asychronous Email should be updated or deleted automatically.&lt;br /&gt;
*Add UI to visualize for the task in delayed job queue, instructors should be able to view tasks related to the assignments they have created. 	&lt;br /&gt;
*Keep log of the scheduled tasks when they are scheduled and done, record events in the same log as project [https://github.com/expertiza/expertiza/pull/462 E​1478].		&lt;br /&gt;
*[optional] support more scheduled task:  							 &lt;br /&gt;
**instructors are able to schedule the time to drop all the outstanding reviews (reviews which has not been started) &lt;br /&gt;
**instructors are able to schedule a specific time to send Emails to all the assignment participants who are still not in any team to find or form one. &lt;br /&gt;
**(new) instructor should be able to schedule a time to drop all the topics which are held by 1 person teams.&lt;br /&gt;
&lt;br /&gt;
==Problem Analysis==&lt;br /&gt;
===Wrong displayed time===&lt;br /&gt;
&lt;br /&gt;
*Initially, when we set a due time to test the mail features, we found the display of time is incorrect.&lt;br /&gt;
**In the “Assignment Edit”-&amp;gt;“Due dates”, when we modify the “Date &amp;amp; time” of the deadline, the displayed time will be 4 hours ahead of the time we saved.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  [[File:Wrong display of time.png‎  |frame|center|Set due time]].&lt;br /&gt;
 This picture shows the time we set before clicking &amp;quot;save&amp;quot; button.&lt;br /&gt;
  [[File:Wrong display of time 2.png‎  |frame|center|After we click the save button, we can see that all the time are 4 hours ahead of the set time.]].&lt;br /&gt;
This picture shows the set time after clicking &amp;quot;save&amp;quot; button.&lt;br /&gt;
**Reasons: After we analyze, we found Rails’ default timezone is UTC. However,,,,,,,,,,,,,,,,,,,,,&lt;br /&gt;
&lt;br /&gt;
===Different time zone===&lt;br /&gt;
&lt;br /&gt;
*In the previous version, when current time is compared with the time stored in database, they may apply to different time zones so that the result of comparison may be wrong. 截图&lt;br /&gt;
&lt;br /&gt;
===New deadline replace the old one===&lt;br /&gt;
&lt;br /&gt;
* We found only one due_time record associated with different period in the database:&lt;br /&gt;
&lt;br /&gt;
**In expertiza, one assignment has several period, such as submission, review, metareview. Administrates are able to set and postpone due dates for each period     separately.&lt;br /&gt;
**In the previous version, when the instructor postpone the review deadline and then postpone the submit deadline, the submit deadline’s modification will replace the the review deadline’s modification in database. &lt;br /&gt;
**In this case, if both of them need Email reminder, there will be no Email about the former modified deadline.&lt;br /&gt;
**After our analysis, we found the due time object is identified with assignment_id, instead of ,,,,,,,,,,,,截图&lt;br /&gt;
&lt;br /&gt;
===UI issues===&lt;br /&gt;
*In the previous version, there is no UI to display the reminders of assignments. There is no way for instructors to view their delayed tasks related to an assignment.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
===Unified time zone===&lt;br /&gt;
*We can convert current time to the same time zone as the deadline stored in database. Then the result of comparison will be right so that it can be used for further usage.&lt;br /&gt;
===Separate deadline of each topic period===&lt;br /&gt;
*In each Assignment, each deadline type (E.g review, submit, metareview) should has its own Email reminder time in the database. New postponed deadline of one type can only replace the same deadline type in the same assignment id category.&lt;br /&gt;
===Add UI to visualize for scheduled tasks===&lt;br /&gt;
*In the UI module, we are going to display the scheduled time for reminder emails of submit, review and final review. And when reminder or due date are modified, the displayed content will also be changed. 截图？&lt;br /&gt;
&lt;br /&gt;
===Keep log of the scheduled tasks===&lt;br /&gt;
&lt;br /&gt;
===support more schedule tasks===&lt;br /&gt;
*In the Assignment Edit page-&amp;gt;Due dates: &lt;br /&gt;
**When we set the review’s due date, create a “delayed job”  at the same time. When the review is due, it will automatically find all the outstanding reviews(reviews which has not been started) in the database then delete them. &lt;br /&gt;
**Add a new teamup deadline, set up a reminder and create a “delayed job” at the same time. When “delayed job” is triggered, it will automatically find all the assignment participants who are still not in any team in the database, and send Emails to them to find teammate.&lt;br /&gt;
**When teamup time is due, the system will find all the topics which are held by 1 person teams in the database, then the professor can drop those topics.&lt;br /&gt;
&lt;br /&gt;
[[File:scheduled tasks.png|frame|center|Scheduled Tasks]]&lt;br /&gt;
&lt;br /&gt;
==Puzzles==&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95266</id>
		<title>CSC/ECE 517 Spring 2015/oss E1509 lds</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95266"/>
		<updated>2015-03-21T22:28:28Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Deleting redundant button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1509. Refactoring SignUpController and SignUpSheetController ==&lt;br /&gt;
&lt;br /&gt;
This page talks about an open source project based on Expertiza. As a part of contribution to Expertiza, this project aims to refactor SignUpController and SignUpSheetControllers.&lt;br /&gt;
&lt;br /&gt;
=== Introduction to Expertiza ===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is supported by the National Science Foundation. And it is an open source application and the source code can be cloned on [https://github.com/expertiza/expertiza Github] . &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
===Classes involved===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* sign_up_sheet.rb &lt;br /&gt;
* sign_up_topic.rb &lt;br /&gt;
* assignments_controller.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
* and possibly other model classes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What it does===&lt;br /&gt;
&lt;br /&gt;
Lists topics available for an assignment, checks whether a user is signed up for a topic, allows users to sign up for topics.&lt;br /&gt;
&lt;br /&gt;
===What's wrong with it===&lt;br /&gt;
* These two controllers seem to do almost the same thing.  They have many of the same methods.  &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; is much longer, and has many more recent mods, but some methods of &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; seem more sophisticated than &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;.  So, your first job is to figure out if both controllers are being used.  If not, remove the unused controller.  Or, move the functions to a single controller if that makes sense to do.&lt;br /&gt;
* Neither controller is at all RESTful; i.e.., its method names aren’t the standard names &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;edit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;delete&amp;lt;/code&amp;gt;, etc.  Functionality is divided differently than in a standard controller.&amp;lt;br&amp;gt;a. &amp;lt;code&amp;gt;def confirm_topic(creator_id, topic_id, assignment_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; b. &amp;lt;code&amp;gt;def delete_signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; c.&amp;lt;code&amp;gt;def delete_signup_for_topic(assignment_id,topic_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; d. &amp;lt;code&amp;gt;def other_confirmed_topic_for_user(assignment_id, creator_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;e. &amp;lt;code&amp;gt;def signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; f. &amp;lt;code&amp;gt;def slotAvailable?(topic_id)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Functionality that should be in models is incorporated into the controller.&lt;br /&gt;
* Some methods are too long and appear to do more than one thing&lt;br /&gt;
* This class interfaces with assignments_controller so that a list of topics can be displayed when one is editing an assignment.  Please be careful that your changes do not affect the functionality on the Topics tab of editing an assignment.&lt;br /&gt;
* Rename the controller(s) to &amp;lt;code&amp;gt;SignupController&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;.  (“Sign up”, which gets written as SignUp in camel case, is a verb, whereas “Signup” is a noun.)&lt;br /&gt;
* Some codes does not follow the [https://docs.google.com/a/ncsu.edu/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Rules].&lt;br /&gt;
&lt;br /&gt;
== Modification We Made ==&lt;br /&gt;
=== Removing unused controller ===&lt;br /&gt;
After various analysis and test, we found &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; is never used. So we remove it. The reasons are listed as follows:&lt;br /&gt;
* There is no code about &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt; file.&amp;lt;p&amp;gt;The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/routing.html#the-purpose-of-the-rails-router&amp;lt;/ref&amp;gt;. Rails default routing is resource routing, which allows us to declare all the common routes for a resourceful controller. In our &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt;, we found a matching resourceful route for &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;, which asks the router to map it to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; action.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  resources :signup_sheet &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This route creates several different routes in the application, all mapping to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; controller. &lt;br /&gt;
Here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|HTTP Verb&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Controller#Action&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Used For &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#signup&lt;br /&gt;
| This function lets the user choose a particular topic.&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#delete_signup&lt;br /&gt;
| This function is used to delete a previous signup&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#view_publishing_rights&lt;br /&gt;
| The function is to make sure the publishing rights for a user&lt;br /&gt;
|}&lt;br /&gt;
However, there is not a matching route for &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt;.&lt;br /&gt;
*&amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; has all seven methods in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; with same name. we found these functions are completely achieved via &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;. And after test, we prove that codes in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; never got executed when we ran the project.&lt;br /&gt;
&lt;br /&gt;
=== RESTful style implementation ===&lt;br /&gt;
The purpose of the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; method in the &amp;lt;code&amp;gt;SignupSheet controller&amp;lt;/code&amp;gt; is to list all the topics in the specific assignments. According to RESTful rules, a method that returns a list of all available objects should be named as &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the signup_sheet_controller.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we need to change some references to the method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
verify method: 'post', :only =&amp;gt; [:destroy, :create, :update],&lt;br /&gt;
:redirect_to =&amp;gt; {:action =&amp;gt; :index}&lt;br /&gt;
&lt;br /&gt;
SignUpTopic.reassign_topic(@user_id,params[:assignment_id], params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&lt;br /&gt;
signup_team(@assignment.id, @user_id, params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some others, it is not good to combine some functions with the standard ones. For example, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function creates topics, which is one of the administrator’s functions. However &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; creates a record that includes information for topic and student, which happens when student clicks &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; button. We can see that &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; are designed for different role and different usage so it is not a good idea to combine them together.&lt;br /&gt;
&lt;br /&gt;
=== Moving inappropriate functionality from controller to model ===&lt;br /&gt;
The controller connects the model with the view. In Rails, controllers are implemented as ActionController classes. The controller knows how to process the data that comes from the model and how to pass it onto the view. The controller should not include any database related actions (such as modifying data before it gets saved inside the database). This should be handled in the proper model. So we remove all the database related functionality in the signup_sheet_controller to related models.&lt;br /&gt;
The following files were modified:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/signup_sheet_controller.rb&lt;br /&gt;
app/models/deadline_type.rb&lt;br /&gt;
app/models/due_date.rb&lt;br /&gt;
app/models/participant.rb&lt;br /&gt;
app/models/sign_up_topic.rb&lt;br /&gt;
app/models/signed_up_user.rb&lt;br /&gt;
app/models/topic_deadline.rb&lt;br /&gt;
app/models/topic_dependency.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are two examples on how these files changed.&amp;lt;br&amp;gt;&lt;br /&gt;
1. replace &amp;quot;where&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in&amp;lt;code&amp;gt; sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_with_name_and_assignment_id(name, aid)&lt;br /&gt;
 SignUpTopic.where(topic_name: name, assignment_id: aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2. replace &amp;quot;find_by_sql&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_topic_id_with_assignment_id(params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in &amp;lt;code&amp;gt;sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_topic_id_with_assignment_id(aid)&lt;br /&gt;
 SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Breaking down long methods ===&lt;br /&gt;
We’ve find that lots of methods do more than one thing so we separate a long function into several concise functions and call them in the original function. Here is an example:&lt;br /&gt;
&lt;br /&gt;
There are some preparation works and check works before or after the actual create operation. So we separate two functions &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;. And we call these two functions in &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method instead of executing these codes directly.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
  if topic != nil&lt;br /&gt;
    topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
    if SignedUpUser.find_by_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
        topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
        topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    if @assignment.is_microtask?&lt;br /&gt;
      @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
    end&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render :action =&amp;gt; 'new', :id =&amp;gt; params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def update_topic_info(topic)&lt;br /&gt;
  topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
  if SignedUpUser.find_with_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
    topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
  else&lt;br /&gt;
    if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
      topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; updates topics' some attributes according to received parameters, such as permitted max number of choosers and waitlisted users. This method is separated from function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; because it doesn't really do any creation works.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def check_after_create&lt;br /&gt;
  if @assignment.is_microtask?&lt;br /&gt;
    @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
  end&lt;br /&gt;
  if @assignment.staggered_deadline?&lt;br /&gt;
    topic_set = Array.new&lt;br /&gt;
    topic = @sign_up_topic.id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; check if the assignment is a microtask and if it applies to staggered deadline. If these two conditions are met, then execute corresponding actions. These steps should be separated from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function because it doesn't actually do works related with creation.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
  if topic&lt;br /&gt;
    update_topic_info(topic)&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    check_after_create&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render action: 'new', id: params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method, the two separated methods were called. By this way, function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; will be much shorter and some works do not belong to it can  be finished by other methods.&lt;br /&gt;
&lt;br /&gt;
=== Deleting redundant button ===&lt;br /&gt;
When we move the mouse on the Assignment, there is a &amp;quot;Edit signup sheet&amp;quot; button in the popup menu. It is a redundant button since there already has such a function in Assignment &amp;quot;Edit&amp;quot; menu. What's more it's more reasonable to put this function in &amp;quot;Edit&amp;quot; Assignment because signup sheet is a part of the assignment. So we removed this button. Sometimes after making some changes, the display topics function didn’t work due to some reasons. We’ve fixed those bugs and make sure it still works after our last change.&amp;lt;br&amp;gt;&lt;br /&gt;
We delete the following lines in &amp;lt;code&amp;gt;app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if signup_topic %&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The origin popup menu is as following picture, there is a &amp;lt;code&amp;gt;edit signup sheet &amp;lt;/code&amp;gt; button:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:originPopup.jpg]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;The new popup menu is:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:new_popup.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After modifying, the other assignment functions all works well.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:AssignTopic.png]]&lt;br /&gt;
&lt;br /&gt;
=== Renaming controller ===&lt;br /&gt;
According to the controller name convention&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/action_controller_overview.html&amp;lt;/ref&amp;gt;, a controller should be a singular noun. However, here &amp;lt;code&amp;gt;SignUp&amp;lt;/code&amp;gt; in camel case is a verb. We should modify it to a noun written as &amp;lt;code&amp;gt;Signup&amp;lt;/code&amp;gt;. As a result, we rename all class name &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;. Then the controller name &amp;lt;code&amp;gt;sign_up_sheet_controller&amp;lt;/code&amp;gt; is revised into &amp;lt;code&amp;gt;signup_sheet_controller&amp;lt;/code&amp;gt; automatically.&amp;lt;br&amp;gt;&lt;br /&gt;
Here we also make sure every reference for this controller has been changed to match the new controller name. For example, in &amp;lt;code&amp;gt;views/signup_sheet/_action.html.erb&amp;lt;/code&amp;gt; file, we must make sure this render path is correct as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial =&amp;gt; '/signup_sheet/all_actions', :locals =&amp;gt; {:i=&amp;gt;i, :topic=&amp;gt;topic} %&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Following global rules ===&lt;br /&gt;
According to Global Rules, there are some codes that need some improvements to make it follow the rules correctly. Here are some of what we have done:&lt;br /&gt;
 &lt;br /&gt;
* change &amp;lt;code&amp;gt;users_team.size == 0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;users_team.zero?&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  if users_team.size == 0&lt;br /&gt;
to:&lt;br /&gt;
  if users_team.zero?&lt;br /&gt;
or:&lt;br /&gt;
  if users_team.empty?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;key: 'value'&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;:key =&amp;gt; 'value'&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
to:&lt;br /&gt;
  redirect_to action: 'add_signup_topics_staggered', id: assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;if (var)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;if (var == true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  (assignment.staggered_deadline == true)?&lt;br /&gt;
to:&lt;br /&gt;
  (assignment.staggered_deadline)?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95265</id>
		<title>CSC/ECE 517 Spring 2015/oss E1509 lds</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95265"/>
		<updated>2015-03-21T22:28:10Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Deleting redundant button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1509. Refactoring SignUpController and SignUpSheetController ==&lt;br /&gt;
&lt;br /&gt;
This page talks about an open source project based on Expertiza. As a part of contribution to Expertiza, this project aims to refactor SignUpController and SignUpSheetControllers.&lt;br /&gt;
&lt;br /&gt;
=== Introduction to Expertiza ===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is supported by the National Science Foundation. And it is an open source application and the source code can be cloned on [https://github.com/expertiza/expertiza Github] . &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
===Classes involved===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* sign_up_sheet.rb &lt;br /&gt;
* sign_up_topic.rb &lt;br /&gt;
* assignments_controller.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
* and possibly other model classes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What it does===&lt;br /&gt;
&lt;br /&gt;
Lists topics available for an assignment, checks whether a user is signed up for a topic, allows users to sign up for topics.&lt;br /&gt;
&lt;br /&gt;
===What's wrong with it===&lt;br /&gt;
* These two controllers seem to do almost the same thing.  They have many of the same methods.  &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; is much longer, and has many more recent mods, but some methods of &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; seem more sophisticated than &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;.  So, your first job is to figure out if both controllers are being used.  If not, remove the unused controller.  Or, move the functions to a single controller if that makes sense to do.&lt;br /&gt;
* Neither controller is at all RESTful; i.e.., its method names aren’t the standard names &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;edit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;delete&amp;lt;/code&amp;gt;, etc.  Functionality is divided differently than in a standard controller.&amp;lt;br&amp;gt;a. &amp;lt;code&amp;gt;def confirm_topic(creator_id, topic_id, assignment_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; b. &amp;lt;code&amp;gt;def delete_signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; c.&amp;lt;code&amp;gt;def delete_signup_for_topic(assignment_id,topic_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; d. &amp;lt;code&amp;gt;def other_confirmed_topic_for_user(assignment_id, creator_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;e. &amp;lt;code&amp;gt;def signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; f. &amp;lt;code&amp;gt;def slotAvailable?(topic_id)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Functionality that should be in models is incorporated into the controller.&lt;br /&gt;
* Some methods are too long and appear to do more than one thing&lt;br /&gt;
* This class interfaces with assignments_controller so that a list of topics can be displayed when one is editing an assignment.  Please be careful that your changes do not affect the functionality on the Topics tab of editing an assignment.&lt;br /&gt;
* Rename the controller(s) to &amp;lt;code&amp;gt;SignupController&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;.  (“Sign up”, which gets written as SignUp in camel case, is a verb, whereas “Signup” is a noun.)&lt;br /&gt;
* Some codes does not follow the [https://docs.google.com/a/ncsu.edu/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Rules].&lt;br /&gt;
&lt;br /&gt;
== Modification We Made ==&lt;br /&gt;
=== Removing unused controller ===&lt;br /&gt;
After various analysis and test, we found &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; is never used. So we remove it. The reasons are listed as follows:&lt;br /&gt;
* There is no code about &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt; file.&amp;lt;p&amp;gt;The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/routing.html#the-purpose-of-the-rails-router&amp;lt;/ref&amp;gt;. Rails default routing is resource routing, which allows us to declare all the common routes for a resourceful controller. In our &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt;, we found a matching resourceful route for &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;, which asks the router to map it to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; action.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  resources :signup_sheet &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This route creates several different routes in the application, all mapping to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; controller. &lt;br /&gt;
Here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|HTTP Verb&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Controller#Action&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Used For &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#signup&lt;br /&gt;
| This function lets the user choose a particular topic.&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#delete_signup&lt;br /&gt;
| This function is used to delete a previous signup&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#view_publishing_rights&lt;br /&gt;
| The function is to make sure the publishing rights for a user&lt;br /&gt;
|}&lt;br /&gt;
However, there is not a matching route for &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt;.&lt;br /&gt;
*&amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; has all seven methods in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; with same name. we found these functions are completely achieved via &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;. And after test, we prove that codes in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; never got executed when we ran the project.&lt;br /&gt;
&lt;br /&gt;
=== RESTful style implementation ===&lt;br /&gt;
The purpose of the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; method in the &amp;lt;code&amp;gt;SignupSheet controller&amp;lt;/code&amp;gt; is to list all the topics in the specific assignments. According to RESTful rules, a method that returns a list of all available objects should be named as &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the signup_sheet_controller.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we need to change some references to the method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
verify method: 'post', :only =&amp;gt; [:destroy, :create, :update],&lt;br /&gt;
:redirect_to =&amp;gt; {:action =&amp;gt; :index}&lt;br /&gt;
&lt;br /&gt;
SignUpTopic.reassign_topic(@user_id,params[:assignment_id], params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&lt;br /&gt;
signup_team(@assignment.id, @user_id, params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some others, it is not good to combine some functions with the standard ones. For example, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function creates topics, which is one of the administrator’s functions. However &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; creates a record that includes information for topic and student, which happens when student clicks &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; button. We can see that &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; are designed for different role and different usage so it is not a good idea to combine them together.&lt;br /&gt;
&lt;br /&gt;
=== Moving inappropriate functionality from controller to model ===&lt;br /&gt;
The controller connects the model with the view. In Rails, controllers are implemented as ActionController classes. The controller knows how to process the data that comes from the model and how to pass it onto the view. The controller should not include any database related actions (such as modifying data before it gets saved inside the database). This should be handled in the proper model. So we remove all the database related functionality in the signup_sheet_controller to related models.&lt;br /&gt;
The following files were modified:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/signup_sheet_controller.rb&lt;br /&gt;
app/models/deadline_type.rb&lt;br /&gt;
app/models/due_date.rb&lt;br /&gt;
app/models/participant.rb&lt;br /&gt;
app/models/sign_up_topic.rb&lt;br /&gt;
app/models/signed_up_user.rb&lt;br /&gt;
app/models/topic_deadline.rb&lt;br /&gt;
app/models/topic_dependency.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are two examples on how these files changed.&amp;lt;br&amp;gt;&lt;br /&gt;
1. replace &amp;quot;where&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in&amp;lt;code&amp;gt; sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_with_name_and_assignment_id(name, aid)&lt;br /&gt;
 SignUpTopic.where(topic_name: name, assignment_id: aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2. replace &amp;quot;find_by_sql&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_topic_id_with_assignment_id(params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in &amp;lt;code&amp;gt;sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_topic_id_with_assignment_id(aid)&lt;br /&gt;
 SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Breaking down long methods ===&lt;br /&gt;
We’ve find that lots of methods do more than one thing so we separate a long function into several concise functions and call them in the original function. Here is an example:&lt;br /&gt;
&lt;br /&gt;
There are some preparation works and check works before or after the actual create operation. So we separate two functions &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;. And we call these two functions in &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method instead of executing these codes directly.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
  if topic != nil&lt;br /&gt;
    topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
    if SignedUpUser.find_by_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
        topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
        topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    if @assignment.is_microtask?&lt;br /&gt;
      @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
    end&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render :action =&amp;gt; 'new', :id =&amp;gt; params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def update_topic_info(topic)&lt;br /&gt;
  topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
  if SignedUpUser.find_with_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
    topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
  else&lt;br /&gt;
    if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
      topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; updates topics' some attributes according to received parameters, such as permitted max number of choosers and waitlisted users. This method is separated from function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; because it doesn't really do any creation works.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def check_after_create&lt;br /&gt;
  if @assignment.is_microtask?&lt;br /&gt;
    @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
  end&lt;br /&gt;
  if @assignment.staggered_deadline?&lt;br /&gt;
    topic_set = Array.new&lt;br /&gt;
    topic = @sign_up_topic.id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; check if the assignment is a microtask and if it applies to staggered deadline. If these two conditions are met, then execute corresponding actions. These steps should be separated from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function because it doesn't actually do works related with creation.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
  if topic&lt;br /&gt;
    update_topic_info(topic)&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    check_after_create&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render action: 'new', id: params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method, the two separated methods were called. By this way, function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; will be much shorter and some works do not belong to it can  be finished by other methods.&lt;br /&gt;
&lt;br /&gt;
=== Deleting redundant button ===&lt;br /&gt;
When we move the mouse on the Assignment, there is a &amp;quot;Edit signup sheet&amp;quot; button in the popup menu. It is a redundant button since there already has such a function in Assignment &amp;quot;Edit&amp;quot; menu. What's more it's more reasonable to put this function in &amp;quot;Edit&amp;quot; Assignment because signup sheet is a part of the assignment. So we removed this button. Sometimes after making some changes, the display topics function didn’t work due to some reasons. We’ve fixed those bugs and make sure it still works after our last change.&amp;lt;br&amp;gt;&lt;br /&gt;
We delete the following lines in &amp;lt;code&amp;gt;app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if signup_topic %&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The origin popup menu is as following picture, there is a &amp;lt;code&amp;gt;edit signup sheet &amp;lt;/code&amp;gt; button:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:originPopup.jpg]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;The new popup menu is:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:new_popup.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
After modifying, the other assignment functions all works well.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:AssignTopic.png]]&lt;br /&gt;
&lt;br /&gt;
=== Renaming controller ===&lt;br /&gt;
According to the controller name convention&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/action_controller_overview.html&amp;lt;/ref&amp;gt;, a controller should be a singular noun. However, here &amp;lt;code&amp;gt;SignUp&amp;lt;/code&amp;gt; in camel case is a verb. We should modify it to a noun written as &amp;lt;code&amp;gt;Signup&amp;lt;/code&amp;gt;. As a result, we rename all class name &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;. Then the controller name &amp;lt;code&amp;gt;sign_up_sheet_controller&amp;lt;/code&amp;gt; is revised into &amp;lt;code&amp;gt;signup_sheet_controller&amp;lt;/code&amp;gt; automatically.&amp;lt;br&amp;gt;&lt;br /&gt;
Here we also make sure every reference for this controller has been changed to match the new controller name. For example, in &amp;lt;code&amp;gt;views/signup_sheet/_action.html.erb&amp;lt;/code&amp;gt; file, we must make sure this render path is correct as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial =&amp;gt; '/signup_sheet/all_actions', :locals =&amp;gt; {:i=&amp;gt;i, :topic=&amp;gt;topic} %&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Following global rules ===&lt;br /&gt;
According to Global Rules, there are some codes that need some improvements to make it follow the rules correctly. Here are some of what we have done:&lt;br /&gt;
 &lt;br /&gt;
* change &amp;lt;code&amp;gt;users_team.size == 0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;users_team.zero?&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  if users_team.size == 0&lt;br /&gt;
to:&lt;br /&gt;
  if users_team.zero?&lt;br /&gt;
or:&lt;br /&gt;
  if users_team.empty?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;key: 'value'&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;:key =&amp;gt; 'value'&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
to:&lt;br /&gt;
  redirect_to action: 'add_signup_topics_staggered', id: assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;if (var)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;if (var == true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  (assignment.staggered_deadline == true)?&lt;br /&gt;
to:&lt;br /&gt;
  (assignment.staggered_deadline)?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95263</id>
		<title>CSC/ECE 517 Spring 2015/oss E1509 lds</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95263"/>
		<updated>2015-03-21T22:27:35Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Deleting redundant button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1509. Refactoring SignUpController and SignUpSheetController ==&lt;br /&gt;
&lt;br /&gt;
This page talks about an open source project based on Expertiza. As a part of contribution to Expertiza, this project aims to refactor SignUpController and SignUpSheetControllers.&lt;br /&gt;
&lt;br /&gt;
=== Introduction to Expertiza ===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is supported by the National Science Foundation. And it is an open source application and the source code can be cloned on [https://github.com/expertiza/expertiza Github] . &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
===Classes involved===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* sign_up_sheet.rb &lt;br /&gt;
* sign_up_topic.rb &lt;br /&gt;
* assignments_controller.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
* and possibly other model classes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What it does===&lt;br /&gt;
&lt;br /&gt;
Lists topics available for an assignment, checks whether a user is signed up for a topic, allows users to sign up for topics.&lt;br /&gt;
&lt;br /&gt;
===What's wrong with it===&lt;br /&gt;
* These two controllers seem to do almost the same thing.  They have many of the same methods.  &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; is much longer, and has many more recent mods, but some methods of &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; seem more sophisticated than &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;.  So, your first job is to figure out if both controllers are being used.  If not, remove the unused controller.  Or, move the functions to a single controller if that makes sense to do.&lt;br /&gt;
* Neither controller is at all RESTful; i.e.., its method names aren’t the standard names &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;edit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;delete&amp;lt;/code&amp;gt;, etc.  Functionality is divided differently than in a standard controller.&amp;lt;br&amp;gt;a. &amp;lt;code&amp;gt;def confirm_topic(creator_id, topic_id, assignment_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; b. &amp;lt;code&amp;gt;def delete_signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; c.&amp;lt;code&amp;gt;def delete_signup_for_topic(assignment_id,topic_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; d. &amp;lt;code&amp;gt;def other_confirmed_topic_for_user(assignment_id, creator_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;e. &amp;lt;code&amp;gt;def signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; f. &amp;lt;code&amp;gt;def slotAvailable?(topic_id)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Functionality that should be in models is incorporated into the controller.&lt;br /&gt;
* Some methods are too long and appear to do more than one thing&lt;br /&gt;
* This class interfaces with assignments_controller so that a list of topics can be displayed when one is editing an assignment.  Please be careful that your changes do not affect the functionality on the Topics tab of editing an assignment.&lt;br /&gt;
* Rename the controller(s) to &amp;lt;code&amp;gt;SignupController&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;.  (“Sign up”, which gets written as SignUp in camel case, is a verb, whereas “Signup” is a noun.)&lt;br /&gt;
* Some codes does not follow the [https://docs.google.com/a/ncsu.edu/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Rules].&lt;br /&gt;
&lt;br /&gt;
== Modification We Made ==&lt;br /&gt;
=== Removing unused controller ===&lt;br /&gt;
After various analysis and test, we found &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; is never used. So we remove it. The reasons are listed as follows:&lt;br /&gt;
* There is no code about &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt; file.&amp;lt;p&amp;gt;The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/routing.html#the-purpose-of-the-rails-router&amp;lt;/ref&amp;gt;. Rails default routing is resource routing, which allows us to declare all the common routes for a resourceful controller. In our &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt;, we found a matching resourceful route for &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;, which asks the router to map it to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; action.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  resources :signup_sheet &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This route creates several different routes in the application, all mapping to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; controller. &lt;br /&gt;
Here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|HTTP Verb&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Controller#Action&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Used For &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#signup&lt;br /&gt;
| This function lets the user choose a particular topic.&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#delete_signup&lt;br /&gt;
| This function is used to delete a previous signup&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#view_publishing_rights&lt;br /&gt;
| The function is to make sure the publishing rights for a user&lt;br /&gt;
|}&lt;br /&gt;
However, there is not a matching route for &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt;.&lt;br /&gt;
*&amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; has all seven methods in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; with same name. we found these functions are completely achieved via &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;. And after test, we prove that codes in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; never got executed when we ran the project.&lt;br /&gt;
&lt;br /&gt;
=== RESTful style implementation ===&lt;br /&gt;
The purpose of the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; method in the &amp;lt;code&amp;gt;SignupSheet controller&amp;lt;/code&amp;gt; is to list all the topics in the specific assignments. According to RESTful rules, a method that returns a list of all available objects should be named as &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the signup_sheet_controller.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we need to change some references to the method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
verify method: 'post', :only =&amp;gt; [:destroy, :create, :update],&lt;br /&gt;
:redirect_to =&amp;gt; {:action =&amp;gt; :index}&lt;br /&gt;
&lt;br /&gt;
SignUpTopic.reassign_topic(@user_id,params[:assignment_id], params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&lt;br /&gt;
signup_team(@assignment.id, @user_id, params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some others, it is not good to combine some functions with the standard ones. For example, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function creates topics, which is one of the administrator’s functions. However &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; creates a record that includes information for topic and student, which happens when student clicks &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; button. We can see that &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; are designed for different role and different usage so it is not a good idea to combine them together.&lt;br /&gt;
&lt;br /&gt;
=== Moving inappropriate functionality from controller to model ===&lt;br /&gt;
The controller connects the model with the view. In Rails, controllers are implemented as ActionController classes. The controller knows how to process the data that comes from the model and how to pass it onto the view. The controller should not include any database related actions (such as modifying data before it gets saved inside the database). This should be handled in the proper model. So we remove all the database related functionality in the signup_sheet_controller to related models.&lt;br /&gt;
The following files were modified:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/signup_sheet_controller.rb&lt;br /&gt;
app/models/deadline_type.rb&lt;br /&gt;
app/models/due_date.rb&lt;br /&gt;
app/models/participant.rb&lt;br /&gt;
app/models/sign_up_topic.rb&lt;br /&gt;
app/models/signed_up_user.rb&lt;br /&gt;
app/models/topic_deadline.rb&lt;br /&gt;
app/models/topic_dependency.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are two examples on how these files changed.&amp;lt;br&amp;gt;&lt;br /&gt;
1. replace &amp;quot;where&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in&amp;lt;code&amp;gt; sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_with_name_and_assignment_id(name, aid)&lt;br /&gt;
 SignUpTopic.where(topic_name: name, assignment_id: aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2. replace &amp;quot;find_by_sql&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_topic_id_with_assignment_id(params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in &amp;lt;code&amp;gt;sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_topic_id_with_assignment_id(aid)&lt;br /&gt;
 SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Breaking down long methods ===&lt;br /&gt;
We’ve find that lots of methods do more than one thing so we separate a long function into several concise functions and call them in the original function. Here is an example:&lt;br /&gt;
&lt;br /&gt;
There are some preparation works and check works before or after the actual create operation. So we separate two functions &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;. And we call these two functions in &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method instead of executing these codes directly.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
  if topic != nil&lt;br /&gt;
    topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
    if SignedUpUser.find_by_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
        topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
        topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    if @assignment.is_microtask?&lt;br /&gt;
      @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
    end&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render :action =&amp;gt; 'new', :id =&amp;gt; params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def update_topic_info(topic)&lt;br /&gt;
  topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
  if SignedUpUser.find_with_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
    topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
  else&lt;br /&gt;
    if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
      topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; updates topics' some attributes according to received parameters, such as permitted max number of choosers and waitlisted users. This method is separated from function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; because it doesn't really do any creation works.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def check_after_create&lt;br /&gt;
  if @assignment.is_microtask?&lt;br /&gt;
    @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
  end&lt;br /&gt;
  if @assignment.staggered_deadline?&lt;br /&gt;
    topic_set = Array.new&lt;br /&gt;
    topic = @sign_up_topic.id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; check if the assignment is a microtask and if it applies to staggered deadline. If these two conditions are met, then execute corresponding actions. These steps should be separated from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function because it doesn't actually do works related with creation.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
  if topic&lt;br /&gt;
    update_topic_info(topic)&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    check_after_create&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render action: 'new', id: params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method, the two separated methods were called. By this way, function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; will be much shorter and some works do not belong to it can  be finished by other methods.&lt;br /&gt;
&lt;br /&gt;
=== Deleting redundant button ===&lt;br /&gt;
When we move the mouse on the Assignment, there is a &amp;quot;Edit signup sheet&amp;quot; button in the popup menu. It is a redundant button since there already has such a function in Assignment &amp;quot;Edit&amp;quot; menu. What's more it's more reasonable to put this function in &amp;quot;Edit&amp;quot; Assignment because signup sheet is a part of the assignment. So we removed this button. Sometimes after making some changes, the display topics function didn’t work due to some reasons. We’ve fixed those bugs and make sure it still works after our last change.&amp;lt;br&amp;gt;&lt;br /&gt;
We delete the following lines in &amp;lt;code&amp;gt;app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if signup_topic %&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The origin popup menu is as following picture, there is a &amp;lt;code&amp;gt;edit signup sheet &amp;lt;/code&amp;gt; button:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:originPopup.jpg]]&amp;lt;br&amp;gt;&lt;br /&gt;
The new popup menu is:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:new_popup.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
After modifying, the other assignment functions all works well.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:AssignTopic.png]]&lt;br /&gt;
&lt;br /&gt;
=== Renaming controller ===&lt;br /&gt;
According to the controller name convention&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/action_controller_overview.html&amp;lt;/ref&amp;gt;, a controller should be a singular noun. However, here &amp;lt;code&amp;gt;SignUp&amp;lt;/code&amp;gt; in camel case is a verb. We should modify it to a noun written as &amp;lt;code&amp;gt;Signup&amp;lt;/code&amp;gt;. As a result, we rename all class name &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;. Then the controller name &amp;lt;code&amp;gt;sign_up_sheet_controller&amp;lt;/code&amp;gt; is revised into &amp;lt;code&amp;gt;signup_sheet_controller&amp;lt;/code&amp;gt; automatically.&amp;lt;br&amp;gt;&lt;br /&gt;
Here we also make sure every reference for this controller has been changed to match the new controller name. For example, in &amp;lt;code&amp;gt;views/signup_sheet/_action.html.erb&amp;lt;/code&amp;gt; file, we must make sure this render path is correct as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial =&amp;gt; '/signup_sheet/all_actions', :locals =&amp;gt; {:i=&amp;gt;i, :topic=&amp;gt;topic} %&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Following global rules ===&lt;br /&gt;
According to Global Rules, there are some codes that need some improvements to make it follow the rules correctly. Here are some of what we have done:&lt;br /&gt;
 &lt;br /&gt;
* change &amp;lt;code&amp;gt;users_team.size == 0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;users_team.zero?&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  if users_team.size == 0&lt;br /&gt;
to:&lt;br /&gt;
  if users_team.zero?&lt;br /&gt;
or:&lt;br /&gt;
  if users_team.empty?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;key: 'value'&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;:key =&amp;gt; 'value'&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
to:&lt;br /&gt;
  redirect_to action: 'add_signup_topics_staggered', id: assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;if (var)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;if (var == true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  (assignment.staggered_deadline == true)?&lt;br /&gt;
to:&lt;br /&gt;
  (assignment.staggered_deadline)?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95261</id>
		<title>CSC/ECE 517 Spring 2015/oss E1509 lds</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1509_lds&amp;diff=95261"/>
		<updated>2015-03-21T22:27:17Z</updated>

		<summary type="html">&lt;p&gt;Mdong3: /* Deleting redundant button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1509. Refactoring SignUpController and SignUpSheetController ==&lt;br /&gt;
&lt;br /&gt;
This page talks about an open source project based on Expertiza. As a part of contribution to Expertiza, this project aims to refactor SignUpController and SignUpSheetControllers.&lt;br /&gt;
&lt;br /&gt;
=== Introduction to Expertiza ===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed by Ruby on Rails framework. It serves as a peer review system for professors and students at NC State and some other colleges and universities. Students can submit different assignments and peer-review reusable learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is supported by the National Science Foundation. And it is an open source application and the source code can be cloned on [https://github.com/expertiza/expertiza Github] . &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
===Classes involved===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
* sign_up_sheet.rb &lt;br /&gt;
* sign_up_topic.rb &lt;br /&gt;
* assignments_controller.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
* and possibly other model classes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===What it does===&lt;br /&gt;
&lt;br /&gt;
Lists topics available for an assignment, checks whether a user is signed up for a topic, allows users to sign up for topics.&lt;br /&gt;
&lt;br /&gt;
===What's wrong with it===&lt;br /&gt;
* These two controllers seem to do almost the same thing.  They have many of the same methods.  &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; is much longer, and has many more recent mods, but some methods of &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; seem more sophisticated than &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;.  So, your first job is to figure out if both controllers are being used.  If not, remove the unused controller.  Or, move the functions to a single controller if that makes sense to do.&lt;br /&gt;
* Neither controller is at all RESTful; i.e.., its method names aren’t the standard names &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;edit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;delete&amp;lt;/code&amp;gt;, etc.  Functionality is divided differently than in a standard controller.&amp;lt;br&amp;gt;a. &amp;lt;code&amp;gt;def confirm_topic(creator_id, topic_id, assignment_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; b. &amp;lt;code&amp;gt;def delete_signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; c.&amp;lt;code&amp;gt;def delete_signup_for_topic(assignment_id,topic_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; d. &amp;lt;code&amp;gt;def other_confirmed_topic_for_user(assignment_id, creator_id)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;e. &amp;lt;code&amp;gt;def signup&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; f. &amp;lt;code&amp;gt;def slotAvailable?(topic_id)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Functionality that should be in models is incorporated into the controller.&lt;br /&gt;
* Some methods are too long and appear to do more than one thing&lt;br /&gt;
* This class interfaces with assignments_controller so that a list of topics can be displayed when one is editing an assignment.  Please be careful that your changes do not affect the functionality on the Topics tab of editing an assignment.&lt;br /&gt;
* Rename the controller(s) to &amp;lt;code&amp;gt;SignupController&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;.  (“Sign up”, which gets written as SignUp in camel case, is a verb, whereas “Signup” is a noun.)&lt;br /&gt;
* Some codes does not follow the [https://docs.google.com/a/ncsu.edu/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Rules].&lt;br /&gt;
&lt;br /&gt;
== Modification We Made ==&lt;br /&gt;
=== Removing unused controller ===&lt;br /&gt;
After various analysis and test, we found &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; is never used. So we remove it. The reasons are listed as follows:&lt;br /&gt;
* There is no code about &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt; file.&amp;lt;p&amp;gt;The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/routing.html#the-purpose-of-the-rails-router&amp;lt;/ref&amp;gt;. Rails default routing is resource routing, which allows us to declare all the common routes for a resourceful controller. In our &amp;lt;code&amp;gt;route.rb&amp;lt;/code&amp;gt;, we found a matching resourceful route for &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;, which asks the router to map it to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; action.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  resources :signup_sheet &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This route creates several different routes in the application, all mapping to the &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; controller. &lt;br /&gt;
Here are some examples:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|HTTP Verb&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Controller#Action&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Used For &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#signup&lt;br /&gt;
| This function lets the user choose a particular topic.&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#delete_signup&lt;br /&gt;
| This function is used to delete a previous signup&lt;br /&gt;
|-&lt;br /&gt;
| GET&lt;br /&gt;
| sigh_up_sheet#view_publishing_rights&lt;br /&gt;
| The function is to make sure the publishing rights for a user&lt;br /&gt;
|}&lt;br /&gt;
However, there is not a matching route for &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt;.&lt;br /&gt;
*&amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; has all seven methods in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; with same name. we found these functions are completely achieved via &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt;. And after test, we prove that codes in &amp;lt;code&amp;gt;SignUpController&amp;lt;/code&amp;gt; never got executed when we ran the project.&lt;br /&gt;
&lt;br /&gt;
=== RESTful style implementation ===&lt;br /&gt;
The purpose of the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; method in the &amp;lt;code&amp;gt;SignupSheet controller&amp;lt;/code&amp;gt; is to list all the topics in the specific assignments. According to RESTful rules, a method that returns a list of all available objects should be named as &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the signup_sheet_controller.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we need to change some references to the method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
verify method: 'post', :only =&amp;gt; [:destroy, :create, :update],&lt;br /&gt;
:redirect_to =&amp;gt; {:action =&amp;gt; :index}&lt;br /&gt;
&lt;br /&gt;
SignUpTopic.reassign_topic(@user_id,params[:assignment_id], params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&lt;br /&gt;
signup_team(@assignment.id, @user_id, params[:id])&lt;br /&gt;
redirect_to action: 'index', id: params[:assignment_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some others, it is not good to combine some functions with the standard ones. For example, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function creates topics, which is one of the administrator’s functions. However &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; creates a record that includes information for topic and student, which happens when student clicks &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; button. We can see that &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;signup&amp;lt;/code&amp;gt; are designed for different role and different usage so it is not a good idea to combine them together.&lt;br /&gt;
&lt;br /&gt;
=== Moving inappropriate functionality from controller to model ===&lt;br /&gt;
The controller connects the model with the view. In Rails, controllers are implemented as ActionController classes. The controller knows how to process the data that comes from the model and how to pass it onto the view. The controller should not include any database related actions (such as modifying data before it gets saved inside the database). This should be handled in the proper model. So we remove all the database related functionality in the signup_sheet_controller to related models.&lt;br /&gt;
The following files were modified:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/signup_sheet_controller.rb&lt;br /&gt;
app/models/deadline_type.rb&lt;br /&gt;
app/models/due_date.rb&lt;br /&gt;
app/models/participant.rb&lt;br /&gt;
app/models/sign_up_topic.rb&lt;br /&gt;
app/models/signed_up_user.rb&lt;br /&gt;
app/models/topic_deadline.rb&lt;br /&gt;
app/models/topic_dependency.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are two examples on how these files changed.&amp;lt;br&amp;gt;&lt;br /&gt;
1. replace &amp;quot;where&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in&amp;lt;code&amp;gt; sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_with_name_and_assignment_id(name, aid)&lt;br /&gt;
 SignUpTopic.where(topic_name: name, assignment_id: aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2. replace &amp;quot;find_by_sql&amp;quot; in the controller with a new method in related model.&amp;lt;br&amp;gt;&lt;br /&gt;
Before Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&amp;lt;br&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;signup_sheet_controller.rb&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @duedates = SignUpTopic.find_topic_id_with_assignment_id(params[:id].to_s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also add a related method in &amp;lt;code&amp;gt;sign_up_topic.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_topic_id_with_assignment_id(aid)&lt;br /&gt;
 SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + aid)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Breaking down long methods ===&lt;br /&gt;
We’ve find that lots of methods do more than one thing so we separate a long function into several concise functions and call them in the original function. Here is an example:&lt;br /&gt;
&lt;br /&gt;
There are some preparation works and check works before or after the actual create operation. So we separate two functions &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;. And we call these two functions in &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method instead of executing these codes directly.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.where(topic_name: params[:topic][:topic_name], assignment_id:  params[:id]).first&lt;br /&gt;
  if topic != nil&lt;br /&gt;
    topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
    if SignedUpUser.find_by_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
        topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
        topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    if @assignment.is_microtask?&lt;br /&gt;
      @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
    end&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render :action =&amp;gt; 'new', :id =&amp;gt; params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;Method: &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def update_topic_info(topic)&lt;br /&gt;
  topic.topic_identifier = params[:topic][:topic_identifier]&lt;br /&gt;
  if SignedUpUser.find_with_topic_id(topic.id).nil? || topic.max_choosers == params[:topic][:max_choosers]&lt;br /&gt;
    topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
  else&lt;br /&gt;
    if topic.max_choosers.to_i &amp;lt; params[:topic][:max_choosers].to_i&lt;br /&gt;
      topic.update_waitlisted_users(params[:topic][:max_choosers])&lt;br /&gt;
      topic.max_choosers = params[:topic][:max_choosers]&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = 'Value of maximum choosers can only be increased! No change has been made to max choosers.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;update_topic_info&amp;lt;/code&amp;gt; updates topics' some attributes according to received parameters, such as permitted max number of choosers and waitlisted users. This method is separated from function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; because it doesn't really do any creation works.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def check_after_create&lt;br /&gt;
  if @assignment.is_microtask?&lt;br /&gt;
    @sign_up_topic.micropayment = params[:topic][:micropayment]&lt;br /&gt;
  end&lt;br /&gt;
  if @assignment.staggered_deadline?&lt;br /&gt;
    topic_set = Array.new&lt;br /&gt;
    topic = @sign_up_topic.id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method &amp;lt;code&amp;gt;check_after_create&amp;lt;/code&amp;gt; check if the assignment is a microtask and if it applies to staggered deadline. If these two conditions are met, then execute corresponding actions. These steps should be separated from &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; function because it doesn't actually do works related with creation.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
  topic = SignUpTopic.find_with_name_and_assignment_id(params[:topic][:topic_name], params[:id]).first&lt;br /&gt;
  if topic&lt;br /&gt;
    update_topic_info(topic)&lt;br /&gt;
    topic.category = params[:topic][:category]&lt;br /&gt;
    topic.save&lt;br /&gt;
    redirect_to_sign_up(params[:id])&lt;br /&gt;
  else&lt;br /&gt;
    set_values_for_new_topic&lt;br /&gt;
    check_after_create&lt;br /&gt;
    if @sign_up_topic.save&lt;br /&gt;
      undo_link(&amp;quot;Topic: \&amp;quot;#{@sign_up_topic.topic_name}\&amp;quot; has been created successfully. &amp;quot;)&lt;br /&gt;
      redirect_to edit_assignment_path(@sign_up_topic.assignment_id) + &amp;quot;#tabs-5&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      render action: 'new', id: params[:id]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; method, the two separated methods were called. By this way, function &amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; will be much shorter and some works do not belong to it can  be finished by other methods.&lt;br /&gt;
&lt;br /&gt;
=== Deleting redundant button ===&lt;br /&gt;
When we move the mouse on the Assignment, there is a &amp;quot;Edit signup sheet&amp;quot; button in the popup menu. It is a redundant button since there already has such a function in Assignment &amp;quot;Edit&amp;quot; menu. What's more it's more reasonable to put this function in &amp;quot;Edit&amp;quot; Assignment because signup sheet is a part of the assignment. So we removed this button. Sometimes after making some changes, the display topics function didn’t work due to some reasons. We’ve fixed those bugs and make sure it still works after our last change.&amp;lt;br&amp;gt;&lt;br /&gt;
We delete the following lines in &amp;lt;code&amp;gt;app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if signup_topic %&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the origin popup menu is as following picture, there is a &amp;lt;code&amp;gt;edit signup sheet &amp;lt;/code&amp;gt; button:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:originPopup.jpg]]&amp;lt;br&amp;gt;&lt;br /&gt;
The new popup menu is:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:new_popup.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
After modifying, the other assignment functions all works well.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:AssignTopic.png]]&lt;br /&gt;
&lt;br /&gt;
=== Renaming controller ===&lt;br /&gt;
According to the controller name convention&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/action_controller_overview.html&amp;lt;/ref&amp;gt;, a controller should be a singular noun. However, here &amp;lt;code&amp;gt;SignUp&amp;lt;/code&amp;gt; in camel case is a verb. We should modify it to a noun written as &amp;lt;code&amp;gt;Signup&amp;lt;/code&amp;gt;. As a result, we rename all class name &amp;lt;code&amp;gt;SignUpSheetController&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;SignupSheetController&amp;lt;/code&amp;gt;. Then the controller name &amp;lt;code&amp;gt;sign_up_sheet_controller&amp;lt;/code&amp;gt; is revised into &amp;lt;code&amp;gt;signup_sheet_controller&amp;lt;/code&amp;gt; automatically.&amp;lt;br&amp;gt;&lt;br /&gt;
Here we also make sure every reference for this controller has been changed to match the new controller name. For example, in &amp;lt;code&amp;gt;views/signup_sheet/_action.html.erb&amp;lt;/code&amp;gt; file, we must make sure this render path is correct as follows:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial =&amp;gt; '/signup_sheet/all_actions', :locals =&amp;gt; {:i=&amp;gt;i, :topic=&amp;gt;topic} %&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Following global rules ===&lt;br /&gt;
According to Global Rules, there are some codes that need some improvements to make it follow the rules correctly. Here are some of what we have done:&lt;br /&gt;
 &lt;br /&gt;
* change &amp;lt;code&amp;gt;users_team.size == 0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;users_team.zero?&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  if users_team.size == 0&lt;br /&gt;
to:&lt;br /&gt;
  if users_team.zero?&lt;br /&gt;
or:&lt;br /&gt;
  if users_team.empty?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;key: 'value'&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;:key =&amp;gt; 'value'&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
to:&lt;br /&gt;
  redirect_to action: 'add_signup_topics_staggered', id: assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;code&amp;gt;if (var)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;if (var == true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change:&lt;br /&gt;
  (assignment.staggered_deadline == true)?&lt;br /&gt;
to:&lt;br /&gt;
  (assignment.staggered_deadline)?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mdong3</name></author>
	</entry>
</feed>