How to add slim to rails statistics (stats) for code statistics? - ruby-on-rails

I tried to search and experimented, but couldn't figure out, how to add slim to rails stats views statistics. It is counting only .erb templates, but I want .slim to be added as these are views too.
% bin/rails stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers | 3245 | 1634 | 57 | 218 | 3 | 5 |
| Helpers | 186 | 149 | 0 | 18 | 0 | 6 |
| Jobs | 34 | 20 | 2 | 2 | 1 | 8 |
| Models | 879 | 541 | 25 | 77 | 3 | 5 |
| Mailers | 85 | 53 | 3 | 6 | 2 | 6 |
| Channels | 46 | 28 | 3 | 4 | 1 | 5 |
| Views | 0 | 0 | 0 | 0 | 0 | 0 |
+----------------------+--------+--------+---------+---------+-----+-------+
I could add an extra rules for something like "Slim views", but this would count the .erb templates in views too.

Related

Retrieve last n rows based on one numeric column in google sheet

My data looks like this:
+---------------+-----+-----+------+-----+-----+
| Serial Number | LSL | LCL | DATA | UCL | USL |
+---------------+-----+-----+------+-----+-----+
| 1 | 1 | 3 | 2.3 | 7 | 9 |
| 2 | 1 | 3 | 3.1 | 7 | 9 |
| 3 | 1 | 3 | 2.7 | 7 | 9 |
| 4 | 1 | 3 | 4.9 | 7 | 9 |
| 5 | 1 | 3 | 5 | 7 | 9 |
| 6 | 1 | 3 | 3 | 7 | 9 |
| 7 | 1 | 3 | 10 | 7 | 9 |
| 8 | 1 | 3 | 7.8 | 7 | 9 |
| 9 | 1 | 3 | | 7 | 9 |
| 10 | 1 | 3 | 6.8 | 7 | 9 |
| 11 | 1 | 3 | 10 | 7 | 9 |
| 12 | 1 | 3 | 3.9 | 7 | 9 |
| 13 | 1 | 3 | 11.3 | 7 | 9 |
| 14 | 1 | 3 | | 7 | 9 |
| 15 | 1 | 3 | | 7 | 9 |
| 16 | 1 | 3 | | 7 | 9 |
| 17 | 1 | 3 | | 7 | 9 |
| 18 | 1 | 3 | | 7 | 9 |
| 19 | 1 | 3 | | 7 | 9 |
| 20 | 1 | 3 | | 7 | 9 |
+---------------+-----+-----+------+-----+-----+
I want to query last 7 rows data where the DATA column is not empty. Trying to achieve something like this:
+----+---+---+------+---+---+
| 7 | 1 | 3 | 10 | 7 | 9 |
| 8 | 1 | 3 | 7.8 | 7 | 9 |
| 9 | 1 | 3 | | 7 | 9 |
| 10 | 1 | 3 | 6.8 | 7 | 9 |
| 11 | 1 | 3 | 10 | 7 | 9 |
| 12 | 1 | 3 | 3.9 | 7 | 9 |
| 13 | 1 | 3 | 11.3 | 7 | 9 |
+----+---+---+------+---+---+
But currently, I am only able to get the last 7 rows data which looks like this:
+---------------+-----+-----+------+-----+-----+
| Serial Number | LSL | LCL | DATA | UCL | USL |
+---------------+-----+-----+------+-----+-----+
| 14 | 1 | 3 | | 7 | 9 |
| 15 | 1 | 3 | | 7 | 9 |
| 16 | 1 | 3 | | 7 | 9 |
| 17 | 1 | 3 | | 7 | 9 |
| 18 | 1 | 3 | | 7 | 9 |
| 19 | 1 | 3 | | 7 | 9 |
| 20 | 1 | 3 | | 7 | 9 |
+---------------+-----+-----+------+-----+-----+
The formula I used is:
=SORT(QUERY(Sheet1!A7:F,"order by A desc limit 7"),1,1)
This formula does not incorporate the condition that the last row of DATA column must not be empty. Is there a way to achieve what I am looking for?
Assuming your serial numbers are consecutive and sorted as such.
=QUERY(A:F,"Select * where A >= "&ARRAYFORMULA(INDEX(SORT(A2:F,1,false),MATCH(true,ISNUMBER(INDEX(SORT(A2:F,1,false),,4)),0),1))-6&" limit 7")
Breakdown:
=QUERY(A:F,"Select * where A >= "
//index used to find the first serial number with a number in the data column
&ARRAYFORMULA(INDEX(
//reverse order
SORT(A2:F,1,false),
//find first number in data column of reversed data
MATCH(true,ISNUMBER(
//get fourth column (data column) to check for numbers
INDEX(SORT(A2:F,1,false),,4)
//minus 6 so you can get the 6 rows above and the row found
),0),1))-6
//get the first 7 rows from the serial number that matches.
&" limit 7")
EDIT
After our conversation:
If your first column is a date and your dates are consecutive with no duplicates, you can use this:
=QUERY(A:F,"Select * where A >= date '"&TEXT(INDEX(SORT(A2:F,1,false),MATCH(true,ISNUMBER(INDEX(SORT(A2:F,1,false),,4)),0),1)-6,"yyyy-mm-dd")&"' limit 7")
Breakdown:
=QUERY(A:F,"Select * where A >= date
//date tells query that it's looking for a date value
'"&TEXT(INDEX(SORT(A2:F,1,false),MATCH(true,ISNUMBER(INDEX(SORT(A2:F,1,false),,4)),0),1)-6,
"yyyy-mm-dd")&"' limit 7"))
//text formats the date in the way that query requires: yyyy-mm-dd
Based on description rather than example:
=query(query(A:F,"where D is not NULL order by A desc limit 7"),"order by Col1")
("last 7 rows data where the DATA column is not empty.")

Dynamically lookup and get average using arrayformula

I'm trying to get the average of all rows containing data in my SourceSheet, which need to be matched with the Fish ID A1:F1 in Sheet1 and A2:A5 in SourceSheet. I want to do this by using ARRAYFORMULA() since Sheet1!A2:A5 is dynamic and may contain other values from time to time.
So far, I've only managed the lookup-and-average-part by:
=AVERAGE(ARRAYFORMULA(HLOOKUP($A2,SourceSheet!A:F,ROW(Items!A$2:F),FALSE)))
How do i achieve the result (see below) with out copying this formula down all rows? Thanks in advance!
Source Data (SourceSheet)
+------+--------+-----+--------+---------+---------+
| tuna | mullet | cod | salmon | herring | catfish |
+------+--------+-----+--------+---------+---------+
| 4 | 3 | 5 | 5 | 5 | 3 |
| 5 | 3 | 3 | 1 | 3 | 2 |
| 5 | 4 | 4 | 4 | 4 | 4 |
| 1 | 2 | 1 | 2 | 3 | 1 |
| 3 | 2 | 2 | 2 | 3 | 2 |
| 4 | 2 | 4 | 2 | 3 | 3 |
| 4 | 2 | 2 | 1 | 2 | 1 |
| 4 | 3 | 4 | 3 | 5 | 4 |
| 3 | 4 | 4 | 2 | 5 | 1 |
| 4 | 3 | 4 | 1 | 2 | 2 |
| 2 | 1 | 3 | 1 | 1 | 1 |
| 2 | 4 | 3 | 2 | 2 | 2 |
| 5 | 3 | 5 | 4 | 5 | 2 |
| 4 | 2 | 4 | 2 | 3 | 2 |
| 2 | 4 | 4 | 3 | 4 | 2 |
| 5 | 4 | 5 | 5 | 3 | 2 |
| 3 | 1 | 3 | 3 | 4 | 2 |
+------+--------+-----+--------+---------+---------+
What I'm trying to achieve: (Sheet1)
+---------+---------+
| | Average |
+---------+---------+
| mullet | 2.76 |
| salmon | 2.75 |
| herring | 2.73 |
| catfish | 2.64 |
+---------+---------+
Formula
=ArrayFormula(
MMULT(
hlookup(A2:A5,SourceSheet!A:F,
TRANSPOSE(FILTER(ROW(SourceSheet!A2:A),LEN(SourceSheet!A2:A))),FALSE),
n(ISNUMBER((FILTER(ROW(SourceSheet!A2:A),LEN(SourceSheet!A2:A)))))
)
/
count(SourceSheet!A2:A)
)
Explanation
AVERAGE is an aggregate function. It could take several values separated by commas, one array or several arrays of values as arguments and returns a single value. This kind of functions if are used on an array formulas will return a single value, so when it's require to return an array of values it's required to use other methods.
In this case, MMULT is used to return the sum of values of each row.
See also
Using CHOOSE and CONCATENATE with ARRAYFORMULA in Google Sheets

How to replace multiple values across different datasets in SPSS

I currently have two datasets, RTWANEW2016.sav and MERGED.sav.
RTWANEW2016:
+----+------------+--------+--------+--------+--------+--------+--------+
| id | date | value1 | value2 | value3 | value4 | value5 | value6 |
+----+------------+--------+--------+--------+--------+--------+--------+
| 1 | 01-03-2006 | 3 | 9 | 85 | 766 | 3 | 45 |
| 1 | 03-23-2010 | 56 | 34 | 23 | 33 | 556 | 43 |
| 2 | 12-04-2014 | 56 | 655 | 523 | 566 | 9 | 9 |
| 3 | 07-23-2011 | 34 | 56 | 661 | 23 | 22 | 11 |
| 4 | 03-05-2007 | 45 | 345 | 222 | 556 | 4566 | 4 |
+----+------------+--------+--------+--------+--------+--------+--------+
MERGED:
+----+------------+--------+--------+--------+
| id | date | value4 | value5 | value6 |
+----+------------+--------+--------+--------+
| 1 | 01-03-2006 | 345 | 44 | 5345 |
| 2 | 12-04-2014 | 522 | 55 | 5444 |
| 4 | 03-05-2007 | 234 | 88 | 9001 |
+----+------------+--------+--------+--------+
I want to update RTWANEW2016 with the values from variables "value4", "value5" and "value6" from MERGED.
Notice that some data RTWANEW2016 has duplicate ID's, but different dates, so I would need to sort by both id and date
See the UPDATE command which is designed to achieve this.
Overview (UPDATE command)
UPDATE replaces values in a master file with updated values recorded
in one or more files called transaction files. Cases in the master
file and transaction file are matched according to a key variable.
The master file and the transaction files must be IBM® SPSS®
Statistics data files or datasets available in the current session,
including the active dataset. UPDATE replaces values and creates a new
active dataset, which replaces the original active dataset.
UPDATE is designed to update values of existing variables for existing
cases. Use MATCH FILES to add new variables to a data file and ADD
FILES to add new cases.
UPDATE FILE='/RTWANEW2016.sav'
/FILE='/MERGED.sav'
/BY=ID Date.

How to check RSpec code coverage in Rails application?

I'm working on my very first simple Rails app. And now I just did my homework which I should do before anything else - RSpec tests. I delayed it on purpose because of no experience I even wasn't sure what for and how to do RSpec tests. Finally, I have probably most tests for my models and controllers and it's time for me to think about how much my tests cover the code.
Then I found rake stats, which shows me that:
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 214 | 161 | 4 | 29 | 7 | 3 |
| Helpers | 12 | 12 | 0 | 1 | 0 | 10 |
| Models | 17 | 13 | 2 | 0 | 0 | 0 |
| Mailers | 0 | 0 | 0 | 0 | 0 | 0 |
| Javascripts | 29 | 3 | 0 | 1 | 0 | 1 |
| Libraries | 0 | 0 | 0 | 0 | 0 | 0 |
| Helper specs | 15 | 4 | 0 | 0 | 0 | 0 |
| Controller specs | 170 | 137 | 0 | 0 | 0 | 0 |
| Model specs | 78 | 65 | 0 | 0 | 0 | 0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total | 535 | 395 | 6 | 31 | 5 | 10 |
+----------------------+-------+-------+---------+---------+-----+-------+
Code LOC: 189 Test LOC: 206 Code to Test Ratio: 1:1.1
It shows how many Classes and Methods my controllers and models have. But what I'm missing here is how many are tested. I wish to have it instead of zeros there. At the same time would be nice to know which methods are not covered by tests. Is there a gem that provides that information or some other way to check it?
I'd recommend SimpleCov for this.
Here's a nice starting configuration for it to put in your spec_helper.rb:
SimpleCov.start do
add_filter '/test/'
add_filter '/config/'
add_filter '/vendor/'
add_group 'Controllers', 'app/controllers'
add_group 'Models', 'app/models'
add_group 'Helpers', 'app/helpers'
add_group 'Mailers', 'app/mailers'
end
# OPTIONAL
# This outputs the report to your public folder
# You will want to add this to .gitignore
SimpleCov.coverage_dir 'public/coverage'
This makes it ignore files in your test, config and vendor folders and groups controllers, models, helpers and mailers under their own tabs in the HTML report.

Cucumber table + find("table tr:eq(x)") not working right

I have this cucumber task:
Then I should see following posting modes
| row | day | hour | minute | location | category |
| 1 | 1 | 7 | 0 | 29 | 6 |
| 2 | 2 | 8 | 5 | 27 | 7 |
| 3 | 3 | 9 | 10 | 28 | 18 |
| 4 | 4 | 15 | 15 | 29 | 18 |
| 5 | 5 | 17 | 20 | 27 | 7 |
| 6 | 6 | 20 | 30 | 28 | 6 |
| 6 | 0 | 22 | 50 | 29 | 7 |
And behind it there is this description:
Then /^I should see following posting modes$/ do |table|
table.hashes.each do |posting|
within("#itemPosting .attributeContainer table tbody tr:eq(#{posting[:row]})") do
find("#item_posting_day").value.should == posting[:day]
find("#item_posting_hour").value.should == posting[:hour]
find("#item_posting_minute").value.should == posting[:minute]
find("#item_posting_location").value.should == posting[:location]
find("#item_posting_category").value.should == posting[:category]
end
end
end
So this part:
tr:eq(#{posting[:row]})
doesn't work(it goes to next step, and then gives an error that #item_posting_day is not found.)
But if I do this instead:
tr:eq(4)
It works (finds the #item_posting_day field, gets its value, and then gives an error saying that value is not what is expected to be, but that's ok).
So I don't understand what's the problem with using this syntax:
tr:eq(#{posting[:row]})
It seems that hashes converts column headers to strings, not symbols. Try to use 'row' instead of :row

Resources