Facility Control

 View Only
  • 1.  Really Basic CSV

    Posted 02-10-2021 05:25

    Now for my next totally basic question re: dealing with really simple .CSV files (4items/10-20rows -- Names/Titles etc). I just want to open a file (real path to the file -- Drive:/Path1/Path2/Path3/File.csv ) or better yet, choose from a picker??

    Populate a table or array with each value, then display it in an organized fashion.

    Strangely, the part that I have the most problem with is just loading the file. Can anyone point me to video or tutorial that might help me out on this?

    Thanks,
    Jerry




  • 2.  RE: Really Basic CSV

    Posted 02-10-2021 13:24

    Take a look at the example panels here: https://support.rossvideo.com/hc/en-us/community/posts/360065970252-Free-DashBoard-Example-Panels-for-Everyone, 

    In the Reading and Writing Files or Directories folder, there is an example on Reading a CSV File.    It takes the content of the CSV and puts it into a structured parameter.


    #DashBoard


  • 3.  RE: Really Basic CSV

    Posted 02-10-2021 20:48

    Thanks Ben, I do have those and they've shown me a lot - however even with the CSV example, there are some basics I apparently still don't have. 

    I have no issues with the mechanics of the parsing etc. but I still don't see how the file path is actually derived. As I mentioned, I'd like to see something like:
    Drive:/Path1/Path2/Path3/File.csv

    but instead there is this:

    ogscript.asyncPost('CSV Examples/CSV Reader Data.csv', null, processCSV);

    I get the needed script command and such -- and see that the file is read from a subfolder but I don't see the full path. I'd like to be in control of where the file is. I feel that I'm missing a basic concept here so if you could enlighten me, I'd appreciate it.

    -Jerry


    #DashBoard


  • 4.  RE: Really Basic CSV

    Posted 02-10-2021 21:03

    'CSV Examples/CSV Reader Data.csv' is the path.   In this case, it's relative to the DashBoard folder, so it does not have the Drive:/ part of this.   But you can put the whole path instead.

    I just made a quick change to the example panel so that it's getting the file path from a file parameter.   Does that help?

    Here is the code:

    <abs contexttype="opengear" gridsize="20" keepalive="true">
    <meta>
    <params>
    <param access="1" maxlength="0" name="Column 1" oid="cols.1" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>statecode</value>
    </param>
    <param access="1" maxlength="0" name="Column 2" oid="cols.2" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>county</value>
    </param>
    <param access="1" maxlength="0" name="Column 3" oid="cols.3" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>eq_site_limit</value>
    </param>
    <param access="1" maxlength="0" name="Column 4" oid="cols.4" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>hu_site_limit</value>
    </param>
    <param access="1" maxlength="0" name="Column 5" oid="cols.5" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>fl_site_limit</value>
    </param>
    <param access="1" maxlength="0" name="Column 6" oid="cols.6" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>fr_site_limit</value>
    </param>
    <param access="1" maxlength="0" name="Column 7" oid="cols.7" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>tiv_2011</value>
    </param>
    <param access="1" maxlength="0" name="Column 8" oid="cols.8" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>tiv_2012</value>
    </param>
    <param access="1" maxlength="0" name="Column 9" oid="cols.9" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>eq_site_deductible</value>
    </param>
    <param access="1" maxlength="0" name="Column 10" oid="cols.10" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>hu_site_deductible</value>
    </param>
    <param access="1" maxlength="0" name="Column 11" oid="cols.11" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>fl_site_deductible</value>
    </param>
    <param access="1" maxlength="0" name="Column 12" oid="cols.12" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>fr_site_deductible</value>
    </param>
    <param access="1" maxlength="0" name="Column 13" oid="cols.13" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>point_latitude</value>
    </param>
    <param access="1" maxlength="0" name="Column 14" oid="cols.14" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>point_longitude</value>
    </param>
    <param access="1" maxlength="0" name="Column 15" oid="cols.15" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>line</value>
    </param>
    <param access="1" maxlength="0" name="Column 16" oid="cols.16" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>construction</value>
    </param>
    <param access="1" maxlength="0" name="Column 0" oid="cols.0" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>policyID</value>
    </param>
    <param access="1" constrainttype="STRING_CHOICE" name="table" oid="table" precision="0" type="INT16" value="-1" widget="table">
    <constraint>cols.0</constraint>
    <constraint>cols.1</constraint>
    <constraint>cols.2</constraint>
    <constraint>cols.3</constraint>
    <constraint>cols.4</constraint>
    <constraint>cols.5</constraint>
    <constraint>cols.6</constraint>
    <constraint>cols.7</constraint>
    <constraint>cols.8</constraint>
    <constraint>cols.9</constraint>
    <constraint>cols.10</constraint>
    <constraint>cols.11</constraint>
    <constraint>cols.12</constraint>
    <constraint>cols.13</constraint>
    <constraint>cols.14</constraint>
    <constraint>cols.15</constraint>
    <constraint>cols.16</constraint>
    </param>
    <param access="1" maxlength="0" name="filename" oid="filename" type="STRING" value="CSV%20Examples/CSV%20Reader%20Data2y.csv" widget="file-picker"/>
    </params>
    </meta>
    <label height="60" left="40" name="Reading CSV Files" style="txt-align:west;size:Bigger;" top="40" width="620"/>
    <label height="20" left="40" name="ogScript can be used to read in a CSV file (comma separated values), which is typically produced by a spreadsheet program." style="txt-align:west;" top="100" width="1100"/>
    <label height="20" left="40" name="This panel reads the &quot;CSV Reader Data.csv&quot; file from the CSV Examples folder, and puts the data in a structured parameter." style="txt-align:west;" top="120" width="1120"/>
    <param bottom="20" expand="true" left="40" oid="table" right="20" showlabel="false" top="260"/>
    <button buttontype="push" height="80" left="40" name="Read" top="160" width="180">
    <task tasktype="ogscript">function processCSV(fileContent)
    {
    if (fileContent == null)
    {
    ogscript.debug("CAN'T LOAD FILE");
    return;
    }

    var rows = fileContent.split('\n');
    var dataByColumn = []; //It is more efficient if we only call "SET" on the parameters once

    for (var r = 0; r &lt; rows.length; r++)
    {
    var cols = rows[r].trim().split(',');
    for (var c = 0; c &lt; cols.length; c++)
    {
    if (c &gt;= dataByColumn.length)
    {
    dataByColumn.push([]); //Add a new column if it wasn't already created
    }
    dataByColumn[c][r] = cols[c].trim(); //Push the cell's value into the array of column data at row "r"
    }
    }


    //Now that we have collected all of the data for each column into an array, we can call setAllValues for the array parameter
    for (var c = 0; c &lt; dataByColumn.length; c++)
    {
    params.setAllValues('cols.' + c, dataByColumn[c]); //Set all of the values in the column
    }
    }

    ogscript.asyncPost(params.getValue("filename",0), null, processCSV);</task>
    </button>
    <param expand="true" height="40" left="260" oid="filename" showlabel="false" top="160" width="580"/>
    </abs>

     

     

     


    #DashBoard


  • 5.  RE: Really Basic CSV

    Posted 02-10-2021 23:08

    Ben
    Extremely Helpful!
    -Jerry


    #DashBoard