TimeSeriesCsvService
extends CsvService
in package
Table of Contents
Properties
- $clientTimeZone : string
- $files : array<string|int, string>
- $ids : mixed
- $reportType : string
- $sheet : Worksheet
- $spreadsheet : Spreadsheet
- $statusFormats : array<string|int, mixed>
- $timestampFormat : array<string|int, mixed>
- $values : array<string|int, mixed>
- $zip : ZipArchive
- $zipFileName : string
Methods
- __construct() : mixed
- createEventObject() : string
- handles the creation of event objects for the Excel report
- createSeparateFiles() : self
- Handles the creation of files for the CSV report.
- getFileName() : array<string|int, string>
- Gets the name of an specific file in the files property based on the key value of the array.
- handleFileCreation() : $this
- handleHeaderCreation() : self
- Handles the creation of headers for the CSV file.
- removeEmptyDataSet() : $this
- Removes empty data sets from the values array.
- removeFilesAddedToZip() : self
- Removes the files that have been added to the zip file from the server.
- saveFile() : void
- zipFiles() : $this
- convertValue() : mixed
- Converts the given value to the appropriate data type based on the provided data type string.
- createNewSheet() : void
- Creates a new spreadsheet and sets the active sheet.
- getStatusName() : string
- Determines the status name based on the provided status code.
- setStatusValuesInSheet() : void
- Sets the status values in the spreadsheet based on the status formats.
- setTimestampFormatValues() : void
- Sets the values in the spreadsheet based on the timestamp format.
- setValueBasedOnDataType() : void
- Sets a value in the spreadsheet based on its data type.
Properties
$clientTimeZone
protected
string
$clientTimeZone
$files
protected
array<string|int, string>
$files
= []
$ids
protected
mixed
$ids
$reportType
protected
string
$reportType
$sheet
protected
Worksheet
$sheet
$spreadsheet
protected
Spreadsheet
$spreadsheet
$statusFormats
protected
array<string|int, mixed>
$statusFormats
$timestampFormat
protected
array<string|int, mixed>
$timestampFormat
$values
protected
array<string|int, mixed>
$values
$zip
protected
ZipArchive
$zip
$zipFileName
protected
string
$zipFileName
Methods
__construct()
public
__construct(array<string|int, mixed> $values, array<string|int, mixed> $timestampFormat, string $reportType, array<string|int, mixed> $statusFormats, mixed $ids, string $clientTimeZone) : mixed
Parameters
- $values : array<string|int, mixed>
- $timestampFormat : array<string|int, mixed>
- $reportType : string
- $statusFormats : array<string|int, mixed>
- $ids : mixed
- $clientTimeZone : string
createEventObject()
handles the creation of event objects for the Excel report
public
static createEventObject(array<string|int, mixed>|string|stdClass $value) : string
Parameters
- $value : array<string|int, mixed>|string|stdClass
-
- the value stream
Return values
stringcreateSeparateFiles()
Handles the creation of files for the CSV report.
public
createSeparateFiles(string $filePath) : self
It iterates over the ids of the data streams. For each id, it retrieves the corresponding node and its display name. It then iterates over the values of the data streams. If the id of the data stream matches the current id, it processes the values. For each value, it sets the time, value, and status in the CSV file. Once all values have been processed, it creates a new file and stores the file name.
Parameters
- $filePath : string
Tags
Return values
self —Returns the current instance of the class to allow for method chaining.
getFileName()
Gets the name of an specific file in the files property based on the key value of the array.
public
getFileName(int $index) : array<string|int, string>
Parameters
- $index : int
Return values
array<string|int, string>handleFileCreation()
public
handleFileCreation(string $filePath) : $this
Parameters
- $filePath : string
Tags
Return values
$thishandleHeaderCreation()
Handles the creation of headers for the CSV file.
public
handleHeaderCreation() : self
It iterates over the timestamp formats and sets each one as a header in the CSV file. It then sets "value" as a header. If "code", "name", and "severity" are present in the status formats, it sets each of these as headers as well.
Return values
self —Returns the current instance of the class to allow for method chaining.
removeEmptyDataSet()
Removes empty data sets from the values array.
public
removeEmptyDataSet() : $this
Return values
$thisremoveFilesAddedToZip()
Removes the files that have been added to the zip file from the server.
public
removeFilesAddedToZip() : self
This method iterates over the files stored in the $this->files array, which are the files that have been added to the zip file. Each file is removed from the server using the unlink function. After all files have been removed, the method returns the current object ($this), allowing for method chaining.
Return values
self —Returns the current object, allowing for method chaining.
saveFile()
public
saveFile(string $fileName) : void
Parameters
- $fileName : string
Tags
zipFiles()
public
zipFiles(string $filePath) : $this
Parameters
- $filePath : string
Return values
$thisconvertValue()
Converts the given value to the appropriate data type based on the provided data type string.
private
convertValue(string $dataType, mixed $value) : mixed
It uses a match expression to determine the data type of the value. If the data type is 'float', it converts the value to a float using the floatval function. If the data type is 'int', it converts the value to an integer using the intval function. If the data type is 'bool', it converts the value to a boolean using the boolval function. If the data type is 'object', it converts the value to a JSON string using the createEventObject method. If the data type is not one of the above, it returns the value as is.
Parameters
- $dataType : string
-
The data type to which the value should be converted.
- $value : mixed
-
The value to be converted.
Return values
mixed —The converted value.
createNewSheet()
Creates a new spreadsheet and sets the active sheet.
private
createNewSheet() : void
It initializes a new Spreadsheet object and sets the active sheet to it. After creating the new sheet, it calls the handleHeaderCreation method to set up the headers.
getStatusName()
Determines the status name based on the provided status code.
private
getStatusName(int|string $status) : string
It takes a status code as input, which can be either an integer or a string. If the status code is a string, it converts it to an integer. It then checks the status code and returns a string representing the status name. If the status code is 0, it returns 'Good'. If the status code is 0x80000000, it returns 'Bad'. If the status code is 0x40000000, it returns 'Uncertain'. If the status code is an empty string, it returns an empty string.
Parameters
- $status : int|string
-
The status code to determine the data status from.
Return values
string —The data status determined from the status code.
setStatusValuesInSheet()
Sets the status values in the spreadsheet based on the status formats.
private
setStatusValuesInSheet(string &$col, int $cell, mixed $status, mixed $statusName, mixed $statusDescriptions) : void
It checks if each of the status formats ("code", "name", "severity") is present, and if so, sets the corresponding value in the spreadsheet.
Parameters
- $col : string
-
The column in the spreadsheet where the value should be set.
- $cell : int
-
The row in the spreadsheet where the value should be set.
- $status : mixed
-
The status code that should be set in the spreadsheet if "code" is present in the status formats.
- $statusName : mixed
-
The status name that should be set in the spreadsheet if "name" is present in the status formats.
- $statusDescriptions : mixed
-
The status descriptions that should be set in the spreadsheet if "severity" is present in the status formats.
setTimestampFormatValues()
Sets the values in the spreadsheet based on the timestamp format.
private
setTimestampFormatValues(string &$col, int $cell, DateTime $time) : void
It iterates over the timestamp formats stored in the $this->timestampFormat array. For each format, it sets the corresponding value in the spreadsheet. If the format is 'local_iso', it sets the timezone to the client's timezone and formats the time as an ISO 8601 string. If the format is 'utc_iso', it sets the timezone to UTC and formats the time as an ISO 8601 string. If the format is 'epoch', it sets the value to the Unix timestamp of the time.
Parameters
- $col : string
-
The column in the spreadsheet where the value should be set.
- $cell : int
-
The row in the spreadsheet where the value should be set.
- $time : DateTime
-
The time that should be formatted and set in the spreadsheet.
Tags
setValueBasedOnDataType()
Sets a value in the spreadsheet based on its data type.
private
setValueBasedOnDataType(string &$col, int $cell, string $dataType, mixed $value) : void
It takes a column, a cell, a data type, and a value as parameters. It converts the value to the appropriate data type using the convertValue method, and then sets the converted value in the specified cell of the spreadsheet. After setting the value, it increments the column.
Parameters
- $col : string
-
Reference to the column in the spreadsheet where the value should be set.
- $cell : int
-
The row in the spreadsheet where the value should be set.
- $dataType : string
-
The data type of the value.
- $value : mixed
-
The value to be set in the spreadsheet.