mendicant-original / puzzlenode

Quiz application inspired by Project Euler and the Internet Problem Solving Contest (IPSC)
puzzlenode.com
81 stars 43 forks source link

Populate rake db:seed with realistic sample data #45

Closed jordanbyron closed 12 years ago

jordanbyron commented 13 years ago

I can provide raw puzzle data which can be used to create puzzles. The faker gem can be used to create users and comments

gjp commented 13 years ago

Working on this one as well because sample data is required for work on other issues. I've got user and puzzle description generators so far. I figure I'll need to add submissions, attachments, announcements and wrap it up somehow. Does it make sense to create several rake tasks and call them with blah.invoke? Examples welcome!

A couple of assumptions:

  1. Magic numbers are okay, we just want enough data to fill screens and force pagination, i.e. 100 users, 20 puzzles
  2. The task, or perhaps the subtasks, should not be idempotent. Not sure of this one. I know I don't want to truncate Users after I've set myself up as admin (can this be automated?), but I would like to be able to add more test data at will.
jordanbyron commented 13 years ago

Magic numbers are okay, we just want enough data to fill screens and force pagination, i.e. 100 users, 20 puzzles

I don't really care about forcing pagination. I am confident will_paginate works :) I'd rather we focus on realistic data. I can get you the raw puzzle information and we can use them as seed data. Maybe load them from a csv? And we can use Faker to generate realistic looking users. Create some random submissions for each user so the leaderboard is filled, etc.

The task, or perhaps the subtasks, should not be idempotent. Not sure of this one.

I don't have a perfect answer for this one. I've done it both ways, and I think for Puzzlenode it makes sense to just append these records, rather than clearing the database beforehand. For most developers this will be run once (when they first setup the project) and they will never have to run it again.

I know I don't want to truncate Users after I've set myself up as admin (can this be automated?), but I would like to be able to add more test data at will.

You can still add test data by manually creating records either via the console or through the app. And we might be able to automate creating an admin account with a rake setup task, but that is a different ticket - https://github.com/rmu/puzzlenode/issues/44

gjp commented 13 years ago

I don't really care about forcing pagination. I am confident will_paginate works :)

will_paginate is probably the most reliable gem I've ever used with Rails. :) Let me clarify. I prefer to use enough data to fill up at least one page and part of the next to see what a page looks like with a realistic amount of data. That's what I meant by "forcing pagination". You as the designer know what the pages should look like and how the interfaces (especially admin) will work when you've got more than a handful of users / puzzles / etc. Anyone cloning the site will not, not unless there's enough seed data to represent a working site.

Having a few screens full of fake users will also be useful when working on other open tickets, such as sorting and filtering on the user admin screen and adding windowing to the leaderboard.

I can get you the raw puzzle information and we can use them as seed data.

Do you mean the puzzle description text, attachments, or both? I've been using Faker::Lorem to generate headers, paragraphs, lists, and "code blocks": http://imgur.com/MI3zR (not inlining because it's large)

The same could be done for attachments. Please let me know if you'd like to ship actual puzzle data instead. A CSV loader should work.

I might have time to set up the rest of the generators tonight or tomorrow.

jordanbyron commented 13 years ago

http://imgur.com/MI3zR

This actually looks much better than I had imagined. You did a great job getting lorem ipsum to look just like a real puzzle definition :thumbsup:

You're on the right path here. Go with this and if we decide to later we can always implement the puzzle loader feature. Thanks!

gjp commented 13 years ago

This isn't ready for a pull yet. There are plenty of examples out there on how to seed with single hardcoded strings or Faker inside a simple loop, but I'm having trouble finding good examples of how to structure a non-trivial data generator.

Here's the monolithic version: https://gist.github.com/76917306f2be0b5bdc36

This is a learning exercise for me; I'm making it up as I go along. I'd like to ask for a sanity check, and also for your advice on how to break this up, both in terms of files and namespaces. Pointers to examples would also be very welcome.

Thanks!

jordanbyron commented 13 years ago

This isn't ready for a pull yet.

As long as it is to a point where you are looking for feedback you should send over a pull request. We use tickets to discuss problems and initial approach and pull requests to talk about code.

gjp commented 12 years ago

Hi Jordan,

can we close this one?