User Tools

Site Tools


uphp:functions:get_csv_data

get_csv_data

FW >= 1317

Extract partial CSV data from an existing CSV file

Description

string get_csv_data ( string $filename, string $columns , int $interval] [, int $json] )

This function takes a filename (including the full path) in the $filename parameter and a list of columns to extract in the $columns field. The $interval period in minutes is used to extract data at predefined intervals from the start of the file.

Parameters

$filename: Valid filename of a CSV file (with the first row containing the column names)</html>

$columns: Comma separated list of column headers (case sensitive) to extract from the CSV file

$interval: Interval in minutes between result rows

$json: Return data as CSV by passing 0, or as JSON by passing 1

Return Values

string resultant rows in the format specified (CSV or JSON)

Examples

<?
  $data = get_csv_data("/logs/2024/07/20240708_0.csv","inverter1_AC_Active_Power,meter2_AC_Active_Power_A",30,1);
  print($data);
?>

The above example will display:

[[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
,[0,0]
]

The above example shows zero due to the CSV file having blank entries.

uphp/functions/get_csv_data.txt · Last modified: 2024/07/16 03:03 by admin