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

updating ab chart stats TM-2409 #654

Merged
merged 36 commits into from
Jan 21, 2022

Conversation

SidelineCory24
Copy link

@SidelineCory24 SidelineCory24 commented Jan 6, 2022

FE PR

To-Do:

  • Replace TED with CDO
  • For the Bureau dropdown only show the OC status and OC Bureau (CDO user only) Note: OC Status is being shown under the Status option
  • For Post only show Post with 2+ AB (Available Bidders) once a certain amount of Post are shown
  • For Grade show in numerical order (same order as filters)
  • For Skill show in alphabetical order

Note: Product Owner okay'd adding the OC Bureau dropdown and keeping the Bureau dropdown as well (current assignment)

@SidelineCory24 SidelineCory24 changed the title updating ab chart stats updating ab chart stats TM-2409 Jan 7, 2022
@SidelineCory24
Copy link
Author

Note: only showing Post with 2+ AB was added to the adding OC Bureau to data structure commit

…aPhase-Consulting/State-TalentMap-API into update/available-bidders-chart-stats
Comment on lines 57 to 61
ab_oc_bureau_key = pydash.get(bidder, 'available_bidder_details.oc_bureau')
if ab_oc_bureau_key:
if bidder['available_bidder_details']['oc_bureau'] not in stats['OC Bureau']:
stats['OC Bureau'][bidder['available_bidder_details']['oc_bureau']] = {'name': f"{bidder['available_bidder_details']['oc_bureau']}", 'value': 0}
stats['OC Bureau'][bidder['available_bidder_details']['oc_bureau']]['value'] += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you already defined ab_oc_bureau_key on line 57, you may as well just use that instead of calling out bidder['available_bidder_details']['oc_bureau'] on line 59 again (also happens twice on line 60 and once on line 61).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting this error when trying to make the update, this is the code:

ab_oc_bureau_key = pydash.get(bidder, 'available_bidder_details.oc_bureau')
            if ab_oc_bureau_key:
                if bidder[ab_oc_bureau_key] not in stats['OC Bureau']:
                    stats['OC Bureau'][bidder[ab_oc_bureau_key]] = {'name': f"{bidder[ab_oc_bureau_key]}", 'value': 0}
                stats['OC Bureau'][bidder[ab_oc_bureau_key]]['value'] += 1
                stats_sum['OC Bureau'] += 1

image

Copy link
Author

@SidelineCory24 SidelineCory24 Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disregard, I can't copy/paste, the fix has been pushed

Comment on lines 64 to 66
if bidder['cdo']['full_name'] not in stats['CDO']:
stats['CDO'][bidder['cdo']['full_name']] = {'name': f"CDO {bidder['cdo']['full_name']}", 'value': 0}
stats['CDO'][bidder['cdo']['full_name']]['value'] += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar idea with full_name. Let's just set a variable to reference the fullname like bidderFullName = pydash.get(bidder, 'cdo.full_name') and then reference that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if len(biddersStats['Post']) > 18:
biddersStats['Post'] = filter(lambda post: post['value'] > 1, biddersStats['Post'])

biddersStats['Grade'] = sorted(biddersStats['Grade'], key = lambda grade: grade['name'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sorting compare to the search filters?

Screen Shot 2022-01-12 at 4 04 34 PM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting matches. I can add all the grades if need be to be safe.
image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the OO is the only one that doesn't match
image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes let's include all make sure they match

@mjoyce91
Copy link

See this comment, as it's probably more API related - MetaPhase-Consulting/State-TalentMAP#1909 (comment)

Comment on lines 53 to 108
bureau_key = pydash.get(bidder, 'current_assignment.position.bureau_code')
if bureau_key not in stats['Bureau']:
no_bureau = none_listed
bureau = {'name': f"{bureau_key}", 'value': 0}
stats['Bureau'][bureau_key] = no_bureau if bureau_key == None else bureau
stats['Bureau'][bureau_key]['value'] += 1
stats_sum['Bureau'] += 1

if bidder['grade'] not in stats['Grade']:
stats['Grade'][bidder['grade']] = {'name': f"Grade {bidder['grade']}", 'value': 0}
stats['Grade'][bidder['grade']]['value'] += 1
cdo_full_name_key = pydash.get(bidder, 'cdo.full_name')
if cdo_full_name_key not in stats['CDO']:
no_cdo = none_listed
cdo = {'name': f"{cdo_full_name_key}", 'value': 0}
stats['CDO'][cdo_full_name_key] = no_cdo if cdo_full_name_key == None else cdo
stats['CDO'][cdo_full_name_key]['value'] += 1
stats_sum['CDO'] += 1

grade_key = pydash.get(bidder, 'grade')
if grade_key not in stats['Grade']:
no_grade = none_listed
grade = {'name': f"Grade {grade_key}", 'value': 0}
stats['Grade'][grade_key] = no_grade if grade_key == None else grade
stats['Grade'][grade_key]['value'] += 1
stats_sum['Grade'] += 1

if bidder['pos_location'] not in stats['Post']:
stats['Post'][bidder['pos_location']] = {'name': f"{bidder['pos_location']}", 'value': 0}
stats['Post'][bidder['pos_location']]['value'] += 1
oc_bureau_key = pydash.get(bidder, 'available_bidder_details.oc_bureau')
if oc_bureau_key not in stats['OC Bureau']:
no_oc_bureau = none_listed
oc_bureau = {'name': f"{oc_bureau_key}", 'value': 0}
stats['OC Bureau'][oc_bureau_key] = no_oc_bureau if oc_bureau_key == None else oc_bureau
stats['OC Bureau'][oc_bureau_key]['value'] += 1
stats_sum['OC Bureau'] += 1

post_key = pydash.get(bidder, 'pos_location')
if post_key not in stats['Post']:
no_post = none_listed
post = {'name': f"{post_key}", 'value': 0}
stats['Post'][post_key] = no_post if post_key == None else post
stats['Post'][post_key]['value'] += 1
stats_sum['Post'] += 1

skill = list(deepcopy(filter(None, bidder['skills'])))
skill_key = skill[0]['code']
if skill_key not in stats['Skill']:
stats['Skill'][skill_key] = {'name': f"{skill[0]['description']}", 'value': 0}
no_skill = none_listed
skill = {'name': f"{skill[0]['description']}", 'value': 0}
stats['Skill'][skill_key] = no_skill if skill_key == None else skill
stats['Skill'][skill_key]['value'] += 1
stats_sum['Skill'] += 1

ab_status_key = pydash.get(bidder, 'available_bidder_details.status')
if ab_status_key:
if ab_status_key not in stats['Status']:
stats['Status'][ab_status_key] = {'name': f"{ab_status_key}", 'value': 0}
stats['Status'][ab_status_key]['value'] += 1
stats_sum['Status'] += 1

ted_key = ensure_date(pydash.get(bidder, "current_assignment.end_date"), utc_offset=-5) or 'None listed'
ted_key = "None listed" if ted_key is "None listed" else smart_str(maya.parse(ted_key).datetime().strftime('%m/%d/%Y'))
if ted_key not in stats['TED']:
stats['TED'][ted_key] = {'name': f"{ted_key}", 'value': 0}
stats['TED'][ted_key]['value'] += 1
stats_sum['TED'] += 1
status_key = pydash.get(bidder, 'available_bidder_details.status')
if status_key not in stats['Status']:
no_status = none_listed
status = {'name': f"{status_key}", 'value': 0}
stats['Status'][status_key] = no_status if status_key == None else status
stats['Status'][status_key]['value'] += 1
stats_sum['Status'] += 1
Copy link

@mjoyce91 mjoyce91 Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these blocks of code are doing basically the same thing. What if we abstracted away the differences to a config object to make this more DRY?

  config = [
    { 'key': 'current_assignment.position.bureau_code', 'statsKey': 'Bureau' },
    ...
  ]
  def map_object(x):
    key = pydash.get(bidder, x['key'])
    if key not in stats[x['statsKey']]:
        fallback_text = none_listed
        obj = {'name': f"{key}", 'value': 0}
        stats[(x['statsKey'])[key] = fallback_text if key == None else obj
    stats[x['statsKey']][key]['value'] += 1
    stats_sum[x['statsKey']] += 1

  pydash.for_each(config, map_object)


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make a few edits, also this is not tested

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, except for handling the skill

@SidelineCory24
Copy link
Author

SidelineCory24 commented Jan 18, 2022

Looks like this is causing the improper adding, @mjoyce91 @elizabeth-jimenez
none_listed = {'name': 'None listed', 'value': 0} stats['CDO'][cdo_full_name_key] = none_listed if cdo_full_name_key == None else {'name': f"{cdo_full_name_key}", 'value': 0}

would this make more sense
stats['Grade'][grade_key] = {'name': 'None listed', 'value': 0} if grade_key == None else {'name': f"Grade {grade_key}", 'value': 0}

Mike I saw your comment about the config/function to do all of this code as well

Comment on lines 65 to 77
if stat['key'] == 'skills':
skill = list(deepcopy(filter(None, bidder[stat['key']])))
skill_key = skill[0]['code']
if skill_key not in stats['Skill']:
stats['Skill'][skill_key] = deepcopy(none_listed) if skill_key == None else {'name': f"{skill[0]['description']}", 'value': 0}
stats['Skill'][skill_key]['value'] += 1
stats_sum[stat['statsKey']] += 1
else:
key = pydash.get(bidder, stat['key'])
if key not in stats[stat['statsKey']]:
stats[stat['statsKey']][key] = deepcopy(none_listed) if key == None else {'name': f"{key}", 'value': 0}
stats[stat['statsKey']][key]['value'] += 1
stats_sum[stat['statsKey']] += 1
Copy link

@mjoyce91 mjoyce91 Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're still duplicating a lot of the same code. For example, we always run stats_sum[stat['statsKey']] += 1 regardless of which path the if/else takes, so why have that in both blocks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified skill code has been pushed

@SidelineCory24 SidelineCory24 merged commit 057cf30 into dev Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants