Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add a "computed" field to distinguish between genders? #428

Closed
shalabiahmed opened this issue Jul 4, 2017 · 5 comments
Closed

how to add a "computed" field to distinguish between genders? #428

shalabiahmed opened this issue Jul 4, 2017 · 5 comments

Comments

@shalabiahmed
Copy link

Generate data allows the generation of male or female names. How to add a "computed" field to distinguish between genders after generation? i.e if we selected a male name, a field should state "Male" for example.

@glad2badad
Copy link

I did this using API call (json file) ...

{
"type":"Names",
"title":"Hidden MaleName",
"nRw":"ROW15",
"settings":{
"placeholder":MaleName Surname"
}
},
{
"type":"Names",
"title":"Hidden FemaleName",
"nRw":"ROW16",
"settings":{
"placeholder":FemaleName Surname"
}
},

{
"type":"List",
"title":"Hidden Gender",
"nRw":"ROW51",
"settings":{
"listType":"exactly",
"exactly":1,
"list":"male|female"
}
},
{
"type":"Composite",
"title":"GivenName",
"nRw":"ROW52",
"settings":{
"placeholder":"{if $ROW51 == male}{$ROW15}{else}{$ROW16}{/if}"
}
}

The "Hidden" value in the 'title' attribute triggers a change I made to DataGenerator.class.php file (under resources/classes directory) which allows me to do computations in the json file and pass those values to fields later on in the data generation. If you were to use the values, as written above, you will see 4 output fields where I'm only seeing the last one.

The "nRw" line is simply an extra line of json (data generator ignores this) that I use to help with keeping track of "ROW" #'s in the json file.

Hope this helps. Good luck.

@conradhagemans
Copy link
Contributor

I found a workaround with the existing functionality.
Field1 --> MaleName
Field2 --> FemaleName
Field3 --> Constant Loop 2 --> Male|Female
Field4 --> Composite --> {if $ROW3=="Male"}{$ROW2}{else}{$ROW1}{/if}

Now Field3 is the gender and Field4 has a correspondig firstname

@glad2badad
Copy link

glad2badad commented Jul 5, 2017

Conrad - Looks like we've pretty much hit the same workaround with the exception that I'm using a listType where you're using a Constant Loop. End result is the same. :-)

I only added the Hidden piece because I didn't want the final output to display (in your case Field1, Field2, and Field3) - only the last calculated field (Field4) is what I wanted to be visible.

@shalabiahmed
Copy link
Author

Thank you for your reply.

@benkeen
Copy link
Owner

benkeen commented Jul 29, 2017

Interesting scenario! And thanks for responding, @glad2badad and @conradhagemans.

I've been thinking about this - and some other limitations with the tool - and what I think I'll do is create a new Data Type purely for outlier cases like this. The purpose of this Data Type would be to to access any metadata from any data generated in the row. You can then use that programmatically to do whatever you need.

To explain: when a Data Type generates something to output, like a name, it generally just returns a value for outputting to the results. But it can also provide optional "metadata" for use by other data types (I confess, Name doesn't right now - but I'll add it!). For example, Region reads the current Country to output something appropriate, and City reads the current Region. That allows for some syncing up of the data so you see a country-region-city that are connected to one another. I added this feature for precisely this reason, so Data Types could be smarter and generate data that makes more sense as a whole.

This new Data Type ("Computed" seems as good a name as any!) would be like Composite in that you could use Smarty to access a field in the row $ROW1, but access everything it returns $ROW1.display, $ROW1.placeholder. Placeholder would contain the placeholder string you entered (e.g. for the Name field it would be something like "Name", "FemaleName", "MaleName", "Name Initial. Surname" - whatever you entered in the "placeholder" field). You could then add your own logic to output whatever you wanted. It would also give you access to the row number, which may come in handy too.

Yeah, cool! I like it.

Let me tinker with it a bit. I'll try to get it out today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants