Storing CSV files to a database? - ruby-on-rails

I'm trying to create an app that will store multiple csv files to a database. I have a working app going, and it will store csv files of a particular format. It looks through the header of the csv and stores each row of the csv with the column of the csv corresponding to the property of that row. For example, maybe the columns are date, school, major
if the following row is like this: 05/16/16 | Arizona State | English
then we'll store an object with the date, school, and major corresponding to above.
However, I need to deal with csv files that have different names. Some csv files might have the major column be named "Undergraduate major" and others might have it named "Field of study." Nevertheless, I want to be able to store all the csv files into my database even though the csv might have different names for the columns. What's the best way to approach this?

Related

Repeating value in a tableau worksheet

Hi I have a tableau issue whereby I have a file (File emp with people's name) left joined to 2 reports via the different ID.
File emp
Afterwards I have a 2 sheets in a relationship with file emp as shown below.
Connections
The absent file can only be sync to file emp. Whereas file attendance can only be sync to file details. Hence all file are required.
So in the absent file there is a number of reason for absenteeism which I have group into 2 separate groups.
Absent file
I have several worksheets that works well however one of the worksheet is causing an issue when I input the following columns. Filters are fine as works well with other worksheet.
Columns, Row
Repeated Values
Tried changing the relationship, joins.

Magmi few rows with same SKU error

I´m using magmi to import products with different names (depending on the language selected in store)
Watching the CSV file exported by magento, I had founded that in the first row all product data is stored and in the following one, there is only the fields you wish to add to the "store view" to the desired language (French, in this case ---> fr).
If I empty the database and imported from the CSV magento own, I successfully created the products and the different names and descriptions for each store view.
The problem is that Magmi tells me I need the SKU on the 3rd line, because logically not find the SKU. Using the same SKU in the second and third line, the last line always prevails introduced, crushing the previous.
Any idea how I could intruducir with Magmi, the names and descriptions in other languages without smash the previus data? .... I begin to be a bit desperate!
CSV example rows:
sku;_store;_attribute_set;_type;_category......... name .......short_description ..etc
09110-296555;fr;Default;simple;books;products...name_english ..description_english
;fr;;;;;;;;;;;;;;;;;;;;;;;;;;;;;name_french......... description_french

How to create a column using initials of other column

I am making an app in IOS which makes use of database stored in .sqlite file. So i'm using core data to access my database.
Here i have a column in the table having names of persons,
What i want is to create a new column using this column's values like a hint(say only initials)
e.g. JOHNNY DEPP -> J##### D###
after googling for hours, i'm still in search of solution to this
Please suggest how to do it ..
either way(core data or .sqlite commands)
any help is appreciated, thanks in advance

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.

Creating a data visualization site with 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.

Resources