Note that there are some explanatory texts on larger screens.

plurals
  1. POAverage all values for a each field date
    primarykey
    data
    text
    <p>I'm trying to build a web app that analyzes survey results about movies, that are uploaded to the system manually by an administrator. The results are uploaded based on the date the survey was fielded. There are a number of different categories surveyed and each respondent inputs a number response (from 1-7) for each category, for each movie. I have set up the system so that on the movies index page, you can select a movie and it will bring you to that specific movie's show page on the site. What I'd like to be able to do is have the system display only the averages of the survey results (by category) based on each field date, in a table. </p> <p>Example raw results input by admin:</p> <pre><code>Field Date: 03/23/2013, Interesting:5, Trendy: 6, Funny: 3 Field Date: 03/23/2013, Interesting:6, Trendy: 6, Funny: 7 Field Date: 03/29/2013, Interesting:2, Trendy: 4, Funny: 3 </code></pre> <p>Example of what I want to output in table: </p> <pre><code>Field Date: 03/23/2013, Interesting:5.5, Trendy: 6, Funny: 5 Field Date: 03/29/2013, Interesting:2, Trendy: 4, Funny: 3 </code></pre> <p>Here is my schema: </p> <pre><code>create_table "movies", :force =&gt; true do |t| t.string "name" t.string "category" t.date "field" end create_table "results", :force =&gt; true do |t| t.string "name" t.date "field" t.integer "movie_id" t.integer "interesting" t.integer "trendy" t.integer "funny" end </code></pre> <p>Here is the table in my movies show page: </p> <pre><code>&lt;% @results.order('field DESC').each do |resultz| %&gt; &lt;tr class="tableline" &gt; &lt;td class="tableline"&gt;&lt;%= resultz.field %&gt;&lt;/td&gt; &lt;td class="tableline"&gt;&lt;%= resultz.interesting %&gt;&lt;/td&gt; &lt;td class="tableline"&gt;&lt;%= resultz.trendy %&gt;&lt;/td&gt; &lt;td class="tableline"&gt;&lt;%= resultz.funny %&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>Currently that shows all raw values uploaded by the admin. I think I need to use the average method along with the :group option, but for some reason when I try that out it keeps giving me errors. I don't think DATE_TRUNC works because I'm using sqlite3, though I'm not sure if that's the right reasoning. </p> <p>Any help would be greatly appreciated (even linking to the appropriate documentation)! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload