Creating a data visualization site with Rails - ruby-on-rails

I have a very large excel spreadsheet that consists of a user name, a location, a date, and some fields of numbers, for example.
User,location,date,value1,value2,value3
Steve,NYC,2012,9,1,3
Steve,NYC,2011,3,3,2
Steve,CA,2011,1,2,0
Michael,CA,2012,10,3,2
Michael,CA,2011,10,2,0
How would I go about organizing a rails site such that one can view all the values for a certain user?
For example,
/users/steve/all
would display all the values in descending order of date where user=steve.
/users/steve/nyc
would display all the values in descending order of date where user=steve and location=nyc.
I think I would need to create a users model and import all the data from the excel into the database, but I'm lost about how to do that.
The application, in essence, would be a simple data visualizer. Maybe I have to separate the database and create a user has_many :locations and locations :belongs_to user, I'm not sure. I want the data to be viewed in all sorts of ways—maybe I want to display all the users from a certain location, or view all the locations of a certain user, etc...

I suggest setting up your model within your rails application first. Then, you can just write a rake task probably similar to this question or you can build it from scratch. There's also a railscast.

If you need to directly import from Excel (e.g. the excel sheets are uploade by a user). You can use one of the following gems to importing data from an Excel Sheet
roo Reads new and old excel format (+others)
spreadsheet Reads and writes old exel format
If you only have this one excel sheet it will be far easier to simply export the data to csv and follow the answers given in the stackoverflow question mentioned above.
As for the second part of your question on how to model your database you already had the right idea.
Easiest is to fully model what your domain looks like and transform the data accordingly.

Related

Create a report from google sheets

I have a Google Sheets file I use to enter data on different properties.
Each row in this file represents a single property.
If a certain property is of interest, I would like generate a report for it.
I need a functionality that will extract all data fields from a single row, and insert them in a new file (google sheets or preferably a Google Docs file) with a pre built format that would present the data nicely like a report.
Thanking you in advance
Avi
Here is a very preliminary answer, to see if this is the right direction.
See my sample sheet.
This lets you select, in C3, which address you want a report on. The fields shown in green change as you select a different address. All of the report fields could be modified like this - you just need to point to which column in the Properties database contains the values.
Is this roughly what you were looking to achieve?

Reorganizing Google Sheets data dynamically

I'm currently working with Google Sheets to import data from Contact Form 7 in Wordpress. All the data is coming over fine, but I wanted to see about formatting it in more user friendly fashion. I've simplified the example a bit, but the gist of the form I have created allows the user to request multiple versions of a graphic file with different wording as needed, up to 5(my example has just 2 for simplicity sake).
All the data is imported using the CF7 variables and ideally I wanted to clean this up a bit. What I had thought of as a solution was creating a second sheet that pulls in this data submitted in the first sheet into a more user friendly format, as I intended to use this as a work form for a designer to create the requested graphic once the data is received. With each request the name/department/email/date all stay the same, but I'd like to display the version and line 1 and 2 data on another line. Is it possible to reorganize data like this on the fly, so when a new form is submitted and adds data to sheet 1, sheet 2 would then update with the properly formatted info?
Is this even possible to do? I did some looking online, but didn't anything that really related to this type of data manipulation.
Solution:
Here's what ended up working for my example
=ArrayFormula(QUERY({
Sheet1!A2:D,Sheet1!E2:G,ROW(Sheet1!A2:A);
IFERROR(LEN(Sheet1!A2:D)/0),Sheet1!H2:J,ROW(Sheet1!A2:A);
IFERROR(LEN(Sheet1!A2:D)/0),Sheet1!K2:M,ROW(Sheet1!A2:A);
IFERROR(LEN(Sheet1!A2:D)/0),Sheet1!N2:P,ROW(Sheet1!A2:A);
IFERROR(LEN(Sheet1!A2:D)/0),Sheet1!Q2:S,ROW(Sheet1!A2:A)
},"select Col1,Col2,Col3,Col4,Col5,Col6,Col7 where Col5<>'' order by Col8",1))
Yes, it's possible.
One way is to use arrays and the QUERY function.
For simplicity, let say that
Columns A and B have the general information of the order
Columns C and D have the data for version 1
Columns E and F have the data for version 2
Columns G and H have the data for version 3
On the output sheet, add the headers.
Below of them add a formula like the following:
=ArrayFormula(QUERY({A2:B,C2:D,ROW(A2:A);IFERROR(LEN(A2:B)/0),E2:F,ROW(A2:A);IFERROR(LEN(A2:B)/0),G2:H,ROW(A2:A)},"select Col1,Col2,Col3,Col4 where Col3<>'' order by Col5"))
References start on row 2 to skip the headers to avoid to include them on the output sheet.
ROW(A2:A) is used to keep the order
IFERROR(LEN(A2:B)/0) is a "trick" used to "hide" the order (general information) data for the second and following rows for the same order. On the select parameter of the QUERY function, it's referrey as Col5 on the order by clause.
It's assumed that lookup-choice-1 will never be empty.
NOTES:
If more columns were added, the column numbers should be updated accordingly
Don't use the order by clause to sort the result by the general information columns because the "trick" to hide the "labels". If you need to apply a sort, do it' before applying the above formula, you could do this by sorting the source range through the Data > Sort range... feature, so the data is sorted before it's transformed by the above formula.
See also
Sort and filter your data, an official help article describing Data > Sort range...

Is it safe to "search" creating db records in Rails?

I need to build a search form including some fields like "city, price range, key word and date". I saw this video which is recommending to create a "searches" table. Every time any user made a search, it creates a table row in the db, and show the results depending on the submitted fields.
Seems easy to build but is it safe? I mean, if this is used in the practical world, I think we also have to use "I'm not robot" from Google.
https://www.youtube.com/watch?v=QRE7KxIvUb4&t=29s
Any idea is welcome.

User selected rows when importing CSV to Rails

Is there an accepted best practice to allow users to select the rows associated with columns when importing a CSV file in Ruby on Rails?
Such that they upload the file -> are given a confirmation screen with the list of column headers, and select inputs for each one (populated with the writeable attributes of the model) -> save each CSV row to the model, with the columns selected in the previous step.
Basically, I want the functionality shown here:
http://youtu.be/5Ddnu_NK_-o?t=50s
The way I would go about this, were there not a better way, would be something like this:
User uploads file
Parse CSV
Display first several rows
Display a form with select inputs for each column, populated by the writeable attributes, and cached file
For each of the POST column name parameters, match them to the column (while verifying that no column name is used twice)
Create a new record for each row
I confess that steps 4 and 5 are pretty daunting to me as a newbie to RoR, and it seems like this must be encountered a fair amount, but I haven't found any luck finding gems or tutorials on the subject.

Append Query That Also Selects A Lookup Table Value Based On Text Parsing?

I've posted a demo Access db at http://www.derekbeck.com/Database0.accdb . I'm using Access 2007.
I am importing an excel spreadsheet, which my organization gets weekly, importing it into Access. It gets imported the table [imported Task list]. From there, an append query reformats it and appends it to my [Master Task List] table.
Previously, we have had a form, where we would manually go through the newest imports, and manually select whether our department was the primary POC for a tasking. I want to automate this.
What syntax do I require, such that the append query will parse the text from [imported Task list].[Department], searching for those divisions listed on [OurDepartments] table (those parts of our company for which we are tracking these tasks), and then select the appropriate Lookup field (connected to [OurDepartments] table) in our [Master Task List] table?
I know that's a mouth full... Put another way, I want the append query update the [Master Task List].[OurDepartments], which is a lookup, based on parsing the text of [imported Task list].[Department].
Note the tricky element: we have to parse the text for "BA" as well as "BAD", "BAC", etc. The shorter "BA" might be an interesting issue for this query.
Hoping for a Non-VBA solution.
Thanks for taking a look!
Derek
PS: Would be very helpful if anyone might be able to respond within the work week. Thx!
The answer is here: http://www.utteraccess.com/forum/Append-Query-Selects-L-t1984607.html

Resources