2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 11:26:55 +00:00

57_CALVIEW.pm: -new function age calculation

-new reading for description of terms


git-svn-id: https://svn.fhem.de/fhem/trunk@12900 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
chris1284 2016-12-28 17:19:32 +00:00
parent 138a9b1f10
commit 9e41bc00b5

View File

@ -20,10 +20,12 @@ sub CALVIEW_Initialize($)
$hash->{SetFn} = "CALVIEW_Set"; $hash->{SetFn} = "CALVIEW_Set";
$hash->{NotifyFn} = "CALVIEW_Notify"; $hash->{NotifyFn} = "CALVIEW_Notify";
$hash->{AttrList} = "disable:0,1 " . $hash->{AttrList} = "disable:0,1 " .
"do_not_notify:1,0 " . "do_not_notify:1,0 " .
"isbirthday:1,0 " .
"maxreadings " . "maxreadings " .
"modes:next ". "modes:next ".
"oldStyledReadings:1,0 " . "oldStyledReadings:1,0 " .
"yobfield:_location,_description " .
$readingFnAttributes; $readingFnAttributes;
} }
sub CALVIEW_Define($$){ sub CALVIEW_Define($$){
@ -102,77 +104,89 @@ sub CALVIEW_GetUpdate($){
#replace the "\," with "," #replace the "\," with ","
if(length($item->[1]) > 0){ $item->[1] =~ s/\\,/,/g; } if(length($item->[1]) > 0){ $item->[1] =~ s/\\,/,/g; }
if( defined($item->[4]) && length($item->[4]) > 0){ $item->[4] =~ s/\\,/,/g; } if( defined($item->[4]) && length($item->[4]) > 0){ $item->[4] =~ s/\\,/,/g; }
if( defined($item->[5]) && length($item->[5]) > 0){ $item->[5] =~ s/\\,/,/g; }
push @termineNew,{ push @termineNew,{
bdate => $tempstart[0], bdate => $tempstart[0],
btime => $tempstart[1], btime => $tempstart[1],
summary => $item->[1], summary => $item->[1],
source => $item->[3], source => $item->[3],
location => $item->[4], location => $item->[4],
description => $item->[5],
edate => $tempend[0], edate => $tempend[0],
etime => $tempend[1], etime => $tempend[1],
btimestamp => $bts[0], btimestamp => $bts[0],
mode => $item->[5]}; } mode => $item->[6]};
}
my $todaycounter = 1; my $todaycounter = 1;
my $tomorrowcounter = 1; my $tomorrowcounter = 1;
#my $runningcounter = 1;
my $readingstyle = AttrVal($name,"oldStyledReadings",0); my $readingstyle = AttrVal($name,"oldStyledReadings",0);
my $isbday = AttrVal($name,"isbirthday",0);
my $yobfield = AttrVal($name,"yobfield","_description");
# sort the array by btimestamp # sort the array by btimestamp
my @sdata = map $_->[0], my @sdata = map $_->[0],
sort { $a->[1][0] <=> $b->[1][0] } sort { $a->[1][0] <=> $b->[1][0] }
map [$_, [$_->{btimestamp}]], @termineNew; map [$_, [$_->{btimestamp}]], @termineNew;
if($readingstyle == 0){ if($readingstyle == 0){
for my $termin (@sdata){ #termin als reading term_[3steliger counter] my $age = 0;
my @termyear;
for my $termin (@sdata){
#alter berechnen wenn attribut gesetzt ist. alter wird aus "jahr des termins" - "geburtsjahr aus location oder description" errechnet
if($isbday == 1 ){
@termyear = split(/\./,$termin->{bdate});
if($yobfield eq "_location" && length($termin->{location}) > 0 && $termin->{location}=~ /^\d+$/ ) { $age = $termyear[2] - ($termin->{location});}
elsif($yobfield eq "_description" && length($termin->{description}) > 0 && $termin->{description}=~ /^\d+$/) { $age = $termyear[2] - ($termin->{description});}
else {$age = "no calculation passible"}
}
#standard reading t_[3steliger counter] anlegen
if($isbday == 1 ){ readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_age", $age);}
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdate", $termin->{bdate}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_bdate", $termin->{bdate});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_btime", $termin->{btime}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_btime", $termin->{btime});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_source", $termin->{source}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_source", $termin->{source});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_location", $termin->{location}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_location", $termin->{location});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_description", $termin->{description});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edate", $termin->{edate}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_edate", $termin->{edate});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_etime", $termin->{etime}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_etime", $termin->{etime});
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_mode", $termin->{mode}); readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_mode", $termin->{mode});
last if ($counter++ == $max); #wenn termin heute today readings anlegen
};
for my $termin (@sdata){ #check ob temin heute
#if ($date eq $termin->{bdate} && $termin->{mode} ne "modeStart"){
if ($date eq $termin->{bdate} ){ if ($date eq $termin->{bdate} ){
if($isbday == 1 ){ readingsBulkUpdate($hash, "today_".sprintf ('%03d', $counter)."_age", $age);}
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_bdate", "heute"); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_bdate", "heute");
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_btime", $termin->{btime});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_source", $termin->{source}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_source", $termin->{source});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_location", $termin->{location}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_location", $termin->{location});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_description", $termin->{description});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edate", $termin->{edate}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_edate", $termin->{edate});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_etime", $termin->{etime});
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode}); readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
$todaycounter ++;} $todaycounter ++;
#elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){ }
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute"); #wenn termin morgen tomorrow readings anlegen
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_btime", $termin->{btime});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_summary", $termin->{summary});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_source", $termin->{source});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_location", $termin->{location});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_edate", $termin->{edate});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_etime", $termin->{etime});
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_mode", $termin->{mode});
# $runningcounter ++;}
#check ob termin morgen
elsif ($datenext eq $termin->{bdate}){ elsif ($datenext eq $termin->{bdate}){
if($isbday == 1 ){readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $counter)."_age", $age);}
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen"); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_bdate", "morgen");
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", $termin->{btime}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_btime", $termin->{btime});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_source", $termin->{source}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_source", $termin->{source});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_location", $termin->{location}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_location", $termin->{location});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_description", $termin->{description});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edate", $termin->{edate}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_edate", $termin->{edate});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_etime", $termin->{etime}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_etime", $termin->{etime});
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode}); readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
$tomorrowcounter++;} $tomorrowcounter++;
}
last if ($counter++ == $max);
};
for my $termin (@sdata){
#check ob temin heute
}; };
#readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1)." ts: ".($runningcounter-1));
readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1)); readingsBulkUpdate($hash, "state", "t: ".($counter-1)." td: ".($todaycounter-1)." tm: ".($tomorrowcounter-1));
readingsBulkUpdate($hash, "c-term", $counter-1); readingsBulkUpdate($hash, "c-term", $counter-1);
readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1); readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
readingsBulkUpdate($hash, "c-today", $todaycounter-1); readingsBulkUpdate($hash, "c-today", $todaycounter-1);
#readingsBulkUpdate($hash, "c-started", $runningcounter-1);
} }
else{ else{
my $lastreadingname = ""; my $lastreadingname = "";
@ -199,28 +213,25 @@ sub getsummery($)
my ($hash) = @_; my ($hash) = @_;
my @terminliste ; my @terminliste ;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
# my $calendername = $hash->{KALENDER};
my @calendernamen = split( ",", $hash->{KALENDER}); my @calendernamen = split( ",", $hash->{KALENDER});
my $modi = $attr{$name}{modes}; my $modi = $attr{$name}{modes};
my @modes = split(/,/,$modi); my @modes = split(/,/,$modi);
foreach my $calendername (@calendernamen){ foreach my $calendername (@calendernamen){
#foreach my $mode (@modes){
my $all = CallFn($calendername, "GetFn", $defs{$calendername},(" ","uid", "next")); my $all = CallFn($calendername, "GetFn", $defs{$calendername},(" ","uid", "next"));
my @termine=split(/\n/,$all); my @termine=split(/\n/,$all);
foreach my $uid (@termine){ foreach my $uid (@termine){
#my @uid=split(/\s+/,$termin);
#für jedes event die einzelnen infos holen #für jedes event die einzelnen infos holen
my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid)); my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid));
my @starts = split(/\n/,$tmpstarts); my @starts = split(/\n/,$tmpstarts);
#my $tmptexts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","text", $uid[0]));
#my @texts = split(/\n/,$tmptexts);
my $tmpends = CallFn($calendername, "GetFn", $defs{$calendername},(" ","end", $uid)); my $tmpends = CallFn($calendername, "GetFn", $defs{$calendername},(" ","end", $uid));
my @ends = split(/\n/,$tmpends); my @ends = split(/\n/,$tmpends);
my $tmpsummarys = CallFn($calendername, "GetFn", $defs{$calendername},(" ","summary", $uid)); my $tmpsummarys = CallFn($calendername, "GetFn", $defs{$calendername},(" ","summary", $uid));
my @summarys = split(/\n/,$tmpsummarys); my @summarys = split(/\n/,$tmpsummarys);
my $tmplocations = CallFn($calendername, "GetFn", $defs{$calendername},(" ","location", $uid)); my $tmplocations = CallFn($calendername, "GetFn", $defs{$calendername},(" ","location", $uid));
my @locations = split(/\n/,$tmplocations); my @locations = split(/\n/,$tmplocations);
my $tmpdescriptions = CallFn($calendername, "GetFn", $defs{$calendername},(" ","description", $uid));
my @description = split(/\n/,$tmpdescriptions);
for(my $i = 1; $i <= (scalar(@starts)); $i++) { for(my $i = 1; $i <= (scalar(@starts)); $i++) {
my $internali = $i-1; my $internali = $i-1;
@ -228,10 +239,10 @@ sub getsummery($)
my $termintext = $summarys[$internali]; my $termintext = $summarys[$internali];
my $terminend = $ends[$internali]; my $terminend = $ends[$internali];
my $terminort = $locations[$internali]; my $terminort = $locations[$internali];
push(@terminliste, [$terminstart, $termintext, $terminend, $calendername, $terminort, "next"]); my $termindescription = $description[$internali];
push(@terminliste, [$terminstart, $termintext, $terminend, $calendername, $terminort, $termindescription, "next"]);
} }
}; };
#};
}; };
return @terminliste; return @terminliste;
} }
@ -267,9 +278,10 @@ sub CALVIEW_Notify($$)
<ul>This module creates a device with deadlines based on calendar-devices of the 57_Calendar.pm module. You need to install the perl-modul Date::Parse!</ul> <ul>This module creates a device with deadlines based on calendar-devices of the 57_Calendar.pm module. You need to install the perl-modul Date::Parse!</ul>
<ul>Actually the module supports only the "get <> next" function of the CALENDAR-Modul.</ul> <ul>Actually the module supports only the "get <> next" function of the CALENDAR-Modul.</ul>
<b>Define</b> <b>Define</b>
<ul><code>define &lt;Name&gt; CALVIEW &lt;calendarname(s) separate with ','&gt; &lt;0 next; 1 next 2 for next ; 3 for next ; next &gt; &lt;updateintervall in sec (default 43200)&gt;</code></ul> <ul><code>define &lt;Name&gt; CALVIEW &lt;calendarname(s) separate with ','&gt; &lt;next&gt; &lt;updateintervall in sec (default 43200)&gt;</code></ul>
<ul><code>define myView CALVIEW Googlecalendar next</code></ul> <ul><code>define myView CALVIEW Googlecalendar next</code></ul>
<ul><code>define myView CALVIEW Googlecalendar,holiday next 900</code></ul> <ul><code>define myView CALVIEW Googlecalendar,holiday next 900</code></ul>
<ul>- setting the update interval is not needed normally because every calendar update triggers a caview update</ul>
<a name="CALVIEW set"></a> <a name="CALVIEW set"></a>
<b>Set</b> <b>Set</b>
<ul><code>set &lt;Name&gt; update</code></ul> <ul><code>set &lt;Name&gt; update</code></ul>
@ -280,6 +292,10 @@ sub CALVIEW_Notify($$)
0 / not set - internal notify function enabled (default) <br> 0 / not set - internal notify function enabled (default) <br>
1 - disable the internal notify-function of CALVIEW wich is triggered when one of the given CALENDAR devices has updated 1 - disable the internal notify-function of CALVIEW wich is triggered when one of the given CALENDAR devices has updated
</li><br> </li><br>
<li>isbirthday<br>
0 / not set - no age calculation (default) <br>
1 - age calculation active. The module calculates the age with year given in description or location (see att yobfield).
</li><br>
<li>maxreadings<br> <li>maxreadings<br>
defines the number of max term as readings defines the number of max term as readings
</li><br> </li><br>
@ -287,8 +303,12 @@ sub CALVIEW_Notify($$)
here the CALENDAR modes can be selected , to be displayed in the view here the CALENDAR modes can be selected , to be displayed in the view
</li><br> </li><br>
<li>oldStyledReadings<br> <li>oldStyledReadings<br>
1 readings look like "2015.06.21-00:00" with value "Start of Summer" <br> 0 the default style of readings <br>
0 the default style of readings 1 readings look like "2015.06.21-00:00" with value "Start of Summer"
</li><br>
<li>yobfield<br>
_description - (default) year of birth will be read from term description <br>
_location - year of birth will be read from term location
</li><br> </li><br>
=end html =end html
@ -299,9 +319,10 @@ sub CALVIEW_Notify($$)
<ul>Dieses Modul erstellt ein Device welches als Readings Termine eines oder mehrere Kalender(s), basierend auf dem 57_Calendar.pm Modul, besitzt. Ihr müsst das Perl-Modul Date::Parse installieren!</ul> <ul>Dieses Modul erstellt ein Device welches als Readings Termine eines oder mehrere Kalender(s), basierend auf dem 57_Calendar.pm Modul, besitzt. Ihr müsst das Perl-Modul Date::Parse installieren!</ul>
<ul>Aktuell wird nur die "get <> next" Funktion vom CALENDAR untertstützt.</ul> <ul>Aktuell wird nur die "get <> next" Funktion vom CALENDAR untertstützt.</ul>
<b>Define</b> <b>Define</b>
<ul><code>define &lt;Name&gt; CALVIEW &lt;Kalendername(n) getrennt durch ','&gt; &lt;0 next; 1 next 2 for next ; 3 for next ; next &gt; &lt;updateintervall in sek (default 43200)&gt;</code></ul> <ul><code>define &lt;Name&gt; CALVIEW &lt;Kalendername(n) getrennt durch ','&gt; &lt;next&gt; &lt;updateintervall in sek (default 43200)&gt;</code></ul>
<ul><code>define myView CALVIEW Googlekalender 1</code></ul> <ul><code>define myView CALVIEW Googlekalender next</code></ul>
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul> <ul><code>define myView CALVIEW Googlekalender,holiday next 900</code></ul>
<ul>- die Einstellung des Aktualisierungsintervalls wird normalerweise nicht benötigt, da jede Kalenderaktualisierung ein Caview-Update auslöst</ul>
<a name="CALVIEW set"></a> <a name="CALVIEW set"></a>
<b>Set</b> <b>Set</b>
<ul>update readings:</ul> <ul>update readings:</ul>
@ -312,15 +333,23 @@ sub CALVIEW_Notify($$)
0 / nicht gesetzt - aktiviert die interne Notify-Funktion (Standard) <br> 0 / nicht gesetzt - aktiviert die interne Notify-Funktion (Standard) <br>
1 - deaktiviert die interne Notify-Funktion welche ausgelöst wird wenn sich einer der Kalender aktualisiert hat 1 - deaktiviert die interne Notify-Funktion welche ausgelöst wird wenn sich einer der Kalender aktualisiert hat
</li><br> </li><br>
<li>isbirthday<br>
0 / nicht gesetzt - keine Altersberechnung (Standard) <br>
1 - aktiviert die Altersberechnung im Modul. Das Alter wird aus der in der Terminbeschreibung (description) angegebenen Jahreszahl (Geburtsjahr) berechnet.
</li><br>
<li>maxreadings<br> <li>maxreadings<br>
bestimmt die Anzahl der Termine als Readings bestimmt die Anzahl der Termine als Readings
</li><br> </li><br>
<li>modes<br> <li>modes<br>
hier können die CALENDAR modi gewählt werden, welche in der View angezeigt werden sollen hier können die CALENDAR modi gewählt werden, welche in der View angezeigt werden sollen
</li><br> </li><br>
<li>oldStyledReadings<br> <li>oldStyledReadings<br>
1 aktiviert die Termindarstellung im "alten" Format "2015.06.21-00:00" mit Wert "Start of Summer" <br> 0 die Standarddarstellung für Readings <br>
0 aktivert die Standarddarstellung bdate, btime, usw 1 aktiviert die Termindarstellung im "alten" Format "2015.06.21-00:00" mit Wert "Start of Summer"
</li><br>
<li>yobfield<br>
_description - (der Standard) Geburtsjahr wird aus der Terminbechreibung gelesen <br>
_location - Geburtsjahr wird aus dem Terminort gelesen
</li><br> </li><br>
=end html_DE =end html_DE
=cut =cut