Ejemplo n.º 1
0
Archivo: play.php Proyecto: sni/webmp3
function action_default()
{
    global $config;
    $data = getData();
    if (isset($data["ppid"])) {
        $data = killChild($data);
    }
    if (isset($data["curTrack"]) and isset($data["playlist"][$data["curTrack"]])) {
        $track = $data["playlist"][$data["curTrack"]];
    } else {
        $tmp = $data["playlist"];
        $track = array_shift($tmp);
        $data["curTrack"] = $track["token"];
    }
    doPrint("playing: " . $track["filename"]);
    # clean up playlist
    if ($data['partymode'] == 1) {
        # clean everything up to 3 songs after the current one
        $x = 0;
        $num = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"]) {
                $num = $x;
                continue;
            }
            $x++;
        }
        $num = $num - 3;
        $num = max(0, $num);
        for ($x = 0; $x < $num; $x++) {
            array_shift($data["playlist"]);
        }
    } elseif ($data['partymode'] == 2) {
        # clean everything up to the first song of the cur album
        $newPlaylist = array();
        $found = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"] or $tr['album'] == $track['album']) {
                $found = 1;
            }
            if ($found == 1) {
                $newPlaylist[$token] = $tr;
            }
        }
        $data['playlist'] = $newPlaylist;
    }
    $data["start"] = time();
    $data["length"] = $track["lengths"];
    $data["title"] = $track["title"];
    $data["artist"] = $track["artist"];
    $data["album"] = $track["album"];
    $data["track"] = $track["tracknum"];
    $data["token"] = $track["token"];
    $data["filename"] = $track["filename"];
    if (!isset($track["bitrate"])) {
        $track["bitrate"] = "";
    }
    $data["bitrate"] = $track["bitrate"];
    $data["play"] = 1;
    $data["gmtimestart"] = gmdate("U");
    $data["playingPic"] = getPictureForPath(dirname($track["filename"]));
    if (isset($config["notifyCommand"])) {
        $tmp = $config["notifyCommand"];
        $tmpTrack = $track["tracknum"];
        $tmpArtist = $track["artist"];
        $tmpTitle = $track["title"];
        $tmpArtist = str_replace('\'', '', $tmpArtist);
        $tmpArtist = str_replace('\\"', '', $tmpArtist);
        $tmpArtist = str_replace(';', '', $tmpArtist);
        $tmpTitle = str_replace('\'', '', $tmpTitle);
        $tmpTitle = str_replace('\\"', '', $tmpTitle);
        $tmpTitle = str_replace(';', '', $tmpTitle);
        $tmpTrack = str_replace('\'', '', $tmpTrack);
        $tmpTrack = str_replace('\\"', '', $tmpTrack);
        $tmpTrack = str_replace(';', '', $tmpTrack);
        $tmp = str_replace("%#", $tmpTrack, $tmp);
        $tmp = str_replace("%T", $tmpTitle, $tmp);
        $tmp = str_replace("%A", $tmpArtist, $tmp);
        doPrint("notify: " . $tmp);
        $output = "";
        $rc = 0;
        exec($tmp, $output, $rc);
        if ($rc != 0) {
            doPrint("notify failed: " . join("\n", $output));
        }
    }
    $data["ppid"] = getmypid();
    # most played
    addFileToHitlist($track["filename"]);
    if (strpos($track["filename"], "http://") === 0) {
        doPrint("playing stream");
        $options = $config["playStrOpt"];
        $playBin = $config["streamBin"];
        if (!isset($config["streamUrlPre"])) {
            $config["streamUrlPre"] = "";
        }
        $track["filename"] = $config["streamUrlPre"] . $track["filename"];
        $data["playingStream"] = 1;
    } else {
        doPrint("playing normal file");
        $tmp = explode(".", $track["filename"]);
        $ext = "." . array_pop($tmp);
        if (isset($config["ext"][$ext])) {
            $playBin = $config["ext"][$ext]["binary"];
            $options = $config["ext"][$ext]["option"];
        } else {
            doPrint("Extension {$ext} not supported");
        }
        $data["playingStream"] = 0;
    }
    $options[] = $track["filename"];
    $data["aktBin"] = $playBin;
    storeData($data);
    #$options = array_map("myescapeshellarg", $options);
    setlocale(LC_CTYPE, "en_US.UTF-8");
    $options = array_map("escapeshellarg", $options);
    $data = brokerPlugin("pre_playing_song", $data);
    doPrint("executing: " . $playBin . " " . join(" ", $options));
    system($playBin . " " . join(" ", $options) . ' >> ' . $config["logfile"] . ' 2>&1');
    doPrint("finished playing");
    $data = getData();
    $data = brokerPlugin("post_playing_song", $data);
    unset($data["ppid"]);
    unset($data["start"]);
    unset($data["length"]);
    unset($data["title"]);
    unset($data["track"]);
    unset($data["artist"]);
    unset($data["album"]);
    unset($data["aktBin"]);
    unset($data["playingPic"]);
    $lastToken = $track["token"];
    $track = "";
    storeData($data);
    if ($data["play"]) {
        $data["play"] = 0;
        $track = getNextTrack($data["playlist"], $lastToken);
        if ($track) {
            $data["curTrack"] = $track;
            storeData($data);
            action_default();
        }
    }
}
Ejemplo n.º 2
0
        $notificationMsg = "Name of submitter: " . $name;
        $headers2 = "From: comments@example.com" . "\n";
        $mailRecips = '*****@*****.**' . ', ' . '*****@*****.**';
        $sent2 = mail($mailRecips, 'Flickr upload: Rally', $notificationMsg, $headers2);
        if (!$sent2) {
            $eMore .= "Email notification was not successful.";
        }
        $getStoringInc = (require_once 'storing_data.php');
        if (!$getStoringInc) {
            $eMore .= "Including storing_data.php was not successful.\n";
        }
        $sql = '';
        if ($formname == 'rally') {
            $sql = "INSERT INTO rally (fname, lname, association, city, state, zip, email, photo_filename, photo_title) VALUES (\r\n\t\t\t'" . mysqlEscape($fname) . "',\r\n\t\t\t'" . mysqlEscape($lname) . "',\r\n\t\t\t'" . mysqlEscape($association) . "',\r\n\t\t\t'" . mysqlEscape($city) . "',\r\n\t\t\t'" . mysqlEscape($state) . "',\r\n\t\t\t'" . mysqlEscape($zip) . "',\r\n\t\t\t'" . mysqlEscape($email) . "',\r\n\t\t\t'" . mysqlEscape($photo_filename) . "',\r\n\t\t\t'" . mysqlEscape($title) . "'\r\n\t\t\t)";
        }
        $addRow = storeData($sql, $eMore);
        $eMore .= $addRow;
        if ($eMore != "") {
            $e .= "The photo was (probably) sent to Flickr but was not successfully added to the database.\n" . "Here is some additional information on the subject:\n" . $eMore;
        }
        ?>
		<script type="text/javascript">
		var url = "confirmationPage.html";
		window.location = url;
		</script>
<?php 
    }
}
?>

<!DOCTYPE html >
            $lang = WIKTIONARY_LANG;
        } elseif (strpos($buffer, "{{") !== false && $title != "") {
            $state = "";
        } else {
            if ($state == "definiciones") {
                $buffer = clean($buffer);
                array_push($meanings, $buffer);
            } elseif ($state == "sinonimo") {
                $buffer = clean($buffer);
                if (preg_match("/[a-zA-Z]+/", $buffer)) {
                    array_push($synonyms, $buffer);
                } else {
                    #print "empty: $buffer<br>\n";
                }
            }
        }
        $i++;
        if ($i % 10000 == 0) {
            print $i . "<br>";
        }
        #if ($i > 10000) {
        #	break;
        #}
    }
    fclose($handle);
}
if (sizeof($meanings) > 0) {
    storeData($title, $meanings, $synonyms);
}
print "<br />Done (inserted {$insert_count} headwords).";
page_close();
Ejemplo n.º 4
0
function gpspathFunAll($clientId, $date_offline, $deviceIMEI)
{
    $date_offline = $_GET[date_offline];
    $path1 = $GLOBALS[dataPath] . "src/data/" . date('d-m-Y', strtotime($date_offline)) . "/" . $deviceIMEI . ".txt";
    if (chk_folder($path1)) {
        $file1 = @fopen($path1, "r");
        if ($file1) {
            $i = 0;
            while (!feof($file1)) {
                $data1 = fgets($file1);
            }
            $data1 = getSortedData($data1);
            $km = liveKmsAllPerDay($data1);
            //exit;
            //$data = $data1;
            $devName = getDeviceName($_GET["deviceIMEI"]);
            storeData($data1, $km, $devName, '', '');
            fclose($file1);
        } else {
            $data = 0;
            storeData($data);
        }
    }
}
Ejemplo n.º 5
0
<?php

include '../include/config.php';
include '../include/db.php';
dbconnect();
include '../include/checkprelogin.php';
if (isset($_POST["message"]) && isset($_POST["regId"])) {
    $message = $_POST["message"];
    $gcm_regid = $_POST["regId"];
    // GCM Registration ID
    $data = 0;
    if (isset($_POST["data"])) {
        $data = 1;
    }
    $mid = storeMessage($message, $gcm_regid, $data);
    if (isset($_POST["data"])) {
        storeData($mid, $_POST["data"]);
    }
} else {
    // message details missing
}
dbclose();
Ejemplo n.º 6
0
 public function action_store()
 {
     $library_id = $this->auth();
     $event_tables = array('answers', 'borrows', 'open_scores', 'permissions', 'supports', 'belongs', 'transactions');
     $entity_tables = array('roots', 'branches', 'users', 'authors', 'publications', 'objects', 'matches', 'files');
     function parseRow($data)
     {
         $content = strpos($data, '|');
         $values = explode(',', substr($data, 0, $content - 1));
         $values[] = substr($data, $content + 1);
         return $values;
     }
     function storeData($library_id, $command, $table, $values)
     {
         $event_tables = array('answers', 'borrows', 'open_scores', 'permissions', 'supports', 'belongs', 'transactions');
         $entity_tables = array('roots', 'branches', 'users', 'authors', 'publications', 'objects', 'matches', 'files');
         if (count($values) > 0 && (in_array($table, $event_tables) || in_array($table, $entity_tables))) {
             $query = '';
             $values = join(',', $values);
             if ($command == 'insert') {
                 $query = "insert ignore into {$table} values {$values}";
             } else {
                 if ($command == 'update') {
                     $query = "replace into {$table} values {$values}";
                 } else {
                     if ($command == 'delete') {
                         $query = "delete from {$table} where id in ({$values})" . (in_array($table, $event_tables) ? " and library_id = {$library_id}" : '');
                     } else {
                         returnData('Invalid Db Command');
                     }
                 }
             }
             DB::query($query);
         }
     }
     // extract records
     $logs = explode('|-|', Input::get('xlogs'));
     // data validation
     if (count($logs) != Input::get('count')) {
         returnError(Input::get('count') . ' rows was sent but ' . count($logs) . ' was received');
     }
     // write logs to file
     $logFile = fopen(path('storage') . 'files/' . $library_id . '.log', 'a');
     // insert data into db in groups
     $command = '';
     $table = '';
     $values = array();
     foreach ($logs as $row) {
         // store row before parsing it
         fwrite($logFile, $row . "\n");
         // set new value
         $row = parseRow($row);
         if ($row[0] == 'library') {
             $data = explode(',', str_replace('null', '""', $row[5]));
             DB::query("update libraries set title = {$data[0]}, description = {$data[1]}, started_at = {$data[2]}, image = {$data[3]}, version = {$data[4]} where id = {$library_id}");
             continue;
         }
         if ($row[1] == 'delete') {
             $value = $row[2];
         } else {
             if (in_array($row[0], $event_tables)) {
                 $value = "({$library_id},{$row[2]},{$row[5]})";
             } else {
                 $value = "({$row[2]},{$row[5]})";
             }
         }
         // store values
         if ($table == $row[0] && $command == $row[1] && count($values) < 50) {
             $values[] = $value;
         } else {
             storeData($library_id, $command, $table, $values);
             $command = $row[1];
             $table = $row[0];
             $values = array($value);
         }
     }
     storeData($library_id, $command, $table, $values);
     // copy files into directory
     if (count($_FILES) > 0) {
         foreach ($_FILES as $file) {
             move_uploaded_file($file['tmp_name'], path('storage') . 'files/' . $file['name']);
         }
     }
     // update reghaabat synced_at
     $synced_at = Input::get('synced_at');
     DB::query('update libraries set synced_at = ? where id = ?', array($synced_at, $library_id));
     return returnData(array('synced_at' => $synced_at, 'count' => count($logs)));
 }
Ejemplo n.º 7
0
function action_setToggle()
{
    global $config;
    if (!isset($_REQUEST['param'])) {
        print "missing parameter: param!";
        return 1;
    }
    if (!isset($_REQUEST['button'])) {
        print "missing parameter: button!";
        return 1;
    }
    doPrint("got json toggle request ('" . $_REQUEST['button'] . "', '" . $_REQUEST['param'] . "')");
    # doPrint($_REQUEST);
    $param = 1;
    if ($_REQUEST['param'] == "false") {
        $param = 0;
    }
    $data = getData();
    # Repeat
    if ($_REQUEST['button'] == "Repeat") {
        $data["repeat"] = $param;
        print "Set Repeat to: " . $param;
        storeData($data);
    }
    # Play
    if ($_REQUEST['button'] == "Play") {
        $data["play"] = 1;
        $data["pause"] = 0;
        if (isset($_REQUEST["token"])) {
            $data = brokerPlugin("user_pressed_next", $data);
            $data["curTrack"] = $_REQUEST["token"];
            $data = killChild($data);
        }
        system($config["cliPHPbinary"] . ' play.php >> ' . $config["logfile"] . ' 2>&1 &');
        # wait until play.php started up
        for ($x = 0; $x <= 30; $x++) {
            usleep(50000);
            $data = getData();
            #doPrint("check: ".$x);
            if (isset($data['aktBin'])) {
                $x = 100;
            }
        }
        action_getPlaylist();
    }
    # Stop
    if ($_REQUEST['button'] == "Stop") {
        doPrint("pressed stop");
        $data = brokerPlugin("user_pressed_stop", $data);
        killChild();
        action_getPlaylist();
    }
    # Pause
    if ($_REQUEST['button'] == "Pause") {
        doPrint("pressed pause");
        $signal = 17;
        $data["pause"] = 1;
        if ($param == "false") {
            $data["pause"] = 0;
            $signal = 19;
        }
        # get child pids
        if (isset($data["ppid"])) {
            $pids = getChildPids($data["ppid"]);
            foreach ($pids as $pid) {
                posix_kill($pid, $signal);
            }
            if ($data["pause"]) {
                $data["pauseStart"] = time();
            } else {
                $data["start"] = $data["start"] + (time() - $data["pauseStart"]);
                unset($data["pauseStart"]);
            }
        }
        storeData($data);
    }
    # Mute
    if ($_REQUEST['button'] == "Mute") {
        $data["mute"] = $param;
        $data["quiet"] = 0;
        doPrint("pressed mute");
        $data["origVolume"] = getVolume();
        $_REQUEST["vol"] = 0;
        action_setVolume();
        print "mute set to true";
        storeData($data);
    }
    if ($_REQUEST['button'] == "Unmute") {
        $data["quiet"] = 0;
        $data["mute"] = $param;
        doPrint("pressed unmute");
        $_REQUEST["vol"] = $data['origVolume'];
        unset($data["origVolume"]);
        action_setVolume();
        print "mute set to false";
        storeData($data);
    }
    # Quiet
    if ($_REQUEST['button'] == "Quiet") {
        $data["mute"] = 0;
        $data["quiet"] = $param;
        doPrint("pressed quiet");
        if ($param) {
            $data["origVolume"] = getVolume();
            $_REQUEST["vol"] = $config["quietVol"];
            action_setVolume();
        } else {
            $_REQUEST["vol"] = $data["origVolume"];
            unset($data["origVolume"]);
            action_setVolume();
        }
        print "quiet set to " . $param;
        storeData($data);
    }
    if ($_REQUEST['button'] == "partymode") {
        $data["partymode"] = $_REQUEST['param'];
        print "partymode set to " . $_REQUEST['param'];
        storeData($data);
    }
}
Ejemplo n.º 8
0
function killChild($data = "")
{
    if (empty($data)) {
        $data = getData();
    }
    if (isset($data["ppid"])) {
        killProcessAndChilds($data["ppid"]);
        #    $oridPid = $data["ppid"];
        #    $pids = getChildPids($data["ppid"]);
        #    posix_kill($data["ppid"], SIGINT) || doPrint("failed to send signal to ".$data["ppid"]);
        #    foreach($pids as $pid) {
        #         posix_kill($pid, SIGINT) || doPrint("failed to send signal to ".$pid);
        #    }
        #    posix_kill($data["ppid"], SIGSTOP);
        #    foreach($pids as $pid) {
        #         posix_kill($pid, SIGSTOP) || doPrint("failed to send signal to ".$pid);
        #    }
        #    posix_kill($data["ppid"], SIGKILL) || doPrint("failed to send signal to ".$data["ppid"]);
        #    foreach($pids as $pid) {
        #         doPrint("killed -9: ".getPidData($pid));
        #         posix_kill($pid, SIGKILL) || doPrint("failed to send signal to ".$pid);
        #    }
    }
    system("killall mplayer");
    system("sudo /usr/bin/killall mplayer");
    #$stopFailed = 0;
    #if(isset($origPid) and is_numeric($origPid)) {
    #    $out = getPidData($origPid);
    #    if(!empty($out)) {
    #        $stopFailed = 1;
    #        doPrint(getPidData($out));
    #    }
    #    $pids = getChildPids($origPid);
    #    foreach($pids as $pid) {
    #        $out = getPidData($origPid);
    #        if(!empty($out)) {
    #            $stopFailed = 1;
    #            doPrint(getPidData($out));
    #        }
    #    }
    #}
    #if($stopFailed == 1) {
    #    doPrint("stop failed!");
    #}
    unset($data["ppid"]);
    unset($data["start"]);
    unset($data["length"]);
    unset($data["title"]);
    unset($data["track"]);
    unset($data["artist"]);
    unset($data["album"]);
    unset($data["aktBin"]);
    unset($data["playingPic"]);
    $data["play"] = 0;
    $data["pause"] = 0;
    storeData($data);
    if (file_exists("./var/var/cache.jpg")) {
        unlink("./var/cache.jpg");
    }
    return $data;
}
Ejemplo n.º 9
0
    // while debugging scripts which repeat some actions multiple times
    // reset process monitor timers in each loop
    pmr('some api call to import ' . $fileInfo['name']);
    // 1. step some api call
    runApiCallToGetXMLFile($fileInfo, $memoryLeakData);
    // pms is shortcut for ProcessMonitor::addSummary()
    // when processing can be split in several steps as in this case
    // it is very useful to track time and memory usage for each step separately
    // track api call time + download response time
    pms("get file {$fileInfo['name']} xml: " . ProcessMonitor::formatSize($fileInfo['size'] * 1000, ProcessMonitor::SIZE_AUTO) . " <a href='/examples/processMonitor.php?file={$fileInfo['name']}'>Run again &gt;&gt; </a>" . " <br/> see imported xml: <a href='/some_url/{$fileInfo['name']}' target='_blank'>" . $fileInfo['name'] . "</a>", null, 'time_api_call');
    // 2. step - parsing xml response
    parseXMLFile($fileInfo, $memoryLeakData);
    // track time to validate and parse xml
    pms('parsed ' . $fileInfo['name'], $fileInfo, 'time_parse');
    // 3. step - preparing and storing data to db, etc
    storeData($fileInfo, $memoryLeakData);
    // track time to process and store the data
    pms('processed ' . $fileInfo['name'], $fileInfo, 'time_processed');
    // intentionally condition for always true in this example
    if ($error = true) {
        // pme is shortcut to output error messages
        // you may include whatever data useful for debugging
        // for more variables to dump use array
        pme("Error description", ['some useful data']);
    }
    $count++;
}
pmr("XML files processed: {$count}");
pmr('Total run time: ' . ProcessMonitor::formatTime(ProcessMonitor::getTotalTime()));
// this code should be called on application shutdown event in nette:
// $this->application->onShutdown[] = addJsAfterTheScriptIsDone();
Ejemplo n.º 10
0
if (!$a_id) {
    exit;
}
$json = file_get_contents("https://api.vk.com/method/photos.get?owner_id=" . $id . "&album_id=" . $a_id . "&count=1000&offset=0&photo_sizes=1&extended=1");
$data = json_decode($json);
$response = $data->response;
// var_dump($response[0]);
// echo "This is pid : ".$response[0]->pid."<br></br>" ;
// echo "This is aid : ".$response[0]->aid."<br></br>" ;
// echo "This is owner_id : ".$response[0]->owner_id."<br></br>" ;
// // echo "This is sizes : ".$response[0]->sizes."<br></br>" ;
// // echo "This is text : ".$response[0]->text."<br></br>" ;
// echo "This is likes : ".$response[0]->likes->count."<br></br>" ;
// // var_dump($sizes);
// storeImages($response[0]->sizes, $response[0]->pid);
storeData($response);
function storeData($response)
{
    for ($i = 0; $i < count($response); $i++) {
        // echo "This is pid : ".$response[$i]->pid."<br></br>" ;
        // echo "This is aid : ".$response[$i]->aid."<br></br>" ;
        // echo "This is owner_id : ".$response[$i]->owner_id."<br></br>" ;
        // storeImages($response[$i]->sizes, $response[$i]->pid);
        // echo "This is likes : ".$response[$i]->likes->count."<br></br>" ;
        // echo "************** <br></br>" ;
        $sql = "INSERT INTO PHOTOS (PID, AID, OWNER_ID, LIKES) \n    VALUES ('" . $response[$i]->pid . "','" . $response[$i]->aid . "','" . $response[$i]->owner_id . "','" . $response[$i]->likes->count . "')";
        $res = mysql_query($sql);
        $msg = $res ? successMessage("Uploaded and saved to Photos.") : errorMessage("Problem in saving to photos");
        echo $response[$i]->pid . " : " . $msg . " <br>";
        if ($res) {
            storeImages($response[$i]->sizes, $response[$i]->pid);
Ejemplo n.º 11
0
 function lastFMHandshake($data)
 {
     global $config;
     if (isset($data["lastfm_sessionid"])) {
         return $data;
     }
     if (isset($data["lastfm_last_error"])) {
         if (time() < $data["lastfm_last_error"] + $data["lastfm_error_count"] * 120) {
             doPrint("lastfm: last error was: " . formatDateTime($data["lastfm_last_error"]) . ", no trying again too soon.");
             return $data;
         }
     }
     if (!isset($config["lastfm_user"]) or empty($config["lastfm_user"]) or !isset($config["lastfm_pass"]) or empty($config["lastfm_pass"]) or !isset($config["lastfm_url"]) or empty($config["lastfm_url"])) {
         return $data;
     }
     $now = time();
     $auth = md5(md5($config["lastfm_pass"]) . $now);
     $url = $config["lastfm_url"] . "?hs=true&p=1.2&c=tst&v=1.0&u=" . urlencode($config["lastfm_user"]) . "&t=" . $now . "&a=" . $auth;
     $cont = explode("\n", $this->urlSend($url, 0, 0, ""));
     if (isset($cont[0]) and $cont[0] == "OK") {
         doPrint("lastfm: handshake ok");
         unset($data["lastfm_last_error"]);
         unset($data["lastfm_error_count"]);
         #doPrint($cont);
         $data["lastfm_sessionid"] = $cont[1];
         $data["lastfm_nowplaying"] = $cont[2];
         $data["lastfm_submission"] = $cont[3];
         storeData($data);
     } else {
         doPrint("lastfm: handshake failed: " . join("\n", $cont), "ERROR");
         $data["lastfm_last_error"] = time();
         if (!isset($data["lastfm_error_count"])) {
             $data["lastfm_error_count"] = 0;
         }
         $data["lastfm_error_count"]++;
         unset($data["lastfm_sessionid"]);
         unset($data["lastfm_nowplaying"]);
         unset($data["lastfm_submission"]);
         storeData($data);
     }
     return $data;
 }
Ejemplo n.º 12
0
function update($games, $dbc, $days)
{
    // store all the data into MySQL for the past # of days
    storeData($games, $dbc, 'DAU', $days);
    storeData($games, $dbc, 'MAU', $days);
    storeData($games, $dbc, 'installs', $days);
    storeData($games, $dbc, 'retention_1', $days);
    storeData($games, $dbc, 'retention_3', $days);
    storeData($games, $dbc, 'retention_7', $days);
    storeData($games, $dbc, 'retention_14', $days);
    storeData($games, $dbc, 'retention_28', $days);
    storeData($games, $dbc, 'churn_28', $days);
    storeData($games, $dbc, 'session_length_mean', $days);
    storeData($games, $dbc, 'session_count_mean', $days);
    storeData($games, $dbc, 'stickiness', $days);
    storeData($games, $dbc, 'installs_ratio', $days);
    // initalize the query statement for the returning_users
    $query = "INSERT INTO returning_users (id,time,total) VALUES ";
    // simply calculate the number of returning users based on (DAU - installs)
    $key = array_keys($games);
    $size = sizeOf($key);
    for ($i = 0; $i < $size; $i++) {
        $id = $games[$i]->game_id;
        $name = $games[$i]->name;
        $dau = pullData('DAU', 'none', $days, $games[$i]);
        $installs = pullData('installs', 'none', $days, $games[$i]);
        $k = array_keys($dau);
        $s = sizeOf($k);
        for ($g = 0; $g < $s; $g++) {
            $timestamp = $dau[$g]['timestamp'];
            $datetime = new DateTime("@{$timestamp}");
            $time = $datetime->format('Y-m-d');
            $dauTotal;
            $insTotal;
            $total;
            if (isset($dau[$g]['total'])) {
                $dauTotal = $dau[$g]['total'];
            } else {
                $dauTotal = 0;
            }
            if (isset($installs[$g]['total'])) {
                $insTotal = $installs[$g]['total'];
            } else {
                $insTotal = 0;
            }
            $total = $dauTotal - $insTotal;
            $query .= "('" . $id . "','" . $time . "','" . $total . "'), ";
        }
    }
    $query .= "(0,0,0) ON DUPLICATE KEY UPDATE total = VALUES(total);";
    mysqli_query($dbc, $query);
    mysqli_query($dbc, "DELETE FROM returning_users WHERE id = 0;");
    // store the sums after the raw data are inserted
    storeSum($dbc, 15);
}
Ejemplo n.º 13
0
<?php

$cactiHome = '/Data/webapps/cacti';
include("$cactiHome/include/global.php"); 

if (false == isset($argv[1]) || false == isset($argv[2]))
{
	echo "参数错误,第一个是ip,第二个是文件名,Usage:php store_client_data.php 192.168.1.104 data.info \n";
	exit(1);	
}
$ip = $argv[1];
$fileName = $argv[2];

storeData($ip, $fileName);

function storeData($ip, $fileName)
{
	if (false == file_exists($fileName))
	{
		echo "$fileName,这个文件不存在\n";
		exit(1);
	}
	$services = getServices($ip);
	$pollerOutputs = makePollerOutputs($services, $fileName);
	insertPollerOutput($pollerOutputs);
	exit(0);
}

function getServices($ip)
{
	$sql = sprintf("select local_data_id, rrd_name, arg1 from poller_item where hostname = '%s'", $ip);
if ($paper_type == '0') {
    $result = $mysqli->prepare("(SELECT username, log_metadata.userID, log0.q_id, user_answer, q_type, score_method, display_method, settings, mark, totalpos, option_order, started FROM log0, log_metadata, questions, users WHERE log0.metadataID = log_metadata.id AND log0.q_id = questions.q_id AND paperID = ? AND grade LIKE ? AND users.id = log_metadata.userID AND (users.roles='Student' OR users.roles='graduate') AND started >= ? AND started <= ? {$student_modules_sql}) UNION ALL (SELECT username, log_metadata.userID, log1.q_id, user_answer, q_type, score_method, display_method, settings, mark, totalpos, option_order, started FROM log1, log_metadata, questions,  users WHERE log1.metadataID = log_metadata.id AND log1.q_id=questions.q_id AND paperID = ? AND grade LIKE ? AND users.id = log_metadata.userID AND (users.roles='Student' OR users.roles='graduate') AND started >= ? AND started <= ? " . str_replace('log0', 'log1', $student_modules_sql) . ")");
    $result->bind_param('isssisss', $paperID, $_GET['repcourse'], $startdate, $enddate, $paperID, $_GET['repcourse'], $startdate, $enddate);
} else {
    $result = $mysqli->prepare("SELECT username, log_metadata.userID, log{$paper_type}.q_id, user_answer, q_type, score_method, display_method, settings, mark, totalpos, option_order, started FROM log{$paper_type}, log_metadata, questions, users WHERE log{$paper_type}.metadataID = log_metadata.id AND log{$paper_type}.q_id = questions.q_id AND paperID = ? AND grade LIKE ? AND users.id = log_metadata.userID AND (users.roles='Student' OR users.roles='graduate') AND DATE_ADD(started, INTERVAL 2 MINUTE) >= ? AND started <= ? {$student_modules_sql}");
    $result->bind_param('isss', $paperID, $_GET['repcourse'], $startdate, $enddate);
}
$result->execute();
$result->bind_result($username, $tmp_userID, $question_ID, $tmp_answer, $q_type, $score_method, $display_method, $settings, $mark, $totalpos, $option_order, $started);
while ($result->fetch()) {
    storeData($freq_array, $question_ID, $tmp_answer, $q_type, $display_method, $settings, $mark, $totalpos, $stop_words, 'all');
    if (isset($bottom_cohort[$started][$username])) {
        storeData($bottom_log_array, $question_ID, $tmp_answer, $q_type, $display_method, $settings, $mark, $totalpos, $stop_words, 'bottom');
    }
    if (isset($top_cohort[$started][$username])) {
        storeData($top_log_array, $question_ID, $tmp_answer, $q_type, $display_method, $settings, $mark, $totalpos, $stop_words, 'top');
    }
}
$result->close();
if ($user_total == 0) {
    // No one has taken the paper yet.
    echo '<div class="head_title">';
    echo "<div><img src=\"../artwork/toprightmenu.gif\" id=\"toprightmenu_icon\" /></div>\n";
    echo '<div class="breadcrumb"><a href="../index.php">' . $string['home'] . '</a>';
    if (isset($_GET['folder']) and $_GET['folder'] != '') {
        echo '<img src="../artwork/breadcrumb_arrow.png" class="breadcrumb_arrow" alt="-" /><a href="../folder/index.php?folder=' . $_GET['folder'] . '">' . folder_utils::get_folder_name($_GET['folder'], $mysqli) . '</a>';
    } elseif (isset($_GET['module']) and $_GET['module'] != '') {
        echo '<img src="../artwork/breadcrumb_arrow.png" class="breadcrumb_arrow" alt="-" /><a href="../module/index.php?module=' . $_GET['module'] . '">' . module_utils::get_moduleid_from_id($_GET['module'], $mysqli) . '</a>';
    }
    echo '<img src="../artwork/breadcrumb_arrow.png" class="breadcrumb_arrow" alt="-" /><a href="../paper/details.php?paperID=' . $_GET['paperID'] . '">' . $paper_title . '</a></div>';
    echo "<div class=\"page_title\">" . $string['reporttitle'] . "</div>\n";