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 should I convert new units #27

Closed
Dianelynn1 opened this issue Aug 22, 2020 · 5 comments
Closed

How should I convert new units #27

Dianelynn1 opened this issue Aug 22, 2020 · 5 comments

Comments

@Dianelynn1
Copy link

Since I need to calculate a lot of PP transfer fee every day, I want to use Alfred to quickly calculate the PP fee result. How can I implement this conversion procedure in your workflow?

The PP fee calculation tool I currently use is shown in the link, and the US dollar is needed. The specific value set is 4.4%+0.3USD
https://www.clothnappytree.com/ppcalculator/
image

Thanks for your help!

@Dianelynn1
Copy link
Author

Because I don’t have any experience in programming, I hope you can explain in detail how I can operate or modify your workflow if you can help me.

Thanks again!

@wolph
Copy link
Owner

wolph commented Aug 23, 2020

There are 2 ways to add new units to the system.

  1. By editing this bit of code: https://github.com/WoLpH/alfred-converter/blob/master/converter/extra_units.py
  2. By editing the units XML file: https://github.com/WoLpH/alfred-converter/blob/master/poscUnits22.xml

When editing the extra_units.py file I think you would need something like this as part of the register_post function:

convert.Unit(
  id='dollar',
  name='Dollar',
  annotations=['$', 'dollar'],
  conversion_params=('0', '0', '1', '0'),
).register(units)

convert.Unit(
  id='paypal-fee',
  name='PayPal fee',
  base_unit='dollar',
  conversion_params=('0.3', '0.044', '1', '0'),

Note: the conversion params work like this: (a + b * value) / (c + d * value)

Perhaps I'll add something in the future to make this easier, but for now that's the only option. You're the first to ask for a custom unit :)

@Dianelynn1
Copy link
Author

I compared your new code formats and put them in this section of the extra_units.py file.

But I still don’t seem to add them correctly, because PP-fee is not available in the Alfred 4

image

image
Is this because I put the code in the wrong place or is it just that Alfred made a mistake about using the PP hotkey?

Sorry for taking your time again.

@wolph
Copy link
Owner

wolph commented Oct 16, 2020

It seems I somehow missed your reply... sorry about that

In any case, it looks like my example was a bit too limited to work. I've tried a little more and I've come up with this code:

    params = dict(
        units=units,
        quantity_types=['money'],
        base_unit='dollar',
    )

    add = 0.3
    fee = 4.4
    multiplier = fee * 0.0105
    convert.Unit(
        id='dollar',
        name='Dollar',
        annotations=['$', 'dollar'],
        conversion_params=('0', '1', '1', '0'),
        **params
    ).register(units)

    convert.Unit(
        id='paypal-fee',
        name='PayPal fee',
        annotations=['pp', 'paypal'],
        conversion_params=('-%s' % add, '1', str(multiplier), '0'),
        **params
    ).register(units)

    convert.Unit(
        id='paypal-total',
        name='PayPal Total',
        annotations=['pt'],
        conversion_params=('-%s' % add, '1', str(1 + multiplier), '0'),
        **params
    ).register(units)

If needed you can easily change the 4.4% and +0.3. Note that after editing the code you will have to delete the units.pickle file which caches the calculations.

This is how it looks right now:
image

@Dianelynn1
Copy link
Author

Dianelynn1 commented Oct 17, 2020 via email

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

No branches or pull requests

2 participants