Giter VIP home page Giter VIP logo

Comments (9)

KovtunV avatar KovtunV commented on May 25, 2024 1

I meant we can use it for notifications when some cell is changes we need to notify all cells with formula that uses it. Perhaps that's a bad solution, yes. But with notifications we don't need to run through the all rows.

I don't have a sample because I just imagine what can we do

from nostringevaluating.

KovtunV avatar KovtunV commented on May 25, 2024

To improve performance I suggest follow these recommendations:

  1. Use variables dictionary instead of concatenation IDictionary<string, EvaluatorValue> variables
  2. Tune your custom functions: dont allocate extra memory, etc
  3. If possible store FormulaNodes somewhere and pass to evaluator it instead of string formula.

This is a general recommendarions, for more specific I need more details, if possible - examples

from nostringevaluating.

prakashboston avatar prakashboston commented on May 25, 2024

In a data table, a formula column allows you to perform calculations based on values from other columns. Let's say you have a data table with columns "Quantity" and "Price," and you want to add a formula column for "Total" (Quantity multiplied by Price). The formula in the "Total" column multiplies the corresponding values in the "Quantity" and "Price" columns.
How to perform this operation using our engine

from nostringevaluating.

KovtunV avatar KovtunV commented on May 25, 2024

If we work with numbers only so I can say these recommendations:

  1. use single evaluator object
  2. Use variables dictionary IDictionary<string, EvaluatorValue> variables
  3. If possible to store FormulaNodes somewhere and pass to evaluator it instead of string formula

3 is a really optional you can go with defaults (string formula).

So design can be like:
loop by rows
from the row take two variables Quantity and Price
send to formula
store in a Total column

snippet:

    static void Main()
    {
        var ns = CreateNoString();

        // store a single instance (or one per thread)
        var variables = new Dictionary<string, EvaluatorValue>();

        // fetch data from the row
        var quantity = 14;
        var price = 123.675;

        // update dictionary
        variables["Quantity"] = quantity;
        variables["Price"] = price;

        // calculate total
        var total = ns.CalcNumber("Quantity * Price", variables); // 1731,45
    }

from nostringevaluating.

prakashboston avatar prakashboston commented on May 25, 2024

In a data table, a formula column allows you to perform calculations based on values from other columns. Let's say you have a data table with columns "Quantity" and "Price," and you want to add a formula column for "Total" (Quantity multiplied by Price).
image
In this example, the formula in the "Total" column multiplies the corresponding values in the "Quantity" and "Price" columns.

This I need to achieve without looping by rows

from nostringevaluating.

KovtunV avatar KovtunV commented on May 25, 2024

So you have variables like A2 B2, they should be in a dictionary. Also you have to store all cell formulas with linking to cells somewhere to understand what formula should be reruned.

For example
formula: "A2*B2"
I store this CellFormula
After changing A2 or B2 you should say "Hey, I updated A2 has anybody listen to this cell?"
our Total cell with formula (A2*B2) will take this notification

take values from A2 and B2
put into dictionary
send to evaluator
update Total cell value

OR, if this is too difficult just run for every formula and update all formulas after any changing ¯\_(ツ)_/¯

from nostringevaluating.

prakashboston avatar prakashboston commented on May 25, 2024

var ns = CreateNoString();
// Iterate through each row and calculate the expression
foreach (DataRow row in dtInput.Rows)
{

    // store a single instance (or one per thread)
    var variables = new Dictionary<string, EvaluatorValue>();

    // update dictionary
    variables["Quantity"] =  row["quantity "];
    variables["Price"] = row["price"];

    // calculate total
    var total = ns.CalcNumber("Quantity * Price", variables); 
    row["total"] =total ;

}
I can able to perform using the above code but Is that possible any other way without looping through the data row

from nostringevaluating.

KovtunV avatar KovtunV commented on May 25, 2024

Sure, if I were you I would add Interface into the row IVariablesContainer (if you can extend DataRow) and use row as is

    // calculate total
    row["total"] = ns.CalcNumber("quantity * price", row);

without iterating you should implement some notification service, or maybe MediatR can be usefull here

from nostringevaluating.

prakashboston avatar prakashboston commented on May 25, 2024

Thanks for your response.MediatR is commonly used in the context of application development, it may not be directly applicable to working with DataTables. Data tables are more commonly associated with tabular data structures.
Can I get a sample code for MediatR with DataTable?

from nostringevaluating.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.