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

steal some ideas for useful features from C++ wrapper XLW #16

Open
Laeeth opened this issue Apr 25, 2017 · 0 comments
Open

steal some ideas for useful features from C++ wrapper XLW #16

Laeeth opened this issue Apr 25, 2017 · 0 comments

Comments

@Laeeth
Copy link
Contributor

Laeeth commented Apr 25, 2017

Low priority list of enhancements for some day.
I talked to Joshi (who wrote the XLW framework) years back.
https://blog.adaptiverisk.com/xll/excel/2015/01/21/xlw-part5.html

  1. isEscPressed() function to allow aborting long-running functions.
  2. abortOnEscape(true); to check for escape and abort if so so you don't need to check within a loop (which might not even be in your own code). not worth doing immediately if it will be a pain in neck.
  3. threadsafe attribute if we don't already have it. excel automatically will call functions with this attribute on multiple threads. I think it's just a matter of registration options. I don't think it's easy to introspect code and tell if it's thread safe - function author has to tell our library.
  4. volatile attribute - I think this is at registration time. if we don't already have it.
  5. allow use of Matrices rather than [][]. if you can't make it generic matrix function than use mir arrays.
  6. Showcase example showing integration with python using pyd.
  7. Showcase benchmark to do something useful vs python
  8. Showcase REST example - eg pull data from yahoo, quandl or Federal reserve FRED API
  9. Suppose you have a function that normally returns a double - you should be able to return a string as an error message somehow. XLW uses throw to do that - not sure what makes sense for us.
  10. implement some XLW and PyXLL examples to show ease of use.

Example: xlStats. I haven't checked - probably some error in code.
D example

    import std.algorithm:map,sum;
    import std.range:front;

    @Register(ArgumentText("input range to calculate statistics for"),
        HelpTopic("excel-d"),
        FunctionHelp("calculates mean and variance for input array"),
        ArgumentHelp(["input range to calculate statistics for"]))
    auto xlStats(double[][] inTargetRange)
    {
        auto numCells = (inTargetRange.length > 0) ?
                                     inTargetRange.length * inTargetRange.front.length : 0;
        auto means = inTargetRange.map!(row => row.sum).sum / numCells;
        auto sumSquares = inTargetRange.map!( row => row.map!(cell => cell*cell).sum).sum;
        return [means, sumSquares / numCells - means];
    }
`
Is a bit simpler than the C++ XLW example:
````cpp
 LPXLFOPER EXCEL_EXPORT xlStats(LPXLFOPER inTargetRange) {
        EXCEL_BEGIN;
        XlfOper xlTargetRange(inTargetRange);

        // Temporary variables.
        double averageTmp = 0.0;
        double varianceTmp = 0.0;

        // Iterate over the cells in the incoming matrix.
        for (RW i = 0; i < xlTargetRange.rows(); ++i)
        {
            for (RW j = 0; j < xlTargetRange.columns(); ++j)
            {
                // sums the values.
                double value(xlTargetRange(i,j).AsDouble());
                averageTmp += value;
                // sums the squared values.
                varianceTmp += value * value;
            }
        }
        size_t popSize = xlTargetRange.rows() * xlTargetRange.columns();

        // avoid divide by zero
        if(popSize == 0)
        {
            THROW_XLW("Can't calculate stats on empty range");
        }

        // Initialization of the results Array oper.
        XlfOper result(1, 2);
        // compute average.
        double average = averageTmp / popSize;
        result(0, 0) = average;
        // compute variance
        result(0, 1) = varianceTmp / popSize - average * average;
        return result;
        EXCEL_END;
    }
`
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

1 participant