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

Return value as Python type #5

Open
Tracked by #6
j-ti opened this issue Aug 24, 2023 · 3 comments
Open
Tracked by #6

Return value as Python type #5

j-ti opened this issue Aug 24, 2023 · 3 comments

Comments

@j-ti
Copy link
Contributor

j-ti commented Aug 24, 2023

Should return value e.g. the created account string (which could be put also inside a dictionary) or the matches as Python List:
Could be similar to the following example for returning a python List of dictionaries:

    // Convert MarketOutput to Python List of Dict representing matches
    let pyMatches = PyList::new(py,
        matches.matches.into_iter().map(|mtch| {
            let dict = PyDict::new(py);
            dict.set_item("time", mtch.energy_kwh);
            dict.set_item("bid_id", mtch.bid_id);
            dict.set_item("ask_id", mtch.ask_id);
            dict.set_item("bid_actor", "");
            dict.set_item("ask_actor", "");
            dict.set_item("bid_cluster", 0);
            dict.set_item("ask_cluster", 0);
            dict.set_item("energy", mtch.energy_kwh);
            dict.set_item("price", mtch.price_euro_per_kwh);
            dict.set_item("included_grid_fee", 0);
            dict
        })
    );

As both types are different the account string or the match list could be it self returned within a dictionary with a specific key, i.e. {"account": account_string} or {"matches": pyMatches}

Originally posted by @j-ti in #3 (comment)

@j-ti j-ti mentioned this issue Aug 24, 2023
@j-ti
Copy link
Contributor Author

j-ti commented Aug 24, 2023

Return type should be PyResult<Py<PyDict>>

@j-ti
Copy link
Contributor Author

j-ti commented Aug 24, 2023

We agreed on returning the PyDict by each command function and just forward it to the dispatching run_cli return

@j-ti
Copy link
Contributor Author

j-ti commented Aug 25, 2023

Also Errors should be forwarded, in that turn also commands need to preferably return Error rather than to panic! as these cannot be handled well, e.g. olisystems/BEST-Energy#53

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

1 participant