• 113 views | 3 messages Discussion: LEAP
    Topic: How to assign variable to a file, and read it via APISubscribe | Previous | Next
  • Mostafa Fard 5/10/2019

    Hi,
    Is there anyone who works with LEAP APIs?
    I want to use LEAP APIs to do something like the following command:
    LEAP.Branch("Demand\Household\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:\Input.csv)";
    I am going to set the expression for a variable of a component to read the values from a file (in a specific path) via APIs.
    What is the best practice to do that? using ReadFromFile? using ReadFromExcel? or...?
    What should be the format of the external file (here Input.csv) to set different values for different time slices of a year?
    Also, how can I read the value of a specific time slice via API? (the Value(year, UnitName, Filter) API just get the year. How can I access a specific time slice?) Actually, I am looking for the same concept of Time Step in WEAP.

    Thanks,

  • Taylor Binnington 5/28/2019
      Best Response

    Hi Mostafa -

    Sorry for the wait. To the first part of your question, I would suggest the ReadFromExcel() function, implemented using it's two additional optional arguements. I'm attaching an example file that shows the formatting for the Excel file (appropriate for importing into the Freedonia dataset).

    ReadFromExcel(path\tofile\book1.xlsx, years, tsnames, values)

    Note that this form of the function is only readable using one of LEAP's time-slices variables, such as the System Peak Load Shape. In any case, I'd suggest experimenting with it manually by entering the expressions using the builder, making sure you've got it right before trying to do it via the API.

    To the second part of your question: reading the value of a variable in a specific time slice is a very good question, and it's something that I haven't done. I will continue to muse on this, and if I come up with a solution, I'll post it here. Likewise, feel free to post any of your progress on this question too. I'm sure the community would benefit! What I can say is that there isn't a built-in way to do this using a LEAP function, so you would need to do something clever yourself.

    Good luck,
    Taylor


    Attachments:  Book1.xlsx [4]
  • Mostafa Fard 8/7/2019
      Best Response

    Hi Taylor,
    Related to the second part of my question, I tried a lot but none of them worked. Do you have any suggestion? Indeed, I am in a complete deadlock.
    I do not understand why the read values of a Data or Result variables should be Yearly-Based, via API function. It is not possible to add new API in the next versions of LEAP to support this issue?