TransWikia.com

Converting Dynamic Variable to String for use in an API

Mathematica Asked on December 22, 2020

I am trying to create a code that concatenates a series of dynamic selections (year, month, day) to a string for creating a dynamic date string for use in an API which is to be included in a URLExecute[] function. In the code below, the majority of code seems to work fine. As the user selects the menu options which are dynamic, I have attempted numerous times to create a string of some sort without success. The last grid in the code snippet below is basically broken as I am out of ideas on how to handle the conversion. Once the string is completed, I will send it as part of an API to a SCADA historian.

Any advice whatsoever is greatly appreciated.

YearMenuS = PopupMenu[Dynamic[YearChoiceS], YearList, 1950];
YearMenuE = PopupMenu[Dynamic[YearChoiceE], YearList, 1950];

MonthMenuS = PopupMenu[Dynamic[MonthChoiceS], {"Jan"
                , "Feb"
                    , "Mar"
                        , "Apr",
                "May",
                    "Jun",
                        "Jul",
                "Aug",
                    "Sep",
                        "Nov",
                "Dec"}, "Jan"];

MonthMenuE = PopupMenu[Dynamic[MonthChoiceE], {"Jan"
                , "Feb"
                    , "Mar"
                        , "Apr",
                "May",
                    "Jun",
                        "Jul",
                "Aug",
                    "Sep",
                        "Nov",
                "Dec"}, "Jan"];

DayMenuS = 
  PopupMenu[Dynamic[DayChoiceS], 
   IntegerString[#, 10, 2] & /@ Range[31], 01 ];
DayMenuE = 
  PopupMenu[Dynamic[DayChoiceE], 
   IntegerString[#, 10, 2] & /@ Range[31], 01 ];

Grid[{
  {"Start Date"},
  {YearMenuS, MonthMenuS, DayMenuS},
  {"End Date"},
  {YearMenuE, MonthMenuE, DayMenuE},
  aa = YearMenuS[[1]];
  bb = MonthMenuS[[1]];
  cc = DayMenuS[[1]];
  {  Button["Get Data",
        (*Print[Dynamic  [YearMenuS[[1]]]  ]]  }*)
        txt1 = Print[aa];
        Print[TextString[aa]]; 
        Print[StringJoin[ aa, aa]  ];
        (*txt3=Print[aa,"-",bb,"-",cc];*)
        (*Print[az]*)
        ]}
  
  
  }]
```

One Answer

@PrintDayChoiceS did not quite give me what I wanted -- it produced the solution or day pick but not as a string. The work around i used in the end was to skip the printing and just execute the API within the Button[] function. Not sure if this is the most efficient. But seems to work for the moment. Thanks again @Kuba :)

GetRawDataGrid = Grid[{
    {WellListLabel},
    {WellMenu},
    {BlankLine},
    {SelectDateS},
    {YearMenuS, MonthMenuS, DayMenuS},
    {BlankLine},
    {SelectDateE},
    {YearMenuE, MonthMenuE, DayMenuE},
    aa = MonthMenuS[[1]];
    bb = MonthMenuS[[1]];
    cc = MonthMenuS[[1]];
    {BlankLine},
    {  Button[ExecuteBut,
        
        finalstringS = 
       StringJoin[ToString[YearChoiceS], "-", 
        StringTake[ToString[MonthChoiceS], -2], "-", 
        ToString[DayChoiceS]];
        finalstringE = 
       StringJoin[ToString[YearChoiceE], "-", 
        StringTake[ToString[MonthChoiceE], -2], "-", 
        ToString[DayChoiceE]];
        tqdatatest = 
       URLExecute[
            "http://LAPTOP-XXXX:XXXX/api/v2/getTagData", {"tags" 
-> "XXXX:XXXX.GBGasField.Sine.Tag0002" ,(*Tag0002 is tq*)
                    "startTime" -> finalstringS,
                    "endTime" -> finalstringE
                        }][[3]][[2]][[1]][[2]];
        ]}
    
    
    }, Alignment -> Left, Background -> BCTV];
TabView[{WellListLabel -> GetRawDataGrid}, Background -> BCTV];

```

Answered by Colin Lyle Jordan on December 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP