Changeset 1017

Show
Ignore:
Timestamp:
08/23/06 00:14:13 (2 years ago)
Author:
jm3
Message:

initial FUQ calculations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedmelinks/admin/FUQ/index.php

    r1008 r1017  
    1010                include( "$modules/header.inc.php" );  
    1111                $bg = " bgcolor='#888888' "; 
     12 
     13 
    1214%> 
    1315<h1><%= $title %></h1> 
     
    1820                border: 1px solid gray; 
    1921        } 
    20         thead { 
     22        thead, tfoot { 
     23                color: red; 
    2124                font-weight: bold; 
    2225        } 
     
    3033</style> 
    3134 
    32 <a href="http://toolstomaketools.svnrepository.com/codepot/trac.cgi/ticket/42">the FUQ roadmap</a
     35Threshold: <%= get_fuq_threshold() %
    3336 
    3437<table> 
     
    3639                <tr> 
    3740                        <td> 
    38                                 USER 
     41                                &nbsp; 
     42                        </td> 
     43                        <td> 
     44                                ∂ t betw links (hrs); HIGHER = more humane 
     45                        </td> 
     46                        <td> 
     47                                recency (days) 
     48                        </td> 
     49                        <td> 
     50                                length of usage (days); HIGHER = more humane 
    3951                        </td> 
    4052                        <td> 
    4153                                FUQ 
    42                         </td> 
    43                         <td> 
    44                                 recalc'd FUQ 
    45                         </td> 
    46                         <td> 
    47                                 &delta; two 
    4854                        </td> 
    4955                </tr> 
     
    5157        <tbody> 
    5258<%  
    53         $gp = $guinea_pigs = array( "BrittanySCarter", "pheezy", "gus", "TheFaction", "Cashak", "ahhsum4", "ina", "jm3", "scordero", "testuser1", "knormile", "heathleah", "Kruther1934"); 
     59        $gp = $guinea_pigs =  
     60                array(  
     61                "pheezy", 
     62                "gus", 
     63                "Cashak", 
     64                "ahhsum4", 
     65                "ina", 
     66                "jm3", 
     67                "formalplay", 
     68                "DRaupp", 
     69                "BrittanySCarter",  
     70                "scordero", 
     71                "testuser1", 
     72                "knormile", 
     73                "heathleah", 
     74                "TheFaction", 
     75                "Kruther1934" 
     76                ); 
    5477        $flip = 0; 
    5578        foreach( $gp as $g ) { 
     79 
     80                $fuq = get_fuq( $g ); 
     81                if( $recalc ) 
     82                        $fuq = recalculate_fuq( $g ); 
     83 
     84                if( $fuq < get_fuq_threshold() ) 
     85                        $fuqqed = true; 
    5686%> 
    57         <tr <%= ($flip % 2) == 0 ? "class='tr1'" : "" %>> 
     87        <tr <%= $fuqqed ? "class='FUQQED'" : (($flip % 2) == 0 ? "class='tr1'" : "") %>> 
    5888                <td> 
    5989                        <a href="/u/<%= $g %>"><%= $g %></a> 
    6090                </td> 
    6191                <td> 
    62                         <%= get_fuq( $g ) %> 
     92                        <%= delta_time_between_links( $g, $raw = true ) %>, 
     93                        <%= delta_time_between_links( $g ) %> 
    6394                </td> 
    6495                <td> 
    65                         <%= recalculate_fuq( $g ) %> 
     96                        <%= recency( $g, $raw = true ) %> 
    6697                </td> 
    6798                <td> 
    68                         &delta; last two links: <%= get_fuqqed( $g, 0 ) %> 
     99                        <%= length_of_usage( $g, $raw = true ) %> 
     100                </td> 
     101                <td> 
     102                        <%= 1/recency( $g, $raw = true ) * length_of_usage( $g, $raw = true ) / 1000 %> 
     103                </td> 
     104                <td> 
     105                        <%= $fuq %> 
    69106                </td> 
    70107        </tr> 
     
    73110        } 
    74111%> 
     112<tfoot> 
     113        <tr> 
     114                <td> 
     115                        &nbsp; 
     116                </td> 
     117                <td> 
     118                        < 0.5 = MINUS 1<br /> 
     119                        > 10 = PLUS 1<br /> 
     120                </td> 
     121                <td> 
     122                </td> 
     123                <td> 
     124                        > 45 = PLUS 1 
     125                </td> 
     126        </tr> 
     127</tfoot> 
    75128        <tbody> 
    76129</table> 
     130 
     131<p /> 
     132 
     133<form> 
     134        <input type="hidden" name="recalc" value="1" /> 
     135        <input type="submit" value="recalculate FUQs for these users " /> 
     136</form> 
     137 
     138 
     139<p> 
     140        <a href="http://toolstomaketools.svnrepository.com/codepot/trac.cgi/ticket/42">the FUQ roadmap</a> 
     141</p> 
    77142 
    78143<% include( "$modules/footer.inc.php" ); %> 
  • feedmelinks/login.php

    r960 r1017  
    133133 
    134134Save this message under your pillow in case you forget your username 
    135 and password. Email " . get_maintainer_email() . "with any questions or comments. 
     135and password. Email " . get_maintainer_email() . " with any questions or comments. 
    136136 
    137137Happy Linking! 
    138138 
    139139- jm3  
     140john manoogian III 
    140141  Feed Me Links 
    141142"; 
  • feedmelinks/modules/utils.inc.php

    r1015 r1017  
    88                return run_count( getQuery( "link_exists_for_user", $url, $u )); 
    99        } 
     10 
     11        function diff_in_secs( $db_date_0, $db_date_1 ) { 
     12                $dt0 =  strtotime( $db_date_0 ); 
     13                $dt1 =  strtotime( $db_date_1 ); 
     14                return( $dt0 - $dt1 ); 
     15        } 
     16 
     17        function get_db_date_diff_in_days( $qs ) { 
     18                $con_fuq_slot = mysql_connect(); 
     19                mysql_selectdb( getDBName() ); 
     20                $q = mysql_query( $qs ); 
     21                if( ! $q ) 
     22                        return undefined; 
     23                 
     24                $d0 = mysql_result($q,0); 
     25                $d1 = mysql_result($q,1); 
     26                $diff = round( diff_in_secs( $d0, $d1 ) / 60 / 60 / 24, 4); 
     27                return $diff > 0 ? $diff : 0; 
     28        } 
     29 
     30        function get_simple_rs( $qs ) { 
     31                $con = mysql_connect(); 
     32                mysql_selectdb( getDBName() ); 
     33                $q = mysql_query( $qs ); 
     34                if( ! $q ) 
     35                        return undefined; 
     36                 
     37                return mysql_result($q,0); 
     38        } 
     39 
     40        function get_fuq_threshold() { return 2; } 
    1041 
    1142        function get_fuq( $u ) { 
     
    2354        } 
    2455 
     56        function delta_time_between_links( $u, $raw = false ) { 
     57                $value = get_db_date_diff_in_days( getQuery( "get_fuq_slot_delta_time_between_links", $u )) * 60; 
     58                if( $raw ) 
     59                        return $value; 
     60                else 
     61                        if( $value < 0.5 ) 
     62                                return -1; 
     63                        else if( $value > 10 ) 
     64                                return 1; 
     65                        else 
     66                                return 0; 
     67        } 
     68 
     69        function recency( $u, $raw = false ) { 
     70                $d0 =  get_simple_rs( getQuery( "get_fuq_slot_recency", $u )); 
     71 
     72                $now = getdate(); 
     73                $d1 = $now['year'] ."-". ($now['mon'] < 10 ? "0" : "" ) . $now['mon'] ."-". ($now['mday'] < 10 ? "0" : "" ) . $now['mday'] ." ". $now['hours'] .":". $now['minutes'] .":". $now['seconds']; 
     74                $value = round( diff_in_secs( $d1, $d0 ) / 60 / 60 / 24, 3 ); 
     75                return $value; 
     76        } 
     77 
     78        function length_of_usage( $u, $raw = false ) { 
     79                $r0 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id DESC LIMIT 1;" ); 
     80                $r1 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id ASC LIMIT 1;" ); 
     81                $value = round( diff_in_secs( $r0, $r1 ) / 60 / 60 / 24, 1 ); 
     82                return $value; 
     83        } 
     84 
     85        #loops through the fuq metrics, calculating each of them, and mashes them together to re-calculate a users FUQ 
    2586        function recalculate_fuq( $u ) { 
    26                 run_query( getQuery( "update_fuq", $u, $retval = get_fuq( $u )+0)); 
    27                 return $retval; 
     87 
     88                # calculate new fuq: 
     89                $new_fuq = get_fuq( $u ); 
     90 
     91                $slots = array(  
     92                        "delta_time_between_links" => 0,  
     93                        "length_of_usage" => 0  
     94                ); 
     95 
     96                foreach( $slots as $key => $value ) { $slots[$key] =  call_user_func( $key, $u ); } 
     97 
     98                # mash together slot values here: 
     99                # TBD 
     100 
     101                #foreach( $slots as $slot ) { echo "\$slot = $slot<br>"; } 
     102 
     103                return; 
     104 
     105                run_query( getQuery( "update_fuq", $u, $new_fuq )); # and then set it 
     106                return $new_fuq; 
    28107        } 
    29108 
     
    12481327        } else if( $argWhichQuery  == "get_fuq" ) { 
    12491328                return "SELECT FUQ from linksUsers WHERE userid = '" . urlencode( $args[1] ) . "';"; 
    1250  
     1329         
     1330        } else if( $argWhichQuery  == "get_fuq_slot_delta_time_between_links" ) { 
     1331                return "SELECT createDate FROM links WHERE submitter = '" . urlencode( $args[1] ) ."' ORDER BY id DESC LIMIT 2;"; 
     1332         
     1333        } else if( $argWhichQuery  == "get_fuq_slot_recency" ) { 
     1334                return "select createDate from links where submitter = '" . urlencode( $args[1] ) ."' ORDER BY id DESC LIMIT 1;"; 
     1335         
    12511336        } else if( $argWhichQuery  == "link_exists_for_user" ) { 
    12521337                return "SELECT COUNT(url) FROM links WHERE url = '" . urlencode( $args[1] ) . "' AND submitter = '" . urlencode( $args[2] ) . "';";