cleaned TODO section

master
Fabien Benetou 14 years ago committed by utopiah
parent b2f4a2c394
commit 47be424726
  1. 156
      cookbook/memory_management.php

@ -2,63 +2,97 @@
/*
Mainly based on PageFeed by Daniel Roesler (diafygi)
http://www.pmwiki.org/wiki/Cookbook/PageFeed
conversation array imported from it
http://fabien.benetou.fr/Wiki/MemoryRecipe
TODO
support the regex syntax function calls as done in groupkeypages.php
clean unused code
test with the W3C that feeds generated are proper
update recipe date and name
transform the default call without argument
abstract the date checking function
and facilitate any pattern
addition, substraction, from list, from math func (e.g. mod), ...
note that if backward compability of files is important the 3 formers can remain empty
but ideally the local/config.php file should be modified
weighting for the composite function should read local PTV
if unsset then use the default behavior
make the content of description easier to change
create a variable at the head of the script
ignore empty date field
else Unix epoch bug
! behavior_recall seems to be the most general
modify it to accept negative -> support of preparation
modify it to accept exp as default -> support of memory-recipe
option to regenerate the fields
since a specified date or the first found markup
make sure to check against https://secure.wikimedia.org/wikipedia/en/wiki/Code_smell
*/
## Recipe version information
$RecipeInfo['MemoryManagement']['Version'] = '2011-06-20';
$RecipeInfo['MemoryManagement']['Version'] = '2011-06-28';
## Add action for pagefeed
SDV($HandleActions['memorizationMM'], 'MemorizationMM');
SDV($HandleActions['recallMM'], 'BehaviorRecallMM');
SDV($HandleActions['preparationMM'], 'PreparationMM');
function MemorizationMM($pagename, $auth = 'read'){
GenerateFeed("startrecall", "memorization.xml", false,
"Memorization", "Receive links as reminded to piece of information you want to consolidate as long-term."
);
}
function BehaviorRecallMM($pagename, $auth = 'read'){
GenerateFeed("recall", "recall.xml", false,
"BehaviorRecall", "Receive links as reminded to periodic behaviors you want to transform to habits."
/*
"Day $day recall for page $page started at $daterecall"
"$ScriptUrl/$cleaned_page_name#MemorizationDay$day"
FeedText($page,$page,"description")
*/
);
}
function PreparationMM($pagename, $auth = 'read'){
GenerateFeed("startprepare", "preparation.xml", true,
"Preparation", "Receive links as reminded for consequent events you want to prepare."
/*
"Day $day of preparation for page $page started at $dateprepare"
"$ScriptUrl/$page"
"This is to improve preparation of things you will have to produce. Also don't forget to improve those instructions to be more and more efficient!"
*/
);
}
function mod_pattern_test($day,$timeforward,$step){
$current_unix_day = strtotime(date("Y-m-d"));
$checkdate = strtotime(preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$day));
if ($timeforward)
return (($current_unix_day - $checkdate) % 7*(24*60*60) == 0);
return (($current_unix_day + $checkdate) % $step *(24*60*60) == 0);
}
function exponential_pattern_test($day,$timeforward){
$exponential_pattern = array(1,10,30,60,120,350,700,1500,3000,7000,15000,30000,100000); //exp
#consider comparing the value with its log
$current_unix_day = strtotime(date("Y-m-d"));
$checkdate = strtotime(preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$day));
if ($timeforward)
return in_array(($current_unix_day - $checkdate),$exponential_pattern);
return in_array(($checkdate - $current_unix_day),$exponential_pattern);
}
# from http://www.pmwiki.org/wiki/PmWiki/Functions
function FeedTextMM($pagename, &$page, $tag) {
$text = RetrieveAuthSection("ReadingNotes.GroupHeader","");
$content = MarkupToHTML($pagename, $text);
$text = RetrieveAuthSection($pagename, '##Chapter2');
// note that if this boundary if not found, the entire page is converted
$content .= MarkupToHTML($pagename, $text);
return "<$tag><![CDATA[$content]]></$tag>";
}
function MemorizationMM($pagename, $auth = 'read'){ GenerateFeed(title,description,feedfile,timedirection,pattern); }
function BehaviorRecallMM($pagename, $auth = 'read'){ GenerateFeed(); }
function PreparationMM($pagename, $auth = 'read'){ GenerateFeed(); }
## Create feed from page history
function GenerateFeed() {
function GenerateFeed($varname,$targetfile,$timeforward,$ChannelTitle,$ChannelDescription) {
# GenerateFeed(FeedTitle,FeedDescription,ItemTitle,ItemDescription,Feedfile,Timedirection,Pattern)
# consider defaults : exp, +, ...
global $FarmD, $WikiTitle, $ScriptUrl;
$feeds = "/pub/memoryfeeds/" ;
#### location of the resulting feed
$feedfile = $FarmD."/pub/memoryfeeds/recallfeed.xml"; #change to a pattern when support arguments
#$feedfile = $FarmD."/pub/memoryfeeds/memorizationfeed.xml"; #change to a pattern when support arguments
#$feedfile = $FarmD."/pub/memoryfeeds/preparationfeed.xml"; #change to a pattern when support arguments
$feedfile = $FarmD.$feeds.$targetfile;
if (!file_exists($feedfile)){
if (!touch($feedfile)){
print "Creation of the feed file fails, check write permissions for pmWiki and $feedfile.\nMake sure the target directory exists and with the right write permissions.";
@ -69,103 +103,73 @@ function GenerateFeed() {
$feed_oldcontent = file_get_contents($feedfile);
$feed_newcontent = '';
#### patterns to use
$exponential_pattern = array(1,10,30,60,120,350,700,1500,3000,7000,15000,30000,100000); //exp
$monthly_pattern = array(1,30,60,90,120,150,180,210,240,270,300); //mod30
$weekly_pattern = array(1,7,14,21,28,35,43,50,57,64,71,78,85,93,100,101,107,114,121,128,135,143,150,157,164,171,178,185,193,200); //mod7
$daily_pattern = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30); //mod1
#### variables to check value of
$varname='recall';
#$varname='startrecall';
#$varname='startprepare';
# this can probably be optimized by removing pages that are sure not to have varname
$pages = ListPages();
# 2 loops can be probably optimized since they are ordered by date
foreach ($pages as $page) {
if ( isset(PageTextVar($page,$varname)) ) {
$params = PageTextVar($page,$varname);
if ( isset($params) ) {
$params = explode(" ",$recall);
$patternrecall = $params[1];
#XXX make sure params does contain the date even when " " is not found
$daterecall = $params[0];
if ($daterecall=="") break;
switch($patternrecall){
case "daily": $datestorecall = $daily_pattern; break;
case "weekly": $datestorecall = $weekly_pattern; break;
case "monthly": $datestorecall = $monthly_pattern; break;
default: $datestorecall = $exponential_pattern; break;
case "daily": $pattern_matched = true; break;
case "weekly": $pattern_matched = mod_pattern_test($daterecall,$timeforward,7); break;
case "monthly": $pattern_matched = mod_pattern_test($daterecall,$timeforward,30); break;
default: $pattern_matched = exponential_pattern_test($daterecall,$timeforward); break;
}
$current_unix_day = strtotime(date("Y-m-d"));
$sign = "+";
# else $sign = "-";
foreach ($datestorecall as $day) {
$checkdate = strtotime((preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$daterecall)." $sign $day days"));
# print $daterecall . " + " . $day . " (" . $checkdate . ") == " . date("d/m/Y");
if ($checkdate==$current_unix_day)
{
if ($pattern_matched) {
# generate GUID
$item_GUID = $page.'_'.date("Y-m-d");
# if not present in file using a regex on the GUID
if (preg_match("/$item_GUID/",$feed_oldcontent) == 0)
{
# if not present in file (using a regex on the GUID)
if (preg_match("/$item_GUID/",$feed_oldcontent) == 0){
# generate date
$feed_newitemdate = date(DATE_RSS, time());
# transform line to XML format
$cleaned_page_name = str_replace(".","/",$page);
global $FmtV;
$pagecontent = FmtPageName($FmtV, $page);
# does this actually work?!
# does this actually work?! check FeedText() instead
$ItemTitle = "<title>Day $day recall for page $page started at $daterecall</title>";
$ItemLink = "<link>$ScriptUrl/$cleaned_page_name#BehaviorRecallDay$day</link>";
$ItemDescription = "<description>This is to improve behaviors you decided yourself were valuable. Also don't forget to improve those instructions to be more and more efficient!$pagecontent</description>";
/*
<title>Day $day recall for page $page started at $daterecall</title>
<link>$ScriptUrl/$cleaned_page_name#MemorizationDay$day</link>"
FeedText($page,$page,"description")
$ItemTitle = "Day $day recall for page $page started at $daterecall";
$ItemLink = "$ScriptUrl/$cleaned_page_name#BehaviorRecallDay$day";
$ItemDescription = "This is to improve behaviors you decided yourself were valuable. Also don't forget to improve those instructions to be more and more efficient! $pagecontent";
<title>Day $day of preparation for page $page started at $dateprepare</title>
<link>$ScriptUrl/$page</link>
<description>This is to improve preparation of things you will have to produce. Also don't forget to improve those instructions to be more and more efficient!</description>
*/
# NOTE $ChannelTitle."Day" could be use but that's not really a proper name...
$feed_newitem = "<item>\n
$ItemTitle
$ItemLink
$ItemDescription
<title>$ItemTitle</title>
<link>$ItemLink</link>
<description>$ItemDescription</description>
<guid>$item_GUID</guid>
<pubDate>$feed_newitemdate</pubDate>\n</item>";
# appending the item
$feed_newcontent .= $feed_newitem;
}
break; #we can't have 2 days at the same time, move on to the next page
}
# print "<br/>";
} # check if the next recall day is today
} # check if the next page is tagged
}
# feed should be properly updated
$feed_newdate = date(DATE_RSS, time());
$ChannelTitle = "BehaviorRecall";
#$ChannelTitle="Memorization";
#$ChannelTitle="Preparation";
$feed_header = "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">
<channel>
<title>$ChannelTitle feed for $WikiTitle .</title>
<link>$ScriptUrl</link>
<description>Receive links as reminded to periodic behaviors you want to transform to habits.</description>
<description>$ChannelTitle</description>
<lastBuildDate>$feed_newdate</lastBuildDate>";
$feed_footer = "\n</channel>\n</rss>";
print $feed_header;
print $feed_oldcontent;
print $feed_newcontent;
print $feed_footer;
if (strlen($feed_newcontent)==0)
return;
$write_result = file_put_contents($feedfile,$feed_oldcontent.$feed_newcontent);
if (!$write_result){
if (strlen($feed_oldcontent.$feed_newcontent)>0){

Loading…
Cancel
Save