-
Notifications
You must be signed in to change notification settings - Fork 506
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
2028 - Sort heading for CSV Export #2053
Conversation
… in the post itself. - Missing support for multi value fields - needs cleanup & testing - - Works fine so far with single value fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… correctly for regular non-custom fields
… , making it easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll caveat this with the fact I'm pretty tired. But this looks pretty solid so far. Theres some messy data wrangling, but I think thats mostly due to our messy/mismatched data structure, not your code.
…ority. Modified Base.yml to make alphabetical sort more obvious
…r as in the Formatter
Some data that helped me testing this to verify the heading: Attributes, data for sorting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Great use of comments
- Very good function prototypes
I've read through the sorting, other than code cleaning suggestions, I'm not sure of a better way to sort the data. I'm going to go back through it again. In the mean time, how well does it handle large datasets?
foreach ($fields as $fieldKey => $fieldAttr) { | ||
if (!is_array($fieldAttr)) { | ||
$headingResult[$fieldKey] = $fieldAttr; | ||
} else if (is_array($fieldAttr) && isset($fieldAttr['nativeField'])){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can drop the is_array check because isset will test anything for the presence of a key and the previous if has already confirmed that this must be an array to reach this line.
* uasort is used here to preserve the associative array keys when they are sorted | ||
*/ | ||
uasort($attributeKeys, function ($item1, $item2) { | ||
if ($item1['priority'] == $item2['priority']){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use strict === here since we expect the type to be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah makes sense.
/** | ||
* Separate by fields that have custom priority and fields that do not have custom priority assigned | ||
*/ | ||
foreach ($fields as $fieldKey => $fieldAttr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability could you move the (non)priority splitting into a separate function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing this bit? I meant moving 112-119 to its own function just to make this a top level function. Sorry might have not been clear enough, my bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! I just moved the specific bit with nativeFields :| Sorry about that. I will ping you in a few minutes then with that update
Some example runs from postman:
605 posts export -> 95.75kb -> 8529ms
605 posts export -> 93.95kb -> 8096ms The size difference accounts for fields exported, column diferences (tags, sets and completed_stages column is only always present in the new csv export) |
@willdoran review feedback was addressed. Can you check? Thanks! |
Results from exporting 4510 posts in 2028 and develop branches. 2028 Branch
Develop branch
|
Yep looks good. |
This pull request makes the following changes:
The sorting procedure is:
--- group by survey ID and stage ID
--- sort groups by numerical key (ie: form id =2 + stage id = 2 go after form id 1, stage id 2)
--- sort by priority inside each group. if priority is the same, fall back to alphabetical order
--- flatten, attach to native fields
--- get all records exported with the correct field order by iterating the heading attributes for each record and printing if there is a value.
TODO
Test checklist:
Create one of each type of survey fields in a survey.
Create a second survey with some custom fields
run ./bin/behat
Fixes #2028
Ping @ushahidi/platform