mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-04 05:16:45 +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:
parent
138a9b1f10
commit
9e41bc00b5
@ -20,10 +20,12 @@ sub CALVIEW_Initialize($)
|
||||
$hash->{SetFn} = "CALVIEW_Set";
|
||||
$hash->{NotifyFn} = "CALVIEW_Notify";
|
||||
$hash->{AttrList} = "disable:0,1 " .
|
||||
"do_not_notify:1,0 " .
|
||||
"do_not_notify:1,0 " .
|
||||
"isbirthday:1,0 " .
|
||||
"maxreadings " .
|
||||
"modes:next ".
|
||||
"oldStyledReadings:1,0 " .
|
||||
"yobfield:_location,_description " .
|
||||
$readingFnAttributes;
|
||||
}
|
||||
sub CALVIEW_Define($$){
|
||||
@ -102,77 +104,89 @@ sub CALVIEW_GetUpdate($){
|
||||
#replace the "\," with ","
|
||||
if(length($item->[1]) > 0){ $item->[1] =~ 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,{
|
||||
bdate => $tempstart[0],
|
||||
btime => $tempstart[1],
|
||||
summary => $item->[1],
|
||||
source => $item->[3],
|
||||
location => $item->[4],
|
||||
description => $item->[5],
|
||||
edate => $tempend[0],
|
||||
etime => $tempend[1],
|
||||
btimestamp => $bts[0],
|
||||
mode => $item->[5]}; }
|
||||
mode => $item->[6]};
|
||||
}
|
||||
my $todaycounter = 1;
|
||||
my $tomorrowcounter = 1;
|
||||
#my $runningcounter = 1;
|
||||
my $readingstyle = AttrVal($name,"oldStyledReadings",0);
|
||||
my $isbday = AttrVal($name,"isbirthday",0);
|
||||
my $yobfield = AttrVal($name,"yobfield","_description");
|
||||
# sort the array by btimestamp
|
||||
my @sdata = map $_->[0],
|
||||
sort { $a->[1][0] <=> $b->[1][0] }
|
||||
map [$_, [$_->{btimestamp}]], @termineNew;
|
||||
map [$_, [$_->{btimestamp}]], @termineNew;
|
||||
|
||||
if($readingstyle == 0){
|
||||
for my $termin (@sdata){ #termin als reading term_[3steliger counter]
|
||||
if($readingstyle == 0){
|
||||
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)."_btime", $termin->{btime});
|
||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_summary", $termin->{summary});
|
||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_source", $termin->{source});
|
||||
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)."_etime", $termin->{etime});
|
||||
readingsBulkUpdate($hash, "t_".sprintf ('%03d', $counter)."_mode", $termin->{mode});
|
||||
last if ($counter++ == $max);
|
||||
};
|
||||
for my $termin (@sdata){ #check ob temin heute
|
||||
#if ($date eq $termin->{bdate} && $termin->{mode} ne "modeStart"){
|
||||
#wenn termin heute today readings anlegen
|
||||
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)."_btime", $termin->{btime});
|
||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_summary", $termin->{summary});
|
||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_source", $termin->{source});
|
||||
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)."_etime", $termin->{etime});
|
||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
|
||||
$todaycounter ++;}
|
||||
#elsif ($date eq $termin->{bdate} && $termin->{mode} eq "modeStart"){
|
||||
# readingsBulkUpdate($hash, "started_".sprintf ('%03d', $runningcounter)."_bdate", "heute");
|
||||
# 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
|
||||
readingsBulkUpdate($hash, "today_".sprintf ('%03d', $todaycounter)."_mode", $termin->{mode});
|
||||
$todaycounter ++;
|
||||
}
|
||||
#wenn termin morgen tomorrow readings anlegen
|
||||
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)."_btime", $termin->{btime});
|
||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_summary", $termin->{summary});
|
||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_source", $termin->{source});
|
||||
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)."_etime", $termin->{etime});
|
||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
|
||||
$tomorrowcounter++;}
|
||||
readingsBulkUpdate($hash, "tomorrow_".sprintf ('%03d', $tomorrowcounter)."_mode", $termin->{mode});
|
||||
$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, "c-term", $counter-1);
|
||||
readingsBulkUpdate($hash, "c-tomorrow", $tomorrowcounter-1);
|
||||
readingsBulkUpdate($hash, "c-today", $todaycounter-1);
|
||||
#readingsBulkUpdate($hash, "c-started", $runningcounter-1);
|
||||
}
|
||||
else{
|
||||
my $lastreadingname = "";
|
||||
@ -199,28 +213,25 @@ sub getsummery($)
|
||||
my ($hash) = @_;
|
||||
my @terminliste ;
|
||||
my $name = $hash->{NAME};
|
||||
# my $calendername = $hash->{KALENDER};
|
||||
my @calendernamen = split( ",", $hash->{KALENDER});
|
||||
my $modi = $attr{$name}{modes};
|
||||
my @modes = split(/,/,$modi);
|
||||
foreach my $calendername (@calendernamen){
|
||||
#foreach my $mode (@modes){
|
||||
my $all = CallFn($calendername, "GetFn", $defs{$calendername},(" ","uid", "next"));
|
||||
my @termine=split(/\n/,$all);
|
||||
|
||||
foreach my $uid (@termine){
|
||||
#my @uid=split(/\s+/,$termin);
|
||||
#für jedes event die einzelnen infos holen
|
||||
my $tmpstarts = CallFn($calendername, "GetFn", $defs{$calendername},(" ","start", $uid));
|
||||
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 @ends = split(/\n/,$tmpends);
|
||||
my $tmpsummarys = CallFn($calendername, "GetFn", $defs{$calendername},(" ","summary", $uid));
|
||||
my @summarys = split(/\n/,$tmpsummarys);
|
||||
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++) {
|
||||
my $internali = $i-1;
|
||||
@ -228,10 +239,10 @@ sub getsummery($)
|
||||
my $termintext = $summarys[$internali];
|
||||
my $terminend = $ends[$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;
|
||||
}
|
||||
@ -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>Actually the module supports only the "get <> next" function of the CALENDAR-Modul.</ul>
|
||||
<b>Define</b>
|
||||
<ul><code>define <Name> CALVIEW <calendarname(s) separate with ','> <0 next; 1 next 2 for next ; 3 for next ; next > <updateintervall in sec (default 43200)></code></ul>
|
||||
<ul><code>define <Name> CALVIEW <calendarname(s) separate with ','> <next> <updateintervall in sec (default 43200)></code></ul>
|
||||
<ul><code>define myView CALVIEW Googlecalendar next</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>
|
||||
<b>Set</b>
|
||||
<ul><code>set <Name> update</code></ul>
|
||||
@ -280,6 +292,10 @@ sub CALVIEW_Notify($$)
|
||||
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
|
||||
</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>
|
||||
defines the number of max term as readings
|
||||
</li><br>
|
||||
@ -287,8 +303,12 @@ sub CALVIEW_Notify($$)
|
||||
here the CALENDAR modes can be selected , to be displayed in the view
|
||||
</li><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
|
||||
0 the default style of readings <br>
|
||||
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>
|
||||
=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>Aktuell wird nur die "get <> next" Funktion vom CALENDAR untertstützt.</ul>
|
||||
<b>Define</b>
|
||||
<ul><code>define <Name> CALVIEW <Kalendername(n) getrennt durch ','> <0 next; 1 next 2 for next ; 3 for next ; next > <updateintervall in sek (default 43200)></code></ul>
|
||||
<ul><code>define myView CALVIEW Googlekalender 1</code></ul>
|
||||
<ul><code>define myView CALVIEW Googlekalender,holiday 1 900</code></ul>
|
||||
<ul><code>define <Name> CALVIEW <Kalendername(n) getrennt durch ','> <next> <updateintervall in sek (default 43200)></code></ul>
|
||||
<ul><code>define myView CALVIEW Googlekalender next</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>
|
||||
<b>Set</b>
|
||||
<ul>update readings:</ul>
|
||||
@ -312,15 +333,23 @@ sub CALVIEW_Notify($$)
|
||||
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
|
||||
</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>
|
||||
bestimmt die Anzahl der Termine als Readings
|
||||
</li><br>
|
||||
<li>modes<br>
|
||||
hier können die CALENDAR modi gewählt werden, welche in der View angezeigt werden sollen
|
||||
</li><br>
|
||||
<li>oldStyledReadings<br>
|
||||
1 aktiviert die Termindarstellung im "alten" Format "2015.06.21-00:00" mit Wert "Start of Summer" <br>
|
||||
0 aktivert die Standarddarstellung bdate, btime, usw
|
||||
<li>oldStyledReadings<br>
|
||||
0 die Standarddarstellung für Readings <br>
|
||||
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>
|
||||
=end html_DE
|
||||
=cut
|
Loading…
x
Reference in New Issue
Block a user