Skip to content

Commit

Permalink
Option 'Dezimal Separator' hinzugefügt (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunnyka98 authored Aug 26, 2024
1 parent 632fea8 commit bdb701b
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 47 deletions.
21 changes: 18 additions & 3 deletions MailReport/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@
"moduleID": "{375EAF21-35EF-4BC4-83B3-C780FD8BD88A}"
},
{
"type": "Select",
"type": "SelectVariable",
"requireLogging": 1,
"name": "Variable",
"caption": "Aggregated Variable",
"options": []
"caption": "Aggregated Variable"
},
{
"type": "Select",
"caption": "Decimal Separator",
"name": "DecimalSeparator",
"options": [
{
"caption": "Comma",
"value": ","
},
{
"caption": "Dot",
"value": "."
}
]
},
{
"type": "Select",
Expand Down
5 changes: 4 additions & 1 deletion MailReport/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"December": "Dezember",
"Mail Report active": "Mail Report aktiv",
"None": "Keine",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/mailreport/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/mailreport/"
"Decimal Separator": "Dezimaltrennzeichen",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/mailreport/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/mailreport/",
"Dot": "Punkt",
"Comma": "Komma"
}
}
}
45 changes: 9 additions & 36 deletions MailReport/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function Create()
$this->RegisterPropertyInteger('SMTP', 0);
$this->RegisterPropertyInteger('Variable', 0);
$this->RegisterPropertyInteger('Interval', 1);
$this->RegisterPropertyString('DecimalSeparator', ',');

$this->RegisterPropertyInteger('ArchiveControlID', IPS_GetInstanceListByModuleID(ARCHIVE_CONTROL_MODULE_ID)[0]);
$this->RegisterVariableBoolean('Active', $this->Translate('Mail Report active'), '~Switch');
Expand Down Expand Up @@ -49,36 +50,6 @@ public function ApplyChanges()
}
}

public function GetConfigurationForm()
{
$form = json_decode(file_get_contents(__DIR__ . '/form.json'));

$variableIndex = $this->GetElementIndexByName('Variable');

$variableOptions = [['label' => $this->Translate('None'), 'value' => 0]];
foreach (AC_GetAggregationVariables($this->ReadPropertyInteger('ArchiveControlID'), false) as $variable) {
if ($variable['AggregationActive'] && IPS_ObjectExists($variable['VariableID'])) {
$variableOptions[] = ['label' => $this->CreateLabel($variable['VariableID']), 'value' => $variable['VariableID']];
}
}

$compare = function ($a, $b)
{
if ($a['label'] == $b['label']) {
return 0;
} elseif ($a['label'] == $this->Translate('None')) {
return -1;
} elseif ($b['label'] == $this->Translate('None')) {
return 1;
} else {
return strcmp($a['label'], $b['label']);
}
};
usort($variableOptions, $compare);
$form->elements[$variableIndex]->options = $variableOptions;
return json_encode($form);
}

public function RequestAction($Ident, $Value)
{
switch ($Ident) {
Expand Down Expand Up @@ -128,14 +99,16 @@ public function SendInfo()
$this->GetAggregationEnd(),
0
);
$decimalSeparator = $this->ReadPropertyString('DecimalSeparator');
$csvSeparator = $decimalSeparator == ',' ? ';' : ',';
for ($i = count($aggregatedValues) - 1; $i >= 0; $i--) {
$value = $aggregatedValues[$i];
$dataString = date('j.n.Y H:i:s', $value['TimeStamp']) . ',' .
number_format($value['Avg'], $digits, '.', '') . ',' .
date('j.n.Y H:i:s', $value['MinTime']) . ',' .
number_format($value['Min'], $digits, '.', '') . ',' .
date('j.n.Y H:i:s', $value['MaxTime']) . ',' .
number_format($value['Max'], $digits, '.', '') . "\n";
$dataString = date('j.n.Y H:i:s', $value['TimeStamp']) . $csvSeparator .
number_format($value['Avg'], $digits, $decimalSeparator, '') . $csvSeparator .
date('j.n.Y H:i:s', $value['MinTime']) . $csvSeparator .
number_format($value['Min'], $digits, $decimalSeparator, '') . $csvSeparator .
date('j.n.Y H:i:s', $value['MaxTime']) . $csvSeparator .
number_format($value['Max'], $digits, $decimalSeparator, '') . "\n";
fwrite($file, $dataString);
}

Expand Down
15 changes: 15 additions & 0 deletions PDFReportEnergy/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
"name": "EnergyType",
"value": "Gas"
},
{
"type": "Select",
"caption": "Decimal Separator",
"name": "DecimalSeparator",
"options": [
{
"caption": "Comma",
"value": ","
},
{
"caption": "Dot",
"value": "."
}
]
},
{
"type": "SelectVariable",
"caption": "Outside temperature variable (optional)",
Expand Down
5 changes: 4 additions & 1 deletion PDFReportEnergy/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"Last year you used up %s.": "Im Vorjahr hatten sie einen Verbrauch von %s.",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/pdfreport-energy/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/pdfreport-energie/",
"PDFReportEnergy": "PDFReportEnergie",
"Report (PDF, Energy)": "Report (PDF, Energie)"
"Report (PDF, Energy)": "Report (PDF, Energie)",
"Decimal Separator Comma": "Dezimaltrennzeichen",
"Dot": "Punkt",
"Comma": "Komma"
}
}
}
11 changes: 11 additions & 0 deletions PDFReportEnergy/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function Create()
$this->RegisterPropertyInteger('TemperatureID', 1);
$this->RegisterPropertyInteger('PredictionID', 1);
$this->RegisterPropertyInteger('CO2Type', -1);
$this->RegisterPropertyString('DecimalSeparator', ',');

$this->RegisterMediaDocument('ReportPDF', $this->Translate('Report (PDF)'), 'pdf');
}
Expand Down Expand Up @@ -324,6 +325,16 @@ private function FetchData()
$consumption = GetValueFormattedEx($counterID, $consumption);
}

//Format all values if with comma
if ($this->ReadPropertyString('DecimalSeparator') == ',') {
$consumption = str_replace('.', ',', $consumption);
$consumptionLastYear = str_replace('.', ',', $consumptionLastYear);
$avgTemp = str_replace('.', ',', $avgTemp);
$prediction = str_replace('.', ',', $prediction);
$percent = str_replace('.', ',', $percent);
$co2 = str_replace('.', ',', '' . $co2);
}

$data = [
'month' => $month,
'consumption' => $consumption,
Expand Down
15 changes: 15 additions & 0 deletions PDFReportMulti/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@
}
]
},
{
"type": "Select",
"caption": "Decimal Separator",
"name": "DecimalSeparator",
"options": [
{
"caption": "Comma",
"value": ","
},
{
"caption": "Dot",
"value": "."
}
]
},
{
"name": "DataAggregation",
"type": "Select",
Expand Down
5 changes: 4 additions & 1 deletion PDFReportMulti/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"Skip current unfinished dataset": "Überspringe den aktuellen unvollständigen Datensatz",
"Generate report now!": "Jetzt Report generieren!",
"Done! Please open the media file beneath this instance!": "Fertig! Bitte öffnen Sie die Mediendatei unterhalb der Instanz!",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/pdfreport-multi/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/pdfreport-multi/"
"Decimal Separator Comma": "Dezimaltrennzeichen Komma",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/pdfreport-multi/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/pdfreport-multi/",
"Dot": "Punkt",
"Comma": "Komma"
}
}
}
4 changes: 3 additions & 1 deletion PDFReportMulti/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function Create()
$this->RegisterPropertyInteger('DataAggregation', 1);
$this->RegisterPropertyInteger('DataCount', 7);
$this->RegisterPropertyBoolean('DataSkipFirst', true);
$this->RegisterPropertyString('DecimalSeparator', ',');

$this->RegisterMediaDocument('ReportPDF', $this->Translate('Report (PDF)'), 'pdf');
}
Expand Down Expand Up @@ -196,7 +197,8 @@ private function GenerateHTMLRows()
foreach ($json as $data) {
$rows .= '<td style="text-align: center;">';
if (isset($values[$data['VariableID']])) {
$rows .= GetValueFormattedEx($data['VariableID'], $values[$data['VariableID']]);
$value = GetValueFormattedEx($data['VariableID'], $values[$data['VariableID']]);
$rows .= $this->ReadPropertyString('DecimalSeparator') == ',' ? str_replace('.', ',', $value) : $value;
}
$rows .= '</td>';
}
Expand Down
15 changes: 15 additions & 0 deletions PDFReportSingle/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
"name": "DataVariable",
"caption": "Data Source"
},
{
"type": "Select",
"caption": "Decimal Separator",
"name": "DecimalSeparator",
"options": [
{
"caption": "Comma",
"value": ","
},
{
"caption": "Dot",
"value": "."
}
]
},
{
"name": "DataAggregation",
"type": "Select",
Expand Down
5 changes: 4 additions & 1 deletion PDFReportSingle/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
"Data Limit (Min)": "Toleranz (Min)",
"Data Limit (Max)": "Toleranz (Max)",
"Generate report now!": "Jetzt Report generieren!",
"Decimal Separator Comma": "Dezimaltrennzeichen Komma",
"Done! Please open the media file beneath this instance!": "Fertig! Bitte öffnen Sie die Mediendatei unterhalb der Instanz!",
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/pdfreport-single/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/pdfreport-single/"
"https://www.symcon.de/en/service/documentation/module-reference/symconreport/pdfreport-single/": "https://www.symcon.de/de/service/dokumentation/modulreferenz/symconreport/pdfreport-single/",
"Dot": "Punkt",
"Comma": "Komma"
}
}
}
8 changes: 7 additions & 1 deletion PDFReportSingle/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function Create()
$this->RegisterPropertyString('ReportTitle', '');
$this->RegisterPropertyString('ReportFooter', '');
$this->RegisterPropertyInteger('DataVariable', 0);
$this->RegisterPropertyString('DecimalSeparator', ',');
$this->RegisterPropertyInteger('DataAggregation', 1);
$this->RegisterPropertyInteger('DataCount', 7);
$this->RegisterPropertyBoolean('DataSkipFirst', true);
Expand Down Expand Up @@ -198,14 +199,19 @@ private function GenerateHTMLHeader()
private function GenerateHTMLRows()
{
$variableID = $this->ReadPropertyInteger('DataVariable');

$rows = '';
foreach ($this->FetchData() as $data) {
$date = date($this->GetDateTimeFormatForAggreagtion(), $data['TimeStamp']);
$min = GetValueFormattedEx($variableID, $data['Min']);
$max = GetValueFormattedEx($variableID, $data['Max']);
$avg = GetValueFormattedEx($variableID, $data['Avg']);

if ($this->ReadPropertyString('DecimalSeparator') == ',') {
$min = str_replace('.', ',', $min);
$max = str_replace('.', ',', $max);
$avg = str_replace('.', ',', $avg);
}

$status = $this->CheckDataLimit($data['Min'], $data['Max']);

$rows .= <<<EOT
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"name": "Report Modules",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "5.5"
"version": "6.0"
},
"version": "1.4.2",
"version": "1.4.3",
"build": 0,
"date": 0
}

0 comments on commit bdb701b

Please sign in to comment.