Re: Automatic data generation
Re: Automatic data generation
- Subject: Re: Automatic data generation
- From: Ray Kiddy <email@hidden>
- Date: Thu, 21 Aug 2008 10:35:01 -0700
On Aug 21, 2008, at 8:37 AM, Florijan Stamenkovic wrote:
Hi Kieran,
I was thinking of something a bit more elaborate, and covering
wider ground. Attribute generation would be an aspect of it.
What I'd like to have:
1. Isolating logic from EO classes, the framework would encapsulate
all the functionality
2. Desired value hints (ranges, scales and precision for numeric
info, length for data and strings, ranges for dates)
3. The possibility to override any autogenerated value with a
preset one, maybe the possibility to define property interdependencies
4. Maybe image data autogeneration
5. Relationship handling, maybe with autodetection of
interdependencies between entities to creates EOs and auto-relate,
if not autodetected then still handled but manually
6. Hints for the desired number of EOs to be created
...
In short, I'd like to be able to set a few hints, then call one
line of code, have the framework generate who knows how many EOs,
save them, and voila. No extra dependencies on the project itself.
I still think it could be done, but it will require a bit more
effort ;)
Well, if I make it, I'll give it away, since apparently there is a
need for something like this. It will depend on my boss basically,
but we might require something like this fairly soon, so the odds
are good.
F
Also, it would be wonder independent.
And, it might be fun! :))))))))
I think it definitely would be fun. I have done parts of this. I was
once working on some app that did web template editing. It was at
some company that I have forgotten the name of. We wanted to put in a
smarter preview mode that would, for example, use sample data.
Needless to say, this did not see the light of day anywhere.
It would probably be best to parameterize the process in a couple of
ways. First, a plist-ish structure could supply actual data values
and these could either be used as-is, mixed and matched or combined
in different ways. For example, a sample data bit could look like:
{ firstName = ("Bob", "Tom"); lastName = ("Smith", "Johnson"); city =
"Chicago" }
and this could be used to generate eos that are all the combinations
of these alternative values. For example, this would generate 4 eos
with the names "Bob Smith", "Bob Johnson", "Tom Smith", "Bob Johnson".
Second, you are probably going to want a rule list for constraints on
the generated data. Numbers need to be less than some value, greater
than some value, strings need to be less than some length and so on.
If you did it this way, these structures could be kept in the
internal information of an EOModel and Wonder could be changed to use
them in a better preview mode.
If you want help covering different databases or such, let me know.
This kind of "EOF origami" can be loads of fun.
cheers - ray
On Aug 21, 2008, at 11:15, Kieran Kelleher wrote:
Well, you can roll your own pretty easily.
Just make a ValueGenerator class that makes values, taking
advantage of the ERXLoremIpsumGenerator, have a
myapp.setDevelopmentDefaults=true/false entry in Properties. Then
in your base EOF class, have awakeFromInsertion call a custom
setDevelopmentDefaults method that *only generates* fill-in values
(unique, random or otherwise) where the values are null so you
don't override real awakeFromInsertion defaults.
In setDevelopment defaults, you can then finally call a catch-all
method to do the trivial attribute fillins and do sth like this:
<snip>
public class MyGenericRecord extends ERXGenericRecord {
private static final Logger log = Logger.getLogger
(MyGenericRecord.class);
@Override
public void awakeFromInsertion(EOEditingContext editingContext) {
super.awakeFromInsertion(editingContext);
setDefaultValues();
if (shouldSetDevelopmentDefaults()) {
setDevelopmentDefaults();
} //~ if (shouldSetDevelopmentDefaults())
}
/**
* Can be overridden to set default values. Will get called by
awakeFromInsertion.
* The Velocity EOGen template (_Enity.java) overrides this
method and sets
* default values stored in the attribute userInfo in the model
under the key
* 'defaultValue'.
*/
public void setDefaultValues() {
//intentionally blank
}
/**
* Don't cache this since we may want to change the system
property while doing development.
* It is already cached in system properties.
* @return true if setDevelopmentDefaults should be called when
new entities are created.
*/
public boolean shouldSetDevelopmentDefaults(){
return ERXProperties.booleanForKeyWithDefault
("myGreatApp.setDevelopmentDefaults", false);
}
/**
* Hook method that can be optionally overridden for classes.
* Default is to put lorem ipsum filler garbage. However, you can
override this method and fully
* control the defaults or call super and then customize the
defaults on the attributes you want.
*/
public void setDevelopmentDefaults(){
String TYPE_STRING = "java.lang.String";
String TYPE_DATETIME = "com.webobjects.foundation.NSTimestamp";
String TYPE_DATA = "com.webobjects.foundation.NSData";
String TYPE_NUMBER = "java.lang.Number";
// Grab the entity for this EO
EOEntity entity = ERXEOAccessUtilities.entityForEo(this);
// Get the visible attributes
NSArray attributes = ModelUtilities.publicAttributesForEntity
(entity);
for (java.util.Enumeration attributesEnumerator =
attributes.objectEnumerator(); attributesEnumerator
.hasMoreElements();) {
EOAttribute attribute = (EOAttribute)
attributesEnumerator.nextElement();
// The key
String key = attribute.name();
// Current value
Object currentValue = valueForKey(attribute.name());
if (log.isDebugEnabled())
log.debug(attribute.name() + " has initial value of " +
(currentValue == null ? "null" : currentValue.toString()));
// We only want to update attributes in certain situations
String className = attribute.className();
String valueType = attribute.valueType();
// Check if we should set a default value
// We don't want to stomp over any values set already
if (currentValue == null
&& !attribute.isDerived()
&& !attribute.isReadOnly() ) {
if (log.isDebugEnabled())
log.debug("Processing attribute: " + attribute);
if (TYPE_STRING.equals(className)) {
// String type
String value = ERXLoremIpsumGenerator.words(1, attribute.width
(), attribute.width());
takeValueForKey(value, key);
} else if (TYPE_DATETIME.equals(className)) {
// NSTimestamp - set the current time
takeValueForKey(new NSTimestamp(), key);
} else if (TYPE_DATA.equals(className)){
// NSData type
String value = ERXLoremIpsumGenerator.words(10, 100,
attribute.width());
takeValueForKey(new NSData(value.getBytes()), key);
} else if (TYPE_NUMBER.equals(className)){
// Number type
// Which type of number?
if ("i".equals(valueType)) {
// Integer
takeValueForKey(ValueGenerator.sharedInstance().integerValue
(), key);
} else if ("d".equals(valueType)){
takeValueForKey(ValueGenerator.sharedInstance().doubleValue
(), key);
} else if ("B".equals(valueType)){
takeStoredValueForKey(ValueGenerator.sharedInstance
().bigDecimalValue(), key);
} else if ("c".equals(valueType)) {
takeValueForKey(Boolean.FALSE, key);
} //~ if ("i".equals(valueType))
} //~ if ....
} //~ if (currentValue == null)
} //~ for (java.util.Enumeration attributesEnumerator = ...
}
}
</snip>
On Aug 21, 2008, at 10:56 AM, Florijan Stamenkovic wrote:
Not sure if this has been discussed already, but I could not find
anything in the list archives, nor by quickly googling.
So, I'm thinking of making a framework for automated data
generation, based on a model and some runtime settings. This
would, obviously, be used for testing. Specifically: filling up a
database with arbitrary numbers of nonsense rows, that are
however legal, and proceeding from there.
Has anyone made this already? Skimmed through the wonder API, but
did not see anything that struck a chord...
If nobody ever made it, then why not? It seems a very nice thing
to have, and off the top of my head I can not think of any
insurmountable obstacle to making it...
F
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40ganymede.org
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden