public function ActionWriteSample()
 {
     $myfile = fopen('C:\\Users\\fabio\\Documents\\campioni categorie.csv', 'w') or die("Unable to open file!");
     fwrite($myfile, "");
     fwrite($myfile, "TESTO DEL POST; LINK; ETICHETTA\n");
     $post = FbPost::model()->findAllByAttributes(array(), "post_type !='' order by post_type");
     foreach ($post as $p) {
         $p->message = str_replace("\n", ' ', $p->message);
         $message = '';
         $message = $p->message;
         $link = '';
         $link = $p->link;
         $post_type = '';
         $post_type = $p->post_type;
         $txt = '';
         $txt = $txt . $message . ';' . $link . ';' . $post_type . "\n";
         fwrite($myfile, $txt);
     }
     fclose($myfile);
 }
Пример #2
0
 public function saveGroupFeed($data, $group_id, $param, $session, $limit)
 {
     if ($limit == -1) {
         $i = 0;
         $limit = 100000;
     } else {
         $i = $limit;
     }
     $data_extracted_vector = ' ';
     $data_extracted = $data->getProperty('data');
     while ($data_extracted->getProperty($i) != null && $i <= $limit) {
         $post_id = $data_extracted->getProperty($i)->getProperty('id');
         $caption = strpos($post_id, '_');
         $post_id = substr($post_id, $caption + 1);
         $post = $data_extracted->getProperty($i);
         $group_feed = FbPost::model()->findByPk($post_id);
         if ($group_feed == null) {
             $group_feed = new FbPost();
         }
         $group_feed->fbpid = $post_id;
         $group_feed->caption = $caption;
         $group_feed->author_id = $post->getProperty('from')->getProperty('id');
         $this->saveMemberInfo($post->getProperty('from'));
         $this->saveMember($post->getProperty('from'), $group_id, $param);
         $group_feed->message = $this->removeNames($post->getProperty('message'));
         $group_feed->message = $this->removeBadWords($group_feed->message);
         $group_feed->link = $post->getProperty('link');
         $group_feed->type = $post->getProperty('type');
         if ($post->getProperty('application') != null) {
             $group_feed->application = $post->getProperty('application')->getProperty('name');
         }
         $created_datetime = DateTime::createFromFormat(DateTime::ISO8601, $post->getProperty('created_time'));
         $created_datetime->add(new DateInterval('PT1H'));
         $o = new ReflectionObject($created_datetime);
         $p = $o->getProperty('date');
         $created_date = $p->getValue($created_datetime);
         $group_feed->created_time = $created_date;
         $updated_datetime = DateTime::createFromFormat(DateTime::ISO8601, $post->getProperty('updated_time'));
         $updated_datetime->add(new DateInterval('PT1H'));
         $o = new ReflectionObject($updated_datetime);
         $p = $o->getProperty('date');
         $update_date = $p->getValue($updated_datetime);
         $group_feed->updated_time = $update_date;
         if ($param == 'Exam') {
             $group_feed->exam_group_id = $group_id;
         } else {
             if ($param == 'Degree') {
                 $group_feed->degree_group_id = $group_id;
             }
         }
         $group_feed->validate();
         if ($group_feed->save()) {
             if ($post->getProperty('likes') != null) {
                 $this->saveLikes($post->getProperty('likes')->getProperty('data'), $post_id, 'Post');
             }
             if ($post->getProperty('object_id') != null && $post->getProperty('properties') == null) {
                 try {
                     $this->savePhotos($post->getProperty('object_id'), $post_id, 'Post', $session);
                 } catch (Exception $e) {
                     echo 'eccezione';
                 }
             }
             if ($post->getProperty('comments') != null) {
                 $this->saveComments($post->getProperty('comments'), $post_id, 'Post', $group_id, $param, $session);
             }
         }
         $i++;
     }
     // 		var_dump($data_extracted);
 }
Пример #3
0
</label> <br>				
				<label>Numero di foto nei post: <?php 
    echo $n_total_photo_post_exam;
    ?>
</label> <br>
				<label>Numero di foto nei commenti: <?php 
    echo $n_total_photo_exam_comments;
    ?>
</label>
				
				
<?php 
} else {
    $ref_id = $group->eid;
    $exam = ExamGroup::model()->findByPk($ref_id);
    $posts_exam = FbPost::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    $exam_member = MemberExamGroup::model()->findAllByAttributes(array('user_group_id' => $ref_id));
    // 			array_push($total_post_exam, $posts_exam);
    $docs_exam = FbDoc::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    $files_exam = FbFiles::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    foreach ($posts_exam as $pe) {
        $posts_exam_like = LikeFbPost::model()->findAllByAttributes(array('ref_entity_id' => $pe->fbpid));
        // 				array_push($total_posts_exam_like, $posts_exam_like);
        $n_total_post_exam_like += count($posts_exam_like);
        $photos_exam_post = PhotoFbPost::model()->findAllByAttributes(array('element_id' => $pe->fbpid));
        // 				array_push($total_photo_post_exam, $photos_exam_post);
        $n_total_photo_post_exam += count($photos_exam_post);
        $comments = FbPostComment::model()->findAllByAttributes(array('ref_entity_id' => $pe->fbpid));
        foreach ($comments as $c) {
            array_push($total_exam_post_comment, $c);
            $photo_exam_comments = PhotoFbCommentPost::model()->findAllByAttributes(array('element_id' => $c->cid));
Пример #4
0
 public function deletePost($pid)
 {
     $photo = PhotoFbPost::model()->findAllByAttributes(array('element_id' => $pid));
     foreach ($photo as $ph) {
         if (isset($ph)) {
             unlink($ph->medium);
         }
     }
     FbPost::model()->deleteByPk($pid);
 }
Пример #5
0
 public function featuresRappresentation()
 {
     set_time_limit(0);
     $criteria = new CDbCriteria();
     $criteria->condition = " post_type_l1 is null";
     $post = FbPost::model()->findAll($criteria);
     foreach ($post as $p) {
         $features_rappresentation = new FeaturesRappresentation();
         $features_rappresentation->pid = $p->fbpid;
         $message = strtolower($p->message);
         $features_rappresentation->format_info = substr_count($message, "\n");
         $features_rappresentation->n_char = strlen($message);
         $comments = FbPostComment::model()->findAllByAttributes(array('ref_entity_id' => $p->fbpid));
         $features_rappresentation->n_comment = count($comments);
         $comment_char_lenght = 0;
         $n_like_comment = 0;
         $top_author_comment = "false";
         foreach ($comments as $c) {
             $comment_char_lenght += strlen($c->message);
             $n_like_comment += $c->like_count;
             $author_comment = Users::model()->findByPk($c->author_id);
             if ($author_comment->user_type == "top") {
                 $top_author_comment = "true";
             }
         }
         $features_rappresentation->comment_author_top = $top_author_comment;
         $features_rappresentation->n_char_comment_length = $comment_char_lenght;
         if ($features_rappresentation->comment_author_top != 0 && $features_rappresentation->n_char_comment_length != 0) {
             $features_rappresentation->n_char_comment_length_ratio = round($comment_char_lenght / $features_rappresentation->n_comment, 4);
         } else {
             $features_rappresentation->n_char_comment_length_ratio = 0;
         }
         $features_rappresentation->n_like_comment = $n_like_comment;
         if ($p->link != null) {
             $features_rappresentation->link_presence = "true";
         } else {
             $features_rappresentation->link_presence = "false";
         }
         if ($p->application != null) {
             $features_rappresentation->device = "mobile";
         } else {
             $features_rappresentation->device = "web";
         }
         $photo = PhotoFbPost::model()->findAllByAttributes(array("element_id" => $p->fbpid));
         if ($photo != null) {
             $features_rappresentation->picture_presence = "true";
         } else {
             $features_rappresentation->picture_presence = "false";
         }
         $like = LikeFbPost::model()->findAllByAttributes(array("ref_entity_id" => $p->fbpid));
         $features_rappresentation->n_like = count($like);
         $top_user_like = "false";
         foreach ($like as $l) {
             $author_like = Users::model()->findByPk($l->user_id);
             if ($author_like->user_type == "top") {
                 $top_user_like = "true";
                 break;
             }
         }
         $features_rappresentation->like_top_user = $top_user_like;
         $top_author = "false";
         $author_post = Users::model()->findByPk($p->author_id);
         if ($author_post->user_type == "top") {
             $features_rappresentation->top_author_user = "******";
         } else {
             $features_rappresentation->top_author_user = "******";
         }
         $features_rappresentation->question_mark_presence = substr_count($message, "?");
         $features_rappresentation->math_symbols_presence = $this->checkMathSymbol($message);
         $features_rappresentation->time_element_presence = $this->checkTemporalElement($message);
         $features_rappresentation->save();
     }
     echo 'OK ;)';
 }
Пример #6
0
    public function calcolateMeanAnswerTime($id)
    {
        $sum_time_minutes = 0;
        $no_answer_question = 0;
        $array_sample = array();
        // 		$allPost = FbPost::model()->findAll();
        $allPost = FbPost::model()->findAllByAttributes(array('degree_group_id' => $id));
        if ($allPost == null) {
            $allPost = FbPost::model()->findAllByAttributes(array('exam_group_id' => $id));
        }
        foreach ($allPost as $post) {
            $minutes_single_post = 0;
            $post_time = new DateTime($post->created_time);
            $comment = FbPostComment::model()->findByAttributes(array('ref_entity_id' => $post->fbpid), array('order' => 'created_time ASC'));
            if (isset($comment)) {
                $comment_time = new DateTime($comment->created_time);
                $sum_time = $comment_time->diff($post_time);
                $minutes_single_post += $sum_time->d * 24 * 60 * 60;
                $minutes_single_post += $sum_time->h * 60 * 60;
                $minutes_single_post += $sum_time->i * 60;
                $minutes_single_post += $sum_time->s;
                $post->first_answer_time = $minutes_single_post;
                array_push($array_sample, $minutes_single_post);
                $sum_time_minutes += $sum_time->d * 24 * 60 * 60;
                $sum_time_minutes += $sum_time->h * 60 * 60;
                $sum_time_minutes += $sum_time->i * 60;
                $sum_time_minutes += $sum_time->s;
            } else {
                $post->first_answer_time = 0;
                $no_answer_question += 1;
            }
            // 			$post->validate();
            // 			$post->save();
        }
        $consideredPost = count($allPost) - $no_answer_question;
        echo '<b>Post Considerati: </b>' . $consideredPost;
        ?>
<br><br><?php 
        echo '<b>Post senza risposta: </b>' . $no_answer_question;
        ?>
<br><br><?php 
        echo '<b>Il Tempo medio e: </b>' . ($mean_answer_time = $sum_time_minutes / $consideredPost . ' secondi ');
        ?>
<br><br><?php 
        $dev = 0;
        foreach ($array_sample as $s) {
            $dev += pow($s - $mean_answer_time, 2);
        }
        $dev_std = sqrt($dev / $consideredPost - 1);
        echo '<b>La deviazione standard e: </b>' . $dev_std . ' secondi ';
        ?>
<br><br><?php 
    }