Hello All,
Is it practical to import data from a csv file, via FasteCSV to a
temporary data structure, like a hash, for editing purposes?
I'm looking to read a file, send the data to a temp location, then
compare the file with similar files in a database table, if any. Then
import the edited data to the database table.
Is it practical to import data from a csv file, via FasteCSV to a
temporary data structure, like a hash, for editing purposes?
I don't see why it wouldn't be. FasterCSV::Row has a to_hash() method. I use this regularly to pump CSV rows into ActiveRecord's create!() method to add records to my database.
it pretty much comapres everything tabular, so you can easily compare
CSV files. Its still on beta so its free, and our tech support will be
happy to walk you through the steps required to get it done, should
you run into difficulties
Mr. Gray,
Thank you for the quick reply.
I'm a PHP guy with 3 weeks in Ruby on Rails (Department changed platform
3 months after they hired me)
Could you please point me to a good 'FasterCSV' resource with some
examples?
Thank you very much.
JohnM
James Gray wrote:
···
On Aug 17, 2009, at 10:54 AM, John Mcleod wrote:
Hello All,
Hello.
Is it practical to import data from a csv file, via FasteCSV to a
temporary data structure, like a hash, for editing purposes?
I don't see why it wouldn't be. FasterCSV::Row has a to_hash()
method. I use this regularly to pump CSV rows into ActiveRecord's
create!() method to add records to my database.
I've tested it and it seems to work.
I will however, check out the documentation and your test code.
This is step 1 though. Next, populate a hash with data from the
database comparing data from the CSV file and making a editable CSV grid
(post to rails forum).
I'm not done yet.
Thanks again.
JohnM
James Gray wrote:
···
On Aug 17, 2009, at 11:56 AM, John Mcleod wrote:
Mr. Gray,
You can stick with James. I'm not that old yet.
Thank you for the quick reply.
Sure. Happy to help.
Could you please point me to a good 'FasterCSV' resource with some
examples?
if I understand you correctly you have data in CSV files and you have
a relational database. You want to compare the content of those files
with data already present in the database and edit the CSV data before
importing it into the DB.
I do not know what your schema looks like nor what "comparing" in your
case means, but did you consider first loading CSV data into the
database using some staging table, doing the comparison and editing
there and then copying the data over to the target location? That way
you can use the full power of SQL for comparison purposes. And there
are a lot of tools that allow to edit database data in tabular
representation.
Robert,
Yes, you understand my dilemma.
I want to thank you for your keen insight. I didn't even thought of
that.
When I say "compare", I mean a similarity comparison not an exact
comparison.
I installed 'amatch' gem. It has several comparison features that I
believe will benefit me. In particular, the Levenshtein distance.
Thank you again for the advice.
JohnM
Robert Klemme wrote:
···
John,
if I understand you correctly you have data in CSV files and you have
a relational database. You want to compare the content of those files
with data already present in the database and edit the CSV data before
importing it into the DB.
I do not know what your schema looks like nor what "comparing" in your
case means, but did you consider first loading CSV data into the
database using some staging table, doing the comparison and editing
there and then copying the data over to the target location? That way
you can use the full power of SQL for comparison purposes. And there
are a lot of tools that allow to edit database data in tabular
representation.
Yes, you understand my dilemma.
I want to thank you for your keen insight. I didn't even thought of
that.
It may not be a viable solution in your case but it could be
worthwhile to ponder.
When I say "compare", I mean a similarity comparison not an exact
comparison.
I installed 'amatch' gem. It has several comparison features that I
believe will benefit me. In particular, the Levenshtein distance.
Two things come to mind: depending on the RDBMS you are using it may
have similar tools (functions) for text processing and analysis.
Depending on your requirements you can even write a database function
that calculates Levenshtein Distance.
Second, you could extract the data from the database via any of Ruby's
database interfaces, do the comparison in Ruby code and write out
results. Then, edit them and import the result back into the DB.
Two things come to mind: depending on the RDBMS you are using it may
have similar tools (functions) for text processing and analysis.
Currently, my development database is SQLite, but my supervisor's plan
is to have Oracle as a production database.
Once again, I'll be in learning mode. (knowledge of Oracle = 0) I'm
experienced in mySQL mostly.
Second, you could extract the data from the database via any of Ruby's
database interfaces, ...
Are the "interfaces" easy to work with?
Then, edit them and import the result back into the DB.
I've been looking at jquery jgrid for rails. It looks easy to implement
(that's a topic for another forum)
Thanks again.
John
Robert Klemme wrote:
···
2009/8/18 John Mcleod <john.mcleod@hc.msu.edu>:
Yes, you understand my dilemma.
I want to thank you for your keen insight. I didn't even thought of
that.
It may not be a viable solution in your case but it could be
worthwhile to ponder.
When I say "compare", I mean a similarity comparison not an exact
comparison.
I installed 'amatch' gem. It has several comparison features that I
believe will benefit me. In particular, the Levenshtein distance.
Two things come to mind: depending on the RDBMS you are using it may
have similar tools (functions) for text processing and analysis.
Depending on your requirements you can even write a database function
that calculates Levenshtein Distance.
Second, you could extract the data from the database via any of Ruby's
database interfaces, do the comparison in Ruby code and write out
results. Then, edit them and import the result back into the DB.